فهرست منبع

+ wasm internal object reader: parse the tag section

Nikolay Nikolov 1 سال پیش
والد
کامیت
c527437594
1فایلهای تغییر یافته به همراه46 افزوده شده و 0 حذف شده
  1. 46 0
      compiler/ogwasm.pas

+ 46 - 0
compiler/ogwasm.pas

@@ -2367,6 +2367,7 @@ implementation
         GlobalSectionRead: Boolean = false;
         ExportSectionRead: Boolean = false;
         ElementSectionRead: Boolean = false;
+        TagSectionRead: Boolean = false;
         CodeSectionRead: Boolean = false;
         DataSectionRead: Boolean = false;
         DataCountSectionRead: Boolean = false;
@@ -3661,6 +3662,45 @@ implementation
             Result:=True;
           end;
 
+        function ReadTagSection: Boolean;
+          var
+            TagCount, TagTypeIdx: uint32;
+            i: Integer;
+            Attr: Byte;
+          begin
+            Result:=False;
+            if TagSectionRead then
+              begin
+                InputError('Tag section is duplicated');
+                exit;
+              end;
+            TagSectionRead:=True;
+            if not ReadUleb32(TagCount) then
+              begin
+                InputError('Error reading the tag count from the tag section');
+                exit;
+              end;
+            for i:=0 to TagCount-1 do
+              begin
+                if not Read(Attr,1) then
+                  begin
+                    InputError('Error reading tag attribute');
+                    exit;
+                  end;
+                if not ReadUleb32(TagTypeIdx) then
+                  begin
+                    InputError('Error reading tag type index');
+                    exit;
+                  end;
+              end;
+            if AReader.Pos<>(SectionStart+SectionSize) then
+              begin
+                InputError('Unexpected tag section size');
+                exit;
+              end;
+            Result:=True;
+          end;
+
         function ReadCodeSection: Boolean;
           var
             CodeEntriesCount: uint32;
@@ -3931,6 +3971,12 @@ implementation
                   InputError('Error reading the element section');
                   exit;
                 end;
+            Byte(wsiTag):
+              if not ReadTagSection then
+                begin
+                  InputError('Error reading the tag section');
+                  exit;
+                end;
             Byte(wsiCode):
               if not ReadCodeSection then
                 begin