Fasm 1/2 writed

This commit is contained in:
2018-03-24 20:21:46 +03:00
parent 5f86c714b0
commit 0861047b15
5 changed files with 99 additions and 17 deletions

View File

@@ -2,7 +2,7 @@ unit RuntimeBuilder.Fasm;
interface
uses RuntimeBuilder.Types,FasmOnDelphi;
uses RuntimeBuilder.Types,FasmOnDelphi,System.TypInfo,System.Rtti,winapi.windows;
type
TRTBFasmCompiler=class(TRTBCompiler)
@@ -15,13 +15,22 @@ type
sb:NativeUInt;
public
constructor Create(p:Pointer;sb:NativeUInt);
//function Call(args:array of const;CallType:TRTBCallType=CRTBCallTypeDefault):Variant;override;
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;override;
destructor Destroy;override;
end;
TRTBLib=class abstract
private type
TRTBFasmLibFunc=class(TRTBFasmFunc)
public
//constructor Create(p:Pointer);
//destructor Destroy;override;
end;
private
//function GetFuntion(Name:string):TRTBFunc;virtual;abstract;
public
constructor Create(p:Pointer;sb:NativeUInt);
//property Funtion[Name:string]:TRTBFunc read GetFuntion;
//destructor Destroy;override;
end;
protected
FText:string;
@@ -30,7 +39,7 @@ type
public
constructor Create(Compiler:TRTBFasmCompiler);
function CompilateAsFunc:TRTBFunc;override;
//function CompilateAsLib:TRTBLib;virtual;abstract;
function CompilateAsLib:TRTBLib;virtual;abstract;
end;
public
CompilerMem:NativeUInt;
@@ -46,8 +55,39 @@ uses System.SysUtils;
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmFunc.Create(p:Pointer;sb:NativeUInt);
begin
Self.p:=p;
Self.p:=VirtualAlloc(nil,sb,MEM_COMMIT ,PAGE_EXECUTE_READWRITE);
CopyMemory(Self.p,p,sb);
Self.sb:=sb;
FreeMem(p);
end;
function TRTBFasmCompiler.TRTBFasmSource.TRTBFasmFunc.Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;
{$IFDEF CPUX64}
//function()
{$ENDIF}
begin
{$IFDEF CPUX64}
Result:=Invoke(p,args,ccReg,OutType);
{$ELSE}
case CallType of
CRTBCallTypeRegister,CRTBCallTypeDefault:Result:=Invoke(p,args,ccReg,OutType);
CRTBCallTypeStdCall:Result:=Invoke(p,args,ccStdCall,OutType);
CRTBCallTypeCdecl:Result:=Invoke(p,args,ccCdecl,OutType);
CRTBCallTypePascal:Result:=Invoke(p,args,ccPascal,OutType);
CRTBCallTypeSafeCall:Result:=Invoke(p,args,ccSafeCall,OutType);
end;
{$ENDIF}
end;
destructor TRTBFasmCompiler.TRTBFasmSource.TRTBFasmFunc.Destroy;
begin
VirtualFree(p,sb,MEM_RELEASE);
p:=nil;
end;
constructor TRTBFasmCompiler.TRTBFasmSource.TRTBLib.Create(p:Pointer;sb:NativeUInt);
begin
end;
function TRTBFasmCompiler.TRTBFasmSource.GetText:string;

View File

@@ -2,17 +2,15 @@ unit RuntimeBuilder.Types;
interface
uses System.TypInfo,System.Rtti;
const
CRTBCallTypeNil=$0;
CRTBCallTypeRegister=$1;
CRTBCallTypeStdCall=$2;
CRTBCallTypeCdecl=$3;
CRTBCallTypeClrcall=$4;
CRTBCallTypeThiscall=$5;
CRTBCallTypeVectorcall=$6;
CRTBCallTypeCFastCall=$7;
CRTBCallTypeFortran=$8;
CRTBCallTypeSyscall=$9;
CRTBCallTypePascal=$4;
CRTBCallTypeSafeCall=$5;
CRTBCallType64Call=$40;
CRTBCallTypeDefault=$80;
@@ -23,7 +21,7 @@ type
TRTBFunc=class abstract
public
function Call(args:array of const;CallType:TRTBCallType=CRTBCallTypeDefault):Variant;virtual;abstract;
function Call(OutType:PTypeInfo;args:TArray<TValue>;CallType:TRTBCallType=CRTBCallTypeDefault):TValue;virtual;abstract;
end;
TRTBLib=class abstract