summaryrefslogtreecommitdiff
path: root/src/buildvm_lib.c
diff options
context:
space:
mode:
authorMike Pall <mike>2010-02-13 04:51:56 +0100
committerMike Pall <mike>2010-02-13 04:51:56 +0100
commitc93138b59e8f28b3d412cd7ec0c6631fd27e3e1b (patch)
tree8c0ffe2086ab0b032ed8e9f92ae6fb9d4d040d66 /src/buildvm_lib.c
parent4f8d7be8ea8a103f4d9046188d6005740b74f3d4 (diff)
downloadluajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.tar.gz
luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.tar.bz2
luajit-c93138b59e8f28b3d412cd7ec0c6631fd27e3e1b.zip
Major redesign of function call handling.
Drop call gates. Use function headers, dispatched like bytecodes. Emit BC_FUNCF/BC_FUNCV bytecode at PC 0 for all Lua functions. C functions and ASM fast functions get extra bytecodes. Modify internal calling convention: new base in BASE (formerly in RA). Can now use better C function wrapper semantics (dynamic on/off). Prerequisite for call hooks with zero-overhead if disabled. Prerequisite for compiling recursive calls. Prerequisite for efficient 32/64 bit prototype guards.
Diffstat (limited to 'src/buildvm_lib.c')
-rw-r--r--src/buildvm_lib.c31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/buildvm_lib.c b/src/buildvm_lib.c
index 3cf8f522..e77240c5 100644
--- a/src/buildvm_lib.c
+++ b/src/buildvm_lib.c
@@ -15,7 +15,7 @@ static char modname[80];
15static size_t modnamelen; 15static size_t modnamelen;
16static char funcname[80]; 16static char funcname[80];
17static int modstate, regfunc; 17static int modstate, regfunc;
18static int ffid, recffid; 18static int ffid, recffid, ffasmfunc;
19 19
20enum { 20enum {
21 REGFUNC_OK, 21 REGFUNC_OK,
@@ -77,7 +77,8 @@ static void libdef_module(BuildCtx *ctx, char *p, int arg)
77 libdef_endmodule(ctx); 77 libdef_endmodule(ctx);
78 optr = obuf; 78 optr = obuf;
79 *optr++ = (uint8_t)ffid; 79 *optr++ = (uint8_t)ffid;
80 *optr++ = 0; 80 *optr++ = (uint8_t)ffasmfunc;
81 *optr++ = 0; /* Hash table size. */
81 modstate = 1; 82 modstate = 1;
82 fprintf(ctx->fp, "#ifdef %sMODULE_%s\n", LIBDEF_PREFIX, p); 83 fprintf(ctx->fp, "#ifdef %sMODULE_%s\n", LIBDEF_PREFIX, p);
83 fprintf(ctx->fp, "#undef %sMODULE_%s\n", LIBDEF_PREFIX, p); 84 fprintf(ctx->fp, "#undef %sMODULE_%s\n", LIBDEF_PREFIX, p);
@@ -108,8 +109,9 @@ static int find_ffofs(BuildCtx *ctx, const char *name)
108 109
109static void libdef_func(BuildCtx *ctx, char *p, int arg) 110static void libdef_func(BuildCtx *ctx, char *p, int arg)
110{ 111{
112 if (arg != LIBINIT_CF)
113 ffasmfunc++;
111 if (ctx->mode == BUILD_libdef) { 114 if (ctx->mode == BUILD_libdef) {
112 int ofs = arg != LIBINIT_CF ? find_ffofs(ctx, p) : 0;
113 if (modstate == 0) { 115 if (modstate == 0) {
114 fprintf(stderr, "Error: no module for function definition %s\n", p); 116 fprintf(stderr, "Error: no module for function definition %s\n", p);
115 exit(1); 117 exit(1);
@@ -126,12 +128,8 @@ static void libdef_func(BuildCtx *ctx, char *p, int arg)
126 modstate = 2; 128 modstate = 2;
127 fprintf(ctx->fp, " %s%s", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p); 129 fprintf(ctx->fp, " %s%s", arg ? LABEL_PREFIX_FFH : LABEL_PREFIX_CF, p);
128 } 130 }
129 if (regfunc != REGFUNC_NOREGUV) obuf[1]++; /* Bump hash table size. */ 131 if (regfunc != REGFUNC_NOREGUV) obuf[2]++; /* Bump hash table size. */
130 libdef_name(regfunc == REGFUNC_NOREGUV ? "" : p, arg); 132 libdef_name(regfunc == REGFUNC_NOREGUV ? "" : p, arg);
131 if (arg) {
132 *optr++ = (uint8_t)ofs;
133 *optr++ = (uint8_t)(ofs >> 8);
134 }
135 } 133 }
136 } else if (ctx->mode == BUILD_ffdef) { 134 } else if (ctx->mode == BUILD_ffdef) {
137 fprintf(ctx->fp, "FFDEF(%s)\n", p); 135 fprintf(ctx->fp, "FFDEF(%s)\n", p);
@@ -146,6 +144,9 @@ static void libdef_func(BuildCtx *ctx, char *p, int arg)
146 for (i = 1; p[i] && modname[i-1]; i++) 144 for (i = 1; p[i] && modname[i-1]; i++)
147 if (p[i] == '_') p[i] = '.'; 145 if (p[i] == '_') p[i] = '.';
148 fprintf(ctx->fp, "\"%s\",\n", p); 146 fprintf(ctx->fp, "\"%s\",\n", p);
147 } else if (ctx->mode == BUILD_bcdef) {
148 if (arg != LIBINIT_CF)
149 fprintf(ctx->fp, ",\n%d", find_ffofs(ctx, p));
149 } 150 }
150 ffid++; 151 ffid++;
151 regfunc = REGFUNC_OK; 152 regfunc = REGFUNC_OK;
@@ -253,7 +254,7 @@ static void libdef_set(BuildCtx *ctx, char *p, int arg)
253 if (p[0] == '!' && p[1] == '\0') p[0] = '\0'; /* Set env. */ 254 if (p[0] == '!' && p[1] == '\0') p[0] = '\0'; /* Set env. */
254 libdef_name(p, LIBINIT_STRING); 255 libdef_name(p, LIBINIT_STRING);
255 *optr++ = LIBINIT_SET; 256 *optr++ = LIBINIT_SET;
256 obuf[1]++; /* Bump hash table size. */ 257 obuf[2]++; /* Bump hash table size. */
257 } 258 }
258} 259}
259 260
@@ -298,6 +299,7 @@ void emit_lib(BuildCtx *ctx)
298 if (ctx->mode == BUILD_recdef) 299 if (ctx->mode == BUILD_recdef)
299 fprintf(ctx->fp, "static const uint16_t recff_idmap[] = {\n0,\n0x0100"); 300 fprintf(ctx->fp, "static const uint16_t recff_idmap[] = {\n0,\n0x0100");
300 recffid = ffid = FF_C+1; 301 recffid = ffid = FF_C+1;
302 ffasmfunc = 0;
301 303
302 while ((fname = *ctx->args++)) { 304 while ((fname = *ctx->args++)) {
303 char buf[256]; /* We don't care about analyzing lines longer than that. */ 305 char buf[256]; /* We don't care about analyzing lines longer than that. */
@@ -347,8 +349,19 @@ void emit_lib(BuildCtx *ctx)
347 349
348 if (ctx->mode == BUILD_ffdef) { 350 if (ctx->mode == BUILD_ffdef) {
349 fprintf(ctx->fp, "\n#undef FFDEF\n\n"); 351 fprintf(ctx->fp, "\n#undef FFDEF\n\n");
352 fprintf(ctx->fp,
353 "#ifndef FF_NUM_ASMFUNC\n#define FF_NUM_ASMFUNC %d\n#endif\n\n",
354 ffasmfunc);
350 } else if (ctx->mode == BUILD_vmdef) { 355 } else if (ctx->mode == BUILD_vmdef) {
351 fprintf(ctx->fp, "}\n\n"); 356 fprintf(ctx->fp, "}\n\n");
357 } else if (ctx->mode == BUILD_bcdef) {
358 int i;
359 fprintf(ctx->fp, "\n};\n\n");
360 fprintf(ctx->fp, "LJ_DATADEF const uint16_t lj_bc_mode[] = {\n");
361 fprintf(ctx->fp, "BCDEF(BCMODE)\n");
362 for (i = ffasmfunc-1; i > 0; i--)
363 fprintf(ctx->fp, "BCMODE_FF,\n");
364 fprintf(ctx->fp, "BCMODE_FF\n};\n\n");
352 } else if (ctx->mode == BUILD_recdef) { 365 } else if (ctx->mode == BUILD_recdef) {
353 char *p = (char *)obuf; 366 char *p = (char *)obuf;
354 fprintf(ctx->fp, "\n};\n\n"); 367 fprintf(ctx->fp, "\n};\n\n");