mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-21 21:51:42 +02:00
[PATCH 043/188] adding export section and instructions list
From 44585af463cda01175b1174b5886b00f74c03c9a Mon Sep 17 00:00:00 2001 From: Dmitry Boyarintsev <skalogryz.lists@gmail.com> Date: Wed, 20 Nov 2019 14:13:40 -0500 git-svn-id: branches/wasm@46039 -
This commit is contained in:
parent
0a9db5f83d
commit
b726751b3a
@ -3,7 +3,7 @@ unit wasmmodule;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, wasmbin;
|
||||
Classes, SysUtils;
|
||||
|
||||
type
|
||||
TWasmParam = class(TObject)
|
||||
@ -15,7 +15,7 @@ type
|
||||
|
||||
TWasmType = class(TObject)
|
||||
private
|
||||
params : TList;
|
||||
params : TList;
|
||||
results : TList;
|
||||
public
|
||||
constructor Create;
|
||||
@ -29,6 +29,27 @@ type
|
||||
function ParamCount: Integer;
|
||||
end;
|
||||
|
||||
TWasmInstr = class(TObject)
|
||||
code : byte;
|
||||
operandIdx : string;
|
||||
operandNum : integer;
|
||||
operandText : string;
|
||||
end;
|
||||
|
||||
{ TWasmInstrList }
|
||||
|
||||
TWasmInstrList = class(TObject)
|
||||
private
|
||||
items: TList;
|
||||
function GetItem(i: integer): TWasmInstr;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function AddInstr(acode: byte = 0): TWasmInstr;
|
||||
function Count: Integer;
|
||||
property Item[i: integer]: TWasmInstr read GetItem; default;
|
||||
end;
|
||||
|
||||
{ TWasmFunc }
|
||||
|
||||
TWasmFunc = class(TObject)
|
||||
@ -39,6 +60,7 @@ type
|
||||
id : string;
|
||||
typeIdx : Integer; // if Idx < 0 then type is declared from typeDef
|
||||
typeId : string; // if tpyeID='' then type is declared from typeDef
|
||||
instr : TWasmInstrList;
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
function GetInlineType: TWasmType;
|
||||
@ -46,12 +68,22 @@ type
|
||||
function LocalsCount: integer;
|
||||
end;
|
||||
|
||||
{ TWasmExport }
|
||||
|
||||
TWasmExport = class(TObject)
|
||||
name : string;
|
||||
exportType : byte;
|
||||
exportNum : integer;
|
||||
exportIdx : string;
|
||||
end;
|
||||
|
||||
{ TWasmModule }
|
||||
|
||||
TWasmModule = class(TObject)
|
||||
private
|
||||
types : TList;
|
||||
funcs : TList;
|
||||
types : TList;
|
||||
funcs : TList;
|
||||
exp : TList;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
@ -63,6 +95,10 @@ type
|
||||
function AddType: TWasmType;
|
||||
function GetTypes(i: integer): TWasmType;
|
||||
function TypesCount: integer;
|
||||
|
||||
function AddExport: TWasmExport;
|
||||
function GetExport(i: integer): TWasmExport;
|
||||
function ExportCount: integer;
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -76,6 +112,41 @@ begin
|
||||
l.Clear;
|
||||
end;
|
||||
|
||||
{ TWasmInstrList }
|
||||
|
||||
function TWasmInstrList.GetItem(i: integer): TWasmInstr;
|
||||
begin
|
||||
if (i>=0) and (i < items.Count) then
|
||||
Result:=TWasmInstr(items[i])
|
||||
else
|
||||
Result:=nil;
|
||||
end;
|
||||
|
||||
constructor TWasmInstrList.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
items:=TList.Create;
|
||||
end;
|
||||
|
||||
destructor TWasmInstrList.Destroy;
|
||||
begin
|
||||
ClearList(items);
|
||||
items.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TWasmInstrList.AddInstr(acode: byte = 0): TWasmInstr;
|
||||
begin
|
||||
Result:=TWasmInstr.Create;
|
||||
Result.code:=acode;
|
||||
items.Add(Result);
|
||||
end;
|
||||
|
||||
function TWasmInstrList.Count: Integer;
|
||||
begin
|
||||
Result:=items.Count;
|
||||
end;
|
||||
|
||||
{ TWasmType }
|
||||
|
||||
constructor TWasmType.Create;
|
||||
@ -147,10 +218,13 @@ begin
|
||||
inherited Create;
|
||||
types := TList.Create;
|
||||
funcs := TList.Create;
|
||||
exp := TList.Create;
|
||||
end;
|
||||
|
||||
destructor TWasmModule.Destroy;
|
||||
begin
|
||||
ClearList(exp);
|
||||
exp.Free;
|
||||
ClearList(types);
|
||||
types.Free;
|
||||
ClearList(funcs);
|
||||
@ -196,6 +270,25 @@ begin
|
||||
Result:=types.Count;
|
||||
end;
|
||||
|
||||
function TWasmModule.AddExport: TWasmExport;
|
||||
begin
|
||||
Result:=TWasmExport.Create;
|
||||
exp.add(Result);
|
||||
end;
|
||||
|
||||
function TWasmModule.GetExport(i: integer): TWasmExport;
|
||||
begin
|
||||
if (i>=0) and (i<exp.Count) then
|
||||
Result:=TWasmExport(exp[i])
|
||||
else
|
||||
Result:=nil;
|
||||
end;
|
||||
|
||||
function TWasmModule.ExportCount: integer;
|
||||
begin
|
||||
Result:=exp.Count;
|
||||
end;
|
||||
|
||||
{ TWasmFunc }
|
||||
|
||||
constructor TWasmFunc.Create;
|
||||
@ -203,6 +296,7 @@ begin
|
||||
inherited;
|
||||
typeIdx:=-1;
|
||||
locals:=TList.Create;
|
||||
instr:=TWasmInstrList.Create;
|
||||
end;
|
||||
|
||||
destructor TWasmFunc.Destroy;
|
||||
@ -210,6 +304,7 @@ begin
|
||||
ClearList(locals);
|
||||
locals.Free;
|
||||
finlineType.Free;
|
||||
instr.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user