Merge branch 'feature/debug-output' into develop
This commit is contained in:
commit
1f27b99284
27 files changed
+185
-75
No files matched your search
@@ -3,7 +3,8 @@ param(
|
|||||||
[switch]$Test,
|
[switch]$Test,
|
||||||
[switch]$Clean,
|
[switch]$Clean,
|
||||||
[switch]$Run,
|
[switch]$Run,
|
||||||
[switch]$Help
|
[switch]$Help,
|
||||||
|
[switch]$Debug
|
||||||
)
|
)
|
||||||
|
|
||||||
# Also accept positional string args (e.g. .\build.ps1 clean test run)
|
# Also accept positional string args (e.g. .\build.ps1 clean test run)
|
||||||
@@ -12,6 +13,7 @@ foreach ($a in $args) {
|
|||||||
'test' { $Test = $true }
|
'test' { $Test = $true }
|
||||||
'clean' { $Clean = $true }
|
'clean' { $Clean = $true }
|
||||||
'run' { $Run = $true }
|
'run' { $Run = $true }
|
||||||
|
'debug' { $Debug = $true }
|
||||||
'help' { $Help = $true }
|
'help' { $Help = $true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -22,6 +24,7 @@ if ($Help) {
|
|||||||
Write-Host ' test - Build with tests enabled'
|
Write-Host ' test - Build with tests enabled'
|
||||||
Write-Host ' clean - Clean build outputs'
|
Write-Host ' clean - Clean build outputs'
|
||||||
Write-Host ' run - Run the built executable after building'
|
Write-Host ' run - Run the built executable after building'
|
||||||
|
Write-Host ' debug - Build with debug info and assertions enabled'
|
||||||
Write-Host ' help - Show this help message'
|
Write-Host ' help - Show this help message'
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
@@ -38,7 +41,6 @@ if ($Clean) {
|
|||||||
if (Test-Path $Bin) { Remove-Item $Bin -Recurse -Force }
|
if (Test-Path $Bin) { Remove-Item $Bin -Recurse -Force }
|
||||||
if (Test-Path $Lib) { Remove-Item $Lib -Recurse -Force }
|
if (Test-Path $Lib) { Remove-Item $Lib -Recurse -Force }
|
||||||
Write-Host 'Clean complete.'
|
Write-Host 'Clean complete.'
|
||||||
if (-not $Test -and -not $Run) { exit 0 }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (-not (Test-Path $Bin)) { New-Item $Bin -ItemType Directory | Out-Null }
|
if (-not (Test-Path $Bin)) { New-Item $Bin -ItemType Directory | Out-Null }
|
||||||
@@ -50,7 +52,8 @@ if ($LASTEXITCODE -ne 0) { exit 1 }
|
|||||||
|
|
||||||
# ── Build ────────────────────────────────────────────────────────────
|
# ── Build ────────────────────────────────────────────────────────────
|
||||||
$TestFlags = @()
|
$TestFlags = @()
|
||||||
if ($Test) { $TestFlags = @('-dRUN_TESTS') }
|
if ($Test) { $TestFlags += '-dRUN_TESTS' }
|
||||||
|
if ($Debug) { $TestFlags += '-dDEBUG_OUTPUT' }
|
||||||
|
|
||||||
$fpcArgs = @(
|
$fpcArgs = @(
|
||||||
$TestFlags
|
$TestFlags
|
||||||
@@ -73,6 +76,8 @@ $fpcArgs = @(
|
|||||||
"$Src\project\WASURO.lpr"
|
"$Src\project\WASURO.lpr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Write-Output $fpcArgs
|
||||||
|
|
||||||
& $FPC @fpcArgs
|
& $FPC @fpcArgs
|
||||||
if ($LASTEXITCODE -ne 0) {
|
if ($LASTEXITCODE -ne 0) {
|
||||||
Write-Host "Build failed with error code $LASTEXITCODE"
|
Write-Host "Build failed with error code $LASTEXITCODE"
|
||||||
|
|||||||
@@ -45,3 +45,4 @@ if ($ruleHits -gt 0) {
|
|||||||
# ── Add more rules here ─────────────────────────────────────────────
|
# ── Add more rules here ─────────────────────────────────────────────
|
||||||
if ($fail) { exit 1 }
|
if ($fail) { exit 1 }
|
||||||
Write-Host 'Lint passed.'
|
Write-Host 'Lint passed.'
|
||||||
|
exit 0
|
||||||
+43
-18
@@ -5,12 +5,11 @@ uses
|
|||||||
|
|
||||||
console,
|
console,
|
||||||
|
|
||||||
types,
|
wasm.types.builtin,
|
||||||
|
|
||||||
wasm.types.context,
|
wasm.types.context,
|
||||||
|
wasm.types.stack,
|
||||||
wasm.parser,
|
wasm.parser,
|
||||||
wasm.vm, wasm.test.binary.return42,
|
wasm.vm
|
||||||
wasm.types.stack
|
|
||||||
{$IFDEF RUN_TESTS}
|
{$IFDEF RUN_TESTS}
|
||||||
, wasm.test
|
, wasm.test
|
||||||
, wasm.test.framework
|
, wasm.test.framework
|
||||||
@@ -19,6 +18,9 @@ uses
|
|||||||
|
|
||||||
var
|
var
|
||||||
Context : PWASMProcessContext;
|
Context : PWASMProcessContext;
|
||||||
|
ModuleSize : Int64;
|
||||||
|
ModuleBuffer : TWASMPUInt8;
|
||||||
|
ModuleFile : File;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$IFDEF RUN_TESTS}
|
{$IFDEF RUN_TESTS}
|
||||||
@@ -26,22 +28,45 @@ begin
|
|||||||
wasm.test.run_all_tests;
|
wasm.test.run_all_tests;
|
||||||
halt(wasm.test.framework.FailedTests);
|
halt(wasm.test.framework.FailedTests);
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
writestringln('[main] Initializing VM');
|
console.writestringln('WASURO - WebAssembly Runtime in Object Pascal');
|
||||||
wasm.vm.init();
|
wasm.vm.init();
|
||||||
|
if ParamCount > 0 then begin
|
||||||
writestringln('[main] Parsing WASM Binary');
|
if not FileExists(ParamStr(1)) then begin
|
||||||
Context:= wasm.parser.parse(@wasm.test.binary.return42.BINARY[0], puint8(@wasm.test.binary.return42.BINARY[0] + wasm.test.binary.return42.BINARY_SIZE));
|
console.writestringln('File not found.');
|
||||||
|
halt(1);
|
||||||
writestringln('[main] Running...');
|
end;
|
||||||
Context^.ExecutionState.Running:= true;
|
Assign(ModuleFile, ParamStr(1));
|
||||||
while (wasm.vm.tick(Context)) do;
|
Reset(ModuleFile, 1);
|
||||||
writestringln('[main] Finished Execution');
|
ModuleSize := FileSize(ModuleFile);
|
||||||
writestring('[main] Returns: ');
|
GetMem(ModuleBuffer, ModuleSize);
|
||||||
while Context^.ExecutionState.Operand_Stack^.Top > 0 do begin
|
BlockRead(ModuleFile, ModuleBuffer^, ModuleSize);
|
||||||
write(wasm.types.stack.popi32(Context^.ExecutionState.Operand_Stack),', ');
|
Close(ModuleFile);
|
||||||
|
console.writestringln('Module loaded.');
|
||||||
|
Context := wasm.parser.parse(ModuleBuffer, TWASMPUInt8(ModuleBuffer + ModuleSize));
|
||||||
|
while wasm.vm.tick(Context) do ;
|
||||||
|
console.writestringln('Execution finished.');
|
||||||
|
console.writestringln('');
|
||||||
|
console.writestringln('--- VM State ---');
|
||||||
|
writeln('IP: ', Context^.ExecutionState.IP);
|
||||||
|
writeln('Running: ', Context^.ExecutionState.Running);
|
||||||
|
writeln('');
|
||||||
|
writeln('Operand Stack (', Context^.ExecutionState.Operand_Stack^.Top, ' entries):');
|
||||||
|
if Context^.ExecutionState.Operand_Stack^.Top > 0 then
|
||||||
|
wasm.types.stack.walk(Context^.ExecutionState.Operand_Stack)
|
||||||
|
else
|
||||||
|
console.writestringln(' (empty)');
|
||||||
|
writeln('');
|
||||||
|
writeln('Control Stack (', Context^.ExecutionState.Control_Stack^.Top, ' entries):');
|
||||||
|
if Context^.ExecutionState.Control_Stack^.Top > 0 then
|
||||||
|
wasm.types.stack.walk(Context^.ExecutionState.Control_Stack)
|
||||||
|
else
|
||||||
|
console.writestringln(' (empty)');
|
||||||
|
console.writestringln('----------------');
|
||||||
|
FreeMem(ModuleBuffer);
|
||||||
|
end else begin
|
||||||
|
console.writestringln('Usage: WASURO <module.wasm>');
|
||||||
|
halt(1);
|
||||||
end;
|
end;
|
||||||
writeln();
|
|
||||||
while true do sleep(1000);
|
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@@ -72,8 +72,10 @@ var
|
|||||||
totalSize: TWASMUInt32;
|
totalSize: TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Code - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Code - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// Initialize the read/end pointers
|
// Initialize the read/end pointers
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
@@ -183,8 +185,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -12,8 +12,12 @@ implementation
|
|||||||
|
|
||||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
{ Custom sections are ignored in this implementation }
|
||||||
|
console.writestringln('[wasm.parser] TODO: Custom section skipped.');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -20,8 +20,10 @@ var
|
|||||||
bytesRead : TWASMUInt8;
|
bytesRead : TWASMUInt8;
|
||||||
dataCount : TWASMUInt32;
|
dataCount : TWASMUInt32;
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: DataCount - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: DataCount - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := TWASMPUInt8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
@@ -29,8 +31,10 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, bend, @dataCount);
|
bytesRead := read_leb128_to_uint32(pos, bend, @dataCount);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Data Count: ');
|
writestring('[wasm.parser] Data Count: ');
|
||||||
writeintlnWND(dataCount, 0);
|
writeintlnWND(dataCount, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Pre-allocate data segment storage with correct count.
|
{ Pre-allocate data segment storage with correct count.
|
||||||
The actual segment data will be filled when the Data section is parsed. }
|
The actual segment data will be filled when the Data section is parsed. }
|
||||||
|
|||||||
@@ -25,8 +25,10 @@ var
|
|||||||
segData : TWASMPUInt8;
|
segData : TWASMPUInt8;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Data - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Data - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := TWASMPUInt8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
@@ -74,12 +76,14 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, bend, @dataSize);
|
bytesRead := read_leb128_to_uint32(pos, bend, @dataSize);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Data Segment ');
|
writestring('[wasm.parser] Data Segment ');
|
||||||
writeintWND(i, 0);
|
writeintWND(i, 0);
|
||||||
writestring(' - Mode: 0 Offset: ');
|
writestring(' - Mode: 0 Offset: ');
|
||||||
writeintWND(offset, 0);
|
writeintWND(offset, 0);
|
||||||
writestring(' Size: ');
|
writestring(' Size: ');
|
||||||
writeintlnWND(dataSize, 0);
|
writeintlnWND(dataSize, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Store segment data for bulk memory ops }
|
{ Store segment data for bulk memory ops }
|
||||||
segData := TWASMPUInt8(kalloc(dataSize));
|
segData := TWASMPUInt8(kalloc(dataSize));
|
||||||
@@ -100,10 +104,12 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, bend, @dataSize);
|
bytesRead := read_leb128_to_uint32(pos, bend, @dataSize);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Data Segment ');
|
writestring('[wasm.parser] Data Segment ');
|
||||||
writeintWND(i, 0);
|
writeintWND(i, 0);
|
||||||
writestring(' - Mode: 1 (passive) Size: ');
|
writestring(' - Mode: 1 (passive) Size: ');
|
||||||
writeintlnWND(dataSize, 0);
|
writeintlnWND(dataSize, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Store segment data for bulk memory ops }
|
{ Store segment data for bulk memory ops }
|
||||||
segData := TWASMPUInt8(kalloc(dataSize));
|
segData := TWASMPUInt8(kalloc(dataSize));
|
||||||
@@ -140,6 +146,7 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, bend, @dataSize);
|
bytesRead := read_leb128_to_uint32(pos, bend, @dataSize);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Data Segment ');
|
writestring('[wasm.parser] Data Segment ');
|
||||||
writeintWND(i, 0);
|
writeintWND(i, 0);
|
||||||
writestring(' - Mode: 2 MemIdx: ');
|
writestring(' - Mode: 2 MemIdx: ');
|
||||||
@@ -148,6 +155,7 @@ begin
|
|||||||
writeintWND(offset, 0);
|
writeintWND(offset, 0);
|
||||||
writestring(' Size: ');
|
writestring(' Size: ');
|
||||||
writeintlnWND(dataSize, 0);
|
writeintlnWND(dataSize, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Store segment data for bulk memory ops }
|
{ Store segment data for bulk memory ops }
|
||||||
segData := TWASMPUInt8(kalloc(dataSize));
|
segData := TWASMPUInt8(kalloc(dataSize));
|
||||||
|
|||||||
@@ -23,8 +23,10 @@ var
|
|||||||
tables: PWASMTables;
|
tables: PWASMTables;
|
||||||
indices: TWASMPUInt32;
|
indices: TWASMPUInt32;
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Element - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Element - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
buf_end := buffer;
|
buf_end := buffer;
|
||||||
@@ -33,8 +35,10 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, buf_end, @seg_count);
|
bytesRead := read_leb128_to_uint32(pos, buf_end, @seg_count);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Element Segments: ');
|
writestring('[wasm.parser] Element Segments: ');
|
||||||
writeintlnWND(seg_count, 0);
|
writeintlnWND(seg_count, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
tables := ctx^.ExecutionState.Tables;
|
tables := ctx^.ExecutionState.Tables;
|
||||||
|
|
||||||
@@ -75,12 +79,14 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, buf_end, @func_count);
|
bytesRead := read_leb128_to_uint32(pos, buf_end, @func_count);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Segment ');
|
writestring('[wasm.parser] Segment ');
|
||||||
writeintWND(i, 0);
|
writeintWND(i, 0);
|
||||||
writestring(' - Mode: 0 Offset: ');
|
writestring(' - Mode: 0 Offset: ');
|
||||||
writeintWND(offset, 0);
|
writeintWND(offset, 0);
|
||||||
writestring(' Functions: ');
|
writestring(' Functions: ');
|
||||||
writeintlnWND(func_count, 0);
|
writeintlnWND(func_count, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Store segment data }
|
{ Store segment data }
|
||||||
indices := TWASMPUInt32(kalloc(func_count * sizeof(TWASMUInt32)));
|
indices := TWASMPUInt32(kalloc(func_count * sizeof(TWASMUInt32)));
|
||||||
@@ -112,12 +118,14 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, buf_end, @func_count);
|
bytesRead := read_leb128_to_uint32(pos, buf_end, @func_count);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Segment ');
|
writestring('[wasm.parser] Segment ');
|
||||||
writeintWND(i, 0);
|
writeintWND(i, 0);
|
||||||
writestring(' - Mode: 1 (passive) Kind: ');
|
writestring(' - Mode: 1 (passive) Kind: ');
|
||||||
writeintWND(elem_kind, 0);
|
writeintWND(elem_kind, 0);
|
||||||
writestring(' Functions: ');
|
writestring(' Functions: ');
|
||||||
writeintlnWND(func_count, 0);
|
writeintlnWND(func_count, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
indices := TWASMPUInt32(kalloc(func_count * sizeof(TWASMUInt32)));
|
indices := TWASMPUInt32(kalloc(func_count * sizeof(TWASMUInt32)));
|
||||||
for j := 0 to func_count - 1 do begin
|
for j := 0 to func_count - 1 do begin
|
||||||
@@ -153,6 +161,7 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, buf_end, @func_count);
|
bytesRead := read_leb128_to_uint32(pos, buf_end, @func_count);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Segment ');
|
writestring('[wasm.parser] Segment ');
|
||||||
writeintWND(i, 0);
|
writeintWND(i, 0);
|
||||||
writestring(' - Mode: 2 Table: ');
|
writestring(' - Mode: 2 Table: ');
|
||||||
@@ -161,6 +170,7 @@ begin
|
|||||||
writeintWND(offset, 0);
|
writeintWND(offset, 0);
|
||||||
writestring(' Functions: ');
|
writestring(' Functions: ');
|
||||||
writeintlnWND(func_count, 0);
|
writeintlnWND(func_count, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
indices := TWASMPUInt32(kalloc(func_count * sizeof(TWASMUInt32)));
|
indices := TWASMPUInt32(kalloc(func_count * sizeof(TWASMUInt32)));
|
||||||
for j := 0 to func_count - 1 do begin
|
for j := 0 to func_count - 1 do begin
|
||||||
|
|||||||
@@ -36,8 +36,10 @@ var
|
|||||||
i,j : TWASMUInt32;
|
i,j : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Export - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Export - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// Initialize the read/end pointers
|
// Initialize the read/end pointers
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
@@ -85,8 +87,9 @@ begin
|
|||||||
inc(pos, bytesRead);
|
inc(pos, bytesRead);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -32,8 +32,10 @@ var
|
|||||||
i : TWASMUInt32;
|
i : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Function - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Function - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// Initialize the read/end pointers
|
// Initialize the read/end pointers
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
@@ -64,8 +66,9 @@ begin
|
|||||||
inc(pos, bytesRead);
|
inc(pos, bytesRead);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -49,8 +49,10 @@ var
|
|||||||
tmpU64 : TWASMUInt64;
|
tmpU64 : TWASMUInt64;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Global - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Global - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := TWASMPUInt8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
@@ -115,8 +117,9 @@ begin
|
|||||||
if (pos < bend) and (pos^ = $0B) then
|
if (pos < bend) and (pos^ = $0B) then
|
||||||
Inc(pos);
|
Inc(pos);
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -71,8 +71,10 @@ var
|
|||||||
i, j : TWASMUInt32;
|
i, j : TWASMUInt32;
|
||||||
limitsFlag : TWASMUInt8;
|
limitsFlag : TWASMUInt8;
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Import - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Import - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := TWASMPUInt8(pos + section_length);
|
bend := TWASMPUInt8(pos + section_length);
|
||||||
@@ -84,8 +86,10 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, bend, @ctx^.Sections.ImportSection^.ImportCount);
|
bytesRead := read_leb128_to_uint32(pos, bend, @ctx^.Sections.ImportSection^.ImportCount);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Import Count: ');
|
writestring('[wasm.parser] Import Count: ');
|
||||||
writeintlnWND(ctx^.Sections.ImportSection^.ImportCount, 0);
|
writeintlnWND(ctx^.Sections.ImportSection^.ImportCount, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
if ctx^.Sections.ImportSection^.ImportCount > 0 then begin
|
if ctx^.Sections.ImportSection^.ImportCount > 0 then begin
|
||||||
{ Allocate entries }
|
{ Allocate entries }
|
||||||
@@ -165,8 +169,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -39,8 +39,10 @@ var
|
|||||||
flags : TWASMUInt32;
|
flags : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := TWASMPUInt8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
@@ -77,8 +79,9 @@ begin
|
|||||||
while ctx^.ExecutionState.Memory^.PageCount < mem^.InitialPages do
|
while ctx^.ExecutionState.Memory^.PageCount < mem^.InitialPages do
|
||||||
wasm.types.heap.expand_heap(ctx^.ExecutionState.Memory);
|
wasm.types.heap.expand_heap(ctx^.ExecutionState.Memory);
|
||||||
end;
|
end;
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -16,15 +16,19 @@ var
|
|||||||
funcIdx : TWASMUInt32;
|
funcIdx : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Start - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Start - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
{ Read the start function index }
|
{ Read the start function index }
|
||||||
bytesRead := read_leb128_to_uint32(buffer, TWASMPUInt8(buffer + section_length), @funcIdx);
|
bytesRead := read_leb128_to_uint32(buffer, TWASMPUInt8(buffer + section_length), @funcIdx);
|
||||||
ctx^.Sections.StartIndex := TWASMInt32(funcIdx);
|
ctx^.Sections.StartIndex := TWASMInt32(funcIdx);
|
||||||
|
|
||||||
writestring('[wasm.parser] Start Function Index: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(funcIdx, 0);
|
console.writestring('[wasm.parser] Start Function Index: ');
|
||||||
|
console.writeintlnWND(funcIdx, 0);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -19,8 +19,10 @@ var
|
|||||||
elem_type, limits_flag: TWASMUInt8;
|
elem_type, limits_flag: TWASMUInt8;
|
||||||
tables: PWASMTables;
|
tables: PWASMTables;
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Table - Size: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(section_length, 0);
|
console.writestring('[wasm.parser] Handle Section: Table - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
buf_end := buffer;
|
buf_end := buffer;
|
||||||
@@ -29,8 +31,10 @@ begin
|
|||||||
bytesRead := read_leb128_to_uint32(pos, buf_end, @table_count);
|
bytesRead := read_leb128_to_uint32(pos, buf_end, @table_count);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
|
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writestring('[wasm.parser] Tables: ');
|
writestring('[wasm.parser] Tables: ');
|
||||||
writeintlnWND(table_count, 0);
|
writeintlnWND(table_count, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
tables := ctx^.ExecutionState.Tables;
|
tables := ctx^.ExecutionState.Tables;
|
||||||
tables^.TableCount := table_count;
|
tables^.TableCount := table_count;
|
||||||
@@ -55,17 +59,19 @@ begin
|
|||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
writestring('[wasm.parser] Table ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintWND(i, 0);
|
console.writestring('[wasm.parser] Table ');
|
||||||
writestring(' - ElemType: $');
|
console.writeintWND(i, 0);
|
||||||
writeintWND(elem_type, 0);
|
console.writestring(' - ElemType: $');
|
||||||
writestring(' Initial: ');
|
console.writeintWND(elem_type, 0);
|
||||||
writeintWND(min_size, 0);
|
console.writestring(' Initial: ');
|
||||||
|
console.writeintWND(min_size, 0);
|
||||||
if limits_flag = 1 then begin
|
if limits_flag = 1 then begin
|
||||||
writestring(' Max: ');
|
console.writestring(' Max: ');
|
||||||
writeintWND(max_size, 0);
|
console.writeintWND(max_size, 0);
|
||||||
end;
|
end;
|
||||||
writestringln('');
|
console.writestringln('');
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
tables^.Tables[i].ElementType := elem_type;
|
tables^.Tables[i].ElementType := elem_type;
|
||||||
tables^.Tables[i].Size := min_size;
|
tables^.Tables[i].Size := min_size;
|
||||||
|
|||||||
@@ -59,8 +59,11 @@ var
|
|||||||
i, parsedTypes : TWASMUInt32;
|
i, parsedTypes : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Type - Size: ');
|
|
||||||
writeintlnWND(section_length, 0);
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
|
console.writestring('[wasm.parser] Handle Section: Type - Size: ');
|
||||||
|
console.writeintlnWND(section_length, 0);
|
||||||
|
{$ENDIF}
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
|
|
||||||
// Initialize the type section
|
// Initialize the type section
|
||||||
@@ -118,7 +121,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Walk the wasm.types.builtin
|
// Walk the wasm.types.builtin
|
||||||
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
@@ -79,11 +79,15 @@ begin
|
|||||||
ctx:= newContext();
|
ctx:= newContext();
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
|
|
||||||
writestringln('[wasm.parser] Parsing WASM Binary');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
|
console.writestringln('[wasm.parser] Starting parse of WASM binary.');
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// Check for the WASM Magic
|
// Check for the WASM Magic
|
||||||
if(TWASMPUInt32(pos)^ = wasm.types.constants.WASM_HDR_MAGIC) then begin
|
if(TWASMPUInt32(pos)^ = wasm.types.constants.WASM_HDR_MAGIC) then begin
|
||||||
writestringln('[wasm.parser] Binary is valid.');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
|
console.writestringln('[wasm.parser] Binary is valid.');
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// Set binary to valid
|
// Set binary to valid
|
||||||
ctx^.ValidBinary:= true;
|
ctx^.ValidBinary:= true;
|
||||||
@@ -92,8 +96,10 @@ begin
|
|||||||
// Read the version
|
// Read the version
|
||||||
ctx^.Version:= TWASMPUInt32(pos)^;
|
ctx^.Version:= TWASMPUInt32(pos)^;
|
||||||
inc(pos, 4);
|
inc(pos, 4);
|
||||||
writestring('[wasm.parser] Version: ');
|
{$IFDEF DEBUG_OUTPUT}
|
||||||
writeintlnWND(ctx^.Version, 0);
|
console.writestring('[wasm.parser] Version: ');
|
||||||
|
console.writeintlnWND(ctx^.Version, 0);
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
// Read the sections
|
// Read the sections
|
||||||
while (pos < buffer_end) do begin
|
while (pos < buffer_end) do begin
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ begin
|
|||||||
code[0] := $A0;
|
code[0] := $A0;
|
||||||
ctx := make_test_context(@code[0], 1);
|
ctx := make_test_context(@code[0], 1);
|
||||||
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@nanBits)^);
|
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@nanBits)^);
|
||||||
nanBits := $FFF0000000000000;
|
nanBits := TWASMUInt64($FFF0000000000000);
|
||||||
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@nanBits)^);
|
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@nanBits)^);
|
||||||
wasm.vm.tick(ctx);
|
wasm.vm.tick(ctx);
|
||||||
resultVal := popf64(ctx^.ExecutionState.Operand_Stack);
|
resultVal := popf64(ctx^.ExecutionState.Operand_Stack);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ begin
|
|||||||
assert_true('ceil(+Inf)=+Inf', resultBits = $7FF0000000000000);
|
assert_true('ceil(+Inf)=+Inf', resultBits = $7FF0000000000000);
|
||||||
|
|
||||||
{ Infinity: ceil(-Inf) = -Inf }
|
{ Infinity: ceil(-Inf) = -Inf }
|
||||||
nanBits := $FFF0000000000000;
|
nanBits := TWASMUInt64($FFF0000000000000);
|
||||||
code[0] := $9B;
|
code[0] := $9B;
|
||||||
ctx := make_test_context(@code[0], 1);
|
ctx := make_test_context(@code[0], 1);
|
||||||
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@nanBits)^);
|
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@nanBits)^);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ begin
|
|||||||
assert_u64('max(NaN,1.0) is NaN', resultBits and $7FF8000000000000, $7FF8000000000000);
|
assert_u64('max(NaN,1.0) is NaN', resultBits and $7FF8000000000000, $7FF8000000000000);
|
||||||
|
|
||||||
{ max(-0.0, +0.0) = +0.0 }
|
{ max(-0.0, +0.0) = +0.0 }
|
||||||
negZero := $8000000000000000;
|
negZero := TWASMUInt64($8000000000000000);
|
||||||
code[0] := $A5;
|
code[0] := $A5;
|
||||||
ctx := make_test_context(@code[0], 1);
|
ctx := make_test_context(@code[0], 1);
|
||||||
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@negZero)^);
|
pushf64(ctx^.ExecutionState.Operand_Stack, TWASMPDouble(@negZero)^);
|
||||||
|
|||||||
Loaded 20 of 27 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user