mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-20 17:49:25 +02:00
[PATCH 099/188] update call indirect parsing and binary writing
From 381db5737ad19fe149ad352e732a8af8917f1ae7 Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Tue, 17 Mar 2020 09:21:35 -0400 git-svn-id: branches/wasm@46095 -
This commit is contained in:
parent
01151eb899
commit
0767d971ab
@ -520,7 +520,7 @@ begin
|
|||||||
idx := FindFunc(module, ci.operandText);
|
idx := FindFunc(module, ci.operandText);
|
||||||
AddReloc(INST_RELOC_FLAGS[ci.code].relocType, dst.Position+ofsAddition, idx);
|
AddReloc(INST_RELOC_FLAGS[ci.code].relocType, dst.Position+ofsAddition, idx);
|
||||||
//todo: there's no need
|
//todo: there's no need
|
||||||
WriteU32(dst, LongWord(idx));
|
WriteRelocU32(LongWord(idx));
|
||||||
end else
|
end else
|
||||||
WriteI32Operand(dst, ci.operandText);
|
WriteI32Operand(dst, ci.operandText);
|
||||||
end;
|
end;
|
||||||
@ -529,12 +529,30 @@ begin
|
|||||||
|
|
||||||
|
|
||||||
ipLeb:
|
ipLeb:
|
||||||
|
begin
|
||||||
if INST_RELOC_FLAGS[ci.code].doReloc then begin
|
if INST_RELOC_FLAGS[ci.code].doReloc then begin
|
||||||
AddReloc(INST_RELOC_FLAGS[ci.code].relocType, dst.Position+ofsAddition, ci.operandNum);
|
AddReloc(INST_RELOC_FLAGS[ci.code].relocType, dst.Position+ofsAddition, ci.operandNum);
|
||||||
WriteRelocU32(ci.operandNum)
|
WriteRelocU32(ci.operandNum)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
WriteU32(dst, ci.operandNum);
|
WriteU32(dst, ci.operandNum);
|
||||||
|
end;
|
||||||
|
|
||||||
|
ipCallType:
|
||||||
|
begin
|
||||||
|
if Assigned(ci.insttype) then begin
|
||||||
|
if INST_RELOC_FLAGS[ci.code].doReloc then begin
|
||||||
|
AddReloc(INST_RELOC_FLAGS[ci.code].relocType, dst.Position+ofsAddition, ci.insttype.typeNum);
|
||||||
|
WriteRelocU32(ci.insttype.typeNum);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
WriteU32(dst, ci.insttype.typeNum);
|
||||||
|
end else
|
||||||
|
WriteU32(dst, LongWord(-1)); // this is an error.
|
||||||
|
|
||||||
|
// table index reference
|
||||||
|
WriteU32(dst, ci.operandNum);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
@ -68,7 +68,7 @@ type
|
|||||||
TWasmInstr = class(TObject)
|
TWasmInstr = class(TObject)
|
||||||
code : byte;
|
code : byte;
|
||||||
operandIdx : string;
|
operandIdx : string;
|
||||||
operandNum : integer;
|
operandNum : integer; // for call_indirect this is table index
|
||||||
operandText : string;
|
operandText : string;
|
||||||
insttype : TWasmFuncType; // used by call_indirect only
|
insttype : TWasmFuncType; // used by call_indirect only
|
||||||
function addInstType: TWasmFuncType;
|
function addInstType: TWasmFuncType;
|
||||||
@ -655,11 +655,10 @@ var
|
|||||||
begin
|
begin
|
||||||
for i:=0 to l.Count-1 do begin
|
for i:=0 to l.Count-1 do begin
|
||||||
ci:=l[i];
|
ci:=l[i];
|
||||||
if ci.operandNum>=0 then Continue;
|
|
||||||
case ci.code of
|
case ci.code of
|
||||||
INST_local_get, INST_local_set, INST_local_tee:
|
INST_local_get, INST_local_set, INST_local_tee:
|
||||||
begin
|
begin
|
||||||
if ci.operandIdx<>'' then begin
|
if (ci.operandIdx<>'') and (ci.operandNum<0) then begin
|
||||||
j:=FindParam(f.functype.params, ci.operandIdx);
|
j:=FindParam(f.functype.params, ci.operandIdx);
|
||||||
if j<0 then begin
|
if j<0 then begin
|
||||||
j:=FindParam(f.locals, ci.operandIdx);
|
j:=FindParam(f.locals, ci.operandIdx);
|
||||||
|
@ -250,10 +250,13 @@ begin
|
|||||||
|
|
||||||
ipCallType:
|
ipCallType:
|
||||||
begin
|
begin
|
||||||
//writeln('token type=',sc.token);
|
// call_indirect operator consists of 2 parameters
|
||||||
|
// 1 - type call
|
||||||
|
// 2 - table reference index. Which should always be zero.
|
||||||
ConsumeToken(sc, weOpenBrace);
|
ConsumeToken(sc, weOpenBrace);
|
||||||
ft := ci.addInstType;
|
ft := ci.addInstType;
|
||||||
ParseFuncParamResult(sc, ft);
|
ParseFuncParamResult(sc, ft);
|
||||||
|
ci.operandNum := 0; // table reference index
|
||||||
end;
|
end;
|
||||||
|
|
||||||
//ip2Leb, // memory arguments, ask for offset + align
|
//ip2Leb, // memory arguments, ask for offset + align
|
||||||
|
Loading…
Reference in New Issue
Block a user