lj_bcdump.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. ** Bytecode dump definitions.
  3. ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_BCDUMP_H
  6. #define _LJ_BCDUMP_H
  7. #include "lj_obj.h"
  8. #include "lj_lex.h"
  9. /* -- Bytecode dump format ------------------------------------------------ */
  10. /*
  11. ** dump = header proto+ 0U
  12. ** header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]
  13. ** proto = lengthU pdata
  14. ** pdata = phead bcinsW* uvdataH* kgc* knum* [debugB*]
  15. ** phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU
  16. ** [debuglenU [firstlineU numlineU]]
  17. ** kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }
  18. ** knum = intU0 | (loU1 hiU)
  19. ** ktab = narrayU nhashU karray* khash*
  20. ** karray = ktabk
  21. ** khash = ktabk ktabk
  22. ** ktabk = ktabtypeU { intU | (loU hiU) | strB* }
  23. **
  24. ** B = 8 bit, H = 16 bit, W = 32 bit, U = ULEB128 of W, U0/U1 = ULEB128 of W+1
  25. */
  26. /* Bytecode dump header. */
  27. #define BCDUMP_HEAD1 0x1b
  28. #define BCDUMP_HEAD2 0x4c
  29. #define BCDUMP_HEAD3 0x4a
  30. /* If you perform *any* kind of private modifications to the bytecode itself
  31. ** or to the dump format, you *must* set BCDUMP_VERSION to 0x80 or higher.
  32. */
  33. #define BCDUMP_VERSION 2
  34. /* Compatibility flags. */
  35. #define BCDUMP_F_BE 0x01
  36. #define BCDUMP_F_STRIP 0x02
  37. #define BCDUMP_F_FFI 0x04
  38. #define BCDUMP_F_FR2 0x08
  39. #define BCDUMP_F_KNOWN (BCDUMP_F_FR2*2-1)
  40. #define BCDUMP_F_DETERMINISTIC 0x80000000
  41. /* Type codes for the GC constants of a prototype. Plus length for strings. */
  42. enum {
  43. BCDUMP_KGC_CHILD, BCDUMP_KGC_TAB, BCDUMP_KGC_I64, BCDUMP_KGC_U64,
  44. BCDUMP_KGC_COMPLEX, BCDUMP_KGC_STR
  45. };
  46. /* Type codes for the keys/values of a constant table. */
  47. enum {
  48. BCDUMP_KTAB_NIL, BCDUMP_KTAB_FALSE, BCDUMP_KTAB_TRUE,
  49. BCDUMP_KTAB_INT, BCDUMP_KTAB_NUM, BCDUMP_KTAB_STR
  50. };
  51. /* -- Bytecode reader/writer ---------------------------------------------- */
  52. LJ_FUNC int lj_bcwrite(lua_State *L, GCproto *pt, lua_Writer writer,
  53. void *data, uint32_t flags);
  54. LJ_FUNC GCproto *lj_bcread_proto(LexState *ls);
  55. LJ_FUNC GCproto *lj_bcread(LexState *ls);
  56. #endif