Fasm Added

This commit is contained in:
2018-03-22 00:56:26 +03:00
parent 6aacaf3982
commit 5f86c714b0
4 changed files with 114 additions and 47 deletions

View File

@@ -2,58 +2,90 @@ unit RuntimeBuilder.Fasm;
interface
uses RuntimeBuilder.Types;
uses RuntimeBuilder.Types,FasmOnDelphi;
type
{TRTBFasmFunc=class(TRTBFunc)
public
function Call(args:array of const;CallType:TRTBCallType=CRTBCallTypeDefault):Variant;override;
end;}
{TRTBLib=class abstract
private
function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
public
property Funtion[Name:string]:TRTBFunc read GetFuntion;
end;}
TRTBFasmCompliter=class(TRTBCompliter)
private type
TRTBSource=class abstract
private
FText:string;;
function GetText:string;
procedure SetText(S:string);
TRTBFasmCompiler=class(TRTBCompiler)
protected type
TRTBFasmSource=class(TRTBSource)
protected type
TRTBFasmFunc=class(TRTBFunc)
protected
p:Pointer;
sb:NativeUInt;
public
constructor Create(p:Pointer;sb:NativeUInt);
//function Call(args:array of const;CallType:TRTBCallType=CRTBCallTypeDefault):Variant;override;
end;
TRTBLib=class abstract
private
//function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
public
//property Funtion[Name:string]:TRTBFunc read GetFuntion;
end;
protected
FText:string;
function GetText:string;override;
procedure SetText(S:string);override;
public
constructor Create();
//procedure CompleteAsLib:TRTBLib;virtual;abstract;
//procedure CompleteAsFunc:TRTBLib;virtual;abstract;
end;
constructor Create(Compiler:TRTBFasmCompiler);
function CompilateAsFunc:TRTBFunc;override;
//function CompilateAsLib:TRTBLib;virtual;abstract;
end;
public
CompilerMem:NativeUInt;
MaxSteps:word;
constructor Create(FasmPath:String=FasmPath;AsDll:boolean=false);
//function LoadLib(Name:string):TRTBLib;
function GenNewSrc():TRTBFasmSource;override;
//function CompleteFunc(Source:TRTBSource;args:array of const):TRTBFunc;virtual;abstract;
//function CompleteLib(Source:TRTBSource;args:array of const):TRTBLib;virtual;abstract;
function GenNewSrc():TRTBSource;override;
end;
implementation
constructor TRTBFasmCompliter.TRTBSource.Create();
uses System.SysUtils;
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmFunc.Create(p:Pointer;sb:NativeUInt);
begin
Self.p:=p;
Self.sb:=sb;
end;
function TRTBFasmCompiler.TRTBFasmSource.GetText:string;
begin
Result:=FText;
end;
procedure TRTBFasmCompiler.TRTBFasmSource.SetText(S:string);
begin
FText:=S;
end;
constructor TRTBFasmCompiler.TRTBFasmSource.Create(Compiler:TRTBFasmCompiler);
begin
inherited Create(Compiler);
FText:='';
end;
function GTRTBFasmCompliter.TRTBSource.etText:string;
function TRTBFasmCompiler.TRTBFasmSource.CompilateAsFunc:TRTBFunc;
var
Res:TFasmResult;
begin
Res:=FasmAssemble(Text,(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;
procedure TRTBFasmCompliter.TRTBSource.SetText(S:string);
function TRTBFasmCompliter.GenNewSrc():TRTBSource;
constructor TRTBFasmCompiler.Create(FasmPath:String=FasmPath;AsDll:boolean=false);
begin
Result:=;
CompilerMem:=1024*1024*16;
MaxSteps:=65535;
OpenFASM(FasmPath,AsDll);
end;
function TRTBFasmCompiler.GenNewSrc():TRTBSource;
begin
Result:=TRTBFasmSource.Create(Self);
end;
end.