Fix 32/64 bit portability issue with upval->v.
[luajit-2.0/celess22.git] / src / buildvm.h
blob2581b548c9fd79531366ec66e446c352961d97e9
1 /*
2 ** LuaJIT VM builder.
3 ** Copyright (C) 2005-2010 Mike Pall. See Copyright Notice in luajit.h
4 */
6 #ifndef _BUILDVM_H
7 #define _BUILDVM_H
9 #include <sys/types.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <errno.h>
15 #include "lj_def.h"
16 #include "lj_arch.h"
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. */
22 /* Prefix for scanned library definitions. */
23 #define LIBDEF_PREFIX "LJLIB_"
25 /* Prefix for scanned fold definitions. */
26 #define FOLDDEF_PREFIX "LJFOLD"
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_"
37 /* Extra labels. */
38 #define LABEL_ASM_BEGIN LABEL_PREFIX "vm_asm_begin"
39 #define LABEL_OP_OFS LABEL_PREFIX "vm_op_ofs"
41 /* Forward declaration. */
42 struct dasm_State;
44 /* Build modes. */
45 #if LJ_TARGET_X86ORX64
46 #define BUILDDEFX(_) _(peobj)
47 #else
48 #define BUILDDEFX(_)
49 #endif
51 #define BUILDDEF(_) \
52 _(elfasm) _(coffasm) _(machasm) BUILDDEFX(_) _(raw) \
53 _(ffdef) _(libdef) _(recdef) _(vmdef) \
54 _(folddef)
56 typedef enum {
57 #define BUILDENUM(name) BUILD_##name,
58 BUILDDEF(BUILDENUM)
59 #undef BUILDENUM
60 BUILD__MAX
61 } BuildMode;
63 /* Code relocation. */
64 typedef struct BuildReloc {
65 int32_t ofs;
66 int sym;
67 int type;
68 } BuildReloc;
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;
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);
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 extern const char *const ircall_names[];
107 #endif