Files
RuntimeBuilder/Source/RuntimeBuilder.Fasm.pas
2018-03-22 00:56:26 +03:00

92 lines
2.3 KiB
ObjectPascal

unit RuntimeBuilder.Fasm;
interface
uses RuntimeBuilder.Types,FasmOnDelphi;
type
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(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():TRTBSource;override;
end;
implementation
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 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;
constructor TRTBFasmCompiler.Create(FasmPath:String=FasmPath;AsDll:boolean=false);
begin
CompilerMem:=1024*1024*16;
MaxSteps:=65535;
OpenFASM(FasmPath,AsDll);
end;
function TRTBFasmCompiler.GenNewSrc():TRTBSource;
begin
Result:=TRTBFasmSource.Create(Self);
end;
end.