Browse Source

[PATCH 05/83] updating hl-codegen for wasm

From 6d61294030de89e880edf9529aca2c612d716dfc Mon Sep 17 00:00:00 2001
From: Dmitry Boyarintsev <[email protected]>
Date: Fri, 30 Aug 2019 10:34:54 -0400

git-svn-id: branches/wasm@45882 -
nickysn 5 years ago
parent
commit
21ddbf196b
3 changed files with 179 additions and 240 deletions
  1. 167 225
      compiler/wasm/hlcgcpu.pas
  2. 0 3
      compiler/wasm/itcpuwasm.pas
  3. 12 12
      compiler/wasm/rgcpu.pas

+ 167 - 225
compiler/wasm/hlcgcpu.pas

@@ -234,17 +234,6 @@ uses
 
 
     end;
     end;
 
 
-
-  const
-    opcmp2if: array[TOpCmp] of TAsmOp = (A_None,
-       a_i64_eq,               // OC_EQ
-       a_i64_gt_s, a_i64_lt_s, // OC_GT, OC_LT
-       a_i64_ge_s, a_i64_le_s, // OC_GTE, OC_LTE
-       a_i64_ne,               // OC_NE
-       a_i64_le_u, a_i64_lt_u, // OC_BE, OC_B
-       a_i64_ge_u, a_i64_gt_u  // OC_AE, OC_A
-    );
-
 implementation
 implementation
 
 
   uses
   uses
@@ -255,11 +244,45 @@ implementation
     procinfo,cpuinfo,cgcpu,tgobj;
     procinfo,cpuinfo,cgcpu,tgobj;
 
 
   const
   const
-    TOpCG2IAsmOp : array[topcg] of TAsmOp=(                       { not = xor -1 }
-      A_None,A_None,a_iadd,a_iand,A_none,a_idiv,a_imul,a_imul,a_ineg,A_None,a_ior,a_ishr,a_ishl,a_iushr,a_isub,a_ixor,A_None,A_None
+    TOpCG2IAsmOp : array[topcg] of TAsmOp=(
+      A_None,      {OP_NONE}
+      a_i32_load,  {OP_MOVE, replaced operation with direct load }
+      a_i32_add,   {OP_ADD,  simple addition          }
+      a_i32_and,   {OP_AND,  simple logical and       }
+      a_i32_div_u, {OP_DIV,  simple unsigned division }
+      a_i32_div_s, {OP_IDIV, simple signed division   }
+      a_i32_mul,   {OP_IMUL, simple signed multiply   }
+      a_i32_mul,   {OP_MUL,  simple unsigned multiply }
+      A_None,      {OP_NEG,  simple negate            } // neg = xor + 1
+      A_None,      {OP_NOT,  simple logical not       } // not = xor - 1
+      a_i32_or,    {OP_OR,   simple logical or        }
+      a_i32_shr_s, {OP_SAR,  arithmetic shift-right   }
+      a_i32_shr_s, {OP_SHL,  logical shift left       }
+      a_i32_shr_u, {OP_SHR,  logical shift right      }
+      a_i32_sub,   {OP_SUB,  simple subtraction       }
+      a_i32_xor,   {OP_XOR,  simple exclusive or      }
+      a_i32_rotl,  {OP_ROL,  rotate left              }
+      a_i32_rotr   {OP_ROR   rotate right             }
     );
     );
-    TOpCG2LAsmOp : array[topcg] of TAsmOp=(                       { not = xor -1 }
-      A_None,A_None,a_ladd,a_land,A_none,a_ldiv,a_lmul,a_lmul,a_lneg,A_None,a_lor,a_lshr,a_lshl,a_lushr,a_lsub,a_lxor,A_None,A_None
+    TOpCG2LAsmOp : array[topcg] of TAsmOp=(
+      A_None,      {OP_NONE}
+      a_i64_load,  {OP_MOVE, replaced operation with direct load }
+      a_i64_add,   {OP_ADD,  simple addition          }
+      a_i64_and,   {OP_AND,  simple logical and       }
+      a_i64_div_u, {OP_DIV,  simple unsigned division }
+      a_i64_div_s, {OP_IDIV, simple signed division   }
+      a_i64_mul,   {OP_IMUL, simple signed multiply   }
+      a_i64_mul,   {OP_MUL,  simple unsigned multiply }
+      A_None,      {OP_NEG,  simple negate            } // neg = xor + 1
+      A_None,      {OP_NOT,  simple logical not       } // not = xor - 1
+      a_i64_or,    {OP_OR,   simple logical or        }
+      a_i64_shr_s, {OP_SAR,  arithmetic shift-right   }
+      a_i64_shr_s, {OP_SHL,  logical shift left       }
+      a_i64_shr_u, {OP_SHR,  logical shift right      }
+      a_i64_sub,   {OP_SUB,  simple subtraction       }
+      a_i64_xor,   {OP_XOR,  simple exclusive or      }
+      a_i64_rotl,  {OP_ROL,  rotate left              }
+      a_i64_rotr   {OP_ROR   rotate right             }
     );
     );
 
 
   constructor thlcgwasm.create;
   constructor thlcgwasm.create;
@@ -360,9 +383,6 @@ implementation
 
 
 
 
   procedure thlcgwasm.a_load_const_stack(list : TAsmList;size : tdef;a : tcgint; typ: TRegisterType);
   procedure thlcgwasm.a_load_const_stack(list : TAsmList;size : tdef;a : tcgint; typ: TRegisterType);
-    const
-      int2opc: array[-1..5] of tasmop = (a_iconst_m1,a_iconst_0,a_iconst_1,
-        a_iconst_2,a_iconst_3,a_iconst_4,a_iconst_5);
     begin
     begin
       case typ of
       case typ of
         R_INTREGISTER:
         R_INTREGISTER:
@@ -372,34 +392,12 @@ implementation
               OS_S8,OS_S16,OS_S32:
               OS_S8,OS_S16,OS_S32:
                 begin
                 begin
                   { convert cardinals to longints }
                   { convert cardinals to longints }
-                  a:=longint(a);
-                  if (a>=-1) and
-                     (a<=5) then
-                    list.concat(taicpu.op_none(int2opc[a]))
-                  else if (a>=low(shortint)) and
-                          (a<=high(shortint)) then
-                    list.concat(taicpu.op_const(a_bipush,a))
-                  else if (a>=low(smallint)) and
-                          (a<=high(smallint)) then
-                    list.concat(taicpu.op_const(a_sipush,a))
-                  else
-                    list.concat(taicpu.op_const(a_ldc,a));
-                  { for android verifier }
-                  if (size.typ=orddef) and
-                     (torddef(size).ordtype=uwidechar) then
-                    list.concat(taicpu.op_none(a_i2c));
+                  list.concat(taicpu.op_const(a_i32_const, a));
                 end;
                 end;
               OS_64,OS_S64:
               OS_64,OS_S64:
                 begin
                 begin
-                  case a of
-                    0:
-                      list.concat(taicpu.op_none(a_lconst_0));
-                    1:
-                      list.concat(taicpu.op_none(a_lconst_1));
-                    else
-                      list.concat(taicpu.op_const(a_ldc2_w,a));
-                  end;
-                  incstack(list,1);
+                  list.concat(taicpu.op_const(a_i64_const, a));
+                  incstack(list,1); // why?
                 end;
                 end;
               else
               else
                 internalerror(2010110702);
                 internalerror(2010110702);
@@ -409,7 +407,7 @@ implementation
           begin
           begin
             if a<>0 then
             if a<>0 then
               internalerror(2010110701);
               internalerror(2010110701);
-            list.concat(taicpu.op_none(a_aconst_null));
+            list.concat(taicpu.op_none(a_none));
           end;
           end;
         else
         else
           internalerror(2010110703);
           internalerror(2010110703);
@@ -450,24 +448,12 @@ implementation
       case tfloatdef(size).floattype of
       case tfloatdef(size).floattype of
         s32real:
         s32real:
           begin
           begin
-            if a=0.0 then
-              list.concat(taicpu.op_none(a_fconst_0))
-            else if a=1.0 then
-              list.concat(taicpu.op_none(a_fconst_1))
-            else if a=2.0 then
-              list.concat(taicpu.op_none(a_fconst_2))
-            else
-              list.concat(taicpu.op_single(a_ldc,a));
+            list.concat(taicpu.op_single(a_f32_const, a));
             incstack(list,1);
             incstack(list,1);
           end;
           end;
         s64real:
         s64real:
           begin
           begin
-            if a=0.0 then
-              list.concat(taicpu.op_none(a_dconst_0))
-            else if a=1.0 then
-              list.concat(taicpu.op_none(a_dconst_1))
-            else
-              list.concat(taicpu.op_double(a_ldc2_w,a));
+            list.concat(taicpu.op_double(a_f64_const,a));
             incstack(list,2);
             incstack(list,2);
           end
           end
         else
         else
