Add Base part of code

This commit is contained in:
2018-03-11 21:13:18 +03:00
parent 9843085a34
commit 6ff505a678
4 changed files with 463 additions and 55 deletions

Submodule Fasm4Delphi updated: 9dea543a8c...f41b4fa6da

View File

@@ -22,13 +22,14 @@ interface
uses uses
System.SysUtils, System.SysUtils,
{$IFDEF USEFasm4Delphi}Fasm4Delphi,{$ENDIF} {$IFDEF USEFasm4Delphi}Fasm4Delphi,{$ENDIF}
{$IFDEF USEIOUtils}System.IOUtils{$ENDIF},Windows; {$IFDEF USEIOUtils}System.IOUtils{$ENDIF},Windows,Math;
{$IFNDEF USEFasm4Delphi}
type type
TFasmVersion=packed record TFasmVersion={$IFDEF USEFasm4Delphi}Fasm4Delphi.TFasmVersion;
{$ELSE}packed record
V1,V2:word; V1,V2:word;
end; end;
{$ENDIF}
const const
//General errors and conditions //General errors and conditions
@@ -84,28 +85,93 @@ const
FASMERR_SYMBOL_OUT_OF_SCOPE =-136; FASMERR_SYMBOL_OUT_OF_SCOPE =-136;
FASMERR_USER_ERROR =-140; FASMERR_USER_ERROR =-140;
FASMERR_ASSERTION_FAILED =-141; FASMERR_ASSERTION_FAILED =-141;
{$ENDIF}
type type
TFasmError=FASMERR_ASSERTION_FAILED ..FASM_ERROR; TFasmError=FASMERR_ASSERTION_FAILED ..FASM_ERROR;
TFasmOutPut=record TFasmLine=record
Error:TFasmError; Line:UInt32;
OutStr:string; &File:string;
end; end;
TFasmOut=record TFasmResult=record
OutData:Pointer; OutData:Pointer;
sb:integer; sb:integer;
OutPut:TFasmOutPut; Error:TFasmError;
OutStr:string;
Lines:array of TFasmLine;
end;
TErrorNamePair=record
Name:string;
Code:TFasmError;
end; end;
const const
FASMPath='fasm'; FasmPath='fasm';
FasmErrorCodeNames:array[TFasmError]of string=('assertion failed',//-141
'user error',//-140
'','','',//-139,-138,-137
'symbol out of scope',//-136
'too many repeats',//-135
'data already defined',//-134
'setting already specified',//-133
'section not aligned enough',//-132
'extra characters on line',//-131
'unexpected instruction',//-130
'missing end directive',//-129
'missing end quote',//-128
'symbol already defined',//-127
'reserved word used as symbol',//-126
'invalid name',//-125
'name too long',//-124
'invalid use of symbol',//-123
'undefined symbol',//-122
'value out of range',//-121
'invalid value',//-120
'invalid address',//-119
'invalid expression',//-118
'relative jump out of range',//-117
'long immediate not encodable',//-116
'disallowed combination of registers',//-115
'address sizes do not agree',//-114
'invalid address size',//-113
'operand sizes do not match',//-112
'operand size not specified',//-111
'invalid operand size',//-110
'invalid operand',//-109
'illegal instruction',//-108
'invalid argument',//-107
'unexpected characters',//-106
'incomplete macro',//-105
'invalid macro arguments',//-104
'invalid file format',//-103
'error reading file',//-102
'file not found',//-101
'','','','','','','','','','','','','','','','','','','','','','','','','',
//-100-99-98-97-96-95-94-93-92-91-90-89-88-87-86-85-84-83-82-81-80-79-78-77-76
'','','','','','','','','','','','','','','','','','','','','','','','','',
//-75-74-73-72-71-70-69-68-67-66-65-64-63-62-61-60-59-58-57-56-55-54-53-52-51
'','','','','','','','','','','','','','','','','','','','','','','','','',
//-50-49-48-47-46-45-44-43-42-41-40-39-38-37-36-35-34-33-32-31-30-29-28-27-26
'','','','','','','','','','','','','','','','',
//-25-24-23-22-21-20-19-18-17-16-15-14-13-12-11-10
'invalid definition',//-9
'write failed',//-8
'format limitations excedded',//-7
'cannot generate code',//-6
'unexpected end of source',//-5
'source file not found',//-4
'stack overflow',//-3
'out of memory',//-2
'invalid parameter',//-1
'success.',//0
'working',//1
'error'//2
);
function FasmVersion:TFasmVersion; function FasmVersion:TFasmVersion;
function FasmAssemble(const Source:AnsiString;cbMemorySize:cardinal;nPassesLimit:word=100):TFasmOut; function FasmAssemble(const Source:AnsiString;cbMemorySize:cardinal=1024*1024;nPassesLimit:DWORD=100):TFasmResult;
{function FasmAssembleToFile(const Source,OutFile:AnsiString;cbMemorySize:cardinal;nPassesLimit:word=100):TFasmOutPut; function FasmAssembleToFile(const Source,OutFile:AnsiString;cbMemorySize:cardinal=1024*1024*8;nPassesLimit:DWORD=100):TFasmResult;
function FasmAssembleFile(const Source:AnsiString;cbMemorySize:cardinal;nPassesLimit:word=100):TFasmOut; function FasmAssembleFile(const Source:AnsiString;cbMemorySize:cardinal=1024*1024*8;nPassesLimit:DWORD=100):TFasmResult;
function FasmAssembleFileToFile(const Source,OutFile:AnsiString;cbMemorySize:cardinal;nPassesLimit:word=100):TFasmOutPut;{} function FasmAssembleFileToFile(const Source,OutFile:AnsiString;cbMemorySize:cardinal=1024*1024*8;nPassesLimit:DWORD=100):TFasmResult;
procedure OpenFASM(Location:string=FASMPath;AsDll:boolean=false); procedure OpenFASM(Location:string=FASMPath;AsDll:boolean=false);
procedure SetFasmTemp(Path:string); procedure SetFasmTemp(Path:string);
@@ -132,7 +198,8 @@ SecAtrtrs.bInheritHandle:=true;
ZeroMemory(@StartupInfo,SizeOf(StartupInfo)); ZeroMemory(@StartupInfo,SizeOf(StartupInfo));
StartupInfo.cb:=SizeOf(StartupInfo); StartupInfo.cb:=SizeOf(StartupInfo);
StartupInfo.dwFlags:=STARTF_USESTDHANDLES; StartupInfo.dwFlags:=STARTF_USESTDHANDLES;
Createpipe(OutPut,StartupInfo.hStdOutput,@SecAtrtrs,0); Createpipe(OutPut,StartupInfo.hStdOutput,@SecAtrtrs,1024);
StartupInfo.hStdError:=StartupInfo.hStdOutput;
if not CreateProcess(nil,PChar('"'+FasmLocation+'" '+Command),nil,nil,true,NORMAL_PRIORITY_CLASS,nil,nil,StartupInfo,ProcessInformation)then if not CreateProcess(nil,PChar('"'+FasmLocation+'" '+Command),nil,nil,true,NORMAL_PRIORITY_CLASS,nil,nil,StartupInfo,ProcessInformation)then
RaiseLastOSError; RaiseLastOSError;
WaitForSingleObject(ProcessInformation.hProcess,INFINITE); WaitForSingleObject(ProcessInformation.hProcess,INFINITE);
@@ -184,45 +251,376 @@ end;
{$ENDIF} {$ENDIF}
end; end;
function FasmAssemble(const Source:AnsiString;cbMemorySize:cardinal;nPassesLimit:word=100):TFasmOut; function FasmAssemble(const Source:AnsiString;cbMemorySize:cardinal=1024*1024;nPassesLimit:DWORD=100):TFasmResult;
{$IFDEF USEFasm4Delphi}
var var
{$IFDEF USEFasm4Delphi}
Mem:PFASM_STATE; Mem:PFASM_STATE;
hDisp,hOut:THandle; p:PLINE_HEADER;
n:DWORD; {$ELSE}
Buff:AnsiChar; p:pointer;
SecAtrtrs:TSecurityAttributes;
{$ENDIF} {$ENDIF}
s,s0:string;
nr:cardinal;
FileHandle:THandle;
i,i1:NativeUInt;
i0:TFasmError;
begin begin
{$IFDEF USEFasm4Delphi} {$IFDEF USEFasm4Delphi}
if IsDll then if IsDll then
begin begin
SecAtrtrs.nLength:=SizeOf(TSecurityAttributes);
SecAtrtrs.lpSecurityDescriptor:=nil;
SecAtrtrs.bInheritHandle:=true;
CreatePipe(hOut,hDisp,@SecAtrtrs,0);
GetMem(Mem,cbMemorySize); GetMem(Mem,cbMemorySize);
Result.OutPut.Error:=fasm_Assemble(PAnsiChar(Source),Mem,cbMemorySize,nPassesLimit,hDisp); ZeroMemory(Mem,cbMemorySize);
if Result.OutPut.Error=FASM_OK then Result.Error:=fasm_Assemble(PAnsiChar(Source),Mem,cbMemorySize,nPassesLimit);
if Result.Error=FASM_OK then
begin begin
GetMem(Result.OutData,Mem.output_length);
CopyMemory(Result.OutData,Mem.output_data,Mem.output_length);
Result.sb:=Mem.output_length;
Result.OutStr:='Success.';
end
else
begin
Result.OutData:=nil;
Result.sb:=0;
Result.OutStr:='Error: '+Mem.error_code.ToString+' '+FasmErrorCodeNames[Mem.error_code];
p:=Mem.error_line;
nr:=0;
while(NativeUInt(p)>=NativeUInt(Mem))and(NativeUInt(Mem)+NativeUInt(cbMemorySize)>=NativeUInt(p))do
begin
Result.OutStr:=Result.OutStr+sLineBreak+
string(p.file_path)+'['+p.line_number.ToString+']';
inc(nr);
SetLength(Result.Lines,nr);
Result.Lines[nr-1].Line:=p.line_number;
Result.Lines[nr-1].&File:=string(p.file_path);
p:=p^.macro_calling_line;
end;
end; end;
FreeMem(Mem); FreeMem(Mem);
Result.OutPut.OutStr:='';
while PeekNamedPipe(hOut,@Buff,1,nil,@n,nil) do
if n<>0 then
begin
ReadFile(hOut,Buff,1,n,nil);
Result.OutPut.OutStr:=Result.OutPut.OutStr+Buff;
end
else
break;
CloseHandle(hOut);
CloseHandle(hDisp);
end end
else else
begin begin
{$ENDIF} {$ENDIF}
s:=FasmTemp+GetTickCount.ToString();
FileHandle:=CreateFile(PChar(s+'.in'),GENERIC_WRITE,0,nil,CREATE_ALWAYS,128,0);
WriteFile(FileHandle,PAnsiChar(Source)^,length(Source),nr,nil);
CloseHandle(FileHandle);
Result.OutStr:=RunFasm('-m '+trunc(cbMemorySize/1024).ToString+' -p '+nPassesLimit.ToString+' '+
s+'.in '+s);
DeleteFile(PChar(s+'.in'));
i:=Pos('error: ',Result.OutStr);
s0:=Copy(Result.OutStr,i+length('error: '),Pos('.',Result.OutStr,i)-i-length('error: '));
if i=0 then
Result.Error:=FASM_OK
else
for i0:=FASMERR_ASSERTION_FAILED to FASM_ERROR do
if FasmErrorCodeNames[i0]=s0 then
Result.Error:=i0;
if Result.Error=FASM_OK then
begin
FileHandle:=CreateFile(PWideChar(s),GENERIC_READ,0,nil,3,128,0);
Result.sb:=GetFileSize(FileHandle,nil);
getmem(Result.OutData,Result.sb);
ReadFile(FileHandle,Result.OutData,Result.sb,nr,nil);
CloseHandle(FileHandle);
DeleteFile(PChar(s));
end
else
begin
Result.OutData:=nil;
Result.sb:=0;
i:=Pos(sLineBreak,Result.OutStr)+length(sLineBreak);
nr:=0;
i1:=Pos(']:',Result.OutStr,i);
while i1<>0 do
begin
inc(nr);
SetLength(Result.Lines,nr);
i1:=Pos(' [',Result.OutStr,i);
Result.Lines[nr-1].&File:=Copy(Result.OutStr,i,i1-i);
i:=i1+2;
i1:=Pos(']:',Result.OutStr,i);
Result.Lines[nr-1].Line:=Copy(Result.OutStr,i,i1-i).ToInteger;
for i0:=0 to 2 do
i:=Pos(sLineBreak,Result.OutStr,i)+length(sLineBreak);
i1:=Pos(']:',Result.OutStr,i);
end;
end;
{$IFDEF USEFasm4Delphi}
end;
{$ENDIF}
end;
function FasmAssembleToFile(const Source,OutFile:AnsiString;cbMemorySize:cardinal=1024*1024*8;nPassesLimit:DWORD=100):TFasmResult;
var
{$IFDEF USEFasm4Delphi}
Mem:PFASM_STATE;
p:PLINE_HEADER;
{$ELSE}
p:pointer;
{$ENDIF}
s,s0:string;
nr:cardinal;
FileHandle:THandle;
i,i1:NativeUInt;
i0:TFasmError;
begin
{$IFDEF USEFasm4Delphi}
if IsDll then
begin
GetMem(Mem,cbMemorySize);
ZeroMemory(Mem,cbMemorySize);
Result.Error:=fasm_Assemble(PAnsiChar(Source),Mem,cbMemorySize,nPassesLimit);
Result.OutData:=nil;
Result.sb:=0;
if Result.Error=FASM_OK then
begin
FileHandle:=CreateFile(PWideChar(OutFile),GENERIC_READ,0,nil,3,128,0);
WriteFile(FileHandle,Mem.output_data^,Mem.output_length,nr,nil);
CloseHandle(FileHandle);
Result.OutStr:='Success.';
end
else
begin
Result.OutStr:='Error: '+Mem.error_code.ToString+' '+FasmErrorCodeNames[Mem.error_code];
p:=Mem.error_line;
nr:=0;
while(NativeUInt(p)>=NativeUInt(Mem))and(NativeUInt(Mem)+NativeUInt(cbMemorySize)>=NativeUInt(p))do
begin
Result.OutStr:=Result.OutStr+sLineBreak+
string(p.file_path)+'['+p.line_number.ToString+']';
inc(nr);
SetLength(Result.Lines,nr);
Result.Lines[nr-1].Line:=p.line_number;
Result.Lines[nr-1].&File:=string(p.file_path);
p:=p^.macro_calling_line;
end;
end;
FreeMem(Mem);
end
else
begin
{$ENDIF}
s:=FasmTemp+GetTickCount.ToString();
FileHandle:=CreateFile(PChar(s),GENERIC_WRITE,0,nil,CREATE_ALWAYS,128,0);
WriteFile(FileHandle,PAnsiChar(Source)^,length(Source),nr,nil);
CloseHandle(FileHandle);
Result.OutStr:=RunFasm('-m '+trunc(cbMemorySize/1024).ToString+' -p '+nPassesLimit.ToString+' '+
s+' '+OutFile);
DeleteFile(PChar(s));
i:=Pos('error: ',Result.OutStr);
s0:=Copy(Result.OutStr,i+length('error: '),Pos('.',Result.OutStr,i)-i-length('error: '));
if i=0 then
Result.Error:=FASM_OK
else
for i0:=FASMERR_ASSERTION_FAILED to FASM_ERROR do
if FasmErrorCodeNames[i0]=s0 then
Result.Error:=i0;
Result.OutData:=nil;
Result.sb:=0;
if Result.Error<>FASM_OK then
begin
i:=Pos(sLineBreak,Result.OutStr)+length(sLineBreak);
nr:=0;
i1:=Pos(']:',Result.OutStr,i);
while i1<>0 do
begin
inc(nr);
SetLength(Result.Lines,nr);
i1:=Pos(' [',Result.OutStr,i);
Result.Lines[nr-1].&File:=Copy(Result.OutStr,i,i1-i);
i:=i1+2;
i1:=Pos(']:',Result.OutStr,i);
Result.Lines[nr-1].Line:=Copy(Result.OutStr,i,i1-i).ToInteger;
for i0:=0 to 2 do
i:=Pos(sLineBreak,Result.OutStr,i)+length(sLineBreak);
i1:=Pos(']:',Result.OutStr,i);
end;
end;
{$IFDEF USEFasm4Delphi}
end;
{$ENDIF}
end;
function FasmAssembleFile(const Source:AnsiString;cbMemorySize:cardinal=1024*1024*8;nPassesLimit:DWORD=100):TFasmResult;
var
{$IFDEF USEFasm4Delphi}
Mem:PFASM_STATE;
p:PLINE_HEADER;
{$ELSE}
p:pointer;
{$ENDIF}
s,s0:string;
nr:cardinal;
FileHandle:THandle;
i,i1:NativeUInt;
i0:TFasmError;
begin
{$IFDEF USEFasm4Delphi}
if IsDll then
begin
GetMem(Mem,cbMemorySize);
ZeroMemory(Mem,cbMemorySize);
Result.Error:=fasm_AssembleFile(PAnsiChar(Source),Mem,cbMemorySize,nPassesLimit);
if Result.Error=FASM_OK then
begin
GetMem(Result.OutData,Mem.output_length);
CopyMemory(Result.OutData,Mem.output_data,Mem.output_length);
Result.sb:=Mem.output_length;
Result.OutStr:='Success.';
end
else
begin
Result.OutData:=nil;
Result.sb:=0;
Result.OutStr:='Error: '+Mem.error_code.ToString+' '+FasmErrorCodeNames[Mem.error_code];
p:=Mem.error_line;
nr:=0;
while(NativeUInt(p)>=NativeUInt(Mem))and(NativeUInt(Mem)+NativeUInt(cbMemorySize)>=NativeUInt(p))do
begin
Result.OutStr:=Result.OutStr+sLineBreak+
string(p.file_path)+'['+p.line_number.ToString+']';
inc(nr);
SetLength(Result.Lines,nr);
Result.Lines[nr-1].Line:=p.line_number;
Result.Lines[nr-1].&File:=string(p.file_path);
p:=p^.macro_calling_line;
end;
end;
FreeMem(Mem);
end
else
begin
{$ENDIF}
s:=FasmTemp+GetTickCount.ToString();
Result.OutStr:=RunFasm('-m '+trunc(cbMemorySize/1024).ToString+' -p '+nPassesLimit.ToString+' '+
Source+' '+s);
i:=Pos('error: ',Result.OutStr);
s0:=Copy(Result.OutStr,i+length('error: '),Pos('.',Result.OutStr,i)-i-length('error: '));
if i=0 then
Result.Error:=FASM_OK
else
for i0:=FASMERR_ASSERTION_FAILED to FASM_ERROR do
if FasmErrorCodeNames[i0]=s0 then
Result.Error:=i0;
if Result.Error=FASM_OK then
begin
FileHandle:=CreateFile(PWideChar(s),GENERIC_READ,0,nil,3,128,0);
Result.sb:=GetFileSize(FileHandle,nil);
getmem(Result.OutData,Result.sb);
ReadFile(FileHandle,Result.OutData,Result.sb,nr,nil);
CloseHandle(FileHandle);
DeleteFile(PChar(s));
end
else
begin
Result.OutData:=nil;
Result.sb:=0;
i:=Pos(sLineBreak,Result.OutStr)+length(sLineBreak);
nr:=0;
i1:=Pos(']:',Result.OutStr,i);
while i1<>0 do
begin
inc(nr);
SetLength(Result.Lines,nr);
i1:=Pos(' [',Result.OutStr,i);
Result.Lines[nr-1].&File:=Copy(Result.OutStr,i,i1-i);
i:=i1+2;
i1:=Pos(']:',Result.OutStr,i);
Result.Lines[nr-1].Line:=Copy(Result.OutStr,i,i1-i).ToInteger;
for i0:=0 to 2 do
i:=Pos(sLineBreak,Result.OutStr,i)+length(sLineBreak);
i1:=Pos(']:',Result.OutStr,i);
end;
end;
{$IFDEF USEFasm4Delphi}
end;
{$ENDIF}
end;
function FasmAssembleFileToFile(const Source,OutFile:AnsiString;cbMemorySize:cardinal=1024*1024*8;nPassesLimit:DWORD=100):TFasmResult;
var
{$IFDEF USEFasm4Delphi}
Mem:PFASM_STATE;
p:PLINE_HEADER;
FileHandle:THandle;
{$ELSE}
p:pointer;
{$ENDIF}
s0:string;
nr:cardinal;
i,i1:NativeUInt;
i0:TFasmError;
begin
{$IFDEF USEFasm4Delphi}
if IsDll then
begin
GetMem(Mem,cbMemorySize);
ZeroMemory(Mem,cbMemorySize);
Result.Error:=fasm_AssembleFile(PAnsiChar(Source),Mem,cbMemorySize,nPassesLimit);
Result.OutData:=nil;
Result.sb:=0;
if Result.Error=FASM_OK then
begin
FileHandle:=CreateFile(PWideChar(OutFile),GENERIC_READ,0,nil,3,128,0);
WriteFile(FileHandle,Mem.output_data^,Mem.output_length,nr,nil);
CloseHandle(FileHandle);
Result.OutStr:='Success.';
end
else
begin
Result.OutData:=nil;
Result.sb:=0;
Result.OutStr:='Error: '+Mem.error_code.ToString+' '+FasmErrorCodeNames[Mem.error_code];
p:=Mem.error_line;
nr:=0;
while(NativeUInt(p)>=NativeUInt(Mem))and(NativeUInt(Mem)+NativeUInt(cbMemorySize)>=NativeUInt(p))do
begin
Result.OutStr:=Result.OutStr+sLineBreak+
string(p.file_path)+'['+p.line_number.ToString+']';
inc(nr);
SetLength(Result.Lines,nr);
Result.Lines[nr-1].Line:=p.line_number;
Result.Lines[nr-1].&File:=string(p.file_path);
p:=p^.macro_calling_line;
end;
end;
FreeMem(Mem);
end
else
begin
{$ENDIF}
Result.OutStr:=RunFasm('-m '+trunc(cbMemorySize/1024).ToString+' -p '+nPassesLimit.ToString+' '+
Source+' '+OutFile);
i:=Pos('error: ',Result.OutStr);
s0:=Copy(Result.OutStr,i+length('error: '),Pos('.',Result.OutStr,i)-i-length('error: '));
if i=0 then
Result.Error:=FASM_OK
else
for i0:=FASMERR_ASSERTION_FAILED to FASM_ERROR do
if FasmErrorCodeNames[i0]=s0 then
Result.Error:=i0;
Result.OutData:=nil;
Result.sb:=0;
if Result.Error=FASM_OK then
begin
i:=Pos(sLineBreak,Result.OutStr)+length(sLineBreak);
nr:=0;
i1:=Pos(']:',Result.OutStr,i);
while i1<>0 do
begin
inc(nr);
SetLength(Result.Lines,nr);
i1:=Pos(' [',Result.OutStr,i);
Result.Lines[nr-1].&File:=Copy(Result.OutStr,i,i1-i);
i:=i1+2;
i1:=Pos(']:',Result.OutStr,i);
Result.Lines[nr-1].Line:=Copy(Result.OutStr,i,i1-i).ToInteger;
for i0:=0 to 2 do
i:=Pos(sLineBreak,Result.OutStr,i)+length(sLineBreak);
i1:=Pos(']:',Result.OutStr,i);
end;
end;
{$IFDEF USEFasm4Delphi} {$IFDEF USEFasm4Delphi}
end; end;
{$ENDIF} {$ENDIF}
@@ -231,11 +629,15 @@ end;
procedure OpenFASM(Location:string=FASMPath;AsDll:boolean=false); procedure OpenFASM(Location:string=FASMPath;AsDll:boolean=false);
begin begin
{$IFDEF USEFasm4Delphi} {$IFDEF USEFasm4Delphi}
{$IF Declared(FreeFASM)}
if IsDll then if IsDll then
FreeFASM; FreeFASM;
{$ENDIF}
IsDll:=AsDll; IsDll:=AsDll;
{$IF Declared(LoadFASM)}
if AsDll then if AsDll then
LoadFASM(Location); LoadFASM(Location);
{$ENDIF}
FasmLocation:=Location; FasmLocation:=Location;
{$ELSE} {$ELSE}
if not AsDll then if not AsDll then

BIN
Tests/Test1..bin Normal file

Binary file not shown.

View File

@@ -40,40 +40,46 @@ begin
end; end;
procedure TMyTestObject.Test1; procedure TMyTestObject.Test1;
var
Res:TFasmResult;
begin begin
if fasm_AssembleFile('..\..\Test1.ASM',CompliterMem,CompliterMemSize)<>FASM_OK then Res:=FasmAssembleFileToFile('..\..\Test1.ASM','..\..\Test1..bin');
if Res.Error<>FASM_OK then
raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+ raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+
'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak); 'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak);
end; end;
procedure TMyTestObject.Test2; procedure TMyTestObject.Test2;
var var
Res:TFasmOut; Res:TFasmResult;
begin begin
Res:=FasmAssemble('add eax,',CompliterMemSize); Res:=FasmAssemble('add eax,0');
raise Exception.Create('Answ: '+Res.OutPut.OutStr+sLineBreak); if Res.Error<>FASM_OK then
//'Error Code:'+CompliterMem^.error_code.ToString+sLineBreak); raise Exception.Create('Condition: '+Res.OutStr+sLineBreak+
if Res.OutPut.Error<>FASM_OK then 'Error Code: '+IntToStr(Res.Error)+sLineBreak);
raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+
'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak);
end; end;
procedure TMyTestObject.Test3; procedure TMyTestObject.Test3;
var
Res:TFasmResult;
begin begin
if fasm_AssembleFile('..\..\..\FasmDll\FASM.ASH',CompliterMem,CompliterMemSize)=FASM_OK then Res:=FasmAssembleFile('..\..\..\Fasm4Delphi\FasmDll\FASM.ASH');
raise Exception.Create('FASM is compiling something that it is can not compile at all.'); if Res.Error=FASM_OK then
raise Exception.Create('FASM is compiling something that it is can not compile at all.')
end; end;
procedure TMyTestObject.Test4; procedure TMyTestObject.Test4;
var
Res:TFasmResult;
begin begin
if fasm_Assemble('call -100',CompliterMem,CompliterMemSize)<>FASM_OK then Res:=FasmAssembleToFile('add eax,0','test');
raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+ if Res.Error<>FASM_OK then
'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak); raise Exception.Create('Condition: '+Res.OutStr+sLineBreak+
'Error Code: '+IntToStr(Res.Error)+sLineBreak);
end; end;
initialization initialization
TDUnitX.RegisterTestFixture(TMyTestObject); TDUnitX.RegisterTestFixture(TMyTestObject);
OpenFASM('..\..\..\Fasm4Delphi\FasmDll\FASM.DLL',true); OpenFASM('..\..\..\fasmw172\FASM.EXE');
//OpenFASM('..\..\..\fasmw172\FASM.EXE');
GetMem(CompliterMem,CompliterMemSize); GetMem(CompliterMem,CompliterMemSize);
end. end.