From 5f86c714b01497c1c934d201162415c502a7cb6d Mon Sep 17 00:00:00 2001 From: Artem3213212 Date: Thu, 22 Mar 2018 00:56:26 +0300 Subject: [PATCH] Fasm Added --- Source/RuntimeBuilder.Fasm.pas | 102 +++++++++++++++++++++----------- Source/RuntimeBuilder.Types.pas | 47 ++++++++++++--- Tests/Project2.dpr | 5 +- Tests/Project2.dproj | 7 ++- 4 files changed, 114 insertions(+), 47 deletions(-) diff --git a/Source/RuntimeBuilder.Fasm.pas b/Source/RuntimeBuilder.Fasm.pas index a9a1499..96d4915 100644 --- a/Source/RuntimeBuilder.Fasm.pas +++ b/Source/RuntimeBuilder.Fasm.pas @@ -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. diff --git a/Source/RuntimeBuilder.Types.pas b/Source/RuntimeBuilder.Types.pas index 2f75293..5a52b21 100644 --- a/Source/RuntimeBuilder.Types.pas +++ b/Source/RuntimeBuilder.Types.pas @@ -17,7 +17,7 @@ const CRTBCallTypeDefault=$80; type - TRTBCompliter=class; + TRTBCompiler=class; TRTBCallType=CRTBCallTypeNil..CRTBCallTypeDefault; @@ -27,31 +27,60 @@ type end; TRTBLib=class abstract - private + protected function GetFuntion(Name:string):TRTBFunc;virtual;abstract; public property Funtion[Name:string]:TRTBFunc read GetFuntion; end; TRTBSource=class abstract - private - Compliter:TRTBCompliter; + protected + Compiler:TRTBCompiler; function GetText:string;virtual;abstract; procedure SetText(S:string);virtual;abstract; public - procedure CompleteAsLib:TRTBLib;virtual;abstract; - procedure CompleteAsFunc:TRTBLib;virtual;abstract; + 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; - TRTBCompliter=class abstract + TRTBCompiler=class abstract public function LoadLib(Name:string):TRTBLib;virtual;abstract; function GenNewSrc():TRTBSource;virtual;abstract; - function CompleteFunc(Source:TRTBSource;args:array of const):TRTBFunc;virtual;abstract; - function CompleteLib(Source:TRTBSource;args:array of const):TRTBLib;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. diff --git a/Tests/Project2.dpr b/Tests/Project2.dpr index 7bd138d..2c3a105 100644 --- a/Tests/Project2.dpr +++ b/Tests/Project2.dpr @@ -13,7 +13,10 @@ uses DUnitX.TestFramework, Unit1 in 'Unit1.pas', RuntimeBuilder in '..\Source\RuntimeBuilder.pas', - RuntimeBuilder.Types in '..\Source\RuntimeBuilder.Types.pas'; + RuntimeBuilder.Types in '..\Source\RuntimeBuilder.Types.pas', + RuntimeBuilder.Fasm in '..\Source\RuntimeBuilder.Fasm.pas', + FasmOnDelphi in '..\FasmOnDelphi\Source\FasmOnDelphi.pas', + Fasm4Delphi in '..\FasmOnDelphi\Fasm4Delphi\Source\Fasm4Delphi.pas'; var runner : ITestRunner; diff --git a/Tests/Project2.dproj b/Tests/Project2.dproj index 2864f45..fb66d4f 100644 --- a/Tests/Project2.dproj +++ b/Tests/Project2.dproj @@ -95,6 +95,9 @@ + + + Cfg_2 Base @@ -451,13 +454,13 @@ 1 - + - + False