summaryrefslogtreecommitdiff
path: root/src/host/buildvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/host/buildvm.c')
-rw-r--r--src/host/buildvm.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/host/buildvm.c b/src/host/buildvm.c
index 39c2bc24..ec99e501 100644
--- a/src/host/buildvm.c
+++ b/src/host/buildvm.c
@@ -18,8 +18,10 @@
18#include "lj_obj.h" 18#include "lj_obj.h"
19#include "lj_gc.h" 19#include "lj_gc.h"
20#include "lj_bc.h" 20#include "lj_bc.h"
21#if LJ_HASJIT
21#include "lj_ir.h" 22#include "lj_ir.h"
22#include "lj_ircall.h" 23#include "lj_ircall.h"
24#endif
23#include "lj_frame.h" 25#include "lj_frame.h"
24#include "lj_dispatch.h" 26#include "lj_dispatch.h"
25#if LJ_HASFFI 27#if LJ_HASFFI
@@ -59,10 +61,10 @@ static int collect_reloc(BuildCtx *ctx, uint8_t *addr, int idx, int type);
59#include "../dynasm/dasm_x86.h" 61#include "../dynasm/dasm_x86.h"
60#elif LJ_TARGET_ARM 62#elif LJ_TARGET_ARM
61#include "../dynasm/dasm_arm.h" 63#include "../dynasm/dasm_arm.h"
64#elif LJ_TARGET_ARM64
65#include "../dynasm/dasm_arm64.h"
62#elif LJ_TARGET_PPC 66#elif LJ_TARGET_PPC
63#include "../dynasm/dasm_ppc.h" 67#include "../dynasm/dasm_ppc.h"
64#elif LJ_TARGET_PPCSPE
65#include "../dynasm/dasm_ppc.h"
66#elif LJ_TARGET_MIPS 68#elif LJ_TARGET_MIPS
67#include "../dynasm/dasm_mips.h" 69#include "../dynasm/dasm_mips.h"
68#else 70#else
@@ -110,11 +112,11 @@ static const char *sym_decorate(BuildCtx *ctx,
110 if (p) { 112 if (p) {
111#if LJ_TARGET_X86ORX64 113#if LJ_TARGET_X86ORX64
112 if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj)) 114 if (!LJ_64 && (ctx->mode == BUILD_coffasm || ctx->mode == BUILD_peobj))
113 name[0] = '@'; 115 name[0] = name[1] == 'R' ? '_' : '@'; /* Just for _RtlUnwind@16. */
114 else 116 else
115 *p = '\0'; 117 *p = '\0';
116#elif (LJ_TARGET_PPC || LJ_TARGET_PPCSPE) && !LJ_TARGET_CONSOLE 118#elif LJ_TARGET_PPC && !LJ_TARGET_CONSOLE
117 /* Keep @plt. */ 119 /* Keep @plt etc. */
118#else 120#else
119 *p = '\0'; 121 *p = '\0';
120#endif 122#endif
@@ -179,6 +181,7 @@ static int build_code(BuildCtx *ctx)
179 ctx->nreloc = 0; 181 ctx->nreloc = 0;
180 182
181 ctx->globnames = globnames; 183 ctx->globnames = globnames;
184 ctx->extnames = extnames;
182 ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *)); 185 ctx->relocsym = (const char **)malloc(NRELOCSYM*sizeof(const char *));
183 ctx->nrelocsym = 0; 186 ctx->nrelocsym = 0;
184 for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1; 187 for (i = 0; i < (int)NRELOCSYM; i++) relocmap[i] = -1;
@@ -249,6 +252,7 @@ BCDEF(BCNAME)
249 NULL 252 NULL
250}; 253};
251 254
255#if LJ_HASJIT
252const char *const ir_names[] = { 256const char *const ir_names[] = {
253#define IRNAME(name, m, m1, m2) #name, 257#define IRNAME(name, m, m1, m2) #name,
254IRDEF(IRNAME) 258IRDEF(IRNAME)
@@ -289,7 +293,9 @@ static const char *const trace_errors[] = {
289#include "lj_traceerr.h" 293#include "lj_traceerr.h"
290 NULL 294 NULL
291}; 295};
296#endif
292 297
298#if LJ_HASJIT
293static const char *lower(char *buf, const char *s) 299static const char *lower(char *buf, const char *s)
294{ 300{
295 char *p = buf; 301 char *p = buf;
@@ -300,6 +306,7 @@ static const char *lower(char *buf, const char *s)
300 *p = '\0'; 306 *p = '\0';
301 return buf; 307 return buf;
302} 308}
309#endif
303 310
304/* Emit C source code for bytecode-related definitions. */ 311/* Emit C source code for bytecode-related definitions. */
305static void emit_bcdef(BuildCtx *ctx) 312static void emit_bcdef(BuildCtx *ctx)
@@ -317,24 +324,27 @@ static void emit_bcdef(BuildCtx *ctx)
317/* Emit VM definitions as Lua code for debug modules. */ 324/* Emit VM definitions as Lua code for debug modules. */
318static void emit_vmdef(BuildCtx *ctx) 325static void emit_vmdef(BuildCtx *ctx)
319{ 326{
327#if LJ_HASJIT
320 char buf[80]; 328 char buf[80];
329#endif
321 int i; 330 int i;
322 fprintf(ctx->fp, "-- This is a generated file. DO NOT EDIT!\n\n"); 331 fprintf(ctx->fp, "-- This is a generated file. DO NOT EDIT!\n\n");
323 fprintf(ctx->fp, "assert(require(\"jit\").version == \"%s\", \"LuaJIT core/library version mismatch\")\n\n", LUAJIT_VERSION); 332 fprintf(ctx->fp, "assert(require(\"jit\").version == \"%s\", \"LuaJIT core/library version mismatch\")\n\n", LUAJIT_VERSION);
324 fprintf(ctx->fp, "module(...)\n\n"); 333 fprintf(ctx->fp, "return {\n\n");
325 334
326 fprintf(ctx->fp, "bcnames = \""); 335 fprintf(ctx->fp, "bcnames = \"");
327 for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, "%-6s", bc_names[i]); 336 for (i = 0; bc_names[i]; i++) fprintf(ctx->fp, "%-6s", bc_names[i]);
328 fprintf(ctx->fp, "\"\n\n"); 337 fprintf(ctx->fp, "\",\n\n");
329 338
339#if LJ_HASJIT
330 fprintf(ctx->fp, "irnames = \""); 340 fprintf(ctx->fp, "irnames = \"");
331 for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, "%-6s", ir_names[i]); 341 for (i = 0; ir_names[i]; i++) fprintf(ctx->fp, "%-6s", ir_names[i]);
332 fprintf(ctx->fp, "\"\n\n"); 342 fprintf(ctx->fp, "\",\n\n");
333 343
334 fprintf(ctx->fp, "irfpm = { [0]="); 344 fprintf(ctx->fp, "irfpm = { [0]=");
335 for (i = 0; irfpm_names[i]; i++) 345 for (i = 0; irfpm_names[i]; i++)
336 fprintf(ctx->fp, "\"%s\", ", lower(buf, irfpm_names[i])); 346 fprintf(ctx->fp, "\"%s\", ", lower(buf, irfpm_names[i]));
337 fprintf(ctx->fp, "}\n\n"); 347 fprintf(ctx->fp, "},\n\n");
338 348
339 fprintf(ctx->fp, "irfield = { [0]="); 349 fprintf(ctx->fp, "irfield = { [0]=");
340 for (i = 0; irfield_names[i]; i++) { 350 for (i = 0; irfield_names[i]; i++) {
@@ -344,17 +354,18 @@ static void emit_vmdef(BuildCtx *ctx)
344 if (p) *p = '.'; 354 if (p) *p = '.';
345 fprintf(ctx->fp, "\"%s\", ", buf); 355 fprintf(ctx->fp, "\"%s\", ", buf);
346 } 356 }
347 fprintf(ctx->fp, "}\n\n"); 357 fprintf(ctx->fp, "},\n\n");
348 358
349 fprintf(ctx->fp, "ircall = {\n[0]="); 359 fprintf(ctx->fp, "ircall = {\n[0]=");
350 for (i = 0; ircall_names[i]; i++) 360 for (i = 0; ircall_names[i]; i++)
351 fprintf(ctx->fp, "\"%s\",\n", ircall_names[i]); 361 fprintf(ctx->fp, "\"%s\",\n", ircall_names[i]);
352 fprintf(ctx->fp, "}\n\n"); 362 fprintf(ctx->fp, "},\n\n");
353 363
354 fprintf(ctx->fp, "traceerr = {\n[0]="); 364 fprintf(ctx->fp, "traceerr = {\n[0]=");
355 for (i = 0; trace_errors[i]; i++) 365 for (i = 0; trace_errors[i]; i++)
356 fprintf(ctx->fp, "\"%s\",\n", trace_errors[i]); 366 fprintf(ctx->fp, "\"%s\",\n", trace_errors[i]);
357 fprintf(ctx->fp, "}\n\n"); 367 fprintf(ctx->fp, "},\n\n");
368#endif
358} 369}
359 370
360/* -- Argument parsing ---------------------------------------------------- */ 371/* -- Argument parsing ---------------------------------------------------- */
@@ -491,6 +502,7 @@ int main(int argc, char **argv)
491 case BUILD_vmdef: 502 case BUILD_vmdef:
492 emit_vmdef(ctx); 503 emit_vmdef(ctx);
493 emit_lib(ctx); 504 emit_lib(ctx);
505 fprintf(ctx->fp, "}\n\n");
494 break; 506 break;
495 case BUILD_ffdef: 507 case BUILD_ffdef:
496 case BUILD_libdef: 508 case BUILD_libdef: