Browse Source

* fixed second_int_to_bool for cbool types for WebAssembly

Nikolay Nikolov 4 years ago
parent
commit
968e23546c
1 changed files with 31 additions and 1 deletions
  1. 31 1
      compiler/wasm32/nwasmcnv.pas

+ 31 - 1
compiler/wasm32/nwasmcnv.pas

@@ -133,7 +133,37 @@ implementation
         thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
         thlcgwasm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,left.resultdef,0,R_INTREGISTER);
         thlcgwasm(hlcg).a_cmp_stack_stack(current_asmdata.CurrAsmList,left.resultdef,OC_NE);
-        thlcgwasm(hlcg).resize_stack_int_val(current_asmdata.CurrAsmList,u32inttype,resultdef,false);
+        if is_cbool(resultdef) then
+          begin
+            if is_64bit(resultdef) then
+              current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i64])))
+            else
+              current_asmdata.CurrAsmList.Concat(taicpu.op_functype(a_if,TWasmFuncType.Create([],[wbt_i32])));
+            thlcgwasm(hlcg).incblock;
+            thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
+            if is_64bit(left.resultdef) then
+              current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i64_const, -1) )
+            else if is_32bit(left.resultdef) then
+              current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i32_const, -1) )
+            else if is_16bit(left.resultdef) then
+              current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i32_const, 65535) )
+            else if is_8bit(left.resultdef) then
+              current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i32_const, 255) )
+            else
+              internalerror(2021100101);
+            thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
+            current_asmdata.CurrAsmList.Concat( taicpu.op_none(a_else) );
+            thlcgwasm(hlcg).decstack(current_asmdata.CurrAsmList,1);
+            if is_64bit(left.resultdef) then
+              current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i64_const, 0) )
+            else
+              current_asmdata.CurrAsmList.Concat( taicpu.op_const(a_i32_const, 0) );
+            thlcgwasm(hlcg).incstack(current_asmdata.CurrAsmList,1);
+            current_asmdata.CurrAsmList.concat(taicpu.op_none(a_end_if));
+            thlcgwasm(hlcg).decblock;
+          end
+        else
+          thlcgwasm(hlcg).resize_stack_int_val(current_asmdata.CurrAsmList,u32inttype,resultdef,false);
         location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
         location.register := hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
         thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);