Browse Source

+ support exit()

git-svn-id: branches/wasm@48035 -
nickysn 4 years ago
parent
commit
0cdd7d4d22
1 changed files with 12 additions and 3 deletions
  1. 12 3
      compiler/wasm32/hlcgcpu.pas

+ 12 - 3
compiler/wasm32/hlcgcpu.pas

@@ -47,6 +47,7 @@ uses
                            // if it's in the beggning the jump should be done to the loop (1)
                            // if it's in the beggning the jump should be done to the loop (1)
                            // if the condition at the end, the jump should done to the end of block (0)
                            // if the condition at the end, the jump should done to the end of block (0)
       loopBreakBr: integer;
       loopBreakBr: integer;
+      exitBr: integer;
       fntypelookup : TWasmProcTypeLookup;
       fntypelookup : TWasmProcTypeLookup;
 
 
       constructor create;
       constructor create;
@@ -1389,10 +1390,12 @@ implementation
 
 
   procedure thlcgwasm.a_jmp_always(list: TAsmList; l: tasmlabel);
   procedure thlcgwasm.a_jmp_always(list: TAsmList; l: tasmlabel);
     begin
     begin
-      if l = current_procinfo.CurrBreakLabel then
+      if l=current_procinfo.CurrBreakLabel then
         list.concat(taicpu.op_const(a_br,br_blocks-loopBreakBr))
         list.concat(taicpu.op_const(a_br,br_blocks-loopBreakBr))
-      else if l = current_procinfo.CurrContinueLabel then
+      else if l=current_procinfo.CurrContinueLabel then
         list.concat(taicpu.op_const(a_br,br_blocks-loopContBr))
         list.concat(taicpu.op_const(a_br,br_blocks-loopContBr))
+      else if l=current_procinfo.CurrExitLabel then
+        list.concat(taicpu.op_const(a_br,br_blocks-exitBr))
       else
       else
         Internalerror(2019091806); // unexpected jump
         Internalerror(2019091806); // unexpected jump
     end;
     end;
@@ -1964,11 +1967,17 @@ implementation
   procedure thlcgwasm.gen_entry_code(list: TAsmList);
   procedure thlcgwasm.gen_entry_code(list: TAsmList);
     begin
     begin
       list.concat(Tai_force_line.Create);
       list.concat(Tai_force_line.Create);
+      { todo: inherited? }
+      list.concat(taicpu.op_none(a_block));
+      incblock;
+      exitBr:=br_blocks;
     end;
     end;
 
 
   procedure thlcgwasm.gen_exit_code(list: TAsmList);
   procedure thlcgwasm.gen_exit_code(list: TAsmList);
     begin
     begin
-      { nothing }
+      list.concat(taicpu.op_none(a_end_block));
+      decblock;
+      { todo: inherited? }
     end;
     end;
 
 
   procedure thlcgwasm.a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; srcsize, dstsize: tdef; src, dst: tregister);
   procedure thlcgwasm.a_bit_scan_reg_reg(list: TAsmList; reverse: boolean; srcsize, dstsize: tdef; src, dst: tregister);