mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-19 20:19:25 +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 WriteFuncTypeSect;
|
||||
procedure WriteTableSect;
|
||||
procedure WriteFuncSect;
|
||||
procedure WriteExportSect;
|
||||
procedure WriteCodeSect;
|
||||
@ -84,8 +85,23 @@ type
|
||||
// returns the list of local arrays
|
||||
procedure GetLocalInfo(func: TWasmFunc; out loc: TLocalInfoArray);
|
||||
|
||||
procedure WriteLimit(dst: TStream; amin, amax: LongWord);
|
||||
|
||||
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);
|
||||
var
|
||||
i : integer;
|
||||
@ -231,6 +247,12 @@ begin
|
||||
inc(writeSec);
|
||||
end;
|
||||
|
||||
// 04 tables section
|
||||
if m.TableCount>0 then begin
|
||||
WriteTableSect;
|
||||
inc(writeSec);
|
||||
end;
|
||||
|
||||
// 07 export section
|
||||
if m.ExportCount>0 then begin
|
||||
WriteExportSect;
|
||||
@ -299,6 +321,22 @@ begin
|
||||
SectionEnd(sc);
|
||||
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;
|
||||
var
|
||||
sc : TSectionRec;
|
||||
|
@ -140,7 +140,10 @@ type
|
||||
{ TWasmTable }
|
||||
|
||||
TWasmTable = class(TObject)
|
||||
id : TWasmId;
|
||||
id : TWasmId;
|
||||
elemsType : Byte; // type of elements
|
||||
min : LongWord;
|
||||
max : LongWord;
|
||||
end;
|
||||
|
||||
{ TWasmModule }
|
||||
|
@ -381,6 +381,7 @@ begin
|
||||
sc.Next;
|
||||
ParseId(sc, dst.id);
|
||||
ConsumeToken(sc, weFuncRef);
|
||||
dst.elemsType := elem_type;
|
||||
ConsumeToken(sc, weCloseBrace);
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user