feature: added built-in types as a OS/RTL->VM decoupling mechanism
- Added src/wasm/types/wasm.types.builtin.pas as a decoupling unit. - Updated all units to only use these types. - Added linter step (lint.ps1) to enforce usage of these types.
This commit is contained in:
1 parent
a5192366ed
commit
430ebcd203
143 files changed
+1081
-988
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 "%BIN%" mkdir "%BIN%"
|
||||||
if not exist "%LIB%" mkdir "%LIB%"
|
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%" ^
|
"%FPC%" ^
|
||||||
%TESTFLAGS% ^
|
%TESTFLAGS% ^
|
||||||
-FE"%BIN%" ^
|
-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
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure printCtxCode(ctx : PWASMProcessContext);
|
procedure printCtxCode(ctx : PWASMProcessContext);
|
||||||
var
|
var
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Flat Code: ');
|
writestring('[wasm.parser] Flat Code: ');
|
||||||
@@ -25,15 +25,15 @@ end;
|
|||||||
|
|
||||||
procedure walk(ctx : PWASMProcessContext);
|
procedure walk(ctx : PWASMProcessContext);
|
||||||
var
|
var
|
||||||
localpos, pos, bend : puint8;
|
localpos, pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
currentEntry : PWASMCodeEntry;
|
currentEntry : PWASMCodeEntry;
|
||||||
i,j,l : uint32;
|
i,j,l : TWASMUInt32;
|
||||||
localCount,localTemp,localIndex : uint32;
|
localCount,localTemp,localIndex : TWASMUInt32;
|
||||||
localType: TWasmValueType;
|
localType: TWasmValueType;
|
||||||
codeLength: uint32;
|
codeLength: TWASMUInt32;
|
||||||
codeOffset: uint32;
|
codeOffset: TWASMUInt32;
|
||||||
totalSize: uint32;
|
totalSize: TWASMUInt32;
|
||||||
begin
|
begin
|
||||||
// Walk the code entries
|
// Walk the code entries
|
||||||
for i:=1 to ctx^.Sections.CodeSection^.CodeCount do begin
|
for i:=1 to ctx^.Sections.CodeSection^.CodeCount do begin
|
||||||
@@ -59,17 +59,17 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
localpos, pos, bend : puint8;
|
localpos, pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
currentEntry : PWASMCodeEntry;
|
currentEntry : PWASMCodeEntry;
|
||||||
i,j,l : uint32;
|
i,j,l : TWASMUInt32;
|
||||||
localCount,localTemp,localIndex : uint32;
|
localCount,localTemp,localIndex : TWASMUInt32;
|
||||||
localType: TWasmValueType;
|
localType: TWasmValueType;
|
||||||
codeLength: uint32;
|
codeLength: TWASMUInt32;
|
||||||
codeOffset: uint32;
|
codeOffset: TWASMUInt32;
|
||||||
totalSize: uint32;
|
totalSize: TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Code - Size: ');
|
writestring('[wasm.parser] Handle Section: Code - Size: ');
|
||||||
@@ -77,7 +77,7 @@ begin
|
|||||||
|
|
||||||
// Initialize the read/end pointers
|
// Initialize the read/end pointers
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
bend:= puint8(pos + section_length);
|
bend:= TWASMPUInt8(pos + section_length);
|
||||||
|
|
||||||
// Initialize the code section
|
// Initialize the code section
|
||||||
ctx^.Sections.CodeSection:= PWASMCodeSection(kalloc(sizeof(TWASMCodeSection)));
|
ctx^.Sections.CodeSection:= PWASMCodeSection(kalloc(sizeof(TWASMCodeSection)));
|
||||||
@@ -158,7 +158,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Read the code
|
// Read the code
|
||||||
currentEntry^.Code:= puint8(kalloc(currentEntry^.CodeLength));
|
currentEntry^.Code:= TWASMPUInt8(kalloc(currentEntry^.CodeLength));
|
||||||
for j:=1 to currentEntry^.CodeLength do begin
|
for j:=1 to currentEntry^.CodeLength do begin
|
||||||
currentEntry^.Code[j - 1]:= pos^;
|
currentEntry^.Code[j - 1]:= pos^;
|
||||||
inc(pos);
|
inc(pos);
|
||||||
@@ -171,12 +171,12 @@ begin
|
|||||||
totalSize:= totalSize + currentEntry^.CodeLength;
|
totalSize:= totalSize + currentEntry^.CodeLength;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ctx^.ExecutionState.Code:= puint8(kalloc(totalSize));
|
ctx^.ExecutionState.Code:= TWASMPUInt8(kalloc(totalSize));
|
||||||
ctx^.ExecutionState.Limit:= totalSize;
|
ctx^.ExecutionState.Limit:= totalSize;
|
||||||
localpos:= ctx^.ExecutionState.Code;
|
localpos:= ctx^.ExecutionState.Code;
|
||||||
for i:=1 to ctx^.Sections.CodeSection^.CodeCount do begin
|
for i:=1 to ctx^.Sections.CodeSection^.CodeCount do begin
|
||||||
currentEntry:= @ctx^.Sections.CodeSection^.Entries[i - 1];
|
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
|
for j:=1 to currentEntry^.CodeLength do begin
|
||||||
localpos^:= currentEntry^.Code[j - 1];
|
localpos^:= currentEntry^.Code[j - 1];
|
||||||
inc(localpos);
|
inc(localpos);
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.customSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|||||||
@@ -3,31 +3,31 @@ unit wasm.parser.sections.dataSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types, wasm.types.heap;
|
wasm.types, wasm.types.heap;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
pos, bend : puint8;
|
pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
segCount : uint32;
|
segCount : TWASMUInt32;
|
||||||
i, j : uint32;
|
i, j : TWASMUInt32;
|
||||||
memIdx : uint32;
|
memIdx : TWASMUInt32;
|
||||||
offset : uint32;
|
offset : TWASMUInt32;
|
||||||
dataSize : uint32;
|
dataSize : TWASMUInt32;
|
||||||
opcode : uint8;
|
opcode : TWASMUInt8;
|
||||||
tmpU32 : uint32;
|
tmpU32 : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Data - Size: ');
|
writestring('[wasm.parser] Handle Section: Data - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := puint8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
|
|
||||||
{ Read segment count }
|
{ Read segment count }
|
||||||
bytesRead := read_leb128_to_uint32(pos, bend, @segCount);
|
bytesRead := read_leb128_to_uint32(pos, bend, @segCount);
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.elementSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Element - Size: ');
|
writestring('[wasm.parser] Handle Section: Element - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ unit wasm.parser.sections.exportSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure walk(ctx : PWASMProcessContext);
|
procedure walk(ctx : PWASMProcessContext);
|
||||||
var
|
var
|
||||||
currentEntry : PWASMExportEntry;
|
currentEntry : PWASMExportEntry;
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Walk the export entries
|
// Walk the export entries
|
||||||
@@ -28,12 +28,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
pos, bend : puint8;
|
pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
currentEntry : PWASMExportEntry;
|
currentEntry : PWASMExportEntry;
|
||||||
i,j : uint32;
|
i,j : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Export - Size: ');
|
writestring('[wasm.parser] Handle Section: Export - Size: ');
|
||||||
@@ -41,7 +41,7 @@ begin
|
|||||||
|
|
||||||
// Initialize the read/end pointers
|
// Initialize the read/end pointers
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
bend:= puint8(pos + section_length);
|
bend:= TWASMPUInt8(pos + section_length);
|
||||||
|
|
||||||
// Initialize the export section
|
// Initialize the export section
|
||||||
ctx^.Sections.ExportSection:= PWASMExportSection(kalloc(sizeof(TWASMExportSection)));
|
ctx^.Sections.ExportSection:= PWASMExportSection(kalloc(sizeof(TWASMExportSection)));
|
||||||
@@ -69,12 +69,12 @@ begin
|
|||||||
inc(pos, bytesRead);
|
inc(pos, bytesRead);
|
||||||
|
|
||||||
// Read the export name
|
// 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
|
for j:=0 to currentEntry^.NameLength - 1 do begin
|
||||||
currentEntry^.Name[j]:= char(pos^);
|
currentEntry^.Name[j]:= TWASMChar(pos^);
|
||||||
inc(pos);
|
inc(pos);
|
||||||
end;
|
end;
|
||||||
currentEntry^.Name[currentEntry^.NameLength]:= char($00);
|
currentEntry^.Name[currentEntry^.NameLength]:= TWASMChar($00);
|
||||||
|
|
||||||
// Read the export type
|
// Read the export type
|
||||||
currentEntry^.ExportType:= TWasmExportType(pos^);
|
currentEntry^.ExportType:= TWasmExportType(pos^);
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ unit wasm.parser.sections.functionSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure walk(ctx : PWASMProcessContext);
|
procedure walk(ctx : PWASMProcessContext);
|
||||||
var
|
var
|
||||||
currentFunc : PWASMFunction;
|
currentFunc : PWASMFunction;
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Walk the functions
|
// Walk the functions
|
||||||
@@ -24,12 +24,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
pos, bend : puint8;
|
pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
currentFunc : PWASMFunction;
|
currentFunc : PWASMFunction;
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Function - Size: ');
|
writestring('[wasm.parser] Handle Section: Function - Size: ');
|
||||||
@@ -37,7 +37,7 @@ begin
|
|||||||
|
|
||||||
// Initialize the read/end pointers
|
// Initialize the read/end pointers
|
||||||
pos:= buffer;
|
pos:= buffer;
|
||||||
bend:= puint8(pos + section_length);
|
bend:= TWASMPUInt8(pos + section_length);
|
||||||
|
|
||||||
// Initialize the function section
|
// Initialize the function section
|
||||||
ctx^.Sections.FunctionSection:= PWASMFunctionSection(kalloc(sizeof(TWASMFunctionSection)));
|
ctx^.Sections.FunctionSection:= PWASMFunctionSection(kalloc(sizeof(TWASMFunctionSection)));
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ unit wasm.parser.sections.globalSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure walk(ctx : PWASMProcessContext);
|
procedure walk(ctx : PWASMProcessContext);
|
||||||
var
|
var
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
entry : PWASMGlobalEntry;
|
entry : PWASMGlobalEntry;
|
||||||
begin
|
begin
|
||||||
for i := 0 to ctx^.ExecutionState.Globals^.GlobalCount - 1 do begin
|
for i := 0 to ctx^.ExecutionState.Globals^.GlobalCount - 1 do begin
|
||||||
@@ -35,25 +35,25 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
pos, bend : puint8;
|
pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
globalCount : uint32;
|
globalCount : TWASMUInt32;
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
entry : PWASMGlobalEntry;
|
entry : PWASMGlobalEntry;
|
||||||
valType : uint8;
|
valType : TWASMUInt8;
|
||||||
mutFlag : uint8;
|
mutFlag : TWASMUInt8;
|
||||||
opcode : uint8;
|
opcode : TWASMUInt8;
|
||||||
tmpU32 : uint32;
|
tmpU32 : TWASMUInt32;
|
||||||
tmpU64 : uint64;
|
tmpU64 : TWASMUInt64;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Global - Size: ');
|
writestring('[wasm.parser] Handle Section: Global - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := puint8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
|
|
||||||
{ Read global count }
|
{ Read global count }
|
||||||
bytesRead := read_leb128_to_uint32(pos, bend, @globalCount);
|
bytesRead := read_leb128_to_uint32(pos, bend, @globalCount);
|
||||||
@@ -88,19 +88,19 @@ begin
|
|||||||
$41: begin { i32.const }
|
$41: begin { i32.const }
|
||||||
bytesRead := read_leb128_to_uint32(pos, bend, @tmpU32);
|
bytesRead := read_leb128_to_uint32(pos, bend, @tmpU32);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
entry^.Value.i32Value := int32(tmpU32);
|
entry^.Value.i32Value := TWASMInt32(tmpU32);
|
||||||
end;
|
end;
|
||||||
$42: begin { i64.const }
|
$42: begin { i64.const }
|
||||||
bytesRead := read_leb128_to_uint64(pos, bend, @tmpU64);
|
bytesRead := read_leb128_to_uint64(pos, bend, @tmpU64);
|
||||||
Inc(pos, bytesRead);
|
Inc(pos, bytesRead);
|
||||||
entry^.Value.i64Value := int64(tmpU64);
|
entry^.Value.i64Value := TWASMInt64(tmpU64);
|
||||||
end;
|
end;
|
||||||
$43: begin { f32.const }
|
$43: begin { f32.const }
|
||||||
entry^.Value.f32Value := pfloat(pos)^;
|
entry^.Value.f32Value := TWASMPFloat(pos)^;
|
||||||
Inc(pos, 4);
|
Inc(pos, 4);
|
||||||
end;
|
end;
|
||||||
$44: begin { f64.const }
|
$44: begin { f64.const }
|
||||||
entry^.Value.f64Value := pdouble(pos)^;
|
entry^.Value.f64Value := TWASMPDouble(pos)^;
|
||||||
Inc(pos, 8);
|
Inc(pos, 8);
|
||||||
end;
|
end;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.importSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Import - Size: ');
|
writestring('[wasm.parser] Handle Section: Import - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|||||||
@@ -3,16 +3,16 @@ unit wasm.parser.sections.memorySection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types, wasm.types.heap;
|
wasm.types, wasm.types.heap;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure walk(ctx : PWASMProcessContext);
|
procedure walk(ctx : PWASMProcessContext);
|
||||||
var
|
var
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
mem : PWASMMemoryLimits;
|
mem : PWASMMemoryLimits;
|
||||||
begin
|
begin
|
||||||
for i := 0 to ctx^.Sections.MemorySection^.MemoryCount - 1 do begin
|
for i := 0 to ctx^.Sections.MemorySection^.MemoryCount - 1 do begin
|
||||||
@@ -29,21 +29,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
pos, bend : puint8;
|
pos, bend : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
memCount : uint32;
|
memCount : TWASMUInt32;
|
||||||
i : uint32;
|
i : TWASMUInt32;
|
||||||
mem : PWASMMemoryLimits;
|
mem : PWASMMemoryLimits;
|
||||||
flags : uint32;
|
flags : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|
||||||
pos := buffer;
|
pos := buffer;
|
||||||
bend := puint8(buffer + section_length);
|
bend := TWASMPUInt8(buffer + section_length);
|
||||||
|
|
||||||
{ Read memory count }
|
{ Read memory count }
|
||||||
bytesRead := read_leb128_to_uint32(pos, bend, @memCount);
|
bytesRead := read_leb128_to_uint32(pos, bend, @memCount);
|
||||||
|
|||||||
@@ -3,25 +3,25 @@ unit wasm.parser.sections.startSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
funcIdx : uint32;
|
funcIdx : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Start - Size: ');
|
writestring('[wasm.parser] Handle Section: Start - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|
||||||
{ Read the start function index }
|
{ Read the start function index }
|
||||||
bytesRead := read_leb128_to_uint32(buffer, puint8(buffer + section_length), @funcIdx);
|
bytesRead := read_leb128_to_uint32(buffer, TWASMPUInt8(buffer + section_length), @funcIdx);
|
||||||
ctx^.Sections.StartIndex := int32(funcIdx);
|
ctx^.Sections.StartIndex := TWASMInt32(funcIdx);
|
||||||
|
|
||||||
writestring('[wasm.parser] Start Function Index: ');
|
writestring('[wasm.parser] Start Function Index: ');
|
||||||
writeintlnWND(funcIdx, 0);
|
writeintlnWND(funcIdx, 0);
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ unit wasm.parser.sections.tableSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Table - Size: ');
|
writestring('[wasm.parser] Handle Section: Table - Size: ');
|
||||||
writeintlnWND(section_length, 0);
|
writeintlnWND(section_length, 0);
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ unit wasm.parser.sections.typeSection;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types;
|
wasm.types;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@@ -14,10 +14,10 @@ procedure walk(ctx : PWASMProcessContext);
|
|||||||
var
|
var
|
||||||
currentType : PWASMType;
|
currentType : PWASMType;
|
||||||
currentParam : PWASMParam;
|
currentParam : PWASMParam;
|
||||||
i,j : uint32;
|
i,j : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Walk the types
|
// Walk the wasm.types.builtin
|
||||||
for i:=1 to ctx^.Sections.TypeSection^.TypeCount do begin
|
for i:=1 to ctx^.Sections.TypeSection^.TypeCount do begin
|
||||||
currentType:= @ctx^.Sections.TypeSection^.Types[i - 1];
|
currentType:= @ctx^.Sections.TypeSection^.Types[i - 1];
|
||||||
writestring('[wasm.parser] Index: ');
|
writestring('[wasm.parser] Index: ');
|
||||||
@@ -50,13 +50,13 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure handle(buffer: puint8; section_length: uint32; ctx: PWASMProcessContext);
|
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||||
var
|
var
|
||||||
pos : puint8;
|
pos : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
currentType : PWASMType;
|
currentType : PWASMType;
|
||||||
currentParam : PWASMParam;
|
currentParam : PWASMParam;
|
||||||
i, parsedTypes : uint32;
|
i, parsedTypes : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
writestring('[wasm.parser] Handle Section: Type - Size: ');
|
writestring('[wasm.parser] Handle Section: Type - Size: ');
|
||||||
@@ -67,31 +67,31 @@ begin
|
|||||||
ctx^.Sections.TypeSection:= PWASMTypeSection(kalloc(sizeof(TWASMTypeSection)));
|
ctx^.Sections.TypeSection:= PWASMTypeSection(kalloc(sizeof(TWASMTypeSection)));
|
||||||
ctx^.Sections.TypeSection^.TypeCount:= 0;
|
ctx^.Sections.TypeSection^.TypeCount:= 0;
|
||||||
|
|
||||||
// Read the number of function types
|
// Read the number of function wasm.types.builtin
|
||||||
bytesRead:= read_leb128_to_uint32(buffer, puint8(buffer + section_length), @ctx^.Sections.TypeSection^.TypeCount);
|
bytesRead:= read_leb128_to_uint32(buffer, TWASMPUInt8(buffer + section_length), @ctx^.Sections.TypeSection^.TypeCount);
|
||||||
inc(pos, bytesRead);
|
inc(pos, bytesRead);
|
||||||
|
|
||||||
// Read the function types
|
// Read the function wasm.types.builtin
|
||||||
if(ctx^.Sections.TypeSection^.TypeCount > 0) then begin
|
if(ctx^.Sections.TypeSection^.TypeCount > 0) then begin
|
||||||
// Allocate the first type
|
// Allocate the first type
|
||||||
ctx^.Sections.TypeSection^.Types:= PWASMType(kalloc(sizeof(TWASMType) * ctx^.Sections.TypeSection^.TypeCount));
|
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
|
for parsedTypes:=1 to ctx^.Sections.TypeSection^.TypeCount do begin
|
||||||
currentType:= @ctx^.Sections.TypeSection^.Types[parsedTypes - 1];
|
currentType:= @ctx^.Sections.TypeSection^.Types[parsedTypes - 1];
|
||||||
|
|
||||||
// Check if we are at the end of the buffer
|
// 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
|
// Read the function type
|
||||||
currentType^._type:= pos^;
|
currentType^._type:= pos^;
|
||||||
inc(pos);
|
inc(pos);
|
||||||
|
|
||||||
// Read the number of parameters
|
// 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);
|
inc(pos, bytesRead);
|
||||||
|
|
||||||
// Read the parameter types
|
// Read the parameter wasm.types.builtin
|
||||||
if(currentType^.ParamCount > 0) then begin
|
if(currentType^.ParamCount > 0) then begin
|
||||||
currentType^.ParamTypes:= PWASMParam(kalloc(sizeof(TWASMParam) * currentType^.ParamCount));
|
currentType^.ParamTypes:= PWASMParam(kalloc(sizeof(TWASMParam) * currentType^.ParamCount));
|
||||||
for i:=1 to currentType^.ParamCount do begin
|
for i:=1 to currentType^.ParamCount do begin
|
||||||
@@ -102,10 +102,10 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Read the number of return values
|
// 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);
|
inc(pos, bytesRead);
|
||||||
|
|
||||||
// Read the return types
|
// Read the return wasm.types.builtin
|
||||||
if(currentType^.ReturnCount > 0) then begin
|
if(currentType^.ReturnCount > 0) then begin
|
||||||
currentType^.ReturnTypes:= PWASMParam(kalloc(sizeof(TWASMParam) * currentType^.ReturnCount));
|
currentType^.ReturnTypes:= PWASMParam(kalloc(sizeof(TWASMParam) * currentType^.ReturnCount));
|
||||||
for i:=1 to currentType^.ReturnCount do begin
|
for i:=1 to currentType^.ReturnCount do begin
|
||||||
@@ -117,7 +117,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Walk the types
|
// Walk the wasm.types.builtin
|
||||||
walk(ctx);
|
walk(ctx);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ unit wasm.parser;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, lmemorymanager, console, leb128,
|
wasm.types.builtin, lmemorymanager, console, leb128,
|
||||||
wasm.types, wasm.types.heap, wasm.types.stack,
|
wasm.types, wasm.types.heap, wasm.types.stack,
|
||||||
wasm.parser.sections;
|
wasm.parser.sections;
|
||||||
|
|
||||||
function parse(buffer: puint8; buffer_end: puint8) : PWASMProcessContext;
|
function parse(buffer: TWASMPUInt8; buffer_end: TWASMPUInt8) : PWASMProcessContext;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@@ -50,13 +50,13 @@ begin
|
|||||||
newContext:= ctx;
|
newContext:= ctx;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function parse(buffer: puint8; buffer_end: puint8): PWASMProcessContext;
|
function parse(buffer: TWASMPUInt8; buffer_end: TWASMPUInt8): PWASMProcessContext;
|
||||||
var
|
var
|
||||||
ctx : PWASMProcessContext;
|
ctx : PWASMProcessContext;
|
||||||
pos : puint8;
|
pos : TWASMPUInt8;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
section_id : uint8;
|
section_id : TWASMUInt8;
|
||||||
section_length : uint32;
|
section_length : TWASMUInt32;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Allocate the context
|
// Allocate the context
|
||||||
@@ -66,7 +66,7 @@ begin
|
|||||||
writestringln('[wasm.parser] Parsing WASM Binary');
|
writestringln('[wasm.parser] Parsing WASM Binary');
|
||||||
|
|
||||||
// Check for the WASM Magic
|
// 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.');
|
writestringln('[wasm.parser] Binary is valid.');
|
||||||
|
|
||||||
// Set binary to valid
|
// Set binary to valid
|
||||||
@@ -74,7 +74,7 @@ begin
|
|||||||
inc(pos, 4);
|
inc(pos, 4);
|
||||||
|
|
||||||
// Read the version
|
// Read the version
|
||||||
ctx^.Version:= puint32(pos)^;
|
ctx^.Version:= TWASMPUInt32(pos)^;
|
||||||
inc(pos, 4);
|
inc(pos, 4);
|
||||||
writestring('[wasm.parser] Version: ');
|
writestring('[wasm.parser] Version: ');
|
||||||
writeintlnWND(ctx^.Version, 0);
|
writeintlnWND(ctx^.Version, 0);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types,
|
wasm.types.builtin,
|
||||||
wasm.types,
|
wasm.types,
|
||||||
wasm.parser.sections.customSection,
|
wasm.parser.sections.customSection,
|
||||||
wasm.parser.sections.typeSection,
|
wasm.parser.sections.typeSection,
|
||||||
@@ -18,11 +18,11 @@ uses
|
|||||||
wasm.parser.sections.codeSection,
|
wasm.parser.sections.codeSection,
|
||||||
wasm.parser.sections.dataSection;
|
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
|
implementation
|
||||||
|
|
||||||
procedure handle(sectionId : uint8; buffer : puint8; section_length : uint32; ctx : PWASMProcessContext);
|
procedure handle(sectionId : TWASMUInt8; buffer : TWASMPUInt8; section_length : TWASMUInt32; ctx : PWASMProcessContext);
|
||||||
begin
|
begin
|
||||||
// Handle the section
|
// Handle the section
|
||||||
case sectionId of
|
case sectionId of
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ procedure run;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, wasm.types.heap, wasm.test.framework;
|
wasm.types.builtin, wasm.types.heap, wasm.test.framework;
|
||||||
|
|
||||||
procedure run;
|
procedure run;
|
||||||
var
|
var
|
||||||
h : PWasmHeap;
|
h : PWasmHeap;
|
||||||
v8 : uint8;
|
v8 : TWASMUInt8;
|
||||||
v16 : uint16;
|
v16 : TWASMUInt16;
|
||||||
v32 : uint32;
|
v32 : TWASMUInt32;
|
||||||
v64 : uint64;
|
v64 : TWASMUInt64;
|
||||||
ok : boolean;
|
ok : TWASMBoolean;
|
||||||
begin
|
begin
|
||||||
test_begin('heap');
|
test_begin('heap');
|
||||||
|
|
||||||
@@ -25,33 +25,33 @@ begin
|
|||||||
{ Test: new heap has 1 page }
|
{ Test: new heap has 1 page }
|
||||||
assert_u32('new heap pagecount=1', h^.PageCount, 1);
|
assert_u32('new heap pagecount=1', h^.PageCount, 1);
|
||||||
|
|
||||||
{ Test: write/read uint8 }
|
{ Test: write/read TWASMUInt8 }
|
||||||
ok := write_uint8(0, h, $AB);
|
ok := write_uint8(0, h, $AB);
|
||||||
assert_bool('write_uint8 success', ok, true);
|
assert_bool('write_uint8 success', ok, true);
|
||||||
ok := read_uint8(0, h, @v8);
|
ok := read_uint8(0, h, @v8);
|
||||||
assert_bool('read_uint8 success', ok, true);
|
assert_bool('read_uint8 success', ok, true);
|
||||||
assert_u32('read_uint8 value', uint32(v8), $AB);
|
assert_u32('read_uint8 value', TWASMUInt32(v8), $AB);
|
||||||
|
|
||||||
{ Test: write/read uint16 }
|
{ Test: write/read TWASMUInt16 }
|
||||||
ok := write_uint16(4, h, $1234);
|
ok := write_uint16(4, h, $1234);
|
||||||
assert_bool('write_uint16 success', ok, true);
|
assert_bool('write_uint16 success', ok, true);
|
||||||
ok := read_uint16(4, h, @v16);
|
ok := read_uint16(4, h, @v16);
|
||||||
assert_bool('read_uint16 success', ok, true);
|
assert_bool('read_uint16 success', ok, true);
|
||||||
assert_u32('read_uint16 value', uint32(v16), $1234);
|
assert_u32('read_uint16 value', TWASMUInt32(v16), $1234);
|
||||||
|
|
||||||
{ Test: write/read uint32 }
|
{ Test: write/read TWASMUInt32 }
|
||||||
ok := write_uint32(8, h, $DEADBEEF);
|
ok := write_uint32(8, h, $DEADBEEF);
|
||||||
assert_bool('write_uint32 success', ok, true);
|
assert_bool('write_uint32 success', ok, true);
|
||||||
ok := read_uint32(8, h, @v32);
|
ok := read_uint32(8, h, @v32);
|
||||||
assert_bool('read_uint32 success', ok, true);
|
assert_bool('read_uint32 success', ok, true);
|
||||||
assert_u32('read_uint32 value', v32, $DEADBEEF);
|
assert_u32('read_uint32 value', v32, $DEADBEEF);
|
||||||
|
|
||||||
{ Test: write/read uint64 }
|
{ Test: write/read TWASMUInt64 }
|
||||||
ok := write_uint64(16, h, uint64($CAFEBABE12345678));
|
ok := write_uint64(16, h, TWASMUInt64($CAFEBABE12345678));
|
||||||
assert_bool('write_uint64 success', ok, true);
|
assert_bool('write_uint64 success', ok, true);
|
||||||
ok := read_uint64(16, h, @v64);
|
ok := read_uint64(16, h, @v64);
|
||||||
assert_bool('read_uint64 success', ok, true);
|
assert_bool('read_uint64 success', ok, true);
|
||||||
assert_u64('read_uint64 value', v64, uint64($CAFEBABE12345678));
|
assert_u64('read_uint64 value', v64, TWASMUInt64($CAFEBABE12345678));
|
||||||
|
|
||||||
{ Test: out of bounds read fails }
|
{ Test: out of bounds read fails }
|
||||||
ok := read_uint8($10000, h, @v8);
|
ok := read_uint8($10000, h, @v8);
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ procedure run;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, leb128, wasm.test.framework;
|
wasm.types.builtin, leb128, wasm.test.framework;
|
||||||
|
|
||||||
procedure run;
|
procedure run;
|
||||||
var
|
var
|
||||||
buf : array[0..9] of uint8;
|
buf : array[0..9] of TWASMUInt8;
|
||||||
buf_end : puint8;
|
buf_end : TWASMPUInt8;
|
||||||
res32 : uint32;
|
res32 : TWASMUInt32;
|
||||||
res64 : uint64;
|
res64 : TWASMUInt64;
|
||||||
bytesRead : uint8;
|
bytesRead : TWASMUInt8;
|
||||||
begin
|
begin
|
||||||
test_begin('leb128');
|
test_begin('leb128');
|
||||||
buf_end := @buf[10];
|
buf_end := @buf[10];
|
||||||
@@ -24,13 +24,13 @@ begin
|
|||||||
buf[0] := $00;
|
buf[0] := $00;
|
||||||
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
||||||
assert_u32('u32 value=0', res32, 0);
|
assert_u32('u32 value=0', res32, 0);
|
||||||
assert_u32('u32 value=0 bytes=1', uint32(bytesRead), 1);
|
assert_u32('u32 value=0 bytes=1', TWASMUInt32(bytesRead), 1);
|
||||||
|
|
||||||
{ Test: single byte, value 42 }
|
{ Test: single byte, value 42 }
|
||||||
buf[0] := $2A;
|
buf[0] := $2A;
|
||||||
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
||||||
assert_u32('u32 value=42', res32, 42);
|
assert_u32('u32 value=42', res32, 42);
|
||||||
assert_u32('u32 value=42 bytes=1', uint32(bytesRead), 1);
|
assert_u32('u32 value=42 bytes=1', TWASMUInt32(bytesRead), 1);
|
||||||
|
|
||||||
{ Test: single byte, value 127 }
|
{ Test: single byte, value 127 }
|
||||||
buf[0] := $7F;
|
buf[0] := $7F;
|
||||||
@@ -42,7 +42,7 @@ begin
|
|||||||
buf[1] := $01;
|
buf[1] := $01;
|
||||||
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
||||||
assert_u32('u32 value=128', res32, 128);
|
assert_u32('u32 value=128', res32, 128);
|
||||||
assert_u32('u32 value=128 bytes=2', uint32(bytesRead), 2);
|
assert_u32('u32 value=128 bytes=2', TWASMUInt32(bytesRead), 2);
|
||||||
|
|
||||||
{ Test: two bytes, value 255 }
|
{ Test: two bytes, value 255 }
|
||||||
buf[0] := $FF;
|
buf[0] := $FF;
|
||||||
@@ -62,21 +62,21 @@ begin
|
|||||||
buf[2] := $26;
|
buf[2] := $26;
|
||||||
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
bytesRead := read_leb128_to_uint32(@buf[0], buf_end, @res32);
|
||||||
assert_u32('u32 value=624485', res32, 624485);
|
assert_u32('u32 value=624485', res32, 624485);
|
||||||
assert_u32('u32 value=624485 bytes=3', uint32(bytesRead), 3);
|
assert_u32('u32 value=624485 bytes=3', TWASMUInt32(bytesRead), 3);
|
||||||
|
|
||||||
{ Test: uint64 single byte }
|
{ Test: TWASMUInt64 single byte }
|
||||||
buf[0] := $2A;
|
buf[0] := $2A;
|
||||||
bytesRead := read_leb128_to_uint64(@buf[0], buf_end, @res64);
|
bytesRead := read_leb128_to_uint64(@buf[0], buf_end, @res64);
|
||||||
assert_u64('u64 value=42', res64, 42);
|
assert_u64('u64 value=42', res64, 42);
|
||||||
assert_u32('u64 value=42 bytes=1', uint32(bytesRead), 1);
|
assert_u32('u64 value=42 bytes=1', TWASMUInt32(bytesRead), 1);
|
||||||
|
|
||||||
{ Test: uint64 two bytes }
|
{ Test: TWASMUInt64 two bytes }
|
||||||
buf[0] := $80;
|
buf[0] := $80;
|
||||||
buf[1] := $01;
|
buf[1] := $01;
|
||||||
bytesRead := read_leb128_to_uint64(@buf[0], buf_end, @res64);
|
bytesRead := read_leb128_to_uint64(@buf[0], buf_end, @res64);
|
||||||
assert_u64('u64 value=128', res64, 128);
|
assert_u64('u64 value=128', res64, 128);
|
||||||
|
|
||||||
{ Test: uint64 multi-byte }
|
{ Test: TWASMUInt64 multi-byte }
|
||||||
buf[0] := $E5;
|
buf[0] := $E5;
|
||||||
buf[1] := $8E;
|
buf[1] := $8E;
|
||||||
buf[2] := $26;
|
buf[2] := $26;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ procedure run;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, wasm.types, wasm.types.stack, wasm.test.framework;
|
wasm.types.builtin, wasm.types, wasm.types.stack, wasm.test.framework;
|
||||||
|
|
||||||
procedure run;
|
procedure run;
|
||||||
var
|
var
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ procedure run;
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
types, wasm.types, wasm.types.stack, wasm.vm, wasm.test.framework;
|
wasm.types.builtin, wasm.types, wasm.types.stack, wasm.vm, wasm.test.framework;
|
||||||
|
|
||||||
procedure run;
|
procedure run;
|
||||||
var
|
var
|
||||||
code : array[0..0] of uint8;
|
code : array[0..0] of TWASMUInt8;
|
||||||
ctx : PWASMProcessContext;
|
ctx : PWASMProcessContext;
|
||||||
begin
|
begin
|
||||||
test_begin('opcode.drop');
|
test_begin('opcode.drop');
|
||||||
|
|||||||
Loaded 20 of 143 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user