fix
This commit is contained in:
@@ -2,7 +2,9 @@ unit RuntimeBuilder.Fasm;
|
||||
|
||||
interface
|
||||
|
||||
uses RuntimeBuilder.Types,FasmOnDelphi,System.TypInfo,System.Rtti,winapi.windows;
|
||||
uses
|
||||
System.Classes,System.TypInfo,System.IOUtils,System.Rtti,Winapi.Windows,
|
||||
RuntimeBuilder,FasmOnDelphi;
|
||||
|
||||
type
|
||||
TRTBFasmCompiler=class(TRTBCompiler)
|
||||
@@ -18,19 +20,20 @@ type
|
||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
TRTBLib=class abstract
|
||||
TRTBFasmLib=class(TRTBLib)
|
||||
private type
|
||||
TRTBFasmLibFunc=class(TRTBFasmFunc)
|
||||
public
|
||||
//constructor Create(p:Pointer);
|
||||
//destructor Destroy;override;
|
||||
constructor Create(p:Pointer);
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
private
|
||||
//function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
|
||||
filename:string;
|
||||
Lib:NativeUInt;
|
||||
function GetFuntion(Name:string):TRTBFunc;override;
|
||||
public
|
||||
constructor Create(p:Pointer;sb:NativeUInt);
|
||||
//property Funtion[Name:string]:TRTBFunc read GetFuntion;
|
||||
//destructor Destroy;override;
|
||||
constructor Create(Name:string);
|
||||
destructor Destroy;override;
|
||||
end;
|
||||
protected
|
||||
FText:string;
|
||||
@@ -39,13 +42,16 @@ type
|
||||
public
|
||||
constructor Create(Compiler:TRTBFasmCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;override;
|
||||
function CompilateAsLib:TRTBLib;virtual;abstract;
|
||||
function CompilateAsLib:TRTBLib;override;
|
||||
end;
|
||||
protected
|
||||
function GetIncLibs():string;
|
||||
public
|
||||
CompilerMem:NativeUInt;
|
||||
MaxSteps:word;
|
||||
libs:TStringList;
|
||||
constructor Create(FasmPath:String=FasmPath;AsDll:boolean=false);
|
||||
//function LoadLib(Name:string):TRTBLib;
|
||||
function LoadLib(Name:string):TRTBLib;
|
||||
function GenNewSrc():TRTBSource;override;
|
||||
end;
|
||||
|
||||
@@ -85,9 +91,30 @@ VirtualFree(p,sb,MEM_RELEASE);
|
||||
p:=nil;
|
||||
end;
|
||||
|
||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBLib.Create(p:Pointer;sb:NativeUInt);
|
||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmLib.TRTBFasmLibFunc.Create(p:Pointer);
|
||||
begin
|
||||
Self.p:=p;
|
||||
end;
|
||||
|
||||
destructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmLib.TRTBFasmLibFunc.Destroy;
|
||||
begin
|
||||
p:=nil;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmLib.GetFuntion(Name:string):TRTBFunc;
|
||||
begin
|
||||
Result:=TRTBFasmLibFunc.Create(GetProcAddress(Lib,pwidechar(Name)));
|
||||
end;
|
||||
|
||||
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmLib.Create(Name:string);
|
||||
begin
|
||||
filename:=Name;
|
||||
Lib:=LoadLibrary(pwidechar(Name));
|
||||
end;
|
||||
|
||||
destructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmLib.Destroy;
|
||||
begin
|
||||
FreeLibrary(Lib);
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.GetText:string;
|
||||
@@ -110,17 +137,46 @@ function TRTBFasmCompiler.TRTBFasmSource.CompilateAsFunc:TRTBFunc;
|
||||
var
|
||||
Res:TFasmResult;
|
||||
begin
|
||||
Res:=FasmAssemble(Text,(Compiler as TRTBFasmCompiler).CompilerMem,(Compiler as TRTBFasmCompiler).MaxSteps);
|
||||
Res:=FasmAssemble(Text+(Compiler as TRTBFasmCompiler).GetIncLibs,(Compiler as TRTBFasmCompiler).CompilerMem,(Compiler as TRTBFasmCompiler).MaxSteps);
|
||||
if Res.Error<>FASM_OK then
|
||||
raise Exception.Create(Res.OutStr);
|
||||
Result:=TRTBFasmFunc.Create(Res.OutData,Res.sb);
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.TRTBFasmSource.CompilateAsLib:TRTBLib;
|
||||
var
|
||||
templib:string;
|
||||
Res:TFasmResult;
|
||||
begin
|
||||
templib:=TPath.GetTempFileName;
|
||||
Res:=FasmAssembleToFile({$IFDEF CPUX64}'format PE64 DLL'{$ELSE}'format PE DLL'{$ENDIF}+
|
||||
(Compiler as TRTBFasmCompiler).GetIncLibs+sLineBreak+Text,templib,
|
||||
(Compiler as TRTBFasmCompiler).CompilerMem,(Compiler as TRTBFasmCompiler).MaxSteps);
|
||||
if Res.Error<>FASM_OK then
|
||||
raise Exception.Create(Res.OutStr);
|
||||
Result:=TRTBFasmLib.Create(templib);
|
||||
end;
|
||||
|
||||
constructor TRTBFasmCompiler.Create(FasmPath:String=FasmPath;AsDll:boolean=false);
|
||||
begin
|
||||
CompilerMem:=1024*1024*16;
|
||||
MaxSteps:=65535;
|
||||
OpenFASM(FasmPath,AsDll);
|
||||
libs:=TStringList.Create;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.LoadLib(Name:string):TRTBLib;
|
||||
begin
|
||||
libs.Add(Name);
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.GetIncLibs():string;
|
||||
var
|
||||
i:integer;
|
||||
begin
|
||||
Result:='';
|
||||
for i:=0 to libs.count-1 do
|
||||
Result:=Result+sLineBreak+'include '+#39+libs.Strings[i]+#39;
|
||||
end;
|
||||
|
||||
function TRTBFasmCompiler.GenNewSrc():TRTBSource;
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
unit RuntimeBuilder.Types;
|
||||
|
||||
interface
|
||||
|
||||
uses System.TypInfo,System.Rtti;
|
||||
|
||||
const
|
||||
CRTBCallTypeNil=$0;
|
||||
CRTBCallTypeRegister=$1;
|
||||
CRTBCallTypeStdCall=$2;
|
||||
CRTBCallTypeCdecl=$3;
|
||||
CRTBCallTypePascal=$4;
|
||||
CRTBCallTypeSafeCall=$5;
|
||||
CRTBCallType64Call=$40;
|
||||
CRTBCallTypeDefault=$80;
|
||||
|
||||
type
|
||||
TRTBCompiler=class;
|
||||
|
||||
TRTBCallType=CRTBCallTypeNil..CRTBCallTypeDefault;
|
||||
|
||||
TRTBFunc=class abstract
|
||||
public
|
||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;virtual;abstract;
|
||||
end;
|
||||
|
||||
TRTBLib=class abstract
|
||||
protected
|
||||
function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
|
||||
public
|
||||
property Funtion[Name:string]:TRTBFunc read GetFuntion;
|
||||
end;
|
||||
|
||||
TRTBSource=class abstract
|
||||
protected
|
||||
Compiler:TRTBCompiler;
|
||||
function GetText:string;virtual;abstract;
|
||||
procedure SetText(S:string);virtual;abstract;
|
||||
public
|
||||
constructor Create(Compiler:TRTBCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;virtual;abstract;
|
||||
function CompilateAsLib:TRTBLib;virtual;abstract;
|
||||
procedure LoadFromFile(&File:string);
|
||||
procedure SaveToFile(&File:string);
|
||||
property Text:string read GetText write SetText;
|
||||
end;
|
||||
|
||||
TRTBCompiler=class abstract
|
||||
public
|
||||
function LoadLib(Name:string):TRTBLib;virtual;abstract;
|
||||
function GenNewSrc():TRTBSource;virtual;abstract;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.SysUtils,System.Classes;
|
||||
|
||||
constructor TRTBSource.Create(Compiler:TRTBCompiler);
|
||||
begin
|
||||
Self.Compiler:=Compiler;
|
||||
end;
|
||||
|
||||
procedure TRTBSource.LoadFromFile(&File:string);
|
||||
var
|
||||
Data:TStrings;
|
||||
begin
|
||||
Data:=TStringList.Create;
|
||||
Data.LoadFromFile(&File);
|
||||
Text:=Data.Text;
|
||||
FreeAndNil(Data);
|
||||
end;
|
||||
|
||||
procedure TRTBSource.SaveToFile(&File:string);
|
||||
var
|
||||
Data:TStrings;
|
||||
begin
|
||||
Data:=TStringList.Create;
|
||||
Data.Text:=Text;
|
||||
Data.SaveToFile(&File);
|
||||
FreeAndNil(Data);
|
||||
end;
|
||||
|
||||
end.
|
||||
@@ -2,8 +2,83 @@ unit RuntimeBuilder;
|
||||
|
||||
interface
|
||||
|
||||
uses RuntimeBuilder.Types;
|
||||
uses System.TypInfo,System.Rtti;
|
||||
|
||||
const
|
||||
CRTBCallTypeNil=$0;
|
||||
CRTBCallTypeRegister=$1;
|
||||
CRTBCallTypeStdCall=$2;
|
||||
CRTBCallTypeCdecl=$3;
|
||||
CRTBCallTypePascal=$4;
|
||||
CRTBCallTypeSafeCall=$5;
|
||||
CRTBCallType64Call=$40;
|
||||
CRTBCallTypeDefault=$80;
|
||||
|
||||
type
|
||||
TRTBCompiler=class;
|
||||
|
||||
TRTBCallType=CRTBCallTypeNil..CRTBCallTypeDefault;
|
||||
|
||||
TRTBFunc=class abstract
|
||||
public
|
||||
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;virtual;abstract;
|
||||
end;
|
||||
|
||||
TRTBLib=class abstract
|
||||
protected
|
||||
function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
|
||||
public
|
||||
property Funtion[Name:string]:TRTBFunc read GetFuntion;
|
||||
end;
|
||||
|
||||
TRTBSource=class abstract
|
||||
protected
|
||||
Compiler:TRTBCompiler;
|
||||
function GetText:string;virtual;abstract;
|
||||
procedure SetText(S:string);virtual;abstract;
|
||||
public
|
||||
constructor Create(Compiler:TRTBCompiler);
|
||||
function CompilateAsFunc:TRTBFunc;virtual;abstract;
|
||||
function CompilateAsLib:TRTBLib;virtual;abstract;
|
||||
procedure LoadFromFile(&File:string);
|
||||
procedure SaveToFile(&File:string);
|
||||
property Text:string read GetText write SetText;
|
||||
end;
|
||||
|
||||
TRTBCompiler=class abstract
|
||||
public
|
||||
function LoadLib(Name:string):TRTBLib;virtual;abstract;
|
||||
function GenNewSrc():TRTBSource;virtual;abstract;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
System.SysUtils,System.Classes;
|
||||
|
||||
constructor TRTBSource.Create(Compiler:TRTBCompiler);
|
||||
begin
|
||||
Self.Compiler:=Compiler;
|
||||
end;
|
||||
|
||||
procedure TRTBSource.LoadFromFile(&File:string);
|
||||
var
|
||||
Data:TStrings;
|
||||
begin
|
||||
Data:=TStringList.Create;
|
||||
Data.LoadFromFile(&File);
|
||||
Text:=Data.Text;
|
||||
FreeAndNil(Data);
|
||||
end;
|
||||
|
||||
procedure TRTBSource.SaveToFile(&File:string);
|
||||
var
|
||||
Data:TStrings;
|
||||
begin
|
||||
Data:=TStringList.Create;
|
||||
Data.Text:=Text;
|
||||
Data.SaveToFile(&File);
|
||||
FreeAndNil(Data);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user