Browse Source

* refactored the taicpu_wasm_structured_instruction descendants to use a wstyp enum variable, instead of using the 'is' operator to determine the class type

Nikolay Nikolov 1 year ago
parent
commit
31dff18a61
2 changed files with 20 additions and 5 deletions
  1. 15 0
      compiler/wasm32/aasmcpu.pas
  2. 5 5
      compiler/wasm32/cpupi.pas

+ 15 - 0
compiler/wasm32/aasmcpu.pas

@@ -84,6 +84,14 @@ uses
          procedure Pass2(objdata:TObjData);override;
          procedure Pass2(objdata:TObjData);override;
       end;
       end;
 
 
+      taiwstype = (
+        aitws_if,
+        aitws_block,
+        aitws_loop,
+        aitws_try_delegate,
+        aitws_try_catch
+      );
+
       { taicpu_wasm_structured_instruction }
       { taicpu_wasm_structured_instruction }
 
 
       taicpu_wasm_structured_instruction = class(tai)
       taicpu_wasm_structured_instruction = class(tai)
@@ -91,6 +99,8 @@ uses
         FLabel: TAsmLabel;
         FLabel: TAsmLabel;
         FLabelIsNew: Boolean;
         FLabelIsNew: Boolean;
       public
       public
+        wstyp: taiwstype;
+
         constructor Create;
         constructor Create;
         procedure Map(f: TAsmMapFunc; blockstack: twasmstruc_stack);virtual;abstract;
         procedure Map(f: TAsmMapFunc; blockstack: twasmstruc_stack);virtual;abstract;
         procedure ConvertToFlatList(l: TAsmList);virtual;abstract;
         procedure ConvertToFlatList(l: TAsmList);virtual;abstract;
@@ -335,6 +345,7 @@ uses
         p: tai;
         p: tai;
         ThenDone, ElsePresent, ElseDone: Boolean;
         ThenDone, ElsePresent, ElseDone: Boolean;
       begin
       begin
+        wstyp:=aitws_if;
         inherited Create;
         inherited Create;
         if assigned(a_if_instr.Previous) or assigned(a_if_instr.Next) then
         if assigned(a_if_instr.Previous) or assigned(a_if_instr.Next) then
           internalerror(2023100301);
           internalerror(2023100301);
@@ -541,6 +552,7 @@ uses
         Done: Boolean;
         Done: Boolean;
         p: tai;
         p: tai;
       begin
       begin
+        wstyp:=aitws_block;
         inherited Create;
         inherited Create;
         if assigned(a_block_instr.Previous) or assigned(a_block_instr.Next) then
         if assigned(a_block_instr.Previous) or assigned(a_block_instr.Next) then
           internalerror(2023100304);
           internalerror(2023100304);
@@ -609,6 +621,7 @@ uses
         Done: Boolean;
         Done: Boolean;
         p: tai;
         p: tai;
       begin
       begin
+        wstyp:=aitws_loop;
         inherited Create;
         inherited Create;
         if assigned(a_loop_instr.Previous) or assigned(a_loop_instr.Next) then
         if assigned(a_loop_instr.Previous) or assigned(a_loop_instr.Next) then
           internalerror(2023100306);
           internalerror(2023100306);
@@ -792,6 +805,7 @@ uses
       var
       var
         Done: Boolean;
         Done: Boolean;
       begin
       begin
+        wstyp:=aitws_try_catch;
         inherited internal_create(a_try_asmlist);
         inherited internal_create(a_try_asmlist);
         if assigned(first_ins.Previous) or assigned(first_ins.Next) then
         if assigned(first_ins.Previous) or assigned(first_ins.Next) then
           internalerror(2023100310);
           internalerror(2023100310);
@@ -896,6 +910,7 @@ uses
 
 
     constructor tai_wasmstruc_try_delegate.internal_create(first_ins: taicpu; a_try_asmlist, srclist: TAsmList);
     constructor tai_wasmstruc_try_delegate.internal_create(first_ins: taicpu; a_try_asmlist, srclist: TAsmList);
       begin
       begin
