Browse Source

+ added functions for reading the different types of Wasm object sections

Nikolay Nikolov 1 year ago
parent
commit
90e7b2be56
1 changed files with 76 additions and 2 deletions
  1. 76 2
      compiler/ogwasm.pas

+ 76 - 2
compiler/ogwasm.pas

@@ -210,7 +210,7 @@ interface
 implementation
 implementation
 
 
     uses
     uses
-      verbose,version,globals;
+      cutils,verbose,version,globals;
 
 
     procedure WriteUleb5(d: tdynamicarray; v: uint64);
     procedure WriteUleb5(d: tdynamicarray; v: uint64);
       var
       var
@@ -2137,6 +2137,7 @@ implementation
         ModuleVersion: array [0..3] of Byte;
         ModuleVersion: array [0..3] of Byte;
         i: Integer;
         i: Integer;
       begin
       begin
+        Writeln('CanReadObjData');
         result:=false;
         result:=false;
         if not AReader.read(ModuleMagic,4) then
         if not AReader.read(ModuleMagic,4) then
           exit;
           exit;
@@ -2157,6 +2158,53 @@ implementation
         var
         var
           SectionId: Byte;
           SectionId: Byte;
           SectionSize: uint64;
           SectionSize: uint64;
+          SectionStart: LongInt;
+
+        function ReadCustomSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadTypeSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadImportSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadFunctionSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadGlobalSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadExportSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadCodeSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadDataSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
+        function ReadDataCountSection: Boolean;
+          begin
+            Result:=False;
+          end;
+
         begin
         begin
           Result:=False;
           Result:=False;
           if not AReader.read(SectionId,1) then
           if not AReader.read(SectionId,1) then
@@ -2179,9 +2227,35 @@ implementation
               InputError('Section exceeds beyond the end of file');
               InputError('Section exceeds beyond the end of file');
               exit;
               exit;
             end;
             end;
+          SectionStart:=AReader.Pos;
           { skip the section for now... TODO: parse the section }
           { skip the section for now... TODO: parse the section }
+          case SectionId of
+            Byte(wsiCustom):
+              Result := ReadCustomSection;
+            Byte(wsiType):
+              Result := ReadTypeSection;
+            Byte(wsiImport):
+              Result := ReadImportSection;
+            Byte(wsiFunction):
+              Result := ReadFunctionSection;
+            Byte(wsiGlobal):
+              Result := ReadGlobalSection;
+            Byte(wsiExport):
+              Result := ReadExportSection;
+            Byte(wsiCode):
+              Result := ReadCodeSection;
+            Byte(wsiData):
+              Result := ReadDataSection;
+            Byte(wsiDataCount):
+              Result := ReadDataCountSection;
+            else
+              begin
+                InputError('Unknown section: ' + ToStr(SectionId));
+                exit;
+              end;
+          end;
           if SectionSize>0 then
           if SectionSize>0 then
-            AReader.seek(AReader.Pos+SectionSize);
+            AReader.seek(SectionStart+SectionSize);
           Result:=True;
           Result:=True;
         end;
         end;