From 09f2fa0daffcea9d44570641d341b4fd40346cf4 Mon Sep 17 00:00:00 2001 From: Nikolay Nikolov Date: Mon, 15 Jul 2024 20:07:38 +0300 Subject: [PATCH] + support the f32.const and f64.const instructions in twasmreader.HandlePlainInstruction --- compiler/rautils.pas | 5 +++- compiler/wasm32/rawasmtext.pas | 46 +++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/compiler/rautils.pas b/compiler/rautils.pas index 57037f5d44..9d7811cd18 100644 --- a/compiler/rautils.pas +++ b/compiler/rautils.pas @@ -45,7 +45,7 @@ type TOprType=(OPR_NONE,OPR_CONSTANT,OPR_SYMBOL,OPR_LOCAL, OPR_REFERENCE,OPR_REGISTER,OPR_COND,OPR_REGSET, OPR_SHIFTEROP,OPR_MODEFLAGS,OPR_SPECIALREG, - OPR_REGPAIR,OPR_FENCEFLAGS,OPR_INDEXEDREG); + OPR_REGPAIR,OPR_FENCEFLAGS,OPR_INDEXEDREG,OPR_FLOATCONSTANT); TOprRec = record case typ:TOprType of @@ -89,6 +89,9 @@ type {$if defined(riscv32) or defined(riscv64)} OPR_FENCEFLAGS: (fenceflags : TFenceFlags); {$endif aarch64} +{$ifdef wasm32} + OPR_FLOATCONSTANT: (floatval:double); +{$endif wasm32} end; TInstruction = class; diff --git a/compiler/wasm32/rawasmtext.pas b/compiler/wasm32/rawasmtext.pas index 22252c76ed..eb9aadba06 100644 --- a/compiler/wasm32/rawasmtext.pas +++ b/compiler/wasm32/rawasmtext.pas @@ -55,6 +55,7 @@ Unit rawasmtext; actasmtoken : tasmtoken; prevasmtoken : tasmtoken; actinttoken : aint; + actfloattoken : double; procedure SetupTables; procedure GetToken; function consume(t : tasmtoken):boolean; @@ -146,6 +147,20 @@ Unit rawasmtext; end; end; + function GetFloatToken: double; + var + s: string; + begin + s:=actasmpattern; + if is_hex then + begin + { TODO: parse hex floats } + internalerror(2024071501); + end + else + Val(s,result); + end; + var len: Integer; tmpS: string; @@ -337,7 +352,10 @@ Unit rawasmtext; end; actasmpattern[0]:=chr(len); if is_float then - actasmtoken:=AS_REALNUM + begin + actasmtoken:=AS_REALNUM; + actfloattoken:=GetFloatToken; + end else begin actasmtoken:=AS_INTNUM; @@ -770,6 +788,32 @@ Unit rawasmtext; Consume(AS_INTNUM); end; end; + { instructions with a float const operand } + a_f32_const, + a_f64_const: + begin + case actasmtoken of + AS_INTNUM: + begin + result.operands[1].opr.typ:=OPR_FLOATCONSTANT; + result.operands[1].opr.floatval:=actinttoken; + Consume(AS_INTNUM); + end; + AS_REALNUM: + begin + result.operands[1].opr.typ:=OPR_FLOATCONSTANT; + result.operands[1].opr.floatval:=actfloattoken; + Consume(AS_REALNUM); + end; + else + begin + { error: expected real } + result.Free; + result:=nil; + Consume(AS_REALNUM); + end; + end; + end; else internalerror(2024071401); end;