2 * Copyright (C) 2001-2008, The Perl Foundation.
6 * Defines the register api
7 * Data Structure and Algorithms:
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
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)
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. */
67 void Parrot_clear_i(PARROT_INTERP
)
68 __attribute__nonnull__(1);
71 void Parrot_clear_n(PARROT_INTERP
)
72 __attribute__nonnull__(1);
75 void Parrot_clear_p(PARROT_INTERP
)
76 __attribute__nonnull__(1);
79 void Parrot_clear_s(PARROT_INTERP
)
80 __attribute__nonnull__(1);
83 void Parrot_free_context(PARROT_INTERP
,
84 ARGMOD(struct Parrot_Context
*ctxp
),
86 __attribute__nonnull__(1)
87 __attribute__nonnull__(2)
91 void parrot_gc_context(PARROT_INTERP
)
92 __attribute__nonnull__(1);
95 void Parrot_pop_context(PARROT_INTERP
)
96 __attribute__nonnull__(1);
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
);
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 */
139 * c-file-style: "parrot"
141 * vim: expandtab shiftwidth=4: