Skip to content

Commit 6fb9e24

Browse files
committed
Allow generation of VM map
1 parent 0c0a5df commit 6fb9e24

File tree

5 files changed

+2165
-4
lines changed

5 files changed

+2165
-4
lines changed

Zend/zend_execute.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3189,6 +3189,8 @@ ZEND_API int ZEND_FASTCALL zend_do_fcall_overloaded(zend_execute_data *call, zva
31893189

31903190
#ifdef ZEND_VM_TRACE_HANDLERS
31913191
# include "zend_vm_trace_handlers.h"
3192+
#elif defined(ZEND_VM_TRACE_MAP)
3193+
# include "zend_vm_trace_map.h"
31923194
#endif
31933195

31943196
#define ZEND_VM_NEXT_OPCODE_EX(check_exception, skip) \

Zend/zend_vm_execute.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60078,6 +60078,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
6007860078
opline = orig_opline;
6007960079
return;
6008060080
HYBRID_DEFAULT:
60081+
VM_TRACE(ZEND_NULL)
6008160082
ZEND_NULL_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
6008260083
HYBRID_BREAK(); /* Never reached */
6008360084
#else

Zend/zend_vm_gen.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ function gen_null_label($f, $kind, $prolog) {
11531153
function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()) {
11541154
global $opcodes, $op_types, $prefix, $op_types_ex;
11551155

1156+
$list = [];
11561157
$next = 0;
11571158
$label = 0;
11581159
if ($spec) {
@@ -1288,7 +1289,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
12881289
}
12891290
};
12901291
};
1291-
$generate = function ($op1, $op2, $extra_spec = array()) use ($f, $kind, $dsc, $prefix, $prolog, $num, $switch_labels, &$label) {
1292+
$generate = function ($op1, $op2, $extra_spec = array()) use ($f, $kind, $dsc, $prefix, $prolog, $num, $switch_labels, &$label, &$list) {
12921293
global $commutative_order;
12931294

12941295
// Check if specialized handler is defined
@@ -1298,6 +1299,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
12981299
(!isset($extra_spec["OP_DATA"]) || isset($dsc["spec"]["OP_DATA"][$extra_spec["OP_DATA"]]))) {
12991300
if (skip_extra_spec_function($op1, $op2, $extra_spec)) {
13001301
gen_null_label($f, $kind, $prolog);
1302+
$list[$label] = null;
13011303
$label++;
13021304
return;
13031305
}
@@ -1307,20 +1309,20 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
13071309
switch ($kind) {
13081310
case ZEND_VM_KIND_CALL:
13091311
out($f,"$prolog{$spec_name}_HANDLER,\n");
1310-
$label++;
13111312
break;
13121313
case ZEND_VM_KIND_SWITCH:
13131314
out($f,$prolog."(void*)(uintptr_t)$switch_labels[$spec_name],\n");
1314-
$label++;
13151315
break;
13161316
case ZEND_VM_KIND_GOTO:
13171317
out($f,$prolog."(void*)&&{$spec_name}_LABEL,\n");
1318-
$label++;
13191318
break;
13201319
}
1320+
$list[$label] = $spec_name;
1321+
$label++;
13211322
} else {
13221323
// Emit pointer to handler of undefined opcode
13231324
gen_null_label($f, $kind, $prolog);
1325+
$list[$label] = null;
13241326
$label++;
13251327
}
13261328
};
@@ -1384,6 +1386,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
13841386
out($f,$prolog."(void*)&&".$dsc["op"]."_LABEL,\n");
13851387
break;
13861388
}
1389+
$list[] = $dsc["op"];
13871390
} else {
13881391
switch ($kind) {
13891392
case ZEND_VM_KIND_CALL:
@@ -1396,6 +1399,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
13961399
out($f,$prolog."(void*)&&ZEND_NULL_LABEL,\n");
13971400
break;
13981401
}
1402+
$list[] = null;
13991403
}
14001404
}
14011405
}
@@ -1413,6 +1417,16 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
14131417
break;
14141418
}
14151419
$specs[$num + 1] = "$label";
1420+
1421+
$l = fopen(__DIR__ . "/zend_vm_handlers.h", "w+") or die("ERROR: Cannot create zend_vm_handlers.h\n");
1422+
out($l, "#define VM_HANDLERS(_) \\\n");
1423+
foreach ($list as $n => $name) {
1424+
if (!is_null($name)) {
1425+
out($l, "\t_($n, $name) \\\n");
1426+
}
1427+
}
1428+
out($l, "\t_($n+1, ZEND_NULL)\n");
1429+
fclose($l);
14161430
}
14171431

14181432
// Generates specialized offsets
@@ -1658,6 +1672,7 @@ function gen_executor_code($f, $spec, $kind, $prolog, &$switch_labels = array())
16581672
out($f,"\t\t\t\topline = orig_opline;\n");
16591673
out($f,"\t\t\t\treturn;\n");
16601674
out($f,"\t\t\tHYBRID_DEFAULT:\n");
1675+
out($f,"\t\t\t\tVM_TRACE(ZEND_NULL)\n");
16611676
out($f,"\t\t\t\tZEND_NULL_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);\n");
16621677
out($f,"\t\t\t\tHYBRID_BREAK(); /* Never reached */\n");
16631678
break;

0 commit comments

Comments
 (0)