Compare commits
5
Commits
feature/WASI
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b6115c88eb | ||
|
|
152e6dc241 | ||
|
|
ac4c631a5c | ||
|
|
5bb7107997 | ||
|
|
757d762faf |
No files matched your search
File diff suppressed because it is too large.
Load diff
+1
-1
@@ -36,7 +36,7 @@ type
|
||||
sInt8 = shortint;
|
||||
sInt16 = smallint;
|
||||
sInt32 = integer;
|
||||
sInt64 = longint;
|
||||
sInt64 = int64;
|
||||
|
||||
Float = Single;
|
||||
|
||||
|
||||
+15
-6
@@ -2,7 +2,7 @@ program WASURO;
|
||||
|
||||
uses
|
||||
sysutils,
|
||||
console,
|
||||
wasm.vm.io,
|
||||
wasm.types.builtin,
|
||||
wasm.types.context,
|
||||
wasm,
|
||||
@@ -16,6 +16,12 @@ uses
|
||||
{$ENDIF}
|
||||
;
|
||||
|
||||
{ Emu-layer writechar hook — forwards to RTL Write for host OS output }
|
||||
procedure emu_writechar(ch : TWASMChar);
|
||||
begin
|
||||
Write(ch);
|
||||
end;
|
||||
|
||||
var
|
||||
Context : PWASMProcessContext;
|
||||
ModuleSize : Int64;
|
||||
@@ -23,19 +29,22 @@ var
|
||||
ModuleFile : File;
|
||||
|
||||
begin
|
||||
{ Wire up the IO subsystem before anything else }
|
||||
wasm.vm.io.io_set_writechar(@emu_writechar);
|
||||
|
||||
{$IFDEF RUN_TESTS}
|
||||
wasm.wasm_init;
|
||||
wasm.test.run_all_tests;
|
||||
halt(wasm.test.framework.FailedTests);
|
||||
{$ELSE}
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestringln('WASURO - WebAssembly Runtime in Object Pascal');
|
||||
wasm.vm.io.writestringln('WASURO - WebAssembly Runtime in Object Pascal');
|
||||
{$ENDIF}
|
||||
wasm.wasm_init;
|
||||
|
||||
if ParamCount > 0 then begin
|
||||
if not FileExists(ParamStr(1)) then begin
|
||||
console.writestringln('File not found.');
|
||||
wasm.vm.io.writestringln('File not found.');
|
||||
halt(1);
|
||||
end;
|
||||
Assign(ModuleFile, ParamStr(1));
|
||||
@@ -53,7 +62,7 @@ begin
|
||||
Context := wasm.wasm_load(ModuleBuffer, TWASMPUInt8(ModuleBuffer + ModuleSize));
|
||||
|
||||
if not Context^.ValidBinary then begin
|
||||
console.writestringln('Error: Invalid WASM binary.');
|
||||
wasm.vm.io.writestringln('Error: Invalid WASM binary.');
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
@@ -63,7 +72,7 @@ begin
|
||||
|
||||
{ Find _start and run to completion }
|
||||
if not wasm.wasm_start(Context) then begin
|
||||
console.writestringln('No _start export found.');
|
||||
wasm.vm.io.writestringln('No _start export found.');
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
@@ -74,7 +83,7 @@ begin
|
||||
FreeMem(ModuleBuffer);
|
||||
halt(Context^.ExitCode);
|
||||
end else begin
|
||||
console.writestringln('Usage: WASURO <module.wasm>');
|
||||
wasm.vm.io.writestringln('Usage: WASURO <module.wasm>');
|
||||
halt(1);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.codeSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.enums, wasm.types.values, wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -73,8 +73,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Code - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Code - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
// Initialize the read/end pointers
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.customSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -13,11 +13,11 @@ implementation
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Custom - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
{ Custom sections are ignored in this implementation }
|
||||
console.writestringln('[wasm.parser] TODO: Custom section skipped.');
|
||||
wasm.vm.io.writestringln('[wasm.parser] TODO: Custom section skipped.');
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -9,7 +9,7 @@ procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMPro
|
||||
|
||||
implementation
|
||||
|
||||
uses console, wasm.types.leb128, lmemorymanager, wasm.types.sections;
|
||||
uses wasm.vm.io, wasm.types.leb128, lmemorymanager, wasm.types.sections;
|
||||
|
||||
{ DataCount section (ID 12): contains a single u32 count of data segments.
|
||||
Pre-allocates the DataSegments array so that bulk memory opcodes
|
||||
@@ -21,8 +21,8 @@ var
|
||||
dataCount : TWASMUInt32;
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: DataCount - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: DataCount - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.dataSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.sections, wasm.types.context, wasm.types.heap;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -26,8 +26,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Data - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Data - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.elementSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -24,8 +24,8 @@ var
|
||||
indices: TWASMPUInt32;
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Element - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Element - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.exportSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -37,8 +37,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Export - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Export - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
// Initialize the read/end pointers
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.functionSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -33,8 +33,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Function - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Function - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
// Initialize the read/end pointers
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.globalSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -50,8 +50,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Global - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Global - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.importSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.enums, wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -72,8 +72,8 @@ var
|
||||
limitsFlag : TWASMUInt8;
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Import - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Import - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.memorySection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.sections, wasm.types.context, wasm.types.heap;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -40,8 +40,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Memory - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.startSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -17,8 +17,8 @@ var
|
||||
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Start - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Start - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
{ Read the start function index }
|
||||
@@ -26,8 +26,8 @@ begin
|
||||
ctx^.Sections.StartIndex := TWASMInt32(funcIdx);
|
||||
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Start Function Index: ');
|
||||
console.writeintlnWND(funcIdx, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Start Function Index: ');
|
||||
wasm.vm.io.writeintlnWND(funcIdx, 0);
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.tableSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -20,8 +20,8 @@ var
|
||||
tables: PWASMTables;
|
||||
begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Table - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Table - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
|
||||
pos := buffer;
|
||||
@@ -60,17 +60,17 @@ begin
|
||||
end;
|
||||
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Table ');
|
||||
console.writeintWND(i, 0);
|
||||
console.writestring(' - ElemType: $');
|
||||
console.writeintWND(elem_type, 0);
|
||||
console.writestring(' Initial: ');
|
||||
console.writeintWND(min_size, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Table ');
|
||||
wasm.vm.io.writeintWND(i, 0);
|
||||
wasm.vm.io.writestring(' - ElemType: $');
|
||||
wasm.vm.io.writeintWND(elem_type, 0);
|
||||
wasm.vm.io.writestring(' Initial: ');
|
||||
wasm.vm.io.writeintWND(min_size, 0);
|
||||
if limits_flag = 1 then begin
|
||||
console.writestring(' Max: ');
|
||||
console.writeintWND(max_size, 0);
|
||||
wasm.vm.io.writestring(' Max: ');
|
||||
wasm.vm.io.writeintWND(max_size, 0);
|
||||
end;
|
||||
console.writestringln('');
|
||||
wasm.vm.io.writestringln('');
|
||||
{$ENDIF}
|
||||
|
||||
tables^.Tables[i].ElementType := elem_type;
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser.sections.typeSection;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.enums, wasm.types.values, wasm.types.sections, wasm.types.context;
|
||||
|
||||
procedure handle(buffer: TWASMPUInt8; section_length: TWASMUInt32; ctx: PWASMProcessContext);
|
||||
@@ -61,8 +61,8 @@ var
|
||||
begin
|
||||
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Handle Section: Type - Size: ');
|
||||
console.writeintlnWND(section_length, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Handle Section: Type - Size: ');
|
||||
wasm.vm.io.writeintlnWND(section_length, 0);
|
||||
{$ENDIF}
|
||||
pos:= buffer;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ unit wasm.parser;
|
||||
interface
|
||||
|
||||
uses
|
||||
wasm.types.builtin, lmemorymanager, console, wasm.types.leb128,
|
||||
wasm.types.builtin, lmemorymanager, wasm.vm.io, wasm.types.leb128,
|
||||
wasm.types.enums, wasm.types.sections, wasm.types.context, wasm.types.heap, wasm.types.stack,
|
||||
wasm.parser.sections, wasm.types.constants;
|
||||
|
||||
@@ -104,13 +104,13 @@ begin
|
||||
pos:= buffer;
|
||||
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestringln('[wasm.parser] Starting parse of WASM binary.');
|
||||
wasm.vm.io.writestringln('[wasm.parser] Starting parse of WASM binary.');
|
||||
{$ENDIF}
|
||||
|
||||
// Check for the WASM Magic
|
||||
if(TWASMPUInt32(pos)^ = wasm.types.constants.WASM_HDR_MAGIC) then begin
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestringln('[wasm.parser] Binary is valid.');
|
||||
wasm.vm.io.writestringln('[wasm.parser] Binary is valid.');
|
||||
{$ENDIF}
|
||||
|
||||
// Set binary to valid
|
||||
@@ -121,8 +121,8 @@ begin
|
||||
ctx^.Version:= TWASMPUInt32(pos)^;
|
||||
inc(pos, 4);
|
||||
{$IFDEF DEBUG_OUTPUT}
|
||||
console.writestring('[wasm.parser] Version: ');
|
||||
console.writeintlnWND(ctx^.Version, 0);
|
||||
wasm.vm.io.writestring('[wasm.parser] Version: ');
|
||||
wasm.vm.io.writeintlnWND(ctx^.Version, 0);
|
||||
{$ENDIF}
|
||||
|
||||
// Read the sections
|
||||
@@ -142,7 +142,7 @@ begin
|
||||
Inc(pos, section_length);
|
||||
end;
|
||||
end else begin
|
||||
writeln('[wasm.parser] Binary missing WASM Magic!');
|
||||
wasm.vm.io.writestringln('[wasm.parser] Binary missing WASM Magic!');
|
||||
ctx^.ValidBinary:= false;
|
||||
end;
|
||||
parse:= ctx;
|
||||
|
||||
@@ -11,7 +11,7 @@ function validate_module(ctx : PWASMProcessContext; var errorMsg : TWASMPChar) :
|
||||
|
||||
implementation
|
||||
|
||||
uses console;
|
||||
uses wasm.vm.io;
|
||||
|
||||
function validate_module(ctx : PWASMProcessContext; var errorMsg : TWASMPChar) : TWASMBoolean;
|
||||
var i : TWASMUInt32;
|
||||
|
||||
@@ -18,7 +18,7 @@ procedure run;
|
||||
implementation
|
||||
|
||||
uses
|
||||
wasm.types.builtin, console, wasm.types.context, wasm.types.stack,
|
||||
wasm.types.builtin, wasm.vm.io, wasm.types.context, wasm.types.stack,
|
||||
wasm.parser, wasm.vm, wasm.test.framework;
|
||||
|
||||
const
|
||||
|
||||
@@ -20,7 +20,7 @@ procedure run;
|
||||
implementation
|
||||
|
||||
uses
|
||||
wasm.types.builtin, console, wasm.types.context, wasm.types.stack,
|
||||
wasm.types.builtin, wasm.vm.io, wasm.types.context, wasm.types.stack,
|
||||
wasm.parser, wasm.vm, wasm.test.framework;
|
||||
|
||||
const
|
||||
|
||||
Loaded 20 of 81 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user