|
@@ -79,8 +79,7 @@ type
|
|
|
|
|
|
TCodeEntry = record
|
|
TCodeEntry = record
|
|
locals : array of TCodeLocalEntry;
|
|
locals : array of TCodeLocalEntry;
|
|
- instCount : integer;
|
|
|
|
- instr : array of TCodeInstr;
|
|
|
|
|
|
+ instBuf : array of byte;
|
|
end;
|
|
end;
|
|
|
|
|
|
TCodeSection = record
|
|
TCodeSection = record
|
|
@@ -123,6 +122,8 @@ procedure ReadCodeEntry(src: TStream; var en: TCodeEntry);
|
|
// reads the code entry into TCodeEntry structure
|
|
// reads the code entry into TCodeEntry structure
|
|
procedure ReadCodeSection(src: TStream; var sc: TCodeSection);
|
|
procedure ReadCodeSection(src: TStream; var sc: TCodeSection);
|
|
|
|
|
|
|
|
+function isUnreachable(const cd: TCodeEntry): Boolean;
|
|
|
|
+
|
|
|
|
|
|
procedure ReadExportEntry(src: TStream; var ex: TExportEntry);
|
|
procedure ReadExportEntry(src: TStream; var ex: TExportEntry);
|
|
// reads the export entry
|
|
// reads the export entry
|
|
@@ -132,6 +133,9 @@ procedure WriteExport(const ex: TExportSection; dst: TStream);
|
|
function isWasmStream(st: TStream): Boolean;
|
|
function isWasmStream(st: TStream): Boolean;
|
|
function isWasmFile(const fn: string): Boolean;
|
|
function isWasmFile(const fn: string): Boolean;
|
|
|
|
|
|
|
|
+const
|
|
|
|
+ INST_TRAP = $00;
|
|
|
|
+
|
|
implementation
|
|
implementation
|
|
|
|
|
|
function ValTypeToStr(id: integer): string;
|
|
function ValTypeToStr(id: integer): string;
|
|
@@ -201,8 +205,10 @@ var
|
|
//pos : int64;
|
|
//pos : int64;
|
|
cnt : Integer;
|
|
cnt : Integer;
|
|
i : integer;
|
|
i : integer;
|
|
|
|
+ eofs : Int64;
|
|
begin
|
|
begin
|
|
sz := ReadU(src);
|
|
sz := ReadU(src);
|
|
|
|
+ eofs := src.Position+sz;
|
|
|
|
|
|
cnt := ReadU(src);
|
|
cnt := ReadU(src);
|
|
SetLength(en.locals, cnt);
|
|
SetLength(en.locals, cnt);
|
|
@@ -210,7 +216,9 @@ begin
|
|
en.locals[i].count := ReadU(src);
|
|
en.locals[i].count := ReadU(src);
|
|
en.locals[i].valtyp := src.ReadByte;
|
|
en.locals[i].valtyp := src.ReadByte;
|
|
end;
|
|
end;
|
|
-
|
|
|
|
|
|
+ SetLength(en.instBuf, eofs-src.Position);
|
|
|
|
+ if (length(en.instBuf)>0) then
|
|
|
|
+ src.Read(en.instBuf[0], length(en.instBuf));
|
|
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -225,6 +233,11 @@ begin
|
|
ReadCodeEntry(src, sc.entries[i]);
|
|
ReadCodeEntry(src, sc.entries[i]);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function isUnreachable(const cd: TCodeEntry): Boolean;
|
|
|
|
+begin
|
|
|
|
+ Result:=(length(cd.instBuf)>0) and (cd.instBuf[0]=INST_TRAP);
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure ReadExportEntry(src: TStream; var ex: TExportEntry);
|
|
procedure ReadExportEntry(src: TStream; var ex: TExportEntry);
|
|
begin
|
|
begin
|
|
ex.name := ReadName(src);
|
|
ex.name := ReadName(src);
|