Browse Source

- removed the TObjectReader parameter from ReadUleb, ReadUleb32 and ReadName

Nikolay Nikolov 1 year ago
parent
commit
16c18e845f
1 changed files with 28 additions and 24 deletions
  1. 28 24
      compiler/ogwasm.pas

+ 28 - 24
compiler/ogwasm.pas

@@ -2155,8 +2155,12 @@ implementation
           SectionSize: uint32;
           SectionSize: uint32;
           SectionStart: LongInt;
           SectionStart: LongInt;
 
 
+        function read(out b;len:longint):boolean;
+          begin
+            result:=AReader.read(b,len);
+          end;
 
 
-        function ReadUleb(r: TObjectReader; out v: uint64): boolean;
+        function ReadUleb(out v: uint64): boolean;
           var
           var
             b: byte;
             b: byte;
             shift:integer;
             shift:integer;
@@ -2166,7 +2170,7 @@ implementation
             v:=0;
             v:=0;
             shift:=0;
             shift:=0;
             repeat
             repeat
-              if not r.read(b,1) then
+              if not read(b,1) then
                 exit;
                 exit;
               v:=v or (uint64(b and 127) shl shift);
               v:=v or (uint64(b and 127) shl shift);
               inc(shift,7);
               inc(shift,7);
@@ -2174,13 +2178,13 @@ implementation
             result:=true;
             result:=true;
           end;
           end;
 
 
-        function ReadUleb32(r: TObjectReader; out v: uint32): boolean;
+        function ReadUleb32(out v: uint32): boolean;
           var
           var
             vv: uint64;
             vv: uint64;
           begin
           begin
             result:=false;
             result:=false;
             v:=default(uint32);
             v:=default(uint32);
-            if not ReadUleb(r, vv) then
+            if not ReadUleb(vv) then
               exit;
               exit;
             if vv>high(uint32) then
             if vv>high(uint32) then
               exit;
               exit;
@@ -2188,16 +2192,16 @@ implementation
             result:=true;
             result:=true;
           end;
           end;
 
 
-        function ReadName(r: TObjectReader; out v: ansistring): boolean;
+        function ReadName(out v: ansistring): boolean;
           var
           var
             len: uint32;
             len: uint32;
           begin
           begin
             result:=false;
             result:=false;
-            if not ReadUleb32(r,len) then
+            if not ReadUleb32(len) then
               exit;
               exit;
             SetLength(v,len);
             SetLength(v,len);
             if len>0 then
             if len>0 then
-              result:=r.read(v[1],len)
+              result:=read(v[1],len)
             else
             else
               result:=true;
               result:=true;
           end;
           end;
@@ -2229,7 +2233,7 @@ implementation
                 exit;
                 exit;
               end;
               end;
             TypeSectionRead:=True;
             TypeSectionRead:=True;
-            if not ReadUleb32(AReader, FuncTypesCount) then
+            if not ReadUleb32(FuncTypesCount) then
               begin
               begin
                 InputError('Error reading the func types count');
                 InputError('Error reading the func types count');
                 exit;
                 exit;
@@ -2253,7 +2257,7 @@ implementation
                     InputError('Incorrect function type identifier (expected $60, got $' + HexStr(FuncTypeId,2) + ')');
                     InputError('Incorrect function type identifier (expected $60, got $' + HexStr(FuncTypeId,2) + ')');
                     exit;
                     exit;
                   end;
                   end;
-                if not ReadUleb32(AReader, ParamsCount) then
+                if not ReadUleb32(ParamsCount) then
                   begin
                   begin
                     InputError('Error reading the function parameters count');
                     InputError('Error reading the function parameters count');
                     exit;
                     exit;
@@ -2277,7 +2281,7 @@ implementation
                       end;
                       end;
                     FFuncTypes[i].add_param(wbt);
                     FFuncTypes[i].add_param(wbt);
                   end;
                   end;
-                if not ReadUleb32(AReader, ResultsCount) then
+                if not ReadUleb32(ResultsCount) then
                   begin
                   begin
                     InputError('Error reading the function results count');
                     InputError('Error reading the function results count');
                     exit;
                     exit;
@@ -2327,7 +2331,7 @@ implementation
                 exit;
                 exit;
               end;
               end;
             ImportSectionRead:=True;
             ImportSectionRead:=True;
-            if not ReadUleb32(AReader,ImportsCount) then
+            if not ReadUleb32(ImportsCount) then
               begin
               begin
                 InputError('Error reading the imports count');
                 InputError('Error reading the imports count');
                 exit;
                 exit;
@@ -2339,12 +2343,12 @@ implementation
               end;
               end;
             for i:=0 to ImportsCount-1 do
             for i:=0 to ImportsCount-1 do
               begin
               begin
-                if not ReadName(AReader,ModName) then
+                if not ReadName(ModName) then
                   begin
                   begin
                     InputError('Error reading import module name');
                     InputError('Error reading import module name');
                     exit;
                     exit;
                   end;
                   end;
