Skip to content

Commit

Permalink
Allow generation of VM map
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Feb 22, 2018
1 parent 0c0a5df commit 6fb9e24
Show file tree
Hide file tree
Showing 5 changed files with 2,165 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -3189,6 +3189,8 @@ ZEND_API int ZEND_FASTCALL zend_do_fcall_overloaded(zend_execute_data *call, zva

#ifdef ZEND_VM_TRACE_HANDLERS
# include "zend_vm_trace_handlers.h"
#elif defined(ZEND_VM_TRACE_MAP)
# include "zend_vm_trace_map.h"
#endif

#define ZEND_VM_NEXT_OPCODE_EX(check_exception, skip) \
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_vm_execute.h
Original file line number Diff line number Diff line change
Expand Up @@ -60078,6 +60078,7 @@ ZEND_API void execute_ex(zend_execute_data *ex)
opline = orig_opline;
return;
HYBRID_DEFAULT:
VM_TRACE(ZEND_NULL)
ZEND_NULL_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);
HYBRID_BREAK(); /* Never reached */
#else
Expand Down
23 changes: 19 additions & 4 deletions Zend/zend_vm_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,7 @@ function gen_null_label($f, $kind, $prolog) {
function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()) {
global $opcodes, $op_types, $prefix, $op_types_ex;

$list = [];
$next = 0;
$label = 0;
if ($spec) {
Expand Down Expand Up @@ -1288,7 +1289,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
}
};
};
$generate = function ($op1, $op2, $extra_spec = array()) use ($f, $kind, $dsc, $prefix, $prolog, $num, $switch_labels, &$label) {
$generate = function ($op1, $op2, $extra_spec = array()) use ($f, $kind, $dsc, $prefix, $prolog, $num, $switch_labels, &$label, &$list) {
global $commutative_order;

// Check if specialized handler is defined
Expand All @@ -1298,6 +1299,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
(!isset($extra_spec["OP_DATA"]) || isset($dsc["spec"]["OP_DATA"][$extra_spec["OP_DATA"]]))) {
if (skip_extra_spec_function($op1, $op2, $extra_spec)) {
gen_null_label($f, $kind, $prolog);
$list[$label] = null;
$label++;
return;
}
Expand All @@ -1307,20 +1309,20 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
switch ($kind) {
case ZEND_VM_KIND_CALL:
out($f,"$prolog{$spec_name}_HANDLER,\n");
$label++;
break;
case ZEND_VM_KIND_SWITCH:
out($f,$prolog."(void*)(uintptr_t)$switch_labels[$spec_name],\n");
$label++;
break;
case ZEND_VM_KIND_GOTO:
out($f,$prolog."(void*)&&{$spec_name}_LABEL,\n");
$label++;
break;
}
$list[$label] = $spec_name;
$label++;
} else {
// Emit pointer to handler of undefined opcode
gen_null_label($f, $kind, $prolog);
$list[$label] = null;
$label++;
}
};
Expand Down Expand Up @@ -1384,6 +1386,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
out($f,$prolog."(void*)&&".$dsc["op"]."_LABEL,\n");
break;
}
$list[] = $dsc["op"];
} else {
switch ($kind) {
case ZEND_VM_KIND_CALL:
Expand All @@ -1396,6 +1399,7 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
out($f,$prolog."(void*)&&ZEND_NULL_LABEL,\n");
break;
}
$list[] = null;
}
}
}
Expand All @@ -1413,6 +1417,16 @@ function gen_labels($f, $spec, $kind, $prolog, &$specs, $switch_labels = array()
break;
}
$specs[$num + 1] = "$label";

$l = fopen(__DIR__ . "/zend_vm_handlers.h", "w+") or die("ERROR: Cannot create zend_vm_handlers.h\n");
out($l, "#define VM_HANDLERS(_) \\\n");
foreach ($list as $n => $name) {
if (!is_null($name)) {
out($l, "\t_($n, $name) \\\n");
}
}
out($l, "\t_($n+1, ZEND_NULL)\n");
fclose($l);
}

// Generates specialized offsets
Expand Down Expand Up @@ -1658,6 +1672,7 @@ function gen_executor_code($f, $spec, $kind, $prolog, &$switch_labels = array())
out($f,"\t\t\t\topline = orig_opline;\n");
out($f,"\t\t\t\treturn;\n");
out($f,"\t\t\tHYBRID_DEFAULT:\n");
out($f,"\t\t\t\tVM_TRACE(ZEND_NULL)\n");
out($f,"\t\t\t\tZEND_NULL_HANDLER(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU);\n");
out($f,"\t\t\t\tHYBRID_BREAK(); /* Never reached */\n");
break;
Expand Down
Loading

0 comments on commit 6fb9e24

Please sign in to comment.