Browse Source

* the ReadUleb, ReadUleb32 and ReadName methods moved to be local functions inside TWasmObjInput.ReadObjData.ReadSection

Nikolay Nikolov 1 year ago
parent
commit
36fe4cf43d
1 changed files with 54 additions and 50 deletions
  1. 54 50
      compiler/ogwasm.pas

+ 54 - 50
compiler/ogwasm.pas

@@ -185,10 +185,6 @@ interface
       TWasmObjInput = class(TObjInput)
       TWasmObjInput = class(TObjInput)
       private
       private
         FFuncTypes: array of TWasmFuncType;
         FFuncTypes: array of TWasmFuncType;
-
-        function ReadUleb(r: TObjectReader; out v: uint64): boolean;
-        function ReadUleb32(r: TObjectReader; out v: uint32): boolean;
-        function ReadName(r: TObjectReader; out v: ansistring): boolean;
       public
       public
         constructor create;override;
         constructor create;override;
         destructor Destroy;override;
         destructor Destroy;override;
@@ -2112,52 +2108,6 @@ implementation
                                TWasmObjInput
                                TWasmObjInput
 ****************************************************************************}
 ****************************************************************************}
 
 
-    function TWasmObjInput.ReadUleb(r: TObjectReader; out v: uint64): boolean;
-      var
-        b: byte;
-        shift:integer;
-      begin
-        result:=false;
-        b:=0;
-        v:=0;
-        shift:=0;
-        repeat
-          if not r.read(b,1) then
-            exit;
-          v:=v or (uint64(b and 127) shl shift);
-          inc(shift,7);
-        until (b and 128)=0;
-        result:=true;
-      end;
-
-    function TWasmObjInput.ReadUleb32(r: TObjectReader; out v: uint32): boolean;
-      var
-        vv: uint64;
-      begin
-        result:=false;
-        v:=default(uint32);
-        if not ReadUleb(r, vv) then
-          exit;
-        if vv>high(uint32) then
-          exit;
-        v:=vv;
-        result:=true;
-      end;
-
-    function TWasmObjInput.ReadName(r: TObjectReader; out v: ansistring): boolean;
-      var
-        len: uint32;
-      begin
-        result:=false;
-        if not ReadUleb32(r,len) then
-          exit;
-        SetLength(v,len);
-        if len>0 then
-          result:=r.read(v[1],len)
-        else
-          result:=true;
-      end;
-
     constructor TWasmObjInput.create;
     constructor TWasmObjInput.create;
       begin
       begin
         inherited create;
         inherited create;
@@ -2205,6 +2155,60 @@ implementation
           SectionSize: uint32;
           SectionSize: uint32;
           SectionStart: LongInt;
           SectionStart: LongInt;
 
 
+{          TypeSectionRead: Boolean = false;
+          ImportSectionRead: Boolean = false;
+          FunctionSectionRead: Boolean = false;
+          DataCountSectionRead: Boolean = false;
+
+          DataCount: uint32;}
+
+        function ReadUleb(r: TObjectReader; out v: uint64): boolean;
+          var
+            b: byte;
+            shift:integer;
+          begin
+            result:=false;
+            b:=0;
+            v:=0;
+            shift:=0;
+            repeat
+              if not r.read(b,1) then
+                exit;
+              v:=v or (uint64(b and 127) shl shift);
+              inc(shift,7);
+            until (b and 128)=0;
+            result:=true;
+          end;
+
+        function ReadUleb32(r: TObjectReader; out v: uint32): boolean;
+          var
+            vv: uint64;
+          begin
+            result:=false;
+            v:=default(uint32);
+            if not ReadUleb(r, vv) then
+              exit;
+            if vv>high(uint32) then
+              exit;
+            v:=vv;
+            result:=true;
+          end;
+
+        function ReadName(r: TObjectReader; out v: ansistring): boolean;
+          var
+            len: uint32;
+          begin
+            result:=false;
+            if not ReadUleb32(r,len) then
+              exit;
+            SetLength(v,len);
+            if len>0 then
+              result:=r.read(v[1],len)
+            else
+              result:=true;
+          end;
+
+        var
           TypeSectionRead: Boolean = false;
           TypeSectionRead: Boolean = false;
           ImportSectionRead: Boolean = false;
           ImportSectionRead: Boolean = false;
           FunctionSectionRead: Boolean = false;
           FunctionSectionRead: Boolean = false;