Преглед изворни кода

* procdef directive code generation moved to a separate method

git-svn-id: branches/wasm@47000 -
nickysn пре 4 година
родитељ
комит
fe4f041436
1 измењених фајлова са 49 додато и 41 уклоњено
  1. 49 41
      compiler/wasm32/hlcgcpu.pas

+ 49 - 41
compiler/wasm32/hlcgcpu.pas

@@ -141,6 +141,8 @@ uses
 
 
       { Wasm-specific routines }
       { Wasm-specific routines }
 
 
+      procedure g_procdef(list:TAsmList;pd: tprocdef);
+
       procedure a_load_stack_reg(list : TAsmList;size: tdef;reg: tregister);
       procedure a_load_stack_reg(list : TAsmList;size: tdef;reg: tregister);
       { extra_slots are the slots that are used by the reference, and that
       { extra_slots are the slots that are used by the reference, and that
         will be removed by the store operation }
         will be removed by the store operation }
@@ -1625,50 +1627,10 @@ implementation
 
 
   procedure thlcgwasm.g_proc_entry(list: TAsmList; localsize: longint; nostackframe: boolean);
   procedure thlcgwasm.g_proc_entry(list: TAsmList; localsize: longint; nostackframe: boolean);
     var
     var
-      functype: tai_functype;
       pd: tcpuprocdef;
       pd: tcpuprocdef;
-      i: integer;
-      prm: tcpuparavarsym;
-      bt: TWasmBasicType;
     begin
     begin
       pd:=tcpuprocdef(current_procinfo.procdef);
       pd:=tcpuprocdef(current_procinfo.procdef);
-      functype:=tai_functype.create(pd.mangledname);
-      if Assigned(pd.paras) and (pd.paras.Count>0) then
-        begin
-          for i:=0 to pd.paras.Count-1 do
-            begin
-              prm := tcpuparavarsym(pd.paras[i]);
-              case prm.paraloc[callerside].Size of
-                OS_8..OS_32, OS_S8..OS_S32:
-                  functype.add_param(wbt_i32);
-                OS_64, OS_S64:
-                  functype.add_param(wbt_i64);
-                OS_F32:
-                  functype.add_param(wbt_f32);
-                OS_F64:
-                  functype.add_param(wbt_f64);
-              else
-                // unsupported calleeside parameter type
-                Internalerror(2019093001);
-              end;
-            end;
-        end;
-      if Assigned(pd.returndef) and (pd.returndef.size>0) then
-        begin
-          if not defToWasmBasic(pd.returndef,bt) then
-            bt:=wbt_i32;
-          case bt of
-            wbt_i64:
-              functype.add_result(wbt_i64);
-            wbt_f32:
-              functype.add_result(wbt_f32);
-            wbt_f64:
-              functype.add_result(wbt_f64);
-          else
-            functype.add_result(wbt_i32);
-          end;
-        end;
-      list.Concat(functype);
+      g_procdef(list,pd);
 
 
       tg.gethltemp(list,voidpointertype,voidpointertype.size,tt_persistent,pd.frame_pointer_ref);
       tg.gethltemp(list,voidpointertype,voidpointertype.size,tt_persistent,pd.frame_pointer_ref);
       tg.gethltemp(list,voidpointertype,voidpointertype.size,tt_persistent,pd.base_pointer_ref);
       tg.gethltemp(list,voidpointertype,voidpointertype.size,tt_persistent,pd.base_pointer_ref);
@@ -2041,6 +2003,52 @@ implementation
       internalerror(2012090206);
       internalerror(2012090206);
     end;
     end;
 
 
+    procedure thlcgwasm.g_procdef(list: TAsmList; pd: tprocdef);
+      var
+        functype: tai_functype;
+        i: integer;
+        prm: tcpuparavarsym;
+        bt: TWasmBasicType;
+      begin
+        functype:=tai_functype.create(pd.mangledname);
+        if Assigned(pd.paras) and (pd.paras.Count>0) then
+          begin
+            for i:=0 to pd.paras.Count-1 do
+              begin
+                prm := tcpuparavarsym(pd.paras[i]);
+                case prm.paraloc[callerside].Size of
+                  OS_8..OS_32, OS_S8..OS_S32:
+                    functype.add_param(wbt_i32);
+                  OS_64, OS_S64:
+                    functype.add_param(wbt_i64);
+                  OS_F32:
+                    functype.add_param(wbt_f32);
+                  OS_F64:
+                    functype.add_param(wbt_f64);
+                else
+                  // unsupported calleeside parameter type
+                  Internalerror(2019093001);
+                end;
+              end;
+          end;
+        if Assigned(pd.returndef) and (pd.returndef.size>0) then
+          begin
+            if not defToWasmBasic(pd.returndef,bt) then
+              bt:=wbt_i32;
+            case bt of
+              wbt_i64:
+                functype.add_result(wbt_i64);
+              wbt_f32:
+                functype.add_result(wbt_f32);
+              wbt_f64:
+                functype.add_result(wbt_f64);
+            else
+              functype.add_result(wbt_i32);
+            end;
+          end;
+        list.Concat(functype);
+      end;
+
   procedure thlcgwasm.a_load_stack_reg(list: TAsmList; size: tdef; reg: tregister);
   procedure thlcgwasm.a_load_stack_reg(list: TAsmList; size: tdef; reg: tregister);
     var
     var
       opc: tasmop;
       opc: tasmop;