mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-27 20:54:30 +02:00
* fixed call_indirect for the llvm-mc asm writer
git-svn-id: branches/wasm@47965 -
This commit is contained in:
parent
56f65799d3
commit
35489718f3
@ -32,7 +32,10 @@ interface
|
||||
|
||||
uses
|
||||
globtype,globals,
|
||||
aasmbase,aasmtai,aasmdata,aasmcfi,
|
||||
cpubase,aasmbase,aasmtai,aasmdata,aasmcfi,
|
||||
{$ifdef wasm}
|
||||
aasmcpu,
|
||||
{$endif wasm}
|
||||
assemble;
|
||||
|
||||
type
|
||||
@ -66,6 +69,9 @@ interface
|
||||
procedure WriteTree(p:TAsmList);override;
|
||||
procedure WriteAsmList;override;
|
||||
destructor destroy; override;
|
||||
{$ifdef WASM}
|
||||
procedure WriteFuncType(functype: TWasmFuncType);
|
||||
{$endif WASM}
|
||||
private
|
||||
setcount: longint;
|
||||
procedure WriteDecodedSleb128(a: int64);
|
||||
@ -118,10 +124,7 @@ implementation
|
||||
{$ifdef m68k}
|
||||
cpuinfo,aasmcpu,
|
||||
{$endif m68k}
|
||||
{$ifdef wasm}
|
||||
aasmcpu,
|
||||
{$endif wasm}
|
||||
cpubase,objcasm;
|
||||
objcasm;
|
||||
|
||||
const
|
||||
line_length = 70;
|
||||
@ -720,6 +723,37 @@ implementation
|
||||
end;
|
||||
|
||||
|
||||
{$ifdef WASM}
|
||||
procedure TGNUAssembler.WriteFuncType(functype: TWasmFuncType);
|
||||
var
|
||||
wasm_basic_typ: TWasmBasicType;
|
||||
first: boolean;
|
||||
begin
|
||||
writer.AsmWrite('(');
|
||||
first:=true;
|
||||
for wasm_basic_typ in functype.params do
|
||||
begin
|
||||
if first then
|
||||
first:=false
|
||||
else
|
||||
writer.AsmWrite(',');
|
||||
writer.AsmWrite(gas_wasm_basic_type_str[wasm_basic_typ]);
|
||||
end;
|
||||
writer.AsmWrite(') -> (');
|
||||
first:=true;
|
||||
for wasm_basic_typ in functype.results do
|
||||
begin
|
||||
if first then
|
||||
first:=false
|
||||
else
|
||||
writer.AsmWrite(',');
|
||||
writer.AsmWrite(gas_wasm_basic_type_str[wasm_basic_typ]);
|
||||
end;
|
||||
writer.AsmWrite(')');
|
||||
end;
|
||||
{$endif WASM}
|
||||
|
||||
|
||||
procedure TGNUAssembler.WriteTree(p:TAsmList);
|
||||
|
||||
function needsObject(hp : tai_symbol) : boolean;
|
||||
@ -808,35 +842,6 @@ implementation
|
||||
end;
|
||||
|
||||
{$ifdef WASM}
|
||||
procedure WriteFuncType(functype: TWasmFuncType);
|
||||
var
|
||||
wasm_basic_typ: TWasmBasicType;
|
||||
first: boolean;
|
||||
begin
|
||||
writer.AsmWrite('(');
|
||||
first:=true;
|
||||
for wasm_basic_typ in functype.params do
|
||||
begin
|
||||
if first then
|
||||
first:=false
|
||||
else
|
||||
writer.AsmWrite(',');
|
||||
writer.AsmWrite(gas_wasm_basic_type_str[wasm_basic_typ]);
|
||||
end;
|
||||
writer.AsmWrite(') -> (');
|
||||
first:=true;
|
||||
for wasm_basic_typ in functype.results do
|
||||
begin
|
||||
if first then
|
||||
first:=false
|
||||
else
|
||||
writer.AsmWrite(',');
|
||||
writer.AsmWrite(gas_wasm_basic_type_str[wasm_basic_typ]);
|
||||
end;
|
||||
writer.AsmWrite(')');
|
||||
end;
|
||||
|
||||
|
||||
procedure WriteFuncTypeDirective(hp:tai_functype);
|
||||
begin
|
||||
writer.AsmWrite(#9'.functype'#9);
|
||||
|
@ -44,7 +44,7 @@ uses
|
||||
{ taicpu }
|
||||
|
||||
taicpu = class(tai_cpu_abstract_sym)
|
||||
typecode : string; // used for call_indirect
|
||||
functype : TWasmFuncType; // used for call_indirect
|
||||
constructor op_none(op : tasmop);
|
||||
|
||||
constructor op_reg(op : tasmop;_op1 : tregister);
|
||||
@ -57,7 +57,7 @@ uses
|
||||
constructor op_single(op : tasmop;_op1 : single);
|
||||
constructor op_double(op : tasmop;_op1 : double);
|
||||
|
||||
constructor op_callindirect(const atypecode: string);
|
||||
constructor op_callindirect(afunctype: TWasmFuncType);
|
||||
//constructor op_string(op : tasmop;_op1len : aint;_op1 : pchar);
|
||||
//constructor op_wstring(op : tasmop;_op1 : pcompilerwidestring);
|
||||
|
||||
@ -251,9 +251,9 @@ implementation
|
||||
loaddouble(0,_op1);
|
||||
end;
|
||||
|
||||
constructor taicpu.op_callindirect(const atypecode: string);
|
||||
constructor taicpu.op_callindirect(afunctype: TWasmFuncType);
|
||||
begin
|
||||
typecode := atypecode;
|
||||
functype := afunctype;
|
||||
op_none(a_call_indirect);
|
||||
end;
|
||||
|
||||
|
@ -297,7 +297,6 @@ implementation
|
||||
var
|
||||
cpu : taicpu;
|
||||
i : integer;
|
||||
isprm : boolean;
|
||||
writer: TExternalAssemblerOutputFile;
|
||||
begin
|
||||
writer:=owner.writer;
|
||||
@ -306,23 +305,8 @@ implementation
|
||||
writer.AsmWrite(gas_op2str[cpu.opcode]);
|
||||
|
||||
if (cpu.opcode = a_call_indirect) then begin
|
||||
// special wat2wasm syntax "call_indirect (type x)"
|
||||
writer.AsmWrite(#9);
|
||||
isprm := true;
|
||||
for i:=1 to length(cpu.typecode) do
|
||||
if cpu.typecode[i]=':' then
|
||||
isprm:=false
|
||||
else begin
|
||||
if isprm then writer.AsmWrite('(param ')
|
||||
else writer.AsmWrite('(result ');
|
||||
case cpu.typecode[i] of
|
||||
'i': writer.AsmWrite('i32');
|
||||
'I': writer.AsmWrite('i64');
|
||||
'f': writer.AsmWrite('f32');
|
||||
'F': writer.AsmWrite('f64');
|
||||
end;
|
||||
writer.AsmWrite(')');
|
||||
end;
|
||||
owner.WriteFuncType(cpu.functype);
|
||||
writer.AsmLn;
|
||||
exit;
|
||||
end;
|
||||
|
@ -247,21 +247,22 @@ implementation
|
||||
if (cpu.opcode = a_call_indirect) then begin
|
||||
// special wat2wasm syntax "call_indirect (type x)"
|
||||
writer.AsmWrite(#9);
|
||||
isprm := true;
|
||||
for i:=1 to length(cpu.typecode) do
|
||||
if cpu.typecode[i]=':' then
|
||||
isprm:=false
|
||||
else begin
|
||||
if isprm then writer.AsmWrite('(param ')
|
||||
else writer.AsmWrite('(result ');
|
||||
case cpu.typecode[i] of
|
||||
'i': writer.AsmWrite('i32');
|
||||
'I': writer.AsmWrite('i64');
|
||||
'f': writer.AsmWrite('f32');
|
||||
'F': writer.AsmWrite('f64');
|
||||
end;
|
||||
writer.AsmWrite(')');
|
||||
end;
|
||||
// todo: fix
|
||||
//isprm := true;
|
||||
//for i:=1 to length(cpu.typecode) do
|
||||
// if cpu.typecode[i]=':' then
|
||||
// isprm:=false
|
||||
// else begin
|
||||
// if isprm then writer.AsmWrite('(param ')
|
||||
// else writer.AsmWrite('(result ');
|
||||
// case cpu.typecode[i] of
|
||||
// 'i': writer.AsmWrite('i32');
|
||||
// 'I': writer.AsmWrite('i64');
|
||||
// 'f': writer.AsmWrite('f32');
|
||||
// 'F': writer.AsmWrite('f64');
|
||||
// end;
|
||||
// writer.AsmWrite(')');
|
||||
// end;
|
||||
writer.AsmLn;
|
||||
exit;
|
||||
end;
|
||||
|
@ -386,7 +386,7 @@ implementation
|
||||
function thlcgwasm.a_call_reg(list: TAsmList; pd: tabstractprocdef; reg: tregister; const paras: array of pcgpara): tcgpara;
|
||||
begin
|
||||
a_load_reg_stack(list, ptrsinttype, reg);
|
||||
current_asmdata.CurrAsmList.Concat(taicpu.op_callindirect( WasmGetTypeCode(pd)) );
|
||||
current_asmdata.CurrAsmList.Concat(taicpu.op_callindirect(tcpuprocdef(pd).create_functype));
|
||||
result:=hlcg.get_call_result_cgpara(pd, nil);
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user