dasm_proto.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. ** DynASM encoding engine prototypes.
  3. ** Copyright (C) 2005-2021 Mike Pall. All rights reserved.
  4. ** Released under the MIT license. See dynasm.lua for full copyright notice.
  5. */
  6. #ifndef _DASM_PROTO_H
  7. #define _DASM_PROTO_H
  8. #include <stddef.h>
  9. #include <stdarg.h>
  10. #define DASM_IDENT "DynASM 1.5.0"
  11. #define DASM_VERSION 10500 /* 1.5.0 */
  12. #ifndef Dst_DECL
  13. #define Dst_DECL dasm_State **Dst
  14. #endif
  15. #ifndef Dst_REF
  16. #define Dst_REF (*Dst)
  17. #endif
  18. #ifndef DASM_FDEF
  19. #define DASM_FDEF extern
  20. #endif
  21. #ifndef DASM_M_GROW
  22. #define DASM_M_GROW(ctx, t, p, sz, need) \
  23. do { \
  24. size_t _sz = (sz), _need = (need); \
  25. if (_sz < _need) { \
  26. if (_sz < 16) _sz = 16; \
  27. while (_sz < _need) _sz += _sz; \
  28. (p) = (t *)realloc((p), _sz); \
  29. if ((p) == NULL) exit(1); \
  30. (sz) = _sz; \
  31. } \
  32. } while(0)
  33. #endif
  34. #ifndef DASM_M_FREE
  35. #define DASM_M_FREE(ctx, p, sz) free(p)
  36. #endif
  37. /* Internal DynASM encoder state. */
  38. typedef struct dasm_State dasm_State;
  39. /* Initialize and free DynASM state. */
  40. DASM_FDEF void dasm_init(Dst_DECL, int maxsection);
  41. DASM_FDEF void dasm_free(Dst_DECL);
  42. /* Setup global array. Must be called before dasm_setup(). */
  43. DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);
  44. /* Grow PC label array. Can be called after dasm_setup(), too. */
  45. DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);
  46. /* Setup encoder. */
  47. DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);
  48. /* Feed encoder with actions. Calls are generated by pre-processor. */
  49. DASM_FDEF void dasm_put(Dst_DECL, int start, ...);
  50. /* Link sections and return the resulting size. */
  51. DASM_FDEF int dasm_link(Dst_DECL, size_t *szp);
  52. /* Encode sections into buffer. */
  53. DASM_FDEF int dasm_encode(Dst_DECL, void *buffer);
  54. /* Get PC label offset. */
  55. DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);
  56. #ifdef DASM_CHECKS
  57. /* Optional sanity checker to call between isolated encoding steps. */
  58. DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch);
  59. #else
  60. #define dasm_checkstep(a, b) 0
  61. #endif
  62. #endif /* _DASM_PROTO_H */