xref: /PHP-8.3/ext/opcache/jit/dynasm/dasm_proto.h (revision 16d59a59)
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 
7 #ifndef _DASM_PROTO_H
8 #define _DASM_PROTO_H
9 
10 #include <stddef.h>
11 #include <stdarg.h>
12 
13 #define DASM_IDENT	"DynASM 1.5.0"
14 #define DASM_VERSION	10500	/* 1.5.0 */
15 
16 #ifndef Dst_DECL
17 #define Dst_DECL	dasm_State **Dst
18 #endif
19 
20 #ifndef Dst_REF
21 #define Dst_REF		(*Dst)
22 #endif
23 
24 #ifndef DASM_FDEF
25 #define DASM_FDEF	extern
26 #endif
27 
28 #ifndef DASM_M_GROW
29 #define DASM_M_GROW(ctx, t, p, sz, need) \
30   do { \
31     size_t _sz = (sz), _need = (need); \
32     if (_sz < _need) { \
33       if (_sz < 16) _sz = 16; \
34       while (_sz < _need) _sz += _sz; \
35       (p) = (t *)realloc((p), _sz); \
36       if ((p) == NULL) exit(1); \
37       (sz) = _sz; \
38     } \
39   } while(0)
40 #endif
41 
42 #ifndef DASM_M_FREE
43 #define DASM_M_FREE(ctx, p, sz)	free(p)
44 #endif
45 
46 /* Internal DynASM encoder state. */
47 typedef struct dasm_State dasm_State;
48 
49 
50 /* Initialize and free DynASM state. */
51 DASM_FDEF void dasm_init(Dst_DECL, int maxsection);
52 DASM_FDEF void dasm_free(Dst_DECL);
53 
54 /* Setup global array. Must be called before dasm_setup(). */
55 DASM_FDEF void dasm_setupglobal(Dst_DECL, void **gl, unsigned int maxgl);
56 
57 /* Grow PC label array. Can be called after dasm_setup(), too. */
58 DASM_FDEF void dasm_growpc(Dst_DECL, unsigned int maxpc);
59 
60 /* Setup encoder. */
61 DASM_FDEF void dasm_setup(Dst_DECL, const void *actionlist);
62 
63 /* Feed encoder with actions. Calls are generated by pre-processor. */
64 DASM_FDEF void dasm_put(Dst_DECL, int start, ...);
65 
66 /* Link sections and return the resulting size. */
67 DASM_FDEF int dasm_link(Dst_DECL, size_t *szp);
68 
69 /* Encode sections into buffer. */
70 DASM_FDEF int dasm_encode(Dst_DECL, void *buffer);
71 
72 /* Get PC label offset. */
73 DASM_FDEF int dasm_getpclabel(Dst_DECL, unsigned int pc);
74 
75 #ifdef DASM_CHECKS
76 /* Optional sanity checker to call between isolated encoding steps. */
77 DASM_FDEF int dasm_checkstep(Dst_DECL, int secmatch);
78 #else
79 #define dasm_checkstep(a, b)	0
80 #endif
81 
82 
83 #endif /* _DASM_PROTO_H */
84