diff options
Diffstat (limited to 'src/lj_ir.c')
-rw-r--r-- | src/lj_ir.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/lj_ir.c b/src/lj_ir.c index 1efb12f0..cf0b6b55 100644 --- a/src/lj_ir.c +++ b/src/lj_ir.c | |||
@@ -6,16 +6,22 @@ | |||
6 | #define lj_ir_c | 6 | #define lj_ir_c |
7 | #define LUA_CORE | 7 | #define LUA_CORE |
8 | 8 | ||
9 | /* For pointers to libc/libm functions. */ | ||
10 | #include <stdio.h> | ||
11 | #include <math.h> | ||
12 | |||
9 | #include "lj_obj.h" | 13 | #include "lj_obj.h" |
10 | 14 | ||
11 | #if LJ_HASJIT | 15 | #if LJ_HASJIT |
12 | 16 | ||
13 | #include "lj_gc.h" | 17 | #include "lj_gc.h" |
14 | #include "lj_str.h" | 18 | #include "lj_str.h" |
19 | #include "lj_tab.h" | ||
15 | #include "lj_ir.h" | 20 | #include "lj_ir.h" |
16 | #include "lj_jit.h" | 21 | #include "lj_jit.h" |
17 | #include "lj_iropt.h" | 22 | #include "lj_iropt.h" |
18 | #include "lj_trace.h" | 23 | #include "lj_trace.h" |
24 | #include "lj_lib.h" | ||
19 | 25 | ||
20 | /* Some local macros to save typing. Undef'd at the end. */ | 26 | /* Some local macros to save typing. Undef'd at the end. */ |
21 | #define IR(ref) (&J->cur.ir[(ref)]) | 27 | #define IR(ref) (&J->cur.ir[(ref)]) |
@@ -32,6 +38,17 @@ IRDEF(IRMODE) | |||
32 | 0 | 38 | 0 |
33 | }; | 39 | }; |
34 | 40 | ||
41 | /* C call info for CALL* instructions. */ | ||
42 | LJ_DATADEF const CCallInfo lj_ir_callinfo[] = { | ||
43 | #define IRCALLCI(name, nargs, kind, type, flags) \ | ||
44 | { (ASMFunction)name, \ | ||
45 | (nargs)|(CCI_CALL_##kind)|(IRT_##type<<CCI_OTSHIFT)|(flags) }, | ||
46 | IRCALLDEF(IRCALLCI) | ||
47 | #undef IRCALLCI | ||
48 | { NULL, 0 } | ||
49 | }; | ||
50 | |||
51 | |||
35 | /* -- IR emitter ---------------------------------------------------------- */ | 52 | /* -- IR emitter ---------------------------------------------------------- */ |
36 | 53 | ||
37 | /* Grow IR buffer at the top. */ | 54 | /* Grow IR buffer at the top. */ |
@@ -92,6 +109,25 @@ TRef LJ_FASTCALL lj_ir_emit(jit_State *J) | |||
92 | return TREF(ref, irt_t((ir->t = fins->t))); | 109 | return TREF(ref, irt_t((ir->t = fins->t))); |
93 | } | 110 | } |
94 | 111 | ||
112 | /* Emit call to a C function. */ | ||
113 | TRef lj_ir_call(jit_State *J, IRCallID id, ...) | ||
114 | { | ||
115 | const CCallInfo *ci = &lj_ir_callinfo[id]; | ||
116 | uint32_t n = CCI_NARGS(ci); | ||
117 | TRef tr = TREF_NIL; | ||
118 | va_list argp; | ||
119 | va_start(argp, id); | ||
120 | if ((ci->flags & CCI_L)) n--; | ||
121 | if (n > 0) | ||
122 | tr = va_arg(argp, IRRef); | ||
123 | while (n-- > 1) | ||
124 | tr = emitir(IRT(IR_CARG, IRT_NIL), tr, va_arg(argp, IRRef)); | ||
125 | va_end(argp); | ||
126 | if (CCI_OP(ci) == IR_CALLS) | ||
127 | J->needsnap = 1; /* Need snapshot after call with side effect. */ | ||
128 | return emitir(CCI_OPTYPE(ci), tr, id); | ||
129 | } | ||
130 | |||
95 | /* -- Interning of constants ---------------------------------------------- */ | 131 | /* -- Interning of constants ---------------------------------------------- */ |
96 | 132 | ||
97 | /* | 133 | /* |