mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-14 23:30:43 +02:00
[PATCH 100/188] writing proper tables binary information
From 2824a87b3f4fc9948124b48e50414f30a9b0d24f Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Tue, 17 Mar 2020 09:41:49 -0400 git-svn-id: branches/wasm@46096 -
This commit is contained in:
parent
0767d971ab
commit
5997e5bb56
@ -51,6 +51,7 @@ type
|
|||||||
|
|
||||||
procedure WriteImportSect;
|
procedure WriteImportSect;
|
||||||
procedure WriteFuncTypeSect;
|
procedure WriteFuncTypeSect;
|
||||||
|
procedure WriteTableSect;
|
||||||
procedure WriteFuncSect;
|
procedure WriteFuncSect;
|
||||||
procedure WriteExportSect;
|
procedure WriteExportSect;
|
||||||
procedure WriteCodeSect;
|
procedure WriteCodeSect;
|
||||||
@ -84,8 +85,23 @@ type
|
|||||||
// returns the list of local arrays
|
// returns the list of local arrays
|
||||||
procedure GetLocalInfo(func: TWasmFunc; out loc: TLocalInfoArray);
|
procedure GetLocalInfo(func: TWasmFunc; out loc: TLocalInfoArray);
|
||||||
|
|
||||||
|
procedure WriteLimit(dst: TStream; amin, amax: LongWord);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
procedure WriteLimit(dst: TStream; amin, amax: LongWord);
|
||||||
|
begin
|
||||||
|
if not Assigned(dst) then Exit;
|
||||||
|
if amax>0 then begin
|
||||||
|
dst.WriteByte(1);
|
||||||
|
WriteU32(dst, amin);
|
||||||
|
WriteU32(dst, amax);
|
||||||
|
end else begin
|
||||||
|
dst.WriteByte(0);
|
||||||
|
WriteU32(dst, amin);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure GetLocalInfo(func: TWasmFunc; out loc: TLocalInfoArray);
|
procedure GetLocalInfo(func: TWasmFunc; out loc: TLocalInfoArray);
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
@ -231,6 +247,12 @@ begin
|
|||||||
inc(writeSec);
|
inc(writeSec);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// 04 tables section
|
||||||
|
if m.TableCount>0 then begin
|
||||||
|
WriteTableSect;
|
||||||
|
inc(writeSec);
|
||||||
|
end;
|
||||||
|
|
||||||
// 07 export section
|
// 07 export section
|
||||||
if m.ExportCount>0 then begin
|
if m.ExportCount>0 then begin
|
||||||
WriteExportSect;
|
WriteExportSect;
|
||||||
@ -299,6 +321,22 @@ begin
|
|||||||
SectionEnd(sc);
|
SectionEnd(sc);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TBinWriter.WriteTableSect;
|
||||||
|
var
|
||||||
|
sc : TSectionRec;
|
||||||
|
i : integer;
|
||||||
|
t : TWasmTable;
|
||||||
|
begin
|
||||||
|
SectionBegin(SECT_TABLE, sc);
|
||||||
|
WriteU32(dst, module.TableCount);
|
||||||
|
for i:=0 to module.TableCount-1 do begin
|
||||||
|
t:=module.GetTable(i);
|
||||||
|
dst.WriteByte(t.elemsType);
|
||||||
|
WriteLimit(dst, t.min, t.max);
|
||||||
|
end;
|
||||||
|
SectionEnd(sc);
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TBinWriter.WriteFuncSect;
|
procedure TBinWriter.WriteFuncSect;
|
||||||
var
|
var
|
||||||
sc : TSectionRec;
|
sc : TSectionRec;
|
||||||
|
@ -140,7 +140,10 @@ type
|
|||||||
{ TWasmTable }
|
{ TWasmTable }
|
||||||
|
|
||||||
TWasmTable = class(TObject)
|
TWasmTable = class(TObject)
|
||||||
id : TWasmId;
|
id : TWasmId;
|
||||||
|
elemsType : Byte; // type of elements
|
||||||
|
min : LongWord;
|
||||||
|
max : LongWord;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TWasmModule }
|
{ TWasmModule }
|
||||||
|
@ -381,6 +381,7 @@ begin
|
|||||||
sc.Next;
|
sc.Next;
|
||||||
ParseId(sc, dst.id);
|
ParseId(sc, dst.id);
|
||||||
ConsumeToken(sc, weFuncRef);
|
ConsumeToken(sc, weFuncRef);
|
||||||
|
dst.elemsType := elem_type;
|
||||||
ConsumeToken(sc, weCloseBrace);
|
ConsumeToken(sc, weCloseBrace);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user