Przeglądaj źródła

* replaced several internal errors, related to the WebAssembly labels
resolution with more meaningful error messages, in order to ease the
debugging of the compiler. Based on patch by Pierre.

Nikolay Nikolov 3 lat temu
rodzic
commit
e74797d411
2 zmienionych plików z 20 dodań i 12 usunięć
  1. 14 11
      compiler/wasm32/cpupi.pas
  2. 6 1
      compiler/wasm32/hlcgcpu.pas

+ 14 - 11
compiler/wasm32/cpupi.pas

@@ -180,7 +180,7 @@ implementation
 
 
     class procedure twasmexceptionstatehandler_nativeexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
     class procedure twasmexceptionstatehandler_nativeexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
       begin
       begin
-        internalerror(2021100503);
+        Message1(parser_f_unsupported_feature,'nested exception');
       end;
       end;
 
 
     class procedure twasmexceptionstatehandler_nativeexceptions.begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister);
     class procedure twasmexceptionstatehandler_nativeexceptions.begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister);
@@ -263,7 +263,7 @@ implementation
 
 
     class procedure twasmexceptionstatehandler_bfexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
     class procedure twasmexceptionstatehandler_bfexceptions.handle_nested_exception(list:TAsmList;var t:texceptiontemps;var entrystate: texceptionstate);
       begin
       begin
-        internalerror(2021100502);
+        Message1(parser_f_unsupported_feature,'nested exception');
       end;
       end;
 
 
     class procedure twasmexceptionstatehandler_bfexceptions.begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister);
     class procedure twasmexceptionstatehandler_bfexceptions.begin_catch(list: TAsmList; excepttype: tobjectdef; nextonlabel: tasmlabel; out exceptlocdef: tdef; out exceptlocreg: tregister);
@@ -471,7 +471,7 @@ implementation
                           if (cblock=nil) or
                           if (cblock=nil) or
                              (cblock.blockstart.opcode<>a_if) or
                              (cblock.blockstart.opcode<>a_if) or
                              assigned(cblock.elseinstr) then
                              assigned(cblock.elseinstr) then
-                            internalerror(2021102302);
+                            Message1(parser_f_unsupported_feature,'misplaced a_else');
                           cblock.elseinstr:=lastinstr;
                           cblock.elseinstr:=lastinstr;
                         end;
                         end;
 
 
@@ -482,14 +482,14 @@ implementation
                         begin
                         begin
                           dec(cur_nesting_depth);
                           dec(cur_nesting_depth);
                           if cur_nesting_depth<0 then
                           if cur_nesting_depth<0 then
-                            internalerror(2021102001);
+                            Message1(parser_f_unsupported_feature,'negative nesting level');
                           cblock:=twasmblockitem(blockstack.GetLast);
                           cblock:=twasmblockitem(blockstack.GetLast);
                           if (cblock=nil) or
                           if (cblock=nil) or
                              ((cblock.blockstart.opcode=a_block) and (lastinstr.opcode<>a_end_block)) or
                              ((cblock.blockstart.opcode=a_block) and (lastinstr.opcode<>a_end_block)) or
                              ((cblock.blockstart.opcode=a_loop) and (lastinstr.opcode<>a_end_loop)) or
                              ((cblock.blockstart.opcode=a_loop) and (lastinstr.opcode<>a_end_loop)) or
                              ((cblock.blockstart.opcode=a_if) and (lastinstr.opcode<>a_end_if)) or
                              ((cblock.blockstart.opcode=a_if) and (lastinstr.opcode<>a_end_if)) or
                              ((cblock.blockstart.opcode=a_try) and (lastinstr.opcode<>a_end_try)) then
                              ((cblock.blockstart.opcode=a_try) and (lastinstr.opcode<>a_end_try)) then
-                            internalerror(2021102301);
+                            Message1(parser_f_unsupported_feature,'incompatible nesting level');
                           cblock.free;
                           cblock.free;
                         end;
                         end;
 
 
@@ -518,7 +518,7 @@ implementation
               hp:=tai(hp.Next);
               hp:=tai(hp.Next);
             end;
             end;
           if cur_nesting_depth<>0 then
           if cur_nesting_depth<>0 then
-            internalerror(2021102002);
+            Message1(parser_f_unsupported_feature,'unbalanced nesting level');
           blockstack.free;
           blockstack.free;
         end;
         end;
 
 
@@ -526,6 +526,7 @@ implementation
         var
         var
           hp: tai;
           hp: tai;
           instr: taicpu;
           instr: taicpu;