@@ -540,7 +526,7 @@ implementation
       end;
       end;
       if trunc32 then
       if trunc32 then
         begin
         begin
-          list.concat(taicpu.op_none(a_l2i));
+          list.concat(taicpu.op_none(a_i32_trunc_s_f32)); // todo: there are several truncs
           decstack(list,1);
           decstack(list,1);
         end;
         end;
     end;
     end;
@@ -667,6 +653,9 @@ implementation
       opc: tasmop;
       opc: tasmop;
       primitivetype: boolean;
       primitivetype: boolean;
     begin
     begin
+      internalerror(2019083001); // arrays are note yet supported
+
+      (*
       elemdef:=arrdef;
       elemdef:=arrdef;
       if initdim>1 then
       if initdim>1 then
         begin
         begin
@@ -688,14 +677,15 @@ implementation
           }
           }
           { get the type of the elements of the array we are creating }
           { get the type of the elements of the array we are creating }
           elemdef:=tarraydef(arrdef).elementdef;
           elemdef:=tarraydef(arrdef).elementdef;
-          { todo: WASM
+
+          { todo: WASM. Todo: array data structures needs to be stored in Memory
           mangledname:=jvmarrtype(elemdef,primitivetype);
           mangledname:=jvmarrtype(elemdef,primitivetype);
-          }
           if primitivetype then
           if primitivetype then
             opc:=a_newarray
             opc:=a_newarray
           else
           else
             opc:=a_anewarray;
             opc:=a_anewarray;
           list.concat(taicpu.op_sym(opc,current_asmdata.RefAsmSymbol(mangledname,AT_METADATA)));
           list.concat(taicpu.op_sym(opc,current_asmdata.RefAsmSymbol(mangledname,AT_METADATA)));
+          }
         end;
         end;
       { all dimensions are removed from the stack, an array reference is
       { all dimensions are removed from the stack, an array reference is
         added }
         added }
@@ -768,12 +758,15 @@ implementation
               internalerror(2011081801);
               internalerror(2011081801);
           end;
           end;
         end;
         end;
+        *)
     end;
     end;
 
 
   procedure thlcgwasm.g_getarraylen(list: TAsmList; const arrloc: tlocation);
   procedure thlcgwasm.g_getarraylen(list: TAsmList; const arrloc: tlocation);
     var
     var
       nillab,endlab: tasmlabel;
       nillab,endlab: tasmlabel;
     begin
     begin
