aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--examples/php-on-wasm/php-wasm.php14
-rw-r--r--src/Execution/Runtime.php20
2 files changed, 1 insertions, 33 deletions
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php
index c82862f..9072bf0 100644
--- a/examples/php-on-wasm/php-wasm.php
+++ b/examples/php-on-wasm/php-wasm.php
@@ -6,7 +6,6 @@ require_once __DIR__ . '/../../vendor/autoload.php';
use Nsfisis\Waddiwasi\BinaryFormat\Decoder;
use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException;
-use Nsfisis\Waddiwasi\Debug\Debug;
use Nsfisis\Waddiwasi\Execution\ExternVal;
use Nsfisis\Waddiwasi\Execution\FuncInst;
use Nsfisis\Waddiwasi\Execution\Refs;
@@ -26,16 +25,13 @@ EOS;
$wasmBinary = file_get_contents(__DIR__ . '/php-wasm.wasm');
\assert($wasmBinary !== false);
-fprintf(STDERR, "Decoding...\n");
try {
$module = (new Decoder($wasmBinary))->decode();
- // Debug::printImports($module);
} catch (InvalidBinaryFormatException $e) {
fprintf(STDERR, $e->getMessage() . "\n");
exit(1);
}
-fprintf(STDERR, "Instantiating...\n");
$hostFuncs = [
makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env__invoke_iii(...)),
makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)),
@@ -140,19 +136,11 @@ foreach ($hostFuncs as $hostFunc) {
$runtime = Runtime::instantiate($store, $module, $externVals);
$codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD);
-fprintf(STDERR, "Executing...\n");
$results = $runtime->invoke("php_wasm_run", [$codePtr]);
\assert(\count($results) === 1);
$exitCode = $results[0];
\assert(\is_int($exitCode));
-fprintf(STDERR, "Exit code: $exitCode\n");
-fprintf(STDERR, "Memory peak usage: %s\n", memory_get_peak_usage());
-fprintf(STDERR, "\n\n");
-foreach ($runtime->getInstrMetrics() as $instr => [$count, $time]) {
- fprintf(STDERR, "%s: %d %d %f\n", $instr, $time, $count, $time / $count);
-}
-
function allocateStringOnWasmMemory(Runtime $runtime, string $str): int
{
// Plus 1 for the null terminator in C.
@@ -788,8 +776,6 @@ function hostFunc__env____syscall_openat(Runtime $runtime): void
$mode = 0;
}
- // echo "syscall_openat: $path, $flags, $mode\n";
-
// no such file
$runtime->stack->pushValue(-44);
}
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php
index d47906e..3a67ec9 100644
--- a/src/Execution/Runtime.php
+++ b/src/Execution/Runtime.php
@@ -203,7 +203,6 @@ final class Runtime
private function doInvokeFunc(int $funcAddr): void
{
- // echo "Invoke: $funcAddr\n";
$fn = $this->store->funcs[$funcAddr];
if ($fn instanceof FuncInsts\Wasm) {
$this->doInvokeWasmFunc($fn, $funcAddr);
@@ -212,7 +211,6 @@ final class Runtime
} else {
throw new RuntimeException("doInvokeFunc: unreachable");
}
- // echo "Return: $funcAddr\n";
}
private function doInvokeWasmFunc(FuncInsts\Wasm $fn, int $funcAddr): void
@@ -325,12 +323,7 @@ final class Runtime
private function execInstr(Instr $instr): ?int
{
- static $debug = 0;
- // if ($debug >= 3) echo "Exec: " . $instr::opName() . "\n";
-
- // $startTime = hrtime(true);
-
- $result = match ($instr::class) {
+ return match ($instr::class) {
Instrs\Numeric\F32Abs::class => $this->execInstrNumericF32Abs($instr),
Instrs\Numeric\F32Add::class => $this->execInstrNumericF32Add($instr),
Instrs\Numeric\F32Ceil::class => $this->execInstrNumericF32Ceil($instr),
@@ -537,12 +530,6 @@ final class Runtime
Instrs\Control\Unreachable::class => $this->execInstrControlUnreachable($instr),
default => throw new RuntimeException("invalid instruction"),
};
-
- // $this->instrMetrics[$instr::opName()] ??= [0, 0];
- // $this->instrMetrics[$instr::opName()][0] += 1;
- // $this->instrMetrics[$instr::opName()][1] += hrtime(true) - $startTime;
-
- return $result;
}
private function execInstrNumericF32Abs(Instrs\Numeric\F32Abs $instr): void
@@ -2186,11 +2173,6 @@ final class Runtime
} elseif ($result === 0) {
if ($n === 1) {
if ($this->stack->top() instanceof Label) {
- // echo "loop: top is label\n";
- // echo " f: " . $f->debugName . "\n";
- // foreach ($instrs as $instr) {
- // echo " " . $instr::opName() . "\n";
- // }
// WORKAROUND:
$this->stack->pushValue(0);
}