mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-23 13:39:18 +02:00
+ implemented int to real conversion
git-svn-id: branches/wasm@48081 -
This commit is contained in:
parent
cf35b0d2a9
commit
9bd282eb3b
@ -25,7 +25,7 @@ unit nwasmcnv;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
ncnv,ncgcnv;
|
node,ncnv,ncgcnv;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
@ -33,20 +33,95 @@ interface
|
|||||||
|
|
||||||
twasmtypeconvnode = class(tcgtypeconvnode)
|
twasmtypeconvnode = class(tcgtypeconvnode)
|
||||||
protected
|
protected
|
||||||
|
function first_int_to_real: tnode; override;
|
||||||
|
procedure second_int_to_real;override;
|
||||||
procedure second_int_to_bool;override;
|
procedure second_int_to_bool;override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
globals,aasmdata,
|
verbose,globals,globtype,aasmdata,
|
||||||
defutil,
|
defutil,cpubase,
|
||||||
cgbase,cgutils,pass_2,
|
cgbase,cgutils,pass_1,pass_2,
|
||||||
|
aasmcpu,
|
||||||
|
symdef,
|
||||||
hlcgobj,hlcgcpu;
|
hlcgobj,hlcgcpu;
|
||||||
|
|
||||||
|
|
||||||
{ twasmtypeconvnode }
|
{ twasmtypeconvnode }
|
||||||
|
|
||||||
|
function twasmtypeconvnode.first_int_to_real: tnode;
|
||||||
|
begin
|
||||||
|
first_int_to_real:=nil;
|
||||||
|
if left.resultdef.size<4 then
|
||||||
|
begin
|
||||||
|
inserttypeconv(left,s32inttype);
|
||||||
|
firstpass(left);
|
||||||
|
end;
|
||||||
|
expectloc:=LOC_FPUREGISTER;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure twasmtypeconvnode.second_int_to_real;
|
||||||
|
var
|
||||||
|
op: TAsmOp;
|
||||||
|
begin
|
||||||
|
secondpass(left);
|
||||||
|
if codegenerror then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
case tfloatdef(resultdef).floattype of
|
||||||
|
s32real:
|
||||||
|
begin
|
||||||
|
if is_64bitint(left.resultdef) or
|
||||||
|
is_currency(left.resultdef) then
|
||||||
|
begin
|
||||||
|
if is_signed(left.resultdef) then
|
||||||
|
op:=a_f32_convert_s_i64
|
||||||
|
else
|
||||||
|
op:=a_f32_convert_u_i64;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{ other integers are supposed to be 32 bit }
|
||||||
|
begin
|
||||||
|
if is_signed(left.resultdef) then
|
||||||
|
op:=a_f32_convert_s_i32
|
||||||
|
else
|
||||||
|
op:=a_f32_convert_u_i32;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
s64real:
|
||||||
|
begin
|
||||||
|
if is_64bitint(left.resultdef) or
|
||||||
|
is_currency(left.resultdef) then
|
||||||
|
begin
|
||||||
|
if is_signed(left.resultdef) then
|
||||||
|
op:=a_f64_convert_s_i64
|
||||||
|
else
|
||||||
|
op:=a_f64_convert_u_i64;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
{ other integers are supposed to be 32 bit }
|
||||||
|
begin
|
||||||
|
if is_signed(left.resultdef) then
|
||||||
|
op:=a_f64_convert_s_i32
|
||||||
|
else
|
||||||
|
op:=a_f64_convert_u_i32;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
else
|
||||||
|
internalerror(2021010501);
|
||||||
|
end;
|
||||||
|
|
||||||
|
thlcgwasm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
|
||||||
|
current_asmdata.CurrAsmList.concat(taicpu.op_none(op));
|
||||||
|
location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
|
||||||
|
location.register := hlcg.getfpuregister(current_asmdata.CurrAsmList,resultdef);
|
||||||
|
thlcgwasm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,resultdef,location);
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
procedure twasmtypeconvnode.second_int_to_bool;
|
procedure twasmtypeconvnode.second_int_to_bool;
|
||||||
begin
|
begin
|
||||||
secondpass(left);
|
secondpass(left);
|
||||||
|
Loading…
Reference in New Issue
Block a user