+        wstyp:=aitws_try_delegate;
         inherited internal_create(a_try_asmlist);
         inherited internal_create(a_try_asmlist);
         if assigned(first_ins.Previous) or assigned(first_ins.Next) then
         if assigned(first_ins.Previous) or assigned(first_ins.Next) then
           internalerror(2023100309);
           internalerror(2023100309);

+ 5 - 5
compiler/wasm32/cpupi.pas

@@ -387,7 +387,7 @@ implementation
     function tcpuprocinfo.ConvertIfToBrIf(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
     function tcpuprocinfo.ConvertIfToBrIf(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
       begin
       begin
         result.typ:=amfrtNoChange;
         result.typ:=amfrtNoChange;
-        if (ai.typ=ait_wasm_structured_instruction) and (ai is tai_wasmstruc_if) then
+        if (ai.typ=ait_wasm_structured_instruction) and (taicpu_wasm_structured_instruction(ai).wstyp=aitws_if) then
           begin
           begin
             result.typ:=amfrtNewList;
             result.typ:=amfrtNewList;
             result.newlist:=TAsmList.Create;
             result.newlist:=TAsmList.Create;
@@ -398,7 +398,7 @@ implementation
     function tcpuprocinfo.ConvertLoopToBr(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
     function tcpuprocinfo.ConvertLoopToBr(ai: tai; blockstack: twasmstruc_stack): TAsmMapFuncResult;
       begin
       begin
         result.typ:=amfrtNoChange;
         result.typ:=amfrtNoChange;
-        if (ai.typ=ait_wasm_structured_instruction) and (ai is tai_wasmstruc_loop) then
+        if (ai.typ=ait_wasm_structured_instruction) and (taicpu_wasm_structured_instruction(ai).wstyp=aitws_loop) then
           begin
           begin
             result.typ:=amfrtNewList;
             result.typ:=amfrtNewList;
             result.newlist:=TAsmList.Create;
             result.newlist:=TAsmList.Create;
@@ -825,17 +825,17 @@ implementation
             begin
             begin
               if hp.typ=ait_wasm_structured_instruction then
               if hp.typ=ait_wasm_structured_instruction then
                 begin
                 begin
-                  if not (hp is tai_wasmstruc_try) then
+                  if not (taicpu_wasm_structured_instruction(hp).wstyp in [aitws_try_catch,aitws_try_delegate]) then
                     internalerror(2023102201);
                     internalerror(2023102201);
                   resolve_labels_of_asmlist_with_try_blocks_recursive(tai_wasmstruc_try(hp).try_asmlist);
                   resolve_labels_of_asmlist_with_try_blocks_recursive(tai_wasmstruc_try(hp).try_asmlist);
-                  if hp is tai_wasmstruc_try_catch then
+                  if taicpu_wasm_structured_instruction(hp).wstyp=aitws_try_catch then
                     with tai_wasmstruc_try_catch(hp) do
                     with tai_wasmstruc_try_catch(hp) do
                       begin
                       begin
                         for i:=low(catch_list) to high(catch_list) do
                         for i:=low(catch_list) to high(catch_list) do
                           resolve_labels_of_asmlist_with_try_blocks_recursive(catch_list[i].asmlist);
                           resolve_labels_of_asmlist_with_try_blocks_recursive(catch_list[i].asmlist);
                         resolve_labels_of_asmlist_with_try_blocks_recursive(catch_all_asmlist);
                         resolve_labels_of_asmlist_with_try_blocks_recursive(catch_all_asmlist);
                       end
                       end
-                  else if hp is tai_wasmstruc_try_delegate then
+                  else if taicpu_wasm_structured_instruction(hp).wstyp=aitws_try_delegate then
                     {nothing}
                     {nothing}
                   else
                   else
                     internalerror(2023102202);
                     internalerror(2023102202);