FasmOnDelphi Update + Fasm Implementation Update
This commit is contained in:
2
.gitmodules
vendored
2
.gitmodules
vendored
@@ -1,6 +1,6 @@
|
||||
[submodule "FasmOnDelphi"]
|
||||
path = lib/FasmOnDelphi
|
||||
url = git@git.teamfnd.ru:artem3213212/FasmOnDelphi.git
|
||||
url = https://github.com/TeamFND/FasmOnDelphi.git
|
||||
[submodule "lib/pLua-XE"]
|
||||
path = lib/pLua-XE
|
||||
url = https://github.com/felipedaragon/pLua-XE.git
|
||||
|
||||
@@ -33,10 +33,11 @@ type
|
||||
p:Pointer;
|
||||
sb:NativeUInt;
|
||||
funcs:TDictionary<string,NativeUInt>;
|
||||
regvars:TDictionary<string,TPair<NativeUInt,PTypeInfo>>;
|
||||
function GetFuntion(Name:string):TRTBFunc;override;
|
||||
{function GetVar(Name:string):TRTBVar;override;}
|
||||
public
|
||||
constructor Create(p:Pointer;sb:NativeUInt;funcs:TDictionary<string,NativeUInt>);
|
||||
constructor Create(p:Pointer;sb:NativeUInt;funcs:TDictionary<string,NativeUInt>;regvars:TDictionary<string,TPair<NativeUInt,PTypeInfo>>);
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
protected
|
||||
@@ -69,9 +70,9 @@ type
|
||||
procedure DelVariable(NameSpace:string;Name:string);override;}
|
||||
|
||||
procedure &Register(NameSpace:string;Name:string;&Type:TRTBType);override;
|
||||
//procedure UnRegister(NameSpace:string;Name:string;&Type:TRTBType);override;
|
||||
procedure UnRegister(NameSpace:string;Name:string);override;
|
||||
procedure RegisterFunction(NameSpace:string;Name:string);override;
|
||||
//procedure UnRegisterFunction(NameSpace:string;Name:string);override;
|
||||
procedure UnRegisterFunction(NameSpace:string;Name:string);override;
|
||||
|
||||
function Compilate:TRTBModule;override;
|
||||
destructor Destroy;override;
|
||||
@@ -123,18 +124,18 @@ begin
|
||||
Result:=TRTBFasmLibFunc.Create(GetProcAddress(Lib,pwidechar(Name)));
|
||||
end;*)
|
||||
|
||||
{$POINTERMATH ON}
|
||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.GetFuntion(Name:string):TRTBFunc;
|
||||
begin
|
||||
Result:=TRTBFasmFunc.Create(Pointer(PNativeUInt(NativeUInt(funcs.Items[Name])+NativeUInt(p))^+NativeUInt(p)));
|
||||
end;
|
||||
|
||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.Create(p:Pointer;sb:NativeUInt;funcs:TDictionary<string,NativeUInt>);
|
||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmModule.Create(p:Pointer;sb:NativeUInt;funcs:TDictionary<string,NativeUInt>;regvars:TDictionary<string,TPair<NativeUInt,PTypeInfo>>);
|
||||
begin
|
||||
Self.p:=VirtualAlloc(nil,sb,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
|
||||
CopyMemory(Self.p,p,sb);
|
||||
Self.sb:=sb;
|
||||
Self.funcs:=funcs;
|
||||
Self.regvars:=regvars;
|
||||
FreeMem(p);
|
||||
end;
|
||||
|
||||
@@ -168,6 +169,7 @@ inherited Create(Compiler);
|
||||
FText:='';
|
||||
libs:=TStringList.Create;
|
||||
funcs:=TStringList.Create;
|
||||
regvars:=TList<TPair<string,PTypeInfo>>.Create;
|
||||
end;
|
||||
|
||||
{function TRTBFasmCompiler.TRTBFasmSource.LoadLib(Name:string):TRTBLib;
|
||||
@@ -178,12 +180,24 @@ end;}
|
||||
procedure TRTBFasmCompiler.TRTBFasmSource.&Register(NameSpace:string;Name:string;&Type:TRTBType);
|
||||
begin
|
||||
if NameSpace<>'' then
|
||||
&Register('',NameSpace+'.'+Name,&Type)
|
||||
regvars.Add(TPair<string,PTypeInfo>.Create(NameSpace+'.'+Name,&Type))
|
||||
else
|
||||
begin
|
||||
|
||||
//
|
||||
regvars.Add(TPair<string,PTypeInfo>.Create(Name,&Type));
|
||||
end;
|
||||
|
||||
procedure TRTBFasmCompiler.TRTBFasmSource.UnRegister(NameSpace:string;Name:string);
|
||||
var
|
||||
i:NativeUInt;
|
||||
begin
|
||||
if NameSpace<>'' then
|
||||
Name:=NameSpace+'.'+Name;
|
||||
if regvars.Count<>0 then
|
||||
for i:=0 to regvars.Count-1 do
|
||||
if regvars.Items[i].Key=Name then
|
||||
begin
|
||||
regvars.Delete(i);
|
||||
Break;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TRTBFasmCompiler.TRTBFasmSource.RegisterFunction(NameSpace:string;Name:string);
|
||||
@@ -194,35 +208,58 @@ else
|
||||
funcs.Add(Name);
|
||||
end;
|
||||
|
||||
procedure TRTBFasmCompiler.TRTBFasmSource.UnRegisterFunction(NameSpace:string;Name:string);
|
||||
var
|
||||
i:NativeUInt;
|
||||
begin
|
||||
if NameSpace<>'' then
|
||||
Name:=NameSpace+'.'+Name;
|
||||
with funcs do
|
||||
Delete(IndexOf(Name));
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.Compilate:TRTBModule;
|
||||
var
|
||||
templib,pointerDecl,FuncDecl:string;
|
||||
templib,pointerDecl,PreDecl:string;
|
||||
Res:TFasmResult;
|
||||
i:NativeUInt;
|
||||
i,base:NativeUInt;
|
||||
FuncDict:TDictionary<string,NativeUInt>;
|
||||
RegVarDict:TDictionary<string,TPair<NativeUInt,PTypeInfo>>;
|
||||
begin
|
||||
case SizeOf(pointer) of
|
||||
2:pointerDecl:='dw ';
|
||||
4:pointerDecl:='dd ';
|
||||
8:pointerDecl:='dq ';
|
||||
end;
|
||||
FuncDecl:='';
|
||||
PreDecl:='';
|
||||
FuncDict:=TDictionary<string,NativeUInt>.Create();
|
||||
for i:=0 to funcs.Count-1 do
|
||||
begin
|
||||
FuncDecl:=FuncDecl+pointerDecl+funcs.Strings[i]+sLineBreak;
|
||||
FuncDict.Add(funcs.Strings[i],i*SizeOf(pointer));
|
||||
end;
|
||||
Res:=FasmAssemble(FuncDecl+Text+GetIncLibs,(Compiler as TRTBFasmCompiler).CompilerMem,(Compiler as TRTBFasmCompiler).MaxSteps);
|
||||
with funcs do
|
||||
if Count<>0 then
|
||||
for i:=0 to Count-1 do
|
||||
begin
|
||||
PreDecl:=PreDecl+pointerDecl+Strings[i]+sLineBreak;
|
||||
FuncDict.Add(Strings[i],i*SizeOf(pointer));
|
||||
end;
|
||||
base:=SizeOf(pointer)*funcs.Count;
|
||||
RegVarDict:=TDictionary<string,TPair<NativeUInt,PTypeInfo>>.Create();
|
||||
with regvars do
|
||||
if Count<>0 then
|
||||
for i:=0 to Count-1 do
|
||||
begin
|
||||
PreDecl:=PreDecl+pointerDecl+Items[i].Key+sLineBreak;
|
||||
RegVarDict.Add(Items[i].Key,TPair<NativeUInt,PTypeInfo>.Create(base+i*SizeOf(pointer),Items[i].Value));
|
||||
end;
|
||||
Res:=FasmAssemble(PreDecl+Text+GetIncLibs,(Compiler as TRTBFasmCompiler).CompilerMem,(Compiler as TRTBFasmCompiler).MaxSteps);
|
||||
if Res.Error<>FASM_OK then
|
||||
raise Exception.Create(Res.OutStr);
|
||||
Result:=TRTBFasmModule.Create(Res.OutData,Res.sb,FuncDict);
|
||||
Result:=TRTBFasmModule.Create(Res.OutData,Res.sb,FuncDict,RegVarDict);
|
||||
end;
|
||||
|
||||
destructor TRTBFasmCompiler.TRTBFasmSource.Destroy;
|
||||
begin
|
||||
FreeAndNil(libs);
|
||||
FreeAndNil(funcs);
|
||||
FreeAndNil(regvars);
|
||||
end;
|
||||
|
||||
constructor TRTBFasmCompiler.Create(FasmPath:String=FasmPath;AsDll:boolean=false);
|
||||
|
||||
@@ -72,7 +72,7 @@ type
|
||||
procedure DelVariable(NameSpace:string;Name:string);virtual;abstract;
|
||||
|
||||
procedure &Register(NameSpace:string;Name:string;&Type:TRTBType);virtual;abstract;
|
||||
procedure UnRegister(NameSpace:string;Name:string;&Type:TRTBType);virtual;abstract;
|
||||
procedure UnRegister(NameSpace:string;Name:string);virtual;abstract;
|
||||
procedure &RegisterFunction(NameSpace:string;Name:string);virtual;abstract;
|
||||
procedure UnRegisterFunction(NameSpace:string;Name:string);virtual;abstract;
|
||||
|
||||
|
||||
@@ -21,13 +21,16 @@ procedure TRuntimeBuilderTestObject.Test1();
|
||||
var
|
||||
Fasm:TRTBFasmCompiler;
|
||||
Src:TRTBSource;
|
||||
Module:TRTBModule;
|
||||
Func1:TRTBFunc;
|
||||
begin
|
||||
Fasm:=TRTBFasmCompiler.Create('..\..\..\lib\FasmOnDelphi\fasmw172\fasm');
|
||||
Src:=Fasm.GenNewSrc;
|
||||
Src.Text:='use32'+sLineBreak+'main:'+sLineBreak+'pop ecx'+sLineBreak+'pop eax'+sLineBreak+'jmp ecx';
|
||||
Src.Text:='use32'+sLineBreak+'main:'+sLineBreak+'pop ecx'+sLineBreak+'pop eax'+sLineBreak+'jmp ecx'+sLineBreak+'Pmain dd 0';
|
||||
Src.RegisterFunction('','main');
|
||||
Func1:=src.Compilate.Funtion['main'];
|
||||
Src.Register('','Pmain',TypeInfo(pointer));
|
||||
Module:=Src.Compilate;
|
||||
Func1:=Module.Funtion['main'];
|
||||
if 454<>Func1.Call(TypeInfo(integer),[454],CRTBCallTypeStdCall).AsInteger then
|
||||
begin
|
||||
raise Exception.Create('Error in test1');
|
||||
|
||||
Submodule lib/FasmOnDelphi updated: dd1e5ff80a...acb5bd9c9b
Reference in New Issue
Block a user