tagged release 0.7.1
[parrot.git] / include / parrot / register.h
blobdba273d82e59a9ebec756e201d185915dbfe74f1
1 /* register.h
2 * Copyright (C) 2001-2008, The Perl Foundation.
3 * SVN Info
4 * $Id$
5 * Overview:
6 * Defines the register api
7 * Data Structure and Algorithms:
8 * History:
9 * Notes:
10 * References:
13 #ifndef PARROT_REGISTER_H_GUARD
14 #define PARROT_REGISTER_H_GUARD
16 #include "parrot/string.h"
17 #include "parrot/compiler.h"
18 #include "parrot/stacks.h"
21 * Macros to make accessing registers more convenient/readable.
24 #define CTX_REG_NUM(ctx, x) (ctx)->bp.regs_n[-1L-(x)]
25 #define CTX_REG_INT(ctx, x) (ctx)->bp.regs_i[x]
26 #define CTX_REG_PMC(ctx, x) (ctx)->bp_ps.regs_p[-1L-(x)]
27 #define CTX_REG_STR(ctx, x) (ctx)->bp_ps.regs_s[x]
29 #define REG_NUM(interp, x) CTX_REG_NUM(&(interp)->ctx, (x))
30 #define REG_INT(interp, x) CTX_REG_INT(&(interp)->ctx, (x))
31 #define REG_PMC(interp, x) CTX_REG_PMC(&(interp)->ctx, (x))
32 #define REG_STR(interp, x) CTX_REG_STR(&(interp)->ctx, (x))
35 * and a set of macros to access a register by offset, used
36 * in JIT emit prederef code
37 * The offsets are relative to interp->ctx.bp.
39 * Reg order in imcc/reg_alloc.c is "INSP" TODO make defines
42 #define REGNO_INT 0
43 #define REGNO_NUM 1
44 #define REGNO_STR 2
45 #define REGNO_PMC 3
47 #define __CTX interp->ctx.state
48 #define _SIZEOF_INTS (sizeof (INTVAL) * __CTX->n_regs_used[REGNO_INT])
49 #define _SIZEOF_NUMS (sizeof (FLOATVAL) * __CTX->n_regs_used[REGNO_NUM])
50 #define _SIZEOF_PMCS (sizeof (PMC*) * __CTX->n_regs_used[REGNO_PMC])
51 #define _SIZEOF_STRS (sizeof (STRING*) * __CTX->n_regs_used[REGNO_STR])
53 #define REG_OFFS_NUM(x) (sizeof (FLOATVAL) * (-1L - (x)))
54 #define REG_OFFS_INT(x) (sizeof (INTVAL) * (x))
55 #define REG_OFFS_PMC(x) (_SIZEOF_INTS + sizeof (PMC*) * \
56 (__CTX->n_regs_used[REGNO_PMC] - 1L - (x)))
57 #define REG_OFFS_STR(x) (sizeof (STRING*) * (x) + _SIZEOF_INTS + _SIZEOF_PMCS)
60 struct Stack_Chunk;
61 struct Parrot_Context; /* parrot/interpreter.h */
63 /* HEADERIZER BEGIN: src/gc/register.c */
64 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
66 PARROT_API
67 void Parrot_clear_i(PARROT_INTERP)
68 __attribute__nonnull__(1);
70 PARROT_API
71 void Parrot_clear_n(PARROT_INTERP)
72 __attribute__nonnull__(1);
74 PARROT_API
75 void Parrot_clear_p(PARROT_INTERP)
76 __attribute__nonnull__(1);
78 PARROT_API
79 void Parrot_clear_s(PARROT_INTERP)
80 __attribute__nonnull__(1);
82 PARROT_API
83 void Parrot_free_context(PARROT_INTERP,
84 ARGMOD(struct Parrot_Context *ctxp),
85 int re_use)
86 __attribute__nonnull__(1)
87 __attribute__nonnull__(2)
88 FUNC_MODIFIES(*ctxp);
90 PARROT_API
91 void parrot_gc_context(PARROT_INTERP)
92 __attribute__nonnull__(1);
94 PARROT_API
95 void Parrot_pop_context(PARROT_INTERP)
96 __attribute__nonnull__(1);
98 PARROT_API
99 PARROT_WARN_UNUSED_RESULT
100 PARROT_CANNOT_RETURN_NULL
101 struct Parrot_Context * Parrot_push_context(PARROT_INTERP,
102 ARGMOD(INTVAL *n_regs_used))
103 __attribute__nonnull__(1)
104 __attribute__nonnull__(2)
105 FUNC_MODIFIES(*n_regs_used);
107 PARROT_API
108 void Parrot_set_context_threshold(SHIM_INTERP,
109 SHIM(struct Parrot_Context *ctxp));
111 void create_initial_context(PARROT_INTERP)
112 __attribute__nonnull__(1);
114 void destroy_context(PARROT_INTERP)
115 __attribute__nonnull__(1);
117 PARROT_CANNOT_RETURN_NULL
118 PARROT_WARN_UNUSED_RESULT
119 struct Parrot_Context * Parrot_alloc_context(PARROT_INTERP,
120 ARGMOD(INTVAL *number_regs_used))
121 __attribute__nonnull__(1)
122 __attribute__nonnull__(2)
123 FUNC_MODIFIES(*number_regs_used);
125 PARROT_WARN_UNUSED_RESULT
126 PARROT_CANNOT_RETURN_NULL
127 struct Parrot_Context * Parrot_dup_context(PARROT_INTERP,
128 ARGIN(const struct Parrot_Context *old))
129 __attribute__nonnull__(1)
130 __attribute__nonnull__(2);
132 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
133 /* HEADERIZER END: src/gc/register.c */
135 #endif /* PARROT_REGISTER_H_GUARD */
138 * Local variables:
139 * c-file-style: "parrot"
140 * End:
141 * vim: expandtab shiftwidth=4: