mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-27 05:32:28 +02:00
+ support the f32.const and f64.const instructions in twasmreader.HandlePlainInstruction
This commit is contained in:
parent
02e90adfe1
commit
09f2fa0daf
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user