Browse Source

+ implemented TWasmObjInput.CanReadObjData: checks for WASM header and version

Nikolay Nikolov 1 year ago
parent
commit
b9668a88c6
1 changed files with 21 additions and 0 deletions
  1. 21 0
      compiler/ogwasm.pas

+ 21 - 0
compiler/ogwasm.pas

@@ -185,6 +185,7 @@ interface
       TWasmObjInput = class(TObjInput)
       public
         constructor create;override;
+        class function CanReadObjData(AReader:TObjectreader):boolean;override;
       end;
 
       { TWasmAssembler }
@@ -2099,6 +2100,26 @@ implementation
         cobjdata:=TWasmObjData;
       end;
 
+    class function TWasmObjInput.CanReadObjData(AReader: TObjectreader): boolean;
+      var
+        ModuleMagic: array [0..3] of Byte;
+        ModuleVersion: array [0..3] of Byte;
+        i: Integer;
+      begin
+        result:=false;
+        if not AReader.read(ModuleMagic,4) then
+          exit;
+        for i:=0 to 3 do
+          if ModuleMagic[i]<>WasmModuleMagic[i] then
+            exit;
+        if not AReader.read(ModuleVersion,4) then
+          exit;
+        for i:=0 to 3 do
+          if ModuleVersion[i]<>WasmVersion[i] then
+            exit;
+        result:=true;
+      end;
+
 {****************************************************************************
                                TWasmAssembler
 ****************************************************************************}