-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjitfu.c
169 lines (145 loc) · 4.55 KB
/
jitfu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
+----------------------------------------------------------------------+
| PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 2018 Joe Watkins <[email protected]> |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: [email protected] |
+----------------------------------------------------------------------+
*/
/* $Id$ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_closures.h"
#include "zend_exceptions.h"
#include "php_jitfu.h"
zend_class_entry *jit_exception_ce;
ZEND_DECLARE_MODULE_GLOBALS(jitfu);
#include "bits/context.h"
#include "bits/type.h"
#include "bits/struct.h"
#include "bits/signature.h"
#include "bits/function.h"
#include "bits/label.h"
#include "bits/value.h"
/* {{{ jit_module_entry
*/
zend_module_entry jitfu_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_JITFU_EXTNAME,
NULL,
PHP_MINIT(jitfu),
NULL,
PHP_RINIT(jitfu),
PHP_RSHUTDOWN(jitfu),
PHP_MINFO(jitfu),
#if ZEND_MODULE_API_NO >= 20010901
PHP_JITFU_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
/* }}} */
#ifdef COMPILE_DL_JITFU
#ifdef ZTS
ZEND_TSRMLS_CACHE_DEFINE();
#endif
ZEND_GET_MODULE(jitfu)
#endif
static inline void php_jit_globals_ctor(zend_jitfu_globals *jg) {}
static inline const char* php_jit_exception_type(int type) {
switch (type) {
case JIT_RESULT_OK: return "none";
case JIT_RESULT_OVERFLOW: return "overflow";
case JIT_RESULT_ARITHMETIC: return "arithmetic";
case JIT_RESULT_DIVISION_BY_ZERO: return "division by zero";
case JIT_RESULT_COMPILE_ERROR: return "compile error";
case JIT_RESULT_OUT_OF_MEMORY: return "out of memory";
case JIT_RESULT_NULL_REFERENCE: return "null reference";
case JIT_RESULT_NULL_FUNCTION: return "null function";
case JIT_RESULT_CALLED_NESTED: return "called nested";
case JIT_RESULT_OUT_OF_BOUNDS: return "out of bounds";
case JIT_RESULT_UNDEFINED_LABEL: return "undefined label";
case JIT_RESULT_MEMORY_FULL: return "memory full";
default: return "unknown error";
}
}
static inline void* php_jit_exception_handler(int type) {
TSRMLS_FETCH();
zend_throw_exception_ex
(jit_exception_ce, type, php_jit_exception_type(type));
}
/* {{{ PHP_MINIT_FUNCTION
*/
PHP_MINIT_FUNCTION(jitfu)
{
zend_class_entry ce;
ZEND_INIT_MODULE_GLOBALS(jitfu, php_jit_globals_ctor, NULL);
jit_exception_set_handler(php_jit_exception_handler);
INIT_NS_CLASS_ENTRY(ce, "JITFU", "Exception", NULL);
PHP_MINIT(JITFU_Context)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(JITFU_Type)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(JITFU_Struct)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(JITFU_Signature)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(JITFU_Func)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(JITFU_Value)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(JITFU_Label)(INIT_FUNC_ARGS_PASSTHRU);
jit_exception_ce = zend_register_internal_class_ex
(&ce, zend_exception_get_default());
return SUCCESS;
}
/* }}} */
/* {{{ PHP_RINIT_FUNCTION
*/
PHP_RINIT_FUNCTION(jitfu)
{
#ifdef ZTS
ZEND_TSRMLS_CACHE_UPDATE();
#endif
zend_hash_init(&JG(types), 8, NULL, ZVAL_PTR_DTOR, 0);
}
/* }}} */
/* {{{ PHP_RSHUTDOWN_FUNCTION
*/
PHP_RSHUTDOWN_FUNCTION(jitfu)
{
zend_hash_destroy(&JG(types));
}
/* }}} */
/* {{{ PHP_MINFO_FUNCTION
*/
PHP_MINFO_FUNCTION(jitfu)
{
php_info_print_table_start();
php_info_print_table_header(2, "JIT-Fu support", "enabled");
php_info_print_table_end();
}
/* }}} */
#include "bits/context.h"
#include "bits/type.h"
#include "bits/struct.h"
#include "bits/signature.h"
#include "bits/function.h"
#include "bits/value.h"
#include "bits/label.h"
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim600: noet sw=4 ts=4 fdm=marker
* vim<600: noet sw=4 ts=4
*/