2009-12-08 18:46:35 +00:00
|
|
|
/*
|
|
|
|
** LuaJIT VM builder.
|
2012-01-23 21:42:30 +00:00
|
|
|
** Copyright (C) 2005-2012 Mike Pall. See Copyright Notice in luajit.h
|
2009-12-08 18:46:35 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BUILDVM_H
|
|
|
|
#define _BUILDVM_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "lj_def.h"
|
|
|
|
#include "lj_arch.h"
|
|
|
|
|
|
|
|
/* Hardcoded limits. Increase as needed. */
|
2011-04-16 21:31:30 +00:00
|
|
|
#define BUILD_MAX_RELOC 200 /* Max. number of relocations. */
|
2009-12-08 18:46:35 +00:00
|
|
|
#define BUILD_MAX_FOLD 4096 /* Max. number of fold rules. */
|
|
|
|
|
|
|
|
/* Prefix for scanned library definitions. */
|
|
|
|
#define LIBDEF_PREFIX "LJLIB_"
|
|
|
|
|
|
|
|
/* Prefix for scanned fold definitions. */
|
|
|
|
#define FOLDDEF_PREFIX "LJFOLD"
|
|
|
|
|
|
|
|
/* Prefixes for generated labels. */
|
|
|
|
#define LABEL_PREFIX "lj_"
|
|
|
|
#define LABEL_PREFIX_BC LABEL_PREFIX "BC_"
|
|
|
|
#define LABEL_PREFIX_FF LABEL_PREFIX "ff_"
|
|
|
|
#define LABEL_PREFIX_CF LABEL_PREFIX "cf_"
|
|
|
|
#define LABEL_PREFIX_FFH LABEL_PREFIX "ffh_"
|
|
|
|
#define LABEL_PREFIX_LIBCF LABEL_PREFIX "lib_cf_"
|
|
|
|
#define LABEL_PREFIX_LIBINIT LABEL_PREFIX "lib_init_"
|
|
|
|
|
|
|
|
/* Forward declaration. */
|
|
|
|
struct dasm_State;
|
|
|
|
|
|
|
|
/* Build modes. */
|
|
|
|
#define BUILDDEF(_) \
|
2010-08-03 20:09:12 +00:00
|
|
|
_(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \
|
2010-02-05 19:15:01 +00:00
|
|
|
_(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \
|
2009-12-08 18:46:35 +00:00
|
|
|
_(folddef)
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
#define BUILDENUM(name) BUILD_##name,
|
|
|
|
BUILDDEF(BUILDENUM)
|
|
|
|
#undef BUILDENUM
|
|
|
|
BUILD__MAX
|
|
|
|
} BuildMode;
|
|
|
|
|
|
|
|
/* Code relocation. */
|
|
|
|
typedef struct BuildReloc {
|
|
|
|
int32_t ofs;
|
|
|
|
int sym;
|
|
|
|
int type;
|
|
|
|
} BuildReloc;
|
|
|
|
|
2010-04-14 15:13:13 +00:00
|
|
|
typedef struct BuildSym {
|
|
|
|
const char *name;
|
|
|
|
int32_t ofs;
|
|
|
|
} BuildSym;
|
|
|
|
|
2009-12-08 18:46:35 +00:00
|
|
|
/* Build context structure. */
|
|
|
|
typedef struct BuildCtx {
|
|
|
|
/* DynASM state pointer. Should be first member. */
|
|
|
|
struct dasm_State *D;
|
|
|
|
/* Parsed command line. */
|
|
|
|
BuildMode mode;
|
|
|
|
FILE *fp;
|
|
|
|
const char *outname;
|
|
|
|
char **args;
|
|
|
|
/* Code and symbols generated by DynASM. */
|
|
|
|
uint8_t *code;
|
|
|
|
size_t codesz;
|
2010-04-14 15:13:13 +00:00
|
|
|
int npc, nglob, nsym, nreloc, nrelocsym;
|
2009-12-08 18:46:35 +00:00
|
|
|
void **glob;
|
2010-04-14 15:13:13 +00:00
|
|
|
BuildSym *sym;
|
|
|
|
const char **relocsym;
|
|
|
|
int32_t *bc_ofs;
|
|
|
|
const char *beginsym;
|
2009-12-08 18:46:35 +00:00
|
|
|
/* Strings generated by DynASM. */
|
|
|
|
const char *const *globnames;
|
|
|
|
const char *dasm_ident;
|
|
|
|
const char *dasm_arch;
|
|
|
|
/* Relocations. */
|
|
|
|
BuildReloc reloc[BUILD_MAX_RELOC];
|
|
|
|
} BuildCtx;
|
|
|
|
|
|
|
|
extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz);
|
|
|
|
extern void emit_asm(BuildCtx *ctx);
|
|
|
|
extern void emit_peobj(BuildCtx *ctx);
|
|
|
|
extern void emit_lib(BuildCtx *ctx);
|
|
|
|
extern void emit_fold(BuildCtx *ctx);
|
|
|
|
|
|
|
|
extern const char *const bc_names[];
|
|
|
|
extern const char *const ir_names[];
|
2010-12-31 00:00:54 +00:00
|
|
|
extern const char *const irt_names[];
|
2009-12-08 18:46:35 +00:00
|
|
|
extern const char *const irfpm_names[];
|
|
|
|
extern const char *const irfield_names[];
|
2009-12-08 19:35:29 +00:00
|
|
|
extern const char *const ircall_names[];
|
2009-12-08 18:46:35 +00:00
|
|
|
|
|
|
|
#endif
|