+          hlabel: tasmsymbol;
           cur_nesting_depth: longint;
           cur_nesting_depth: longint;
         begin
         begin
           cur_nesting_depth:=0;
           cur_nesting_depth:=0;
@@ -549,22 +550,22 @@ implementation
                       begin
                       begin
                         dec(cur_nesting_depth);
                         dec(cur_nesting_depth);
                         if cur_nesting_depth<0 then
                         if cur_nesting_depth<0 then
-                          internalerror(2021102003);
+                          Message1(parser_f_unsupported_feature,'negative nesting level');
                       end;
                       end;
 
 
                     a_br,
                     a_br,
                     a_br_if:
                     a_br_if:
                       begin
                       begin
                         if instr.ops<>1 then
                         if instr.ops<>1 then
-                          internalerror(2021102004);
+                          Message1(parser_f_unsupported_feature,'a_br or a_br_if with wrong operand count');
                         if instr.oper[0]^.typ=top_ref then
                         if instr.oper[0]^.typ=top_ref then
                           begin
                           begin
                             if not assigned(instr.oper[0]^.ref^.symbol) then
                             if not assigned(instr.oper[0]^.ref^.symbol) then
-                              internalerror(2021102005);
+                              Message1(parser_f_unsupported_feature,'a_br or a_br_if with wrong ref operand');
                             if (instr.oper[0]^.ref^.base<>NR_NO) or
                             if (instr.oper[0]^.ref^.base<>NR_NO) or
                                (instr.oper[0]^.ref^.index<>NR_NO) or
                                (instr.oper[0]^.ref^.index<>NR_NO) or
                                (instr.oper[0]^.ref^.offset<>0) then
                                (instr.oper[0]^.ref^.offset<>0) then
-                              internalerror(2021102006);
+                              Message1(parser_f_unsupported_feature,'a_br or a_br_if with wrong ref type');
                             if (instr.oper[0]^.ref^.symbol.nestingdepth<>-1) and
                             if (instr.oper[0]^.ref^.symbol.nestingdepth<>-1) and
                                (cur_nesting_depth>=instr.oper[0]^.ref^.symbol.nestingdepth) then
                                (cur_nesting_depth>=instr.oper[0]^.ref^.symbol.nestingdepth) then
                               instr.loadconst(0,cur_nesting_depth-instr.oper[0]^.ref^.symbol.nestingdepth)
                               instr.loadconst(0,cur_nesting_depth-instr.oper[0]^.ref^.symbol.nestingdepth)
@@ -573,6 +574,8 @@ implementation
 {$ifndef EXTDEBUG}
 {$ifndef EXTDEBUG}
                                 internalerror(2021102007);
                                 internalerror(2021102007);
 {$endif EXTDEBUG}
 {$endif EXTDEBUG}
+                                hlabel:=tasmsymbol(instr.oper[0]^.ref^.symbol);
+                                asmlist.insertafter(tai_comment.create(strpnew('Unable to find destination of label '+hlabel.name)),hp);
                               end;
                               end;
                           end;
                           end;
                       end;
                       end;
@@ -584,7 +587,7 @@ implementation
               hp:=tai(hp.Next);
               hp:=tai(hp.Next);
             end;
             end;
           if cur_nesting_depth<>0 then
           if cur_nesting_depth<>0 then
-            internalerror(2021102008);
+            Message1(parser_f_unsupported_feature,'unbalanced nesting level');
         end;
         end;
 
 
       procedure resolve_labels(asmlist: TAsmList);
       procedure resolve_labels(asmlist: TAsmList);

+ 6 - 1
compiler/wasm32/hlcgcpu.pas

@@ -1791,7 +1791,12 @@ implementation
       else if l=current_procinfo.CurrExitLabel then
       else if l=current_procinfo.CurrExitLabel then
         list.concat(taicpu.op_sym(a_br,l))
         list.concat(taicpu.op_sym(a_br,l))
       else
       else
-        Internalerror(2019091806); // unexpected jump
+        begin
+{$ifndef EXTDEBUG}
+          Internalerror(2019091806); // unexpected jump
+{$endif EXTDEBUG}
+          list.concat(tai_comment.create(strpnew('Unable to find destination of label '+l.name)));
+        end;
     end;
     end;
 
 
   procedure thlcgwasm.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);
   procedure thlcgwasm.a_loadfpu_ref_ref(list: TAsmList; fromsize, tosize: tdef; const ref1, ref2: treference);