diff options
Diffstat (limited to 'src/buildvm.h')
-rw-r--r-- | src/buildvm.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/buildvm.h b/src/buildvm.h new file mode 100644 index 00000000..e55527fd --- /dev/null +++ b/src/buildvm.h | |||
@@ -0,0 +1,106 @@ | |||
1 | /* | ||
2 | ** LuaJIT VM builder. | ||
3 | ** Copyright (C) 2005-2009 Mike Pall. See Copyright Notice in luajit.h | ||
4 | */ | ||
5 | |||
6 | #ifndef _BUILDVM_H | ||
7 | #define _BUILDVM_H | ||
8 | |||
9 | #include <sys/types.h> | ||
10 | #include <stdio.h> | ||
11 | #include <stdlib.h> | ||
12 | #include <string.h> | ||
13 | #include <errno.h> | ||
14 | |||
15 | #include "lj_def.h" | ||
16 | #include "lj_arch.h" | ||
17 | |||
18 | /* Hardcoded limits. Increase as needed. */ | ||
19 | #define BUILD_MAX_RELOC 100 /* Max. number of relocations. */ | ||
20 | #define BUILD_MAX_FOLD 4096 /* Max. number of fold rules. */ | ||
21 | |||
22 | /* Prefix for scanned library definitions. */ | ||
23 | #define LIBDEF_PREFIX "LJLIB_" | ||
24 | |||
25 | /* Prefix for scanned fold definitions. */ | ||
26 | #define FOLDDEF_PREFIX "LJFOLD" | ||
27 | |||
28 | /* Prefixes for generated labels. */ | ||
29 | #define LABEL_PREFIX "lj_" | ||
30 | #define LABEL_PREFIX_BC LABEL_PREFIX "BC_" | ||
31 | #define LABEL_PREFIX_FF LABEL_PREFIX "ff_" | ||
32 | #define LABEL_PREFIX_CF LABEL_PREFIX "cf_" | ||
33 | #define LABEL_PREFIX_FFH LABEL_PREFIX "ffh_" | ||
34 | #define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_" | ||
35 | #define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_" | ||
36 | |||
37 | /* Extra labels. */ | ||
38 | #define LABEL_ASM_BEGIN LABEL_PREFIX "vm_asm_begin" | ||
39 | #define LABEL_OP_OFS LABEL_PREFIX "vm_op_ofs" | ||
40 | |||
41 | /* Forward declaration. */ | ||
42 | struct dasm_State; | ||
43 | |||
44 | /* Build modes. */ | ||
45 | #if LJ_TARGET_X86ORX64 | ||
46 | #define BUILDDEFX(_) _(peobj) | ||
47 | #else | ||
48 | #define BUILDDEFX(_) | ||
49 | #endif | ||
50 | |||
51 | #define BUILDDEF(_) \ | ||
52 | _(asm) _(elfasm) _(coffasm) _(machasm) BUILDDEFX(_) _(raw) \ | ||
53 | _(ffdef) _(libdef) _(recdef) _(vmdef) \ | ||
54 | _(folddef) | ||
55 | |||
56 | typedef enum { | ||
57 | #define BUILDENUM(name) BUILD_##name, | ||
58 | BUILDDEF(BUILDENUM) | ||
59 | #undef BUILDENUM | ||
60 | BUILD__MAX | ||
61 | } BuildMode; | ||
62 | |||
63 | /* Code relocation. */ | ||
64 | typedef struct BuildReloc { | ||
65 | int32_t ofs; | ||
66 | int sym; | ||
67 | int type; | ||
68 | } BuildReloc; | ||
69 | |||
70 | /* Build context structure. */ | ||
71 | typedef struct BuildCtx { | ||
72 | /* DynASM state pointer. Should be first member. */ | ||
73 | struct dasm_State *D; | ||
74 | /* Parsed command line. */ | ||
75 | BuildMode mode; | ||
76 | FILE *fp; | ||
77 | const char *outname; | ||
78 | char **args; | ||
79 | /* Code and symbols generated by DynASM. */ | ||
80 | uint8_t *code; | ||
81 | size_t codesz; | ||
82 | int npc, nglob, nsym, nreloc; | ||
83 | void **glob; | ||
84 | int *perm; | ||
85 | int32_t *sym_ofs; | ||
86 | /* Strings generated by DynASM. */ | ||
87 | const char *const *extnames; | ||
88 | const char *const *globnames; | ||
89 | const char *dasm_ident; | ||
90 | const char *dasm_arch; | ||
91 | /* Relocations. */ | ||
92 | BuildReloc reloc[BUILD_MAX_RELOC]; | ||
93 | } BuildCtx; | ||
94 | |||
95 | extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz); | ||
96 | extern void emit_asm(BuildCtx *ctx); | ||
97 | extern void emit_peobj(BuildCtx *ctx); | ||
98 | extern void emit_lib(BuildCtx *ctx); | ||
99 | extern void emit_fold(BuildCtx *ctx); | ||
100 | |||
101 | extern const char *const bc_names[]; | ||
102 | extern const char *const ir_names[]; | ||
103 | extern const char *const irfpm_names[]; | ||
104 | extern const char *const irfield_names[]; | ||
105 | |||
106 | #endif | ||