-                if not ReadName(AReader,Name) then
+                if not ReadName(Name) then
                   begin
                   begin
                     InputError('Error import name');
                     InputError('Error import name');
                     exit;
                     exit;
@@ -2357,7 +2361,7 @@ implementation
                 case ImportType of
                 case ImportType of
                   $00:  { func }
                   $00:  { func }
                     begin
                     begin
-                      if not ReadUleb32(AReader,typidx) then
+                      if not ReadUleb32(typidx) then
                         begin
                         begin
                           InputError('Error reading type index for func import');
                           InputError('Error reading type index for func import');
                           exit;
                           exit;
@@ -2393,7 +2397,7 @@ implementation
                       case TableLimitsKind of
                       case TableLimitsKind of
                         $00:
                         $00:
                           begin
                           begin
-                            if not ReadUleb32(AReader,TableLimitsMin) then
+                            if not ReadUleb32(TableLimitsMin) then
                               begin
                               begin
                                 InputError('Error reading table limits min for table import');
                                 InputError('Error reading table limits min for table import');
                                 exit;
                                 exit;
@@ -2401,12 +2405,12 @@ implementation
                           end;
                           end;
                         $01:
                         $01:
                           begin
                           begin
-                            if not ReadUleb32(AReader,TableLimitsMin) then
+                            if not ReadUleb32(TableLimitsMin) then
                               begin
                               begin
                                 InputError('Error reading table limits min for table import');
                                 InputError('Error reading table limits min for table import');
                                 exit;
                                 exit;
                               end;
                               end;
-                            if not ReadUleb32(AReader,TableLimitsMax) then
+                            if not ReadUleb32(TableLimitsMax) then
                               begin
                               begin
                                 InputError('Error reading table limits max for table import');
                                 InputError('Error reading table limits max for table import');
                                 exit;
                                 exit;
@@ -2434,7 +2438,7 @@ implementation
                       case MemoryLimitsKind of
                       case MemoryLimitsKind of
                         $00:
                         $00:
                           begin
                           begin
-                            if not ReadUleb32(AReader,MemoryLimitsMin) then
+                            if not ReadUleb32(MemoryLimitsMin) then
                               begin
                               begin
                                 InputError('Error reading memory limits min for memory import');
                                 InputError('Error reading memory limits min for memory import');
                                 exit;
                                 exit;
@@ -2442,12 +2446,12 @@ implementation
                           end;
                           end;
                         $01:
                         $01:
                           begin
                           begin
-                            if not ReadUleb32(AReader,MemoryLimitsMin) then
+                            if not ReadUleb32(MemoryLimitsMin) then
                               begin
                               begin
                                 InputError('Error reading memory limits min for memory import');
                                 InputError('Error reading memory limits min for memory import');
                                 exit;
                                 exit;
                               end;
                               end;
-                            if not ReadUleb32(AReader,MemoryLimitsMax) then
+                            if not ReadUleb32(MemoryLimitsMax) then
                               begin
                               begin
                                 InputError('Error reading memory limits max for memory import');
                                 InputError('Error reading memory limits max for memory import');
                                 exit;
                                 exit;
@@ -2521,7 +2525,7 @@ implementation
                 exit;
                 exit;
               end;
               end;
             FunctionSectionRead:=True;
             FunctionSectionRead:=True;
-            if not ReadUleb32(AReader,FunctionsCount) then
+            if not ReadUleb32(FunctionsCount) then
               begin
               begin
                 InputError('Error reading the functions count');
                 InputError('Error reading the functions count');
                 exit;
                 exit;
@@ -2533,7 +2537,7 @@ implementation
               end;
               end;
             for i:=0 to FunctionsCount-1 do
             for i:=0 to FunctionsCount-1 do
               begin
               begin
-                if not ReadUleb32(AReader,typidx) then
+                if not ReadUleb32(typidx) then
                   begin
                   begin
                     InputError('Error reading type index for function');
                     InputError('Error reading type index for function');
                     exit;
                     exit;
@@ -2583,7 +2587,7 @@ implementation
                 exit;
                 exit;
               end;
               end;
             DataCountSectionRead:=True;
             DataCountSectionRead:=True;
-            if not ReadUleb32(AReader,v) then
+            if not ReadUleb32(v) then
               begin
               begin
                 InputError('Error reading the data count from the data count section');
                 InputError('Error reading the data count from the data count section');
                 exit;
                 exit;
@@ -2604,7 +2608,7 @@ implementation
               InputError('Error reading section ID');
               InputError('Error reading section ID');
               exit;
               exit;
             end;
             end;
-          if not ReadUleb32(AReader,SectionSize) then
+          if not ReadUleb32(SectionSize) then
             begin
             begin
               InputError('Error reading section size');
               InputError('Error reading section size');
               exit;
               exit;