Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6794c52a77 | ||
|
|
7cc4459dfd | ||
|
|
ae344e7495 | ||
|
|
430ebcd203 |
No files matched your search
@@ -13,6 +13,10 @@ if "%1"=="test" set TESTFLAGS=-dRUN_TESTS
|
||||
if not exist "%BIN%" mkdir "%BIN%"
|
||||
if not exist "%LIB%" mkdir "%LIB%"
|
||||
|
||||
REM ── Lint ────────────────────────────────────────────────────────────
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT%lint.ps1" -SrcRoot "%SRC%"
|
||||
if %ERRORLEVEL% NEQ 0 exit /b 1
|
||||
|
||||
"%FPC%" ^
|
||||
%TESTFLAGS% ^
|
||||
-FE"%BIN%" ^
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
# lint.ps1 — Static lint rules for the WASURO project
|
||||
# Called by build.bat before compilation. Exit 1 on any violation.
|
||||
param(
|
||||
[string]$SrcRoot = (Join-Path $PSScriptRoot 'src')
|
||||
)
|
||||
|
||||
$fail = $false
|
||||
|
||||
# ── Rule: No native types in src\wasm ────────────────────────────────
|
||||
# All code under src\wasm must use TWASM* aliases from wasm.types.builtin.
|
||||
# Only wasm.types.builtin.pas itself may reference the raw types.
|
||||
$forbiddenTypes = @(
|
||||
'uint8','uint16','uint32','uint64',
|
||||
'sint8','sint16',
|
||||
'int32','int64',
|
||||
'float','double',
|
||||
'puint8','puint16','puint32','puint64',
|
||||
'pfloat','pdouble','pchar',
|
||||
'boolean','char','void','integer'
|
||||
)
|
||||
$pattern = '(?i)(?<![a-z0-9_])(' + ($forbiddenTypes -join '|') + ')(?![a-z0-9_])'
|
||||
|
||||
$files = Get-ChildItem (Join-Path $SrcRoot 'wasm') -Recurse -Filter '*.pas' |
|
||||
Where-Object { $_.Name -ne 'wasm.types.builtin.pas' }
|
||||
|
||||
$ruleHits = 0
|
||||
foreach ($file in $files) {
|
||||
$content = [IO.File]::ReadAllText($file.FullName)
|
||||
$matches = [regex]::Matches($content, $pattern)
|
||||
if ($matches.Count -gt 0) {
|
||||
$found = @{}
|
||||
foreach ($m in $matches) { $found[$m.Value.ToLower()] = $true }
|
||||
$list = ($found.Keys | Sort-Object) -join ', '
|
||||
Write-Host " $($file.Name): $list"
|
||||
$ruleHits++
|
||||
}
|
||||
}
|
||||
|
||||
if ($ruleHits -gt 0) {
|
||||
Write-Host ''
|
||||
Write-Host "Lint failed: $ruleHits file(s) use native types. Use TWASM* from wasm.types.builtin instead."
|
||||
$fail = $true
|
||||
}
|
||||
|
||||
# ── Add more rules here ─────────────────────────────────────────────
|
||||
|
||||
if ($fail) { exit 1 }
|
||||
Write-Host 'Lint passed.'
|
||||
@@ -3,16 +3,16 @@ unit wasm.parser.sections.codeSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure printCtxCode(ctx : PWASMProcessContext);
|
||||
var
|
||||
i : uint32;
|
||||
i : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Flat Code: ');
|
||||
@@ -25,15 +25,15 @@ end;
|
||||
|
||||
procedure walk(ctx : PWASMProcessContext);
|
||||
var
|
||||
localpos, pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
localpos, pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
currentEntry : PWASMCodeEntry;
|
||||
i,j,l : uint32;
|
||||
localCount,localTemp,localIndex : uint32;
|
||||
i,j,l : TWASMUInt32;
|
||||
localCount,localTemp,localIndex : TWASMUInt32;
|
||||
localType: TWasmValueType;
|
||||
codeLength: uint32;
|
||||
codeOffset: uint32;
|
||||
totalSize: uint32;
|
||||
codeLength: TWASMUInt32;
|
||||
codeOffset: TWASMUInt32;
|
||||
totalSize: TWASMUInt32;
|
||||
begin
|
||||
// Walk the code entries
|
||||
for i:=1 to ctx^.Sections.CodeSection^.CodeCount do begin
|
||||
@@ -59,17 +59,17 @@ begin
|
||||
end;
|
||||
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
localpos, pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
localpos, pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
currentEntry : PWASMCodeEntry;
|
||||
i,j,l : uint32;
|
||||
localCount,localTemp,localIndex : uint32;
|
||||
i,j,l : TWASMUInt32;
|
||||
localCount,localTemp,localIndex : TWASMUInt32;
|
||||
localType: TWasmValueType;
|
||||
codeLength: uint32;
|
||||
codeOffset: uint32;
|
||||
totalSize: uint32;
|
||||
codeLength: TWASMUInt32;
|
||||
codeOffset: TWASMUInt32;
|
||||
totalSize: TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Code - Size: ');
|
||||
@@ -77,7 +77,7 @@ begin
|
||||
|
||||
// Initialize the read/end pointers
|
||||
pos:= buffer;
|
||||
bend:= puint8(pos + section_length);
|
||||
bend:= TWASMPUInt8(pos + section_length);
|
||||
|
||||
// Initialize the code section
|
||||
ctx^.Sections.CodeSection:= PWASMCodeSection(kalloc(sizeof(TWASMCodeSection)));
|
||||
@@ -158,7 +158,7 @@ begin
|
||||
end;
|
||||
|
||||
// Read the code
|
||||
currentEntry^.Code:= puint8(kalloc(currentEntry^.CodeLength));
|
||||
currentEntry^.Code:= TWASMPUInt8(kalloc(currentEntry^.CodeLength));
|
||||
for j:=1 to currentEntry^.CodeLength do begin
|
||||
currentEntry^.Code[j - 1]:= pos^;
|
||||
inc(pos);
|
||||
@@ -171,12 +171,12 @@ begin
|
||||
totalSize:= totalSize + currentEntry^.CodeLength;
|
||||
end;
|
||||
|
||||
ctx^.ExecutionState.Code:= puint8(kalloc(totalSize));
|
||||
ctx^.ExecutionState.Code:= TWASMPUInt8(kalloc(totalSize));
|
||||
ctx^.ExecutionState.Limit:= totalSize;
|
||||
localpos:= ctx^.ExecutionState.Code;
|
||||
for i:=1 to ctx^.Sections.CodeSection^.CodeCount do begin
|
||||
currentEntry:= @ctx^.Sections.CodeSection^.Entries[i - 1];
|
||||
currentEntry^.CodeIndex:= uint32(localpos - ctx^.ExecutionState.Code);
|
||||
currentEntry^.CodeIndex:= TWASMUInt32(localpos - ctx^.ExecutionState.Code);
|
||||
for j:=1 to currentEntry^.CodeLength do begin
|
||||
localpos^:= currentEntry^.Code[j - 1];
|
||||
inc(localpos);
|
||||
|
||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.customSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
@@ -3,31 +3,31 @@ unit wasm.parser.sections.dataSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types, wasm.types.heap;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
segCount : uint32;
|
||||
i, j : uint32;
|
||||
memIdx : uint32;
|
||||
offset : uint32;
|
||||
dataSize : uint32;
|
||||
opcode : uint8;
|
||||
tmpU32 : uint32;
|
||||
pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
segCount : TWASMUInt32;
|
||||
i, j : TWASMUInt32;
|
||||
memIdx : TWASMUInt32;
|
||||
offset : TWASMUInt32;
|
||||
dataSize : TWASMUInt32;
|
||||
opcode : TWASMUInt8;
|
||||
tmpU32 : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Data - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
pos := buffer;
|
||||
bend := puint8(buffer + section_length);
|
||||
bend := TWASMPUInt8(buffer + section_length);
|
||||
|
||||
{ Read segment count }
|
||||
bytesRead := read_leb128_to_uint32(pos, bend, @segCount);
|
||||
|
||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.elementSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Element - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
@@ -3,17 +3,17 @@ unit wasm.parser.sections.exportSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure walk(ctx : PWASMProcessContext);
|
||||
var
|
||||
currentEntry : PWASMExportEntry;
|
||||
i : uint32;
|
||||
i : TWASMUInt32;
|
||||
|
||||
begin
|
||||
// Walk the export entries
|
||||
@@ -28,12 +28,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
currentEntry : PWASMExportEntry;
|
||||
i,j : uint32;
|
||||
i,j : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Export - Size: ');
|
||||
@@ -41,7 +41,7 @@ begin
|
||||
|
||||
// Initialize the read/end pointers
|
||||
pos:= buffer;
|
||||
bend:= puint8(pos + section_length);
|
||||
bend:= TWASMPUInt8(pos + section_length);
|
||||
|
||||
// Initialize the export section
|
||||
ctx^.Sections.ExportSection:= PWASMExportSection(kalloc(sizeof(TWASMExportSection)));
|
||||
@@ -69,12 +69,12 @@ begin
|
||||
inc(pos, bytesRead);
|
||||
|
||||
// Read the export name
|
||||
currentEntry^.Name:= pchar(kalloc(currentEntry^.NameLength + 1));
|
||||
currentEntry^.Name:= TWASMPChar(kalloc(currentEntry^.NameLength + 1));
|
||||
for j:=0 to currentEntry^.NameLength - 1 do begin
|
||||
currentEntry^.Name[j]:= char(pos^);
|
||||
currentEntry^.Name[j]:= TWASMChar(pos^);
|
||||
inc(pos);
|
||||
end;
|
||||
currentEntry^.Name[currentEntry^.NameLength]:= char($00);
|
||||
currentEntry^.Name[currentEntry^.NameLength]:= TWASMChar($00);
|
||||
|
||||
// Read the export type
|
||||
currentEntry^.ExportType:= TWasmExportType(pos^);
|
||||
|
||||
@@ -3,17 +3,17 @@ unit wasm.parser.sections.functionSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure walk(ctx : PWASMProcessContext);
|
||||
var
|
||||
currentFunc : PWASMFunction;
|
||||
i : uint32;
|
||||
i : TWASMUInt32;
|
||||
|
||||
begin
|
||||
// Walk the functions
|
||||
@@ -24,12 +24,12 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
currentFunc : PWASMFunction;
|
||||
i : uint32;
|
||||
i : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Function - Size: ');
|
||||
@@ -37,7 +37,7 @@ begin
|
||||
|
||||
// Initialize the read/end pointers
|
||||
pos:= buffer;
|
||||
bend:= puint8(pos + section_length);
|
||||
bend:= TWASMPUInt8(pos + section_length);
|
||||
|
||||
// Initialize the function section
|
||||
ctx^.Sections.FunctionSection:= PWASMFunctionSection(kalloc(sizeof(TWASMFunctionSection)));
|
||||
|
||||
@@ -3,16 +3,16 @@ unit wasm.parser.sections.globalSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure walk(ctx : PWASMProcessContext);
|
||||
var
|
||||
i : uint32;
|
||||
i : TWASMUInt32;
|
||||
entry : PWASMGlobalEntry;
|
||||
begin
|
||||
for i := 0 to ctx^.ExecutionState.Globals^.GlobalCount - 1 do begin
|
||||
@@ -35,25 +35,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
globalCount : uint32;
|
||||
i : uint32;
|
||||
pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
globalCount : TWASMUInt32;
|
||||
i : TWASMUInt32;
|
||||
entry : PWASMGlobalEntry;
|
||||
valType : uint8;
|
||||
mutFlag : uint8;
|
||||
opcode : uint8;
|
||||
tmpU32 : uint32;
|
||||
tmpU64 : uint64;
|
||||
valType : TWASMUInt8;
|
||||
mutFlag : TWASMUInt8;
|
||||
opcode : TWASMUInt8;
|
||||
tmpU32 : TWASMUInt32;
|
||||
tmpU64 : TWASMUInt64;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Global - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
pos := buffer;
|
||||
bend := puint8(buffer + section_length);
|
||||
bend := TWASMPUInt8(buffer + section_length);
|
||||
|
||||
{ Read global count }
|
||||
bytesRead := read_leb128_to_uint32(pos, bend, @globalCount);
|
||||
@@ -88,19 +88,19 @@ begin
|
||||
$41: begin { i32.const }
|
||||
bytesRead := read_leb128_to_uint32(pos, bend, @tmpU32);
|
||||
Inc(pos, bytesRead);
|
||||
entry^.Value.i32Value := int32(tmpU32);
|
||||
entry^.Value.i32Value := TWASMInt32(tmpU32);
|
||||
end;
|
||||
$42: begin { i64.const }
|
||||
bytesRead := read_leb128_to_uint64(pos, bend, @tmpU64);
|
||||
Inc(pos, bytesRead);
|
||||
entry^.Value.i64Value := int64(tmpU64);
|
||||
entry^.Value.i64Value := TWASMInt64(tmpU64);
|
||||
end;
|
||||
$43: begin { f32.const }
|
||||
entry^.Value.f32Value := pfloat(pos)^;
|
||||
entry^.Value.f32Value := TWASMPFloat(pos)^;
|
||||
Inc(pos, 4);
|
||||
end;
|
||||
$44: begin { f64.const }
|
||||
entry^.Value.f64Value := pdouble(pos)^;
|
||||
entry^.Value.f64Value := TWASMPDouble(pos)^;
|
||||
Inc(pos, 8);
|
||||
end;
|
||||
else
|
||||
|
||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.importSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Import - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
@@ -3,16 +3,16 @@ unit wasm.parser.sections.memorySection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types, wasm.types.heap;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure walk(ctx : PWASMProcessContext);
|
||||
var
|
||||
i : uint32;
|
||||
i : TWASMUInt32;
|
||||
mem : PWASMMemoryLimits;
|
||||
begin
|
||||
for i := 0 to ctx^.Sections.MemorySection^.MemoryCount - 1 do begin
|
||||
@@ -29,21 +29,21 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
pos, bend : puint8;
|
||||
bytesRead : uint8;
|
||||
memCount : uint32;
|
||||
i : uint32;
|
||||
pos, bend : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
memCount : TWASMUInt32;
|
||||
i : TWASMUInt32;
|
||||
mem : PWASMMemoryLimits;
|
||||
flags : uint32;
|
||||
flags : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
pos := buffer;
|
||||
bend := puint8(buffer + section_length);
|
||||
bend := TWASMPUInt8(buffer + section_length);
|
||||
|
||||
{ Read memory count }
|
||||
bytesRead := read_leb128_to_uint32(pos, bend, @memCount);
|
||||
|
||||
@@ -3,25 +3,25 @@ unit wasm.parser.sections.startSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
bytesRead : uint8;
|
||||
funcIdx : uint32;
|
||||
bytesRead : TWASMUInt8;
|
||||
funcIdx : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Start - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
{ Read the start function index }
|
||||
bytesRead := read_leb128_to_uint32(buffer, puint8(buffer + section_length), @funcIdx);
|
||||
ctx^.Sections.StartIndex := int32(funcIdx);
|
||||
bytesRead := read_leb128_to_uint32(buffer, TWASMPUInt8(buffer + section_length), @funcIdx);
|
||||
ctx^.Sections.StartIndex := TWASMInt32(funcIdx);
|
||||
|
||||
writestring('[wasm.parser] Start Function Index: ');
|
||||
writeintlnWND(funcIdx, 0);
|
||||
|
||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.tableSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Table - Size: ');
|
||||
writeintlnWND(section_length, 0);
|
||||
|
||||
@@ -3,10 +3,10 @@ unit wasm.parser.sections.typeSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
@@ -14,10 +14,10 @@ procedure walk(ctx : PWASMProcessContext);
|
||||
var
|
||||
currentType : PWASMType;
|
||||
currentParam : PWASMParam;
|
||||
i,j : uint32;
|
||||
i,j : TWASMUInt32;
|
||||
|
||||
begin
|
||||
// Walk the types
|
||||
// Walk the wasm.types.builtin
|
||||
for i:=1 to ctx^.Sections.TypeSection^.TypeCount do begin
|
||||
currentType:= @ctx^.Sections.TypeSection^.Types[i - 1];
|
||||
writestring('[wasm.parser] Index: ');
|
||||
@@ -50,13 +50,13 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
var
|
||||
pos : puint8;
|
||||
bytesRead : uint8;
|
||||
pos : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
currentType : PWASMType;
|
||||
currentParam : PWASMParam;
|
||||
i, parsedTypes : uint32;
|
||||
i, parsedTypes : TWASMUInt32;
|
||||
|
||||
begin
|
||||
writestring('[wasm.parser] Handle Section: Type - Size: ');
|
||||
@@ -67,31 +67,31 @@ begin
|
||||
ctx^.Sections.TypeSection:= PWASMTypeSection(kalloc(sizeof(TWASMTypeSection)));
|
||||
ctx^.Sections.TypeSection^.TypeCount:= 0;
|
||||
|
||||
// Read the number of function types
|
||||
bytesRead:= read_leb128_to_uint32(buffer, puint8(buffer + section_length), @ctx^.Sections.TypeSection^.TypeCount);
|
||||
// Read the number of function wasm.types.builtin
|
||||
bytesRead:= read_leb128_to_uint32(buffer, TWASMPUInt8(buffer + section_length), @ctx^.Sections.TypeSection^.TypeCount);
|
||||
inc(pos, bytesRead);
|
||||
|
||||
// Read the function types
|
||||
// Read the function wasm.types.builtin
|
||||
if(ctx^.Sections.TypeSection^.TypeCount > 0) then begin
|
||||
// Allocate the first type
|
||||
ctx^.Sections.TypeSection^.Types:= PWASMType(kalloc(sizeof(TWASMType) * ctx^.Sections.TypeSection^.TypeCount));
|
||||
|
||||
// Read the function types
|
||||
// Read the function wasm.types.builtin
|
||||
for parsedTypes:=1 to ctx^.Sections.TypeSection^.TypeCount do begin
|
||||
currentType:= @ctx^.Sections.TypeSection^.Types[parsedTypes - 1];
|
||||
|
||||
// Check if we are at the end of the buffer
|
||||
if pos >= puint8(buffer + section_length) then Exit;
|
||||
if pos >= TWASMPUInt8(buffer + section_length) then Exit;
|
||||
|
||||
// Read the function type
|
||||
currentType^._type:= pos^;
|
||||
inc(pos);
|
||||
|
||||
// Read the number of parameters
|
||||
bytesRead:= read_leb128_to_uint32(pos, puint8(buffer + section_length), @currentType^.ParamCount);
|
||||
bytesRead:= read_leb128_to_uint32(pos, TWASMPUInt8(buffer + section_length), @currentType^.ParamCount);
|
||||
inc(pos, bytesRead);
|
||||
|
||||
// Read the parameter types
|
||||
// Read the parameter wasm.types.builtin
|
||||
if(currentType^.ParamCount > 0) then begin
|
||||
currentType^.ParamTypes:= PWASMParam(kalloc(sizeof(TWASMParam) * currentType^.ParamCount));
|
||||
for i:=1 to currentType^.ParamCount do begin
|
||||
@@ -102,10 +102,10 @@ begin
|
||||
end;
|
||||
|
||||
// Read the number of return values
|
||||
bytesRead:= read_leb128_to_uint32(pos, puint8(buffer + section_length), @currentType^.ReturnCount);
|
||||
bytesRead:= read_leb128_to_uint32(pos, TWASMPUInt8(buffer + section_length), @currentType^.ReturnCount);
|
||||
inc(pos, bytesRead);
|
||||
|
||||
// Read the return types
|
||||
// Read the return wasm.types.builtin
|
||||
if(currentType^.ReturnCount > 0) then begin
|
||||
currentType^.ReturnTypes:= PWASMParam(kalloc(sizeof(TWASMParam) * currentType^.ReturnCount));
|
||||
for i:=1 to currentType^.ReturnCount do begin
|
||||
@@ -117,7 +117,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
// Walk the types
|
||||
// Walk the wasm.types.builtin
|
||||
walk(ctx);
|
||||
end;
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ unit wasm.parser;
|
||||
interface
|
||||
|
||||
uses
|
||||
types, lmemorymanager, console, leb128,
|
||||
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||
wasm.types, wasm.types.heap, wasm.types.stack,
|
||||
wasm.parser.sections;
|
||||
|
||||
function parse(buffer: puint8; buffer_end: puint8) : PWASMProcessContext;
|
||||
function parse(buffer: TWASMPUInt8; buffer_end: TWASMPUInt8) : PWASMProcessContext;
|
||||
|
||||
implementation
|
||||
|
||||
@@ -50,13 +50,13 @@ begin
|
||||
newContext:= ctx;
|
||||
end;
|
||||
|
||||
function parse(buffer: puint8; buffer_end: puint8): PWASMProcessContext;
|
||||
function parse(buffer: TWASMPUInt8; buffer_end: TWASMPUInt8): PWASMProcessContext;
|
||||
var
|
||||
ctx : PWASMProcessContext;
|
||||
pos : puint8;
|
||||
bytesRead : uint8;
|
||||
section_id : uint8;
|
||||
section_length : uint32;
|
||||
pos : TWASMPUInt8;
|
||||
bytesRead : TWASMUInt8;
|
||||
section_id : TWASMUInt8;
|
||||
section_length : TWASMUInt32;
|
||||
|
||||
begin
|
||||
// Allocate the context
|
||||
@@ -66,7 +66,7 @@ begin
|
||||
writestringln('[wasm.parser] Parsing WASM Binary');
|
||||
|
||||
// Check for the WASM Magic
|
||||
if(puint32(pos)^ = wasm.types.WASM_HDR_MAGIC) then begin
|
||||
if(TWASMPUInt32(pos)^ = wasm.types.WASM_HDR_MAGIC) then begin
|
||||
writestringln('[wasm.parser] Binary is valid.');
|
||||
|
||||
// Set binary to valid
|
||||
@@ -74,7 +74,7 @@ begin
|
||||
inc(pos, 4);
|
||||
|
||||
// Read the version
|
||||
ctx^.Version:= puint32(pos)^;
|
||||
ctx^.Version:= TWASMPUInt32(pos)^;
|
||||
inc(pos, 4);
|
||||
writestring('[wasm.parser] Version: ');
|
||||
writeintlnWND(ctx^.Version, 0);
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections;
|
||||
interface
|
||||
|
||||
uses
|
||||
types,
|
||||
wasm.types.builtin,
|
||||
wasm.types,
|
||||
wasm.parser.sections.customSection,
|
||||
wasm.parser.sections.typeSection,
|
||||
@@ -18,11 +18,11 @@ uses
|
||||
wasm.parser.sections.codeSection,
|
||||
wasm.parser.sections.dataSection;
|
||||
|
||||
procedure handle(sectionId : uint8; buffer : puint8; section_length : uint32; ctx : PWASMProcessContext);
|
||||
procedure handle(sectionId : TWASMUInt8; buffer : TWASMPUInt8; section_length : TWASMUInt32; ctx : PWASMProcessContext);
|
||||
|
||||
implementation
|
||||
|
||||
procedure handle(sectionId : uint8; buffer : puint8; section_length : uint32; ctx : PWASMProcessContext);
|
||||
procedure handle(sectionId : TWASMUInt8; buffer : TWASMPUInt8; section_length : TWASMUInt32; ctx : PWASMProcessContext);
|
||||
begin
|
||||
// Handle the section
|
||||
case sectionId of
|
||||
|
||||
@@ -18,12 +18,12 @@ procedure run;
|
||||
implementation
|
||||
|
||||
uses
|
||||
types, console, wasm.types, wasm.types.stack,
|
||||
wasm.types.builtin, console, wasm.types, wasm.types.stack,
|
||||
wasm.parser, wasm.vm, wasm.test.framework;
|
||||
|
||||
const
|
||||
BINARY_SIZE = 41;
|
||||
BINARY : Array[$00..$28] of uint8 = (
|
||||
BINARY : Array[$00..$28] of TWASMUInt8 = (
|
||||
$00, $61, $73, $6D, { magic }
|
||||
$01, $00, $00, $00, { version 1 }
|
||||
$01, $05, $01, $60, { type section: 1 func type }
|
||||
@@ -46,7 +46,7 @@ var
|
||||
begin
|
||||
test_begin('binary.addnums');
|
||||
|
||||
ctx := wasm.parser.parse(@BINARY[0], puint8(@BINARY[0] + BINARY_SIZE));
|
||||
ctx := wasm.parser.parse(@BINARY[0], TWASMPUInt8(@BINARY[0] + BINARY_SIZE));
|
||||
assert_true('valid binary', ctx^.ValidBinary);
|
||||
|
||||
ctx^.ExecutionState.Running := true;
|
||||
|
||||
@@ -20,12 +20,12 @@ procedure run;
|
||||
implementation
|
||||
|
||||
uses
|
||||
types, console, wasm.types, wasm.types.stack,
|
||||
wasm.types.builtin, console, wasm.types, wasm.types.stack,
|
||||
wasm.parser, wasm.vm, wasm.test.framework;
|
||||
|
||||
const
|
||||
BINARY_SIZE = 44;
|
||||
BINARY : Array[$00..$2B] of uint8 = (
|
||||
BINARY : Array[$00..$2B] of TWASMUInt8 = (
|
||||
$00, $61, $73, $6D, { magic }
|
||||
$01, $00, $00, $00, { version 1 }
|
||||
$01, $05, $01, $60, { type section: 1 func type }
|
||||
@@ -50,7 +50,7 @@ var
|
||||
begin
|
||||
test_begin('binary.arithmetic');
|
||||
|
||||
ctx := wasm.parser.parse(@BINARY[0], puint8(@BINARY[0] + BINARY_SIZE));
|
||||
ctx := wasm.parser.parse(@BINARY[0], TWASMPUInt8(@BINARY[0] + BINARY_SIZE));
|
||||
assert_true('valid binary', ctx^.ValidBinary);
|
||||
|
||||
ctx^.ExecutionState.Running := true;
|
||||
|
||||
@@ -23,12 +23,12 @@ procedure run;
|
||||
implementation
|
||||
|
||||
uses
|
||||
types, console, wasm.types, wasm.types.stack,
|
||||
wasm.types.builtin, console, wasm.types, wasm.types.stack,
|
||||
wasm.parser, wasm.vm, wasm.test.framework;
|
||||
|
||||
const
|
||||
BINARY_SIZE = 51;
|
||||
BINARY : Array[$00..$32] of uint8 = (
|
||||
BINARY : Array[$00..$32] of TWASMUInt8 = (
|
||||
$00, $61, $73, $6D, { magic }
|
||||
$01, $00, $00, $00, { version 1 }
|
||||
$01, $05, $01, $60, { type section: 1 func type }
|
||||
@@ -55,7 +55,7 @@ var
|
||||
begin
|
||||
test_begin('binary.locals');
|
||||
|
||||
ctx := wasm.parser.parse(@BINARY[0], puint8(@BINARY[0] + BINARY_SIZE));
|
||||
ctx := wasm.parser.parse(@BINARY[0], TWASMPUInt8(@BINARY[0] + BINARY_SIZE));
|
||||
assert_true('valid binary', ctx^.ValidBinary);
|
||||
|
||||
{ Set up locals from the parsed code entry for the single function }
|
||||
|
||||
@@ -21,12 +21,12 @@ procedure run;
|
||||
implementation
|
||||
|
||||
uses
|
||||
types, console, wasm.types, wasm.types.stack,
|
||||
wasm.types.builtin, console, wasm.types, wasm.types.stack,
|
||||
wasm.parser, wasm.vm, wasm.test.framework;
|
||||
|
||||
const
|
||||
BINARY_SIZE = 53;
|
||||
BINARY : Array[$00..$34] of uint8 = (
|
||||
BINARY : Array[$00..$34] of TWASMUInt8 = (
|
||||
$00, $61, $73, $6D, { magic }
|
||||
$01, $00, $00, $00, { version 1 }
|
||||
$01, $05, $01, $60, { type section: 1 func type }
|
||||
@@ -52,7 +52,7 @@ var
|
||||
begin
|
||||
test_begin('binary.memroundtrip');
|
||||
|
||||
ctx := wasm.parser.parse(@BINARY[0], puint8(@BINARY[0] + BINARY_SIZE));
|
||||
ctx := wasm.parser.parse(@BINARY[0], TWASMPUInt8(@BINARY[0] + BINARY_SIZE));
|
||||
assert_true('valid binary', ctx^.ValidBinary);
|
||||
|
||||
ctx^.ExecutionState.Running := true;
|
||||
|
||||
Loaded 20 of 148 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user