src/host/buildvm.h - luajit-2.0-src

Data types defined

Macros defined

Source code

  1. /*
  2. ** LuaJIT VM builder.
  3. ** Copyright (C) 2005-2015 Mike Pall. See Copyright Notice in luajit.h
  4. */

  5. #ifndef _BUILDVM_H
  6. #define _BUILDVM_H

  7. #include <sys/types.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <errno.h>

  12. #include "lj_def.h"
  13. #include "lj_arch.h"

  14. /* Hardcoded limits. Increase as needed. */
  15. #define BUILD_MAX_RELOC                200        /* Max. number of relocations. */
  16. #define BUILD_MAX_FOLD                4096        /* Max. number of fold rules. */

  17. /* Prefix for scanned library definitions. */
  18. #define LIBDEF_PREFIX                "LJLIB_"

  19. /* Prefix for scanned fold definitions. */
  20. #define FOLDDEF_PREFIX                "LJFOLD"

  21. /* Prefixes for generated labels. */
  22. #define LABEL_PREFIX                "lj_"
  23. #define LABEL_PREFIX_BC                LABEL_PREFIX "BC_"
  24. #define LABEL_PREFIX_FF                LABEL_PREFIX "ff_"
  25. #define LABEL_PREFIX_CF                LABEL_PREFIX "cf_"
  26. #define LABEL_PREFIX_FFH        LABEL_PREFIX "ffh_"
  27. #define LABEL_PREFIX_LIBCF        LABEL_PREFIX "lib_cf_"
  28. #define LABEL_PREFIX_LIBINIT        LABEL_PREFIX "lib_init_"

  29. /* Forward declaration. */
  30. struct dasm_State;

  31. /* Build modes. */
  32. #define BUILDDEF(_) \
  33.   _(elfasm) _(coffasm) _(machasm) _(peobj) _(raw) \
  34.   _(bcdef) _(ffdef) _(libdef) _(recdef) _(vmdef) \
  35.   _(folddef)

  36. typedef enum {
  37. #define BUILDENUM(name)                BUILD_##name,
  38. BUILDDEF(BUILDENUM)
  39. #undef BUILDENUM
  40.   BUILD__MAX
  41. } BuildMode;

  42. /* Code relocation. */
  43. typedef struct BuildReloc {
  44.   int32_t ofs;
  45.   int sym;
  46.   int type;
  47. } BuildReloc;

  48. typedef struct BuildSym {
  49.   const char *name;
  50.   int32_t ofs;
  51. } BuildSym;

  52. /* Build context structure. */
  53. typedef struct BuildCtx {
  54.   /* DynASM state pointer. Should be first member. */
  55.   struct dasm_State *D;
  56.   /* Parsed command line. */
  57.   BuildMode mode;
  58.   FILE *fp;
  59.   const char *outname;
  60.   char **args;
  61.   /* Code and symbols generated by DynASM. */
  62.   uint8_t *code;
  63.   size_t codesz;
  64.   int npc, nglob, nsym, nreloc, nrelocsym;
  65.   void **glob;
  66.   BuildSym *sym;
  67.   const char **relocsym;
  68.   int32_t *bc_ofs;
  69.   const char *beginsym;
  70.   /* Strings generated by DynASM. */
  71.   const char *const *globnames;
  72.   const char *const *extnames;
  73.   const char *dasm_ident;
  74.   const char *dasm_arch;
  75.   /* Relocations. */
  76.   BuildReloc reloc[BUILD_MAX_RELOC];
  77. } BuildCtx;

  78. extern void owrite(BuildCtx *ctx, const void *ptr, size_t sz);
  79. extern void emit_asm(BuildCtx *ctx);
  80. extern void emit_peobj(BuildCtx *ctx);
  81. extern void emit_lib(BuildCtx *ctx);
  82. extern void emit_fold(BuildCtx *ctx);

  83. extern const char *const bc_names[];
  84. extern const char *const ir_names[];
  85. extern const char *const irt_names[];
  86. extern const char *const irfpm_names[];
  87. extern const char *const irfield_names[];
  88. extern const char *const ircall_names[];

  89. #endif