+      internalerror(2019083001); // arrays are note yet supported
+      (*
       { inline because we have to use the arraylength opcode, which
       { inline because we have to use the arraylength opcode, which
         cannot be represented directly in Pascal. Even though the JVM
         cannot be represented directly in Pascal. Even though the JVM
         supports allocated arrays with length=0, we still also have to
         supports allocated arrays with length=0, we still also have to
@@ -806,13 +799,34 @@ implementation
       incstack(list,1);
       incstack(list,1);
 
 
       a_label(list,endlab);
       a_label(list,endlab);
+      *)
     end;
     end;
 
 
     procedure thlcgwasm.a_cmp_stack_label(list: TAsmlist; size: tdef; cmp_op: topcmp; lab: tasmlabel);
     procedure thlcgwasm.a_cmp_stack_label(list: TAsmlist; size: tdef; cmp_op: topcmp; lab: tasmlabel);
       const
       const
-        opcmp2icmp: array[topcmp] of tasmop = (A_None,
-          a_if_icmpeq,a_if_icmpgt,a_if_icmplt,a_if_icmpge,a_if_icmple,
-          a_if_icmpne,a_if_icmple,a_if_icmplt,a_if_icmpge,a_if_icmpgt);
+        opcmp32: array[topcmp] of tasmop = (
+          A_None,     { OC_NONE, }
+          a_i32_eq,   { OC_EQ,   equality comparison              }
+          a_i32_gt_s, { OC_GT,   greater than (signed)            }
+          a_i32_lt_s, { OC_LT,   less than (signed)               }
+          a_i32_ge_s, { OC_GTE,  greater or equal than (signed)   }
+          a_i32_le_s, { OC_LTE,  less or equal than (signed)      }
+          a_i32_ne,   { OC_NE,   not equal                        }
+          a_i32_le_u, { OC_BE,   less or equal than (unsigned)    }
+          a_i32_lt_u, { OC_B,    less than (unsigned)             }
+          a_i32_ge_u, { OC_AE,   greater or equal than (unsigned) }
+          a_i32_gt_u  { OC_A     greater than (unsigned)          }
+        );
+      const
+        opcmp64: array[TOpCmp] of TAsmOp = (A_None,
+           a_i64_eq,               // OC_EQ
+           a_i64_gt_s, a_i64_lt_s, // OC_GT, OC_LT
+           a_i64_ge_s, a_i64_le_s, // OC_GTE, OC_LTE
+           a_i64_ne,               // OC_NE
+           a_i64_le_u, a_i64_lt_u, // OC_BE, OC_B
+           a_i64_ge_u, a_i64_gt_u  // OC_AE, OC_A
+        );
+
       var
       var
         cgsize: tcgsize;
         cgsize: tcgsize;
       begin
       begin
@@ -825,15 +839,15 @@ implementation
                 OS_16,OS_S16,
                 OS_16,OS_S16,
                 OS_S32,OS_32:
                 OS_S32,OS_32:
                   begin
                   begin
-                    list.concat(taicpu.op_sym(opcmp2icmp[cmp_op],lab));
+                    list.concat(taicpu.op_sym(opcmp32[cmp_op],lab));
                     decstack(list,2);
                     decstack(list,2);
                   end;
                   end;
                 OS_64,OS_S64:
                 OS_64,OS_S64:
                   begin
                   begin
-                    list.concat(taicpu.op_none(a_lcmp));
-                    decstack(list,3);
-                    list.concat(taicpu.op_sym(opcmp2if[cmp_op],lab));
-                    decstack(list,1);
+                    //list.concat(taicpu.op_none(a_lcmp));
+                    //decstack(list,3);
+                    list.concat(taicpu.op_sym(opcmp64[cmp_op],lab));
+                    decstack(list,2);
                   end;
                   end;
                 else
                 else
                   internalerror(2010120538);
                   internalerror(2010120538);
@@ -843,9 +857,9 @@ implementation
             begin
             begin
               case cmp_op of
               case cmp_op of
                 OC_EQ:
                 OC_EQ:
-                  list.concat(taicpu.op_sym(a_if_acmpeq,lab));
+                  list.concat(taicpu.op_sym(a_i64_eq,lab));
                 OC_NE:
                 OC_NE:
-                  list.concat(taicpu.op_sym(a_if_acmpne,lab));
+                  list.concat(taicpu.op_sym(a_i64_ne,lab));
                 else
                 else
                   internalerror(2010120537);
                   internalerror(2010120537);
               end;
               end;
@@ -918,12 +932,12 @@ implementation
           case tfloatdef(resdef).floattype of
           case tfloatdef(resdef).floattype of
             s32real:
             s32real:
               begin
               begin
-                list.concat(taicpu.op_none(a_fconst_0));
+                list.concat(taicpu.op_single(a_f32_const, 0));
                 incstack(list,1);
                 incstack(list,1);
               end;
               end;
             s64real:
             s64real:
               begin
               begin
-                list.concat(taicpu.op_none(a_dconst_0));
+                list.concat(taicpu.op_double(a_f64_const, 0));
                 incstack(list,2);
                 incstack(list,2);
               end;
               end;
             else
             else
@@ -1002,7 +1016,9 @@ implementation
                   a_load_reg_stack(list,voidpointertype,ref.base);
                   a_load_reg_stack(list,voidpointertype,ref.base);
                   if dup then
                   if dup then
                     begin
                     begin
-                      list.concat(taicpu.op_none(a_dup));
+                      internalerror(2019083002);
+                      //todo: add duplicate
+                      //list.concat(taicpu.op_none(a_dup));
                       incstack(list,1);
                       incstack(list,1);
                     end;
                     end;
                   { field name/type encoded in symbol, no index/offset }
                   { field name/type encoded in symbol, no index/offset }
@@ -1068,7 +1084,8 @@ implementation
             a_op_const_stack(list,OP_ADD,s32inttype,ref.offset);
             a_op_const_stack(list,OP_ADD,s32inttype,ref.offset);
           if dup then
           if dup then
             begin
             begin
-              list.concat(taicpu.op_none(a_dup2));
+              internalerror(2019083002); // todo: missing dups
+              //list.concat(taicpu.op_none(a_dup2));
               incstack(list,2);
               incstack(list,2);
             end;
             end;
           result:=2;
           result:=2;
@@ -1273,7 +1290,8 @@ implementation
               a_op_const_stack(list,OP_SHR,size,(size.size*8)-1);
               a_op_const_stack(list,OP_SHR,size,(size.size*8)-1);
               if size.size=8 then
               if size.size=8 then
                 begin
                 begin
-                  list.concat(taicpu.op_none(a_l2i));
+                  //todo: any operands needed?
+                  list.concat(taicpu.op_none(a_i32_wrap_i64));
                   decstack(list,1);
                   decstack(list,1);
                 end;
                 end;
             end
             end
@@ -1317,8 +1335,11 @@ implementation
       maybe_adjust_cmp_stackval(list,size,cmp_op);
       maybe_adjust_cmp_stackval(list,size,cmp_op);
       if ref.base<>NR_EVAL_STACK_BASE then
       if ref.base<>NR_EVAL_STACK_BASE then
         a_load_ref_stack(list,size,ref,prepare_stack_for_ref(list,ref,false))
         a_load_ref_stack(list,size,ref,prepare_stack_for_ref(list,ref,false))
-      else
-        list.concat(taicpu.op_none(a_swap));
+      else begin
+        // todo: need a swap operation?
+        //list.concat(taicpu.op_none(a_swap));
+        Internalerror(2019083003);
+      end;
       maybe_adjust_cmp_stackval(list,size,cmp_op);
       maybe_adjust_cmp_stackval(list,size,cmp_op);
       a_cmp_stack_label(list,size,cmp_op,l);
       a_cmp_stack_label(list,size,cmp_op,l);
     end;
     end;
@@ -1344,7 +1365,7 @@ implementation
 
 
   procedure thlcgwasm.a_jmp_always(list: TAsmList; l: tasmlabel);
   procedure thlcgwasm.a_jmp_always(list: TAsmList; l: tasmlabel);
     begin
     begin
-      list.concat(taicpu.op_sym(a_goto,current_asmdata.RefAsmSymbol(l.name,AT_METADATA)));
+      list.concat(taicpu.op_sym(a_br,current_asmdata.RefAsmSymbol(l.name,AT_METADATA)));
     end;
     end;
 
 
   procedure thlcgwasm.concatcopy_normal_array(list: TAsmList; size: tdef; const source, dest: treference);
   procedure thlcgwasm.concatcopy_normal_array(list: TAsmList; size: tdef; const source, dest: treference);
@@ -1442,7 +1463,8 @@ implementation
      if ndim<>1 then
      if ndim<>1 then
        begin
        begin
          { pop return value, must be the same as dest }
          { pop return value, must be the same as dest }
-         list.concat(taicpu.op_none(a_pop));
+         //list.concat(taicpu.op_none(a_pop));
+         Internalerror(2019083001); // no support for arrays
          decstack(list,1);
          decstack(list,1);
        end;
        end;
     end;
     end;
@@ -1600,41 +1622,8 @@ implementation
     end;
     end;
 
 
   procedure thlcgwasm.g_proc_exit(list: TAsmList; parasize: longint; nostackframe: boolean);
   procedure thlcgwasm.g_proc_exit(list: TAsmList; parasize: longint; nostackframe: boolean);
-    var
-      retdef: tdef;
-      opc: tasmop;
     begin
     begin
-      if current_procinfo.procdef.proctypeoption in [potype_constructor,potype_class_constructor] then
-        retdef:=voidtype
-      else
-        retdef:=current_procinfo.procdef.returndef;
-      case retdef.typ of
-        orddef:
-          case torddef(retdef).ordtype of
-            uvoid:
-              opc:=a_return;
-            s64bit,
-            u64bit,
-            scurrency:
-              opc:=a_lreturn;
-            else
-              opc:=a_ireturn;
-          end;
-        setdef:
-          opc:=a_areturn;
-        floatdef:
-          case tfloatdef(retdef).floattype of
-            s32real:
-              opc:=a_freturn;
-            s64real:
-              opc:=a_dreturn;
-            else
-              internalerror(2011010213);
-          end;
-        else
-          opc:=a_areturn;
-      end;
-      list.concat(taicpu.op_none(opc));
+      list.concat(taicpu.op_none(a_return));
     end;
     end;
 
 
   procedure thlcgwasm.gen_load_return_value(list: TAsmList);
   procedure thlcgwasm.gen_load_return_value(list: TAsmList);
@@ -2035,12 +2024,14 @@ implementation
       incstack(list,1+ord(size.size>4)-extra_slots);
       incstack(list,1+ord(size.size>4)-extra_slots);
       if finishandval<>-1 then
       if finishandval<>-1 then
         a_op_const_stack(list,OP_AND,size,finishandval);
         a_op_const_stack(list,OP_AND,size,finishandval);
-      if ref.checkcast then
-        gen_typecheck(list,a_checkcast,size);
+
+      // there's no cast check in Wasm
+      //if ref.checkcast then
+      //  gen_typecheck(list,a_checkcast,size);
     end;
     end;
 
 
   function thlcgwasm.loadstoreopcref(def: tdef; isload: boolean; const ref: treference; out finishandval: tcgint): tasmop;
   function thlcgwasm.loadstoreopcref(def: tdef; isload: boolean; const ref: treference; out finishandval: tcgint): tasmop;
-    const
+   (* const
                      { isload  static }
                      { isload  static }
       getputopc: array[boolean,boolean] of tasmop =
       getputopc: array[boolean,boolean] of tasmop =
         ((a_putfield,a_putstatic),
         ((a_putfield,a_putstatic),
@@ -2066,7 +2057,8 @@ implementation
                    finishandval:=65535;
                    finishandval:=65535;
             end;
             end;
         end
         end
-      else
+      else *)
+      begin //todo:
         result:=loadstoreopc(def,isload,ref.arrayreftype<>art_none,finishandval);
         result:=loadstoreopc(def,isload,ref.arrayreftype<>art_none,finishandval);
     end;
     end;
 
 
@@ -2079,105 +2071,39 @@ implementation
         R_INTREGISTER:
         R_INTREGISTER:
           begin
           begin
             size:=def.size;
             size:=def.size;
-            if not isarray then
-              begin
-                case size of
-                  1,2,3,4:
-                    if isload then
-                      result:=a_iload
-                    else
-                      result:=a_istore;
-                  8:
-                    if isload then
-                      result:=a_lload
-                    else
-                      result:=a_lstore;
-                  else
-                    internalerror(2011032814);
-                end;
-              end
-            { array }
-            else if isload then
-              begin
-                case size of
-                  1:
-                    begin
-                      result:=a_baload;
-                      if not is_signed(def) and
-                         (def.typ=orddef) and
-                         (torddef(def).high>127) then
-                        finishandval:=255;
-                    end;
-                  2:
-                    begin
-                      if is_widechar(def) then
-                        result:=a_caload
-                      else
-                        begin
-                          result:=a_saload;
-                          { if we'd treat arrays of word as "array of widechar" we
-                            could use a_caload, but that would make for even more
-                            awkward interfacing with external Java code }
-                          if not is_signed(def) and
-                         (def.typ=orddef) and
-                         (torddef(def).high>32767) then
-                            finishandval:=65535;
-                        end;
-                    end;
-                  4: result:=a_iaload;
-                  8: result:=a_laload;
-                  else
-                    internalerror(2010120503);
-                end
-              end
-            else
-              begin
-                case size of
-                  1: result:=a_bastore;
-                  2: if not is_widechar(def) then
-                       result:=a_sastore
-                     else
-                       result:=a_castore;
-                  4: result:=a_iastore;
-                  8: result:=a_lastore;
-                  else
-                    internalerror(2010120508);
-                end
-              end
+            case size of
+              1,2,3,4:
+                if isload then
+                  result:=a_i32_load
+                else
+                  result:=a_i32_store;
+              8:
+                if isload then
+                  result:=a_i64_load
+                else
+                  result:=a_i64_store;
+              else
+                internalerror(2011032814);
+            end;
           end;
           end;
         R_ADDRESSREGISTER:
         R_ADDRESSREGISTER:
-          if not isarray then
-            if isload then
-              result:=a_aload
-            else
-              result:=a_astore
-          else if isload then
-            result:=a_aaload
+          if isload then
+            result:=a_i32_load
           else
           else
-            result:=a_aastore;
+            result:=a_i32_store;
         R_FPUREGISTER:
         R_FPUREGISTER:
           begin
           begin
             case tfloatdef(def).floattype of
             case tfloatdef(def).floattype of
               s32real:
               s32real:
-                if not isarray then
-                  if isload then
-                    result:=a_fload
-                  else
-                    result:=a_fstore
-                else if isload then
-                  result:=a_faload
+                if isload then
+                  result:=a_f32_load
                 else
                 else
-                  result:=a_fastore;
+                  result:=a_f32_store;
               s64real:
               s64real:
-                if not isarray then
-                  if isload then
-                    result:=a_dload
-                  else
-                    result:=a_dstore
-                else if isload then
-                  result:=a_daload
+                if isload then
+                  result:=a_f32_load
                 else
                 else
-                  result:=a_dastore;
+                  result:=a_f32_store
               else
               else
                 internalerror(2010120504);
                 internalerror(2010120504);
             end
             end
@@ -2210,14 +2136,17 @@ implementation
           if not(tocgsize in [OS_S64,OS_64]) then
           if not(tocgsize in [OS_S64,OS_64]) then
             begin
             begin
               { truncate }
               { truncate }
-              list.concat(taicpu.op_none(a_l2i));
+              list.concat(taicpu.op_none(a_i32_wrap_i64));
               decstack(list,1);
               decstack(list,1);
             end;
             end;
         end
         end
       else if tocgsize in [OS_S64,OS_64] then
       else if tocgsize in [OS_S64,OS_64] then
         begin
         begin
           { extend }
           { extend }
-          list.concat(taicpu.op_none(a_i2l));
+          if tocgsize = OS_S64 then
+            list.concat(taicpu.op_none(a_i64_extend_s_i32))
+          else
+            list.concat(taicpu.op_none(a_i64_extend_u_i32));
           incstack(list,1);
           incstack(list,1);
           { if it was an unsigned 32 bit value, remove sign extension }
           { if it was an unsigned 32 bit value, remove sign extension }
           if fromcgsize=OS_32 then
           if fromcgsize=OS_32 then
@@ -2249,17 +2178,25 @@ implementation
            (fromsize<>cwidechartype))) then
            (fromsize<>cwidechartype))) then
         case tocgsize of
         case tocgsize of
           OS_8:
           OS_8:
-            a_op_const_stack(list,OP_AND,s32inttype,255);
+            //todo: conversion
+            //a_op_const_stack(list,OP_AND,s32inttype,255);
+            ;
           OS_S8:
           OS_S8:
-            list.concat(taicpu.op_none(a_i2b));
+            //todo: conversion
+            //list.concat(taicpu.op_none(a_i2b));
+            ;
           OS_16:
           OS_16:
-            if (tosize.typ=orddef) and
-               (torddef(tosize).ordtype=uwidechar) then
-              list.concat(taicpu.op_none(a_i2c))
-            else
-              a_op_const_stack(list,OP_AND,s32inttype,65535);
+            //todo: conversion
+            //if (tosize.typ=orddef) and
+            //   (torddef(tosize).ordtype=uwidechar) then
+            //  list.concat(taicpu.op_none(a_i2c))
+            //else
+            //  a_op_const_stack(list,OP_AND,s32inttype,65535);
+            ;
           OS_S16:
           OS_S16:
-            list.concat(taicpu.op_none(a_i2s));
+            //todo: conversion
+            //list.concat(taicpu.op_none(a_i2s));
+            ;
           else
           else
             ;
             ;
         end;
         end;
@@ -2488,13 +2425,13 @@ implementation
       if (fromsize=OS_F32) and
       if (fromsize=OS_F32) and
          (tosize=OS_F64) then
          (tosize=OS_F64) then
         begin
         begin
-          list.concat(taicpu.op_none(a_f2d));
+          list.concat(taicpu.op_none(a_f64_promote_f32));
           incstack(list,1);
           incstack(list,1);
         end
         end
       else if (fromsize=OS_F64) and
       else if (fromsize=OS_F64) and
               (tosize=OS_F32) then
               (tosize=OS_F32) then
         begin
         begin
-          list.concat(taicpu.op_none(a_d2f));
+          list.concat(taicpu.op_none(a_f32_demote_f64));
           decstack(list,1);
           decstack(list,1);
         end;
         end;
     end;
     end;
@@ -2532,10 +2469,14 @@ implementation
         staticsymtable,
         staticsymtable,
         localsymtable:
         localsymtable:
           { regular and nested procedures are turned into static methods }
           { regular and nested procedures are turned into static methods }
-          opc:=a_invokestatic;
+          opc:=a_call;
         objectsymtable:
         objectsymtable:
           begin
           begin
-            case tobjectdef(pd.owner.defowner).objecttype of
+            Internalerror(2019083004); // no support for symbol table calls
+            opc:=a_call_indirect; // todo: need a reference to a (funccall) table
+
+            {case tobjectdef(pd.owner.defowner).objecttype of
+
               odt_javaclass:
               odt_javaclass:
                 begin
                 begin
                   if (po_classmethod in pd.procoptions) or
                   if (po_classmethod in pd.procoptions) or
@@ -2554,23 +2495,24 @@ implementation
               else
               else
                 internalerror(2010122601);
                 internalerror(2010122601);
             end;
             end;
+            }
           end;
           end;
         recordsymtable:
         recordsymtable:
           begin
           begin
             if (po_staticmethod in pd.procoptions) or
             if (po_staticmethod in pd.procoptions) or
                (pd.proctypeoption=potype_operator) then
                (pd.proctypeoption=potype_operator) then
-              opc:=a_invokestatic
+              opc:=a_call
             else if (pd.visibility=vis_strictprivate) or
             else if (pd.visibility=vis_strictprivate) or
                (pd.proctypeoption=potype_constructor) or
                (pd.proctypeoption=potype_constructor) or
                inheritedcall then
                inheritedcall then
-              opc:=a_invokespecial
+              opc:=a_call
             else
             else
-              opc:=a_invokevirtual;
+              opc:=a_call_indirect;
           end
           end
         else
         else
           internalerror(2010122602);
           internalerror(2010122602);
       end;
       end;
-      if (opc<>a_invokeinterface) then
+      if (opc<>a_call_indirect) then
         list.concat(taicpu.op_sym(opc,current_asmdata.RefAsmSymbol(s,AT_FUNCTION)))
         list.concat(taicpu.op_sym(opc,current_asmdata.RefAsmSymbol(s,AT_FUNCTION)))
       else
       else
         begin
         begin

+ 0 - 3
compiler/wasm/itcpuwasm.pas

@@ -75,9 +75,6 @@ interface
         'i32.store8', 'i32.store16', 'i64.store8', 'i64.store16', 'i64.store32',
         'i32.store8', 'i32.store16', 'i64.store8', 'i64.store16', 'i64.store32',
         // additional memory
         // additional memory
         'grow_memory', 'current_memory'
         'grow_memory', 'current_memory'
-        ,'<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>'
-        ,'<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>'
-        ,'<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>','<none>'
       );
       );
 
 
 implementation
 implementation

+ 12 - 12
compiler/wasm/rgcpu.pas

@@ -89,16 +89,16 @@ implementation
         end;
         end;
 
 
       function issimpleregstore(p: tai; var reg: tregister; doubleprecisionok: boolean): boolean;
       function issimpleregstore(p: tai; var reg: tregister; doubleprecisionok: boolean): boolean;
-        //const
-        //  simplestoressp = [a_astore,a_fstore,a_istore];
-        //  simplestoresdp = [a_dstore,a_lstore];
+        const
+          simplestoressp = [a_f32_store];
+          simplestoresdp = [a_f64_store];
         begin
         begin
           result:=
           result:=
             assigned(p) and
             assigned(p) and
             (p.typ=ait_instruction) and
             (p.typ=ait_instruction) and
-            //((taicpu(p).opcode in simplestoressp) or
-            // (doubleprecisionok and
-            //  (taicpu(p).opcode in simplestoresdp))) and
+            ((taicpu(p).opcode in simplestoressp) or
+             (doubleprecisionok and
+              (taicpu(p).opcode in simplestoresdp))) and
             ((reg=NR_NO) or
             ((reg=NR_NO) or
              (taicpu(p).oper[0]^.typ=top_reg) and
              (taicpu(p).oper[0]^.typ=top_reg) and
              (taicpu(p).oper[0]^.reg=reg));
              (taicpu(p).oper[0]^.reg=reg));
@@ -108,16 +108,16 @@ implementation
         end;
         end;
 
 
       function issimpleregload(p: tai; var reg: tregister; doubleprecisionok: boolean): boolean;
       function issimpleregload(p: tai; var reg: tregister; doubleprecisionok: boolean): boolean;
-        //const
-        //  simpleloadssp = [a_aload,a_fload,a_iload];
-        //  simpleloadsdp = [a_dload,a_lload];
+        const
+          simpleloadssp = [a_f32_load];
+          simpleloadsdp = [a_f64_load];
         begin
         begin
           result:=
           result:=
             assigned(p) and
             assigned(p) and
             (p.typ=ait_instruction) and
             (p.typ=ait_instruction) and
-            //((taicpu(p).opcode in simpleloadssp) or
-            // (doubleprecisionok and
-            //  (taicpu(p).opcode in simpleloadsdp))) and
+            ((taicpu(p).opcode in simpleloadssp) or
+             (doubleprecisionok and
+              (taicpu(p).opcode in simpleloadsdp))) and
             ((reg=NR_NO) or
             ((reg=NR_NO) or
              (taicpu(p).oper[0]^.typ=top_reg) and
              (taicpu(p).oper[0]^.typ=top_reg) and
              (taicpu(p).oper[0]^.reg=reg));
              (taicpu(p).oper[0]^.reg=reg));