This commit is contained in:
2018-02-11 23:55:18 +03:00
parent f7eb6b6d7c
commit 411ee0a981
19 changed files with 2403 additions and 3 deletions

71
.gitignore vendored Normal file
View File

@@ -0,0 +1,71 @@
# Uncomment these types if you want even more clean repository. But be careful.
# Uncomment these types if you want even more clean repository. But be careful.
# It can make harm to an existing project source. Read explanations below.
#
# Resource files are binaries containing manifest, project icon and version info.
# They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files.
#*.res
#
# Type library file (binary). In old Delphi versions it should be stored.
# Since Delphi 2009 it is produced from .ridl file and can safely be ignored.
#*.tlb
#
# Diagram Portfolio file. Used by the diagram editor up to Delphi 7.
# Uncomment this if you are not using diagrams or use newer Delphi version.
#*.ddp
#
# Visual LiveBindings file. Added in Delphi XE2.
# Uncomment this if you are not using LiveBindings Designer.
#*.vlb
#
# Deployment Manager configuration file for your project. Added in Delphi XE2.
# Uncomment this if it is not mobile development and you do not use remote debug feature.
#*.deployproj
#
# C++ object files produced when C/C++ Output file generation is configured.
# Uncomment this if you are not using external objects (zlib library for example).
#*.obj
#
# Delphi compiler-generated binaries (safe to delete)
*.exe
*.dll
*.bpl
*.bpi
*.dcp
*.so
*.apk
*.drc
*.map
*.dres
*.rsm
*.tds
*.dcu
*.lib
*.a
*.o
*.ocx
Temp/
*.tmp
# Delphi autogenerated files (duplicated info)
*.cfg
*.hpp
*Resource.rc
# Delphi local files (user-specific info)
*.local
*.identcache
*.projdata
*.tvsconfig
*.dsk
# Delphi history and backups
__history/
__recovery/
*.~*
# Castalia statistics file (since XE7 Castalia is distributed with Delphi)
*.stat
!FasmDll/

156
FasmDll/DEMO/ASMDEMO.ASM Normal file
View File

@@ -0,0 +1,156 @@
format PE GUI 4.0
entry start
include 'win32a.inc'
include 'fasm.ash'
include 'fedit.ash'
section '.data' data readable writeable
_fedit db 'FEDIT.DLL',0
_caption db 'flat assembler %d.%d',0
_error db 'ERROR',0
_source db 0Dh,0Ah
db ' org 100h',0Dh,0Ah
db 0Dh,0Ah
db ' mov ah,09h ',' ; write',0Dh,0Ah
db ' mov dx,text',0Dh,0Ah
db ' int 21h',0Dh,0Ah
db ' int 20h',0Dh,0Ah
db 0Dh,0Ah
db ' text db "Hello!",24h',0Dh,0Ah
db 0
buffer rb 10000h
fasm_memory:
fasm_state FASM_STATE
rb 800000h-($-fasm_memory) ; reserve total 8 MB for assembler
section '.code' code readable executable
start:
invoke LoadLibrary,_fedit
or eax,eax
jz exit
invoke GetModuleHandle,0
invoke DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
exit:
invoke ExitProcess,0
proc DialogProc hwnddlg,msg,wparam,lparam
push ebx esi edi
cmp [msg],WM_INITDIALOG
je wminitdialog
cmp [msg],WM_COMMAND
je wmcommand
cmp [msg],WM_CLOSE
je wmclose
xor eax,eax
jmp finish
wminitdialog:
invoke fasm_GetVersion
mov edx,eax
and eax,0FFFFh
shr edx,16
cinvoke wsprintf,buffer,_caption,eax,edx
invoke SendMessage,[hwnddlg],WM_SETTEXT,0,buffer
invoke SetDlgItemText,[hwnddlg],ID_SOURCE,_source
jmp processed
wmcommand:
cmp [wparam],BN_CLICKED shl 16 + IDCANCEL
je wmclose
cmp [wparam],BN_CLICKED shl 16 + IDOK
jne processed
invoke GetDlgItemText,[hwnddlg],ID_SOURCE,buffer,10000h
invoke fasm_Assemble,buffer,fasm_memory,800000h,100,NULL
cmp eax,FASM_OK
je show_output
invoke SetDlgItemText,[hwnddlg],ID_OUTPUT,_error
jmp processed
show_output:
mov esi,[fasm_state.output_data]
mov ecx,[fasm_state.output_length]
mov edi,buffer
xor edx,edx
jecxz output_ok
output_to_hex:
test dl,7
jz @f
mov al,20h
stosb
@@:
mov al,[esi+edx]
shr al,4
cmp al,10
sbb al,69h
das
stosb
mov al,[esi+edx]
and al,0Fh
cmp al,10
sbb al,69h
das
stosb
inc edx
test dl,7
jnz @f
mov ax,0D0Ah
stosw
@@:
loop output_to_hex
output_ok:
xor al,al
stosb
invoke SetDlgItemText,[hwnddlg],ID_OUTPUT,buffer
jmp processed
wmclose:
invoke EndDialog,[hwnddlg],0
processed:
mov eax,1
finish:
pop edi esi ebx
ret
endp
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
user32,'USER32.DLL',\
fasm,'FASM.DLL'
include 'api\kernel32.inc'
include 'api\user32.inc'
import fasm,\
fasm_GetVersion,'fasm_GetVersion',\
fasm_Assemble,'fasm_Assemble',\
fasm_AssembleFile,'fasm_AssembleFile'
section '.rsrc' resource data readable
ID_SOURCE = 100
ID_OUTPUT = 101
directory RT_DIALOG,dialogs
resource dialogs,\
37,LANG_ENGLISH+SUBLANG_DEFAULT,demonstration
dialog demonstration,'Memory-to-memory assembly',40,40,180,220,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME
dialogitem 'FEDIT','',ID_SOURCE,10,10,160,120,WS_VISIBLE+WS_BORDER+WS_TABSTOP
dialogitem 'FEDIT','',ID_OUTPUT,10,150,160,60,WS_VISIBLE+WS_BORDER+WS_TABSTOP
dialogitem 'BUTTON','Assemble',IDOK,10,132,160,15,WS_VISIBLE+WS_TABSTOP
enddialog

104
FasmDll/DEMO/FASM.ASH Normal file
View File

@@ -0,0 +1,104 @@
; The following structure resides at the beginning of memory block provided
; to the fasm_Assemble function. The condition field contains the same value
; as the one returned by function.
; When function returns FASM_OK condition, the output_length and
; output_data fields are filled - with pointer to generated output
; (somewhere within the provided memory block) and the count of bytes stored
; there.
; When function returns FASM_ERROR, the error_code is filled with the
; code of specific error that happened and error_line is a pointer to the
; LINE_HEADER structure, providing information about the line that caused
; the error.
struct FASM_STATE
condition dd ?
union
output_length dd ?
error_code dd ?
ends
union
output_data dd ?
error_line dd ?
ends
ends
; The following structure has two variants - it either defines the line
; that was loaded directly from source, or the line that was generated by
; macroinstruction. First case has the highest bit of line_number set to 0,
; while the second case has this bit set.
; In the first case, the file_path field contains pointer to the path of
; source file (empty string if it's the source that was provided directly to
; fasm_Assemble function), the line_number is the number of line within
; that file (starting from 1) and the file_offset field contains the offset
; within the file where the line starts.
; In the second case the macro_calling_line field contains the pointer to
; LINE_HEADER structure for the line which called the macroinstruction, and
; the macro_line field contains the pointer to LINE_HEADER structure for the
; line within the definition of macroinstruction, which generated this one.
struct LINE_HEADER
file_path dd ?
line_number dd ?
union
file_offset dd ?
macro_calling_line dd ?
ends
macro_line dd ?
ends
; General errors and conditions
FASM_OK = 0 ; FASM_STATE points to output
FASM_WORKING = 1
FASM_ERROR = 2 ; FASM_STATE contains error code
FASM_INVALID_PARAMETER = -1
FASM_OUT_OF_MEMORY = -2
FASM_STACK_OVERFLOW = -3
FASM_SOURCE_NOT_FOUND = -4
FASM_UNEXPECTED_END_OF_SOURCE = -5
FASM_CANNOT_GENERATE_CODE = -6
FASM_FORMAT_LIMITATIONS_EXCEDDED = -7
FASM_WRITE_FAILED = -8
FASM_INVALID_DEFINITION = -9
; Error codes for FASM_ERROR condition
FASMERR_FILE_NOT_FOUND = -101
FASMERR_ERROR_READING_FILE = -102
FASMERR_INVALID_FILE_FORMAT = -103
FASMERR_INVALID_MACRO_ARGUMENTS = -104
FASMERR_INCOMPLETE_MACRO = -105
FASMERR_UNEXPECTED_CHARACTERS = -106
FASMERR_INVALID_ARGUMENT = -107
FASMERR_ILLEGAL_INSTRUCTION = -108
FASMERR_INVALID_OPERAND = -109
FASMERR_INVALID_OPERAND_SIZE = -110
FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111
FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112
FASMERR_INVALID_ADDRESS_SIZE = -113
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117
FASMERR_INVALID_EXPRESSION = -118
FASMERR_INVALID_ADDRESS = -119
FASMERR_INVALID_VALUE = -120
FASMERR_VALUE_OUT_OF_RANGE = -121
FASMERR_UNDEFINED_SYMBOL = -122
FASMERR_INVALID_USE_OF_SYMBOL = -123
FASMERR_NAME_TOO_LONG = -124
FASMERR_INVALID_NAME = -125
FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126
FASMERR_SYMBOL_ALREADY_DEFINED = -127
FASMERR_MISSING_END_QUOTE = -128
FASMERR_MISSING_END_DIRECTIVE = -129
FASMERR_UNEXPECTED_INSTRUCTION = -130
FASMERR_EXTRA_CHARACTERS_ON_LINE = -131
FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132
FASMERR_SETTING_ALREADY_SPECIFIED = -133
FASMERR_DATA_ALREADY_DEFINED = -134
FASMERR_TOO_MANY_REPEATS = -135
FASMERR_SYMBOL_OUT_OF_SCOPE = -136
FASMERR_USER_ERROR = -140
FASMERR_ASSERTION_FAILED = -141

69
FasmDll/DEMO/FEDIT.ASH Normal file
View File

@@ -0,0 +1,69 @@
; flat editor mode flags
FEMODE_OVERWRITE = 1
FEMODE_VERTICALSEL = 2
FEMODE_NOUNDO = 4
FEMODE_READONLY = 8
; flat editor search flags
FEFIND_CASESENSITIVE = 1
FEFIND_WHOLEWORDS = 2
FEFIND_BACKWARD = 4
FEFIND_INWHOLETEXT = 8
; flat editor styles
FES_AUTOINDENT = 0001h
FES_AUTOBRACKETS = 0002h
FES_SMARTTABS = 0004h
FES_SECURESEL = 0008h
FES_OPTIMALFILL = 0010h
FES_CONSOLECARET = 0020h
FES_REVIVEDEADKEYS = 0040h
FES_TIMESCROLL = 0080h
; flat editor messages
FEM_SETMODE = WM_USER + 0
FEM_GETMODE = WM_USER + 1
FEM_SETPOS = WM_USER + 2
FEM_GETPOS = WM_USER + 3
FEM_SETSYNTAXHIGHLIGHT = WM_USER + 4
FEM_SETRIGHTCLICKMENU = WM_USER + 5
FEM_SETTEXTCOLOR = WM_USER + 6
FEM_SETSELCOLOR = WM_USER + 7
FEM_FINDFIRST = WM_USER + 8
FEM_FINDNEXT = WM_USER + 9
FEM_CANFINDNEXT = WM_USER + 10
FEM_GETLINELENGTH = WM_USER + 11
FEM_GETLINE = WM_USER + 12
FEM_GETWORDATCARET = WM_USER + 13
FEM_BEGINOPERATION = WM_USER + 14
FEM_ENDOPERATION = WM_USER + 15
FEM_MARKUNMODIFIED = WM_USER + 16
FEM_ISUNMODIFIED = WM_USER + 17
FEM_GETSEARCHTEXT = WM_USER + 18
FEM_GETSEARCHFLAGS = WM_USER + 19
FEM_RELEASESEARCH = WM_USER + 20
FEM_REDO = WM_USER + 84
FEM_CANREDO = WM_USER + 85
; flat editor notifications
FEN_SETFOCUS = 01h
FEN_KILLFOCUS = 02h
FEN_TEXTCHANGE = 03h
FEN_POSCHANGE = 04h
FEN_MODECHANGE = 05h
FEN_OUTOFMEMORY = 0Fh
; flat editor position structure
struct FEPOS
selectionPosition dd ?
selectionLine dd ?
caretPosition dd ?
caretLine dd ?
ends

104
FasmDll/FASM.ASH Normal file
View File

@@ -0,0 +1,104 @@
; The following structure resides at the beginning of memory block provided
; to the fasm_Assemble function. The condition field contains the same value
; as the one returned by function.
; When function returns FASM_OK condition, the output_length and
; output_data fields are filled - with pointer to generated output
; (somewhere within the provided memory block) and the count of bytes stored
; there.
; When function returns FASM_ERROR, the error_code is filled with the
; code of specific error that happened and error_line is a pointer to the
; LINE_HEADER structure, providing information about the line that caused
; the error.
struct FASM_STATE
condition dd ?
union
output_length dd ?
error_code dd ?
ends
union
output_data dd ?
error_line dd ?
ends
ends
; The following structure has two variants - it either defines the line
; that was loaded directly from source, or the line that was generated by
; macroinstruction. First case has the highest bit of line_number set to 0,
; while the second case has this bit set.
; In the first case, the file_path field contains pointer to the path of
; source file (empty string if it's the source that was provided directly to
; fasm_Assemble function), the line_number is the number of line within
; that file (starting from 1) and the file_offset field contains the offset
; within the file where the line starts.
; In the second case the macro_calling_line field contains the pointer to
; LINE_HEADER structure for the line which called the macroinstruction, and
; the macro_line field contains the pointer to LINE_HEADER structure for the
; line within the definition of macroinstruction, which generated this one.
struct LINE_HEADER
file_path dd ?
line_number dd ?
union
file_offset dd ?
macro_calling_line dd ?
ends
macro_line dd ?
ends
; General errors and conditions
FASM_OK = 0 ; FASM_STATE points to output
FASM_WORKING = 1
FASM_ERROR = 2 ; FASM_STATE contains error code
FASM_INVALID_PARAMETER = -1
FASM_OUT_OF_MEMORY = -2
FASM_STACK_OVERFLOW = -3
FASM_SOURCE_NOT_FOUND = -4
FASM_UNEXPECTED_END_OF_SOURCE = -5
FASM_CANNOT_GENERATE_CODE = -6
FASM_FORMAT_LIMITATIONS_EXCEDDED = -7
FASM_WRITE_FAILED = -8
FASM_INVALID_DEFINITION = -9
; Error codes for FASM_ERROR condition
FASMERR_FILE_NOT_FOUND = -101
FASMERR_ERROR_READING_FILE = -102
FASMERR_INVALID_FILE_FORMAT = -103
FASMERR_INVALID_MACRO_ARGUMENTS = -104
FASMERR_INCOMPLETE_MACRO = -105
FASMERR_UNEXPECTED_CHARACTERS = -106
FASMERR_INVALID_ARGUMENT = -107
FASMERR_ILLEGAL_INSTRUCTION = -108
FASMERR_INVALID_OPERAND = -109
FASMERR_INVALID_OPERAND_SIZE = -110
FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111
FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112
FASMERR_INVALID_ADDRESS_SIZE = -113
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117
FASMERR_INVALID_EXPRESSION = -118
FASMERR_INVALID_ADDRESS = -119
FASMERR_INVALID_VALUE = -120
FASMERR_VALUE_OUT_OF_RANGE = -121
FASMERR_UNDEFINED_SYMBOL = -122
FASMERR_INVALID_USE_OF_SYMBOL = -123
FASMERR_NAME_TOO_LONG = -124
FASMERR_INVALID_NAME = -125
FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126
FASMERR_SYMBOL_ALREADY_DEFINED = -127
FASMERR_MISSING_END_QUOTE = -128
FASMERR_MISSING_END_DIRECTIVE = -129
FASMERR_UNEXPECTED_INSTRUCTION = -130
FASMERR_EXTRA_CHARACTERS_ON_LINE = -131
FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132
FASMERR_SETTING_ALREADY_SPECIFIED = -133
FASMERR_DATA_ALREADY_DEFINED = -134
FASMERR_TOO_MANY_REPEATS = -135
FASMERR_SYMBOL_OUT_OF_SCOPE = -136
FASMERR_USER_ERROR = -140
FASMERR_ASSERTION_FAILED = -141

49
FasmDll/FASMDLL.TXT Normal file
View File

@@ -0,0 +1,49 @@
Short description of functions inside FASM.DLL
fasm_GetVersion()
Returns double word containg major version in lower 16 bits,
and minor version in the higher 16 bits.
fasm_Assemble(lpSource,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
Assembles the given source, using the provided memory block as a free
storage space (which is also to contain generated output).
The lpSource should contain a pointer to zero-ended source text.
The lpMemory should be a pointer to the memory block and cbMemorySize
should contain its size. In the beginning of this memory block the
FASM_STATE structure will reside (as defined in FASM.ASH). The assembler
doesn't allocate any memory beside this block, if it is not enough for
its purposes, the function returns with FASM_OUT_OF_MEMORY state.
The nPassesLimit should be a value in range from 1 to 65536, defining
the maximum number of passes the assembler can perform in order to
generate the code (the recommended value is 100). If the limit is reached,
the function returns with state FASM_CANNOT_GENERATE_CODE.
The hDisplayPipe should contain handle of the pipe, to which the output
of DISPLAY directives will be written. If this parameter is NULL, all
the display will get discarded.
If the assembly is successful, function returns FASM_OK value and fills
the output_data and output_length fields of the FASM_STATE structure
(which resides at the beginning of provided memory block) with pointer
to the generated output and count of bytes stored there.
If the assembly failed, function returns one of the other general
conditions as defined in FASM.ASH. If the condition returned is FASM_ERROR,
it means that an error caused by a specific place in source occured,
then the error_code and error_line fields of FASM_STATE are filled,
first one with detailed error code as defined in FASM.ASH, and the second
one with pointer to a structure containing data about line that caused
the error.
fasm_AssembleFile(lpSourceFile,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
This function performs identically to fasm_Assemble, except that it takes
the lpSourceFile parameter in place of lpSource, and it shall contain the
pointer to zero-ended path to file containing the source to assemble.

37
FasmDll/LICENSE.TXT Normal file
View File

@@ -0,0 +1,37 @@
flat assembler version 1.71
Copyright (c) 1999-2014, Tomasz Grysztar.
All rights reserved.
This program is free for commercial and non-commercial use as long as
the following conditions are adhered to.
Copyright remains Tomasz Grysztar, and as such any Copyright notices
in the code are not to be removed.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The licence and distribution terms for any publically available
version or derivative of this code cannot be changed. i.e. this code
cannot simply be copied and put under another distribution licence
(including the GNU Public Licence).

View File

@@ -0,0 +1,147 @@
; flat assembler core
; Copyright (c) 1999-2017, Tomasz Grysztar.
; All rights reserved.
invalid_parameter:
mov eax,FASM_INVALID_PARAMETER
jmp general_error
out_of_memory:
mov eax,FASM_OUT_OF_MEMORY
jmp general_error
stack_overflow:
mov eax,FASM_STACK_OVERFLOW
jmp general_error
main_file_not_found:
mov eax,FASM_SOURCE_NOT_FOUND
jmp general_error
unexpected_end_of_file:
mov eax,FASM_UNEXPECTED_END_OF_SOURCE
jmp general_error
code_cannot_be_generated:
mov eax,FASM_CANNOT_GENERATE_CODE
jmp general_error
format_limitations_exceeded:
mov eax,FASM_FORMAT_LIMITATIONS_EXCEDDED
jmp general_error
invalid_definition:
mov eax,FASM_INVALID_DEFINITION
jmp general_error
write_failed:
mov eax,FASM_WRITE_FAILED
jmp general_error
file_not_found:
mov eax,FASMERR_FILE_NOT_FOUND
jmp assembler_error
error_reading_file:
mov eax,FASMERR_ERROR_READING_FILE
jmp assembler_error
invalid_file_format:
mov eax,FASMERR_INVALID_FILE_FORMAT
jmp assembler_error
invalid_macro_arguments:
mov eax,FASMERR_INVALID_MACRO_ARGUMENTS
jmp assembler_error
incomplete_macro:
mov eax,FASMERR_INCOMPLETE_MACRO
jmp assembler_error
unexpected_characters:
mov eax,FASMERR_UNEXPECTED_CHARACTERS
jmp assembler_error
invalid_argument:
mov eax,FASMERR_INVALID_ARGUMENT
jmp assembler_error
illegal_instruction:
mov eax,FASMERR_ILLEGAL_INSTRUCTION
jmp assembler_error
invalid_operand:
mov eax,FASMERR_INVALID_OPERAND
jmp assembler_error
invalid_operand_size:
mov eax,FASMERR_INVALID_OPERAND_SIZE
jmp assembler_error
operand_size_not_specified:
mov eax,FASMERR_OPERAND_SIZE_NOT_SPECIFIED
jmp assembler_error
operand_sizes_do_not_match:
mov eax,FASMERR_OPERAND_SIZES_DO_NOT_MATCH
jmp assembler_error
invalid_address_size:
mov eax,FASMERR_INVALID_ADDRESS_SIZE
jmp assembler_error
address_sizes_do_not_agree:
mov eax,FASMERR_ADDRESS_SIZES_DO_NOT_AGREE
jmp assembler_error
disallowed_combination_of_registers:
mov eax,FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS
jmp assembler_error
long_immediate_not_encodable:
mov eax,FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE
jmp assembler_error
relative_jump_out_of_range:
mov eax,FASMERR_RELATIVE_JUMP_OUT_OF_RANGE
jmp assembler_error
invalid_expression:
mov eax,FASMERR_INVALID_EXPRESSION
jmp assembler_error
invalid_address:
mov eax,FASMERR_INVALID_ADDRESS
jmp assembler_error
invalid_value:
mov eax,FASMERR_INVALID_VALUE
jmp assembler_error
value_out_of_range:
mov eax,FASMERR_VALUE_OUT_OF_RANGE
jmp assembler_error
undefined_symbol:
mov eax,FASMERR_UNDEFINED_SYMBOL
jmp assembler_error
invalid_use_of_symbol:
mov eax,FASMERR_INVALID_USE_OF_SYMBOL
jmp assembler_error
name_too_long:
mov eax,FASMERR_NAME_TOO_LONG
jmp assembler_error
invalid_name:
mov eax,FASMERR_INVALID_NAME
jmp assembler_error
reserved_word_used_as_symbol:
mov eax,FASMERR_RESERVED_WORD_USED_AS_SYMBOL
jmp assembler_error
symbol_already_defined:
mov eax,FASMERR_SYMBOL_ALREADY_DEFINED
jmp assembler_error
symbol_out_of_scope:
mov eax,FASMERR_SYMBOL_OUT_OF_SCOPE
jmp assembler_error
missing_end_quote:
mov eax,FASMERR_MISSING_END_QUOTE
jmp assembler_error
missing_end_directive:
mov eax,FASMERR_MISSING_END_DIRECTIVE
jmp assembler_error
unexpected_instruction:
mov eax,FASMERR_UNEXPECTED_INSTRUCTION
jmp assembler_error
extra_characters_on_line:
mov eax,FASMERR_EXTRA_CHARACTERS_ON_LINE
jmp assembler_error
section_not_aligned_enough:
mov eax,FASMERR_SECTION_NOT_ALIGNED_ENOUGH
jmp assembler_error
setting_already_specified:
mov eax,FASMERR_SETTING_ALREADY_SPECIFIED
jmp assembler_error
data_already_defined:
mov eax,FASMERR_DATA_ALREADY_DEFINED
jmp assembler_error
too_many_repeats:
mov eax,FASMERR_TOO_MANY_REPEATS
jmp assembler_error
invoked_error:
mov eax,FASMERR_USER_ERROR
jmp assembler_error
assertion_failed:
mov eax,FASMERR_ASSERTION_FAILED
jmp assembler_error

104
FasmDll/SOURCE/DLL/FASM.ASH Normal file
View File

@@ -0,0 +1,104 @@
; The following structure resides at the beginning of memory block provided
; to the fasm_Assemble function. The condition field contains the same value
; as the one returned by function.
; When function returns FASM_OK condition, the output_length and
; output_data fields are filled - with pointer to generated output
; (somewhere within the provided memory block) and the count of bytes stored
; there.
; When function returns FASM_ERROR, the error_code is filled with the
; code of specific error that happened and error_line is a pointer to the
; LINE_HEADER structure, providing information about the line that caused
; the error.
struct FASM_STATE
condition dd ?
union
output_length dd ?
error_code dd ?
ends
union
output_data dd ?
error_line dd ?
ends
ends
; The following structure has two variants - it either defines the line
; that was loaded directly from source, or the line that was generated by
; macroinstruction. First case has the highest bit of line_number set to 0,
; while the second case has this bit set.
; In the first case, the file_path field contains pointer to the path of
; source file (empty string if it's the source that was provided directly to
; fasm_Assemble function), the line_number is the number of line within
; that file (starting from 1) and the file_offset field contains the offset
; within the file where the line starts.
; In the second case the macro_calling_line field contains the pointer to
; LINE_HEADER structure for the line which called the macroinstruction, and
; the macro_line field contains the pointer to LINE_HEADER structure for the
; line within the definition of macroinstruction, which generated this one.
struct LINE_HEADER
file_path dd ?
line_number dd ?
union
file_offset dd ?
macro_calling_line dd ?
ends
macro_line dd ?
ends
; General errors and conditions
FASM_OK = 0 ; FASM_STATE points to output
FASM_WORKING = 1
FASM_ERROR = 2 ; FASM_STATE contains error code
FASM_INVALID_PARAMETER = -1
FASM_OUT_OF_MEMORY = -2
FASM_STACK_OVERFLOW = -3
FASM_SOURCE_NOT_FOUND = -4
FASM_UNEXPECTED_END_OF_SOURCE = -5
FASM_CANNOT_GENERATE_CODE = -6
FASM_FORMAT_LIMITATIONS_EXCEDDED = -7
FASM_WRITE_FAILED = -8
FASM_INVALID_DEFINITION = -9
; Error codes for FASM_ERROR condition
FASMERR_FILE_NOT_FOUND = -101
FASMERR_ERROR_READING_FILE = -102
FASMERR_INVALID_FILE_FORMAT = -103
FASMERR_INVALID_MACRO_ARGUMENTS = -104
FASMERR_INCOMPLETE_MACRO = -105
FASMERR_UNEXPECTED_CHARACTERS = -106
FASMERR_INVALID_ARGUMENT = -107
FASMERR_ILLEGAL_INSTRUCTION = -108
FASMERR_INVALID_OPERAND = -109
FASMERR_INVALID_OPERAND_SIZE = -110
FASMERR_OPERAND_SIZE_NOT_SPECIFIED = -111
FASMERR_OPERAND_SIZES_DO_NOT_MATCH = -112
FASMERR_INVALID_ADDRESS_SIZE = -113
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE = -114
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS = -115
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE = -116
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE = -117
FASMERR_INVALID_EXPRESSION = -118
FASMERR_INVALID_ADDRESS = -119
FASMERR_INVALID_VALUE = -120
FASMERR_VALUE_OUT_OF_RANGE = -121
FASMERR_UNDEFINED_SYMBOL = -122
FASMERR_INVALID_USE_OF_SYMBOL = -123
FASMERR_NAME_TOO_LONG = -124
FASMERR_INVALID_NAME = -125
FASMERR_RESERVED_WORD_USED_AS_SYMBOL = -126
FASMERR_SYMBOL_ALREADY_DEFINED = -127
FASMERR_MISSING_END_QUOTE = -128
FASMERR_MISSING_END_DIRECTIVE = -129
FASMERR_UNEXPECTED_INSTRUCTION = -130
FASMERR_EXTRA_CHARACTERS_ON_LINE = -131
FASMERR_SECTION_NOT_ALIGNED_ENOUGH = -132
FASMERR_SETTING_ALREADY_SPECIFIED = -133
FASMERR_DATA_ALREADY_DEFINED = -134
FASMERR_TOO_MANY_REPEATS = -135
FASMERR_SYMBOL_OUT_OF_SCOPE = -136
FASMERR_USER_ERROR = -140
FASMERR_ASSERTION_FAILED = -141

458
FasmDll/SOURCE/DLL/FASM.ASM Normal file
View File

@@ -0,0 +1,458 @@
; flat assembler DLL interface for Win32
; Copyright (c) 1999-2017, Tomasz Grysztar.
; All rights reserved.
format PE DLL GUI 4.0
entry DLLEntryPoint
include 'win32a.inc'
include 'fasm.ash'
section '.data' data readable writeable
include '..\variable.inc'
state dd ?
esp_save dd ?
source dd ?
source_position dd ?
first_write dd ?
first_write_length dd ?
second_write dd ?
second_write_length dd ?
display_pipe dd ?
systime SYSTEMTIME
tmp dd ?
buffer rb 1000h
section '.text' code readable executable
DLLEntryPoint:
mov eax,TRUE
ret 12
fasm_GetVersion:
mov eax,VERSION_MAJOR + VERSION_MINOR shl 16
ret
fasm_AssembleFile:
mov eax,[lpSource]
mov [input_file],eax
mov [output_file],null_byte
jmp setup_assembler
fasm_Assemble:
virtual at esp+4
lpSource dd ?
lpMemory dd ?
cbMemorySize dd ?
nPassesLimit dd ?
hDisplayPipe dd ?
end virtual
mov eax,[lpSource]
mov [source],eax
mov [source_position],0
mov [input_file],null_byte
mov [output_file],null_byte
setup_assembler:
mov eax,[nPassesLimit]
cmp eax,10000h
ja invalid_parameter
or eax,eax
jz invalid_parameter
mov [passes_limit],ax
mov eax,[lpMemory]
mov ecx,[cbMemorySize]
mov [state],eax
mov [eax+FASM_STATE.condition],FASM_WORKING
sub ecx,sizeof.FASM_STATE
jbe out_of_memory
add eax,sizeof.FASM_STATE
mov [memory_start],eax
mov edx,ecx
shr edx,2
sub ecx,edx
add eax,ecx
mov [memory_end],eax
mov [additional_memory],eax
add eax,edx
mov [additional_memory_end],eax
xor eax,eax
mov [initial_definitions],eax
mov [first_write],eax
mov [second_write],eax
mov eax,[hDisplayPipe]
mov [display_pipe],eax
push ebp ebx esi edi
mov eax,esp
mov [esp_save],eax
and eax,not 0FFFh
add eax,1000h-10000h
mov [stack_limit],eax
call preprocessor
call parser
call assembler
call formatter
mov ebx,[state]
mov [ebx+FASM_STATE.condition],FASM_OK
done:
mov eax,[ebx+FASM_STATE.condition]
pop edi esi ebx ebp
ret 20
general_error:
mov esp,[esp_save]
mov ebx,[state]
mov [ebx+FASM_STATE.condition],eax
jmp done
assembler_error:
mov esp,[esp_save]
mov ebx,[state]
mov [ebx+FASM_STATE.error_code],eax
mov eax,[current_line]
mov [ebx+FASM_STATE.error_line],eax
mov eax,FASM_ERROR
jmp general_error
get_environment_variable:
invoke GetEnvironmentVariable,esi,buffer,1000h
retn
open:
cmp byte [edx],0
je open_memory
invoke CreateFile,edx,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
cmp eax,-1
je file_error
mov ebx,eax
clc
retn
file_error:
stc
retn
open_memory:
xor ebx,ebx
retn
read:
or ebx,ebx
jz read_memory
mov ebp,ecx
invoke ReadFile,ebx,edx,ecx,tmp,0
or eax,eax
jz file_error
cmp ebp,[tmp]
jne file_error
clc
retn
read_memory:
push esi edi
mov esi,[source]
add esi,[source_position]
mov edi,edx
call move_block
pop edi esi
clc
retn
move_block:
mov al,cl
shr ecx,2
rep movsd
mov cl,al
and cl,11b
rep movsb
retn
lseek:
or ebx,ebx
jz seek_memory
movzx eax,al
invoke SetFilePointer,ebx,edx,0,eax
cmp eax,-1
je file_error
retn
seek_memory:
push esi
mov esi,[source]
mov ecx,edx
or al,al
jz seek_forward
add esi,[source_position]
cmp al,2
je seek_source_end
seek_forward:
sub ecx,1
jc seek_complete
seek_in_source:
lodsb
or al,al
loopnz seek_in_source
jnz seek_complete
dec esi
seek_complete:
mov eax,esi
sub eax,[source]
mov [source_position],eax
pop esi
retn
seek_source_end:
lodsb
or al,al
jnz seek_source_end
dec esi
sub esi,edx
cmp esi,[source]
jae seek_complete
mov esi,[source]
jmp seek_complete
create:
or ebx,-1
clc
retn
write:
cmp [first_write],0
jne make_second_write
mov [first_write],edx
mov [first_write_length],ecx
clc
retn
make_second_write:
cmp [second_write],0
jne cannot_write
mov [second_write],edx
mov [second_write_length],ecx
clc
retn
cannot_write:
stc
retn
close:
or ebx,ebx
jz file_closed
cmp ebx,-1
je output_ready
invoke CloseHandle,ebx
file_closed:
retn
output_ready:
mov ebx,[state]
cmp [second_write],0
jne two_part_output
mov eax,[first_write]
mov [ebx+FASM_STATE.output_data],eax
mov eax,[first_write_length]
mov [ebx+FASM_STATE.output_length],eax
retn
two_part_output:
mov eax,[second_write]
mov [ebx+FASM_STATE.output_data],eax
shuffle_output:
mov ecx,[first_write_length]
cmp ecx,[second_write_length]
ja small_second_part
sub [second_write_length],ecx
mov esi,[first_write]
mov edi,[second_write]
call xchg_block
mov [second_write],edi
jmp shuffle_output
xchg_block:
shr ecx,1
jnc xchgb_ok
mov al,[edi]
xchg al,[esi]
stosb
inc esi
xchgb_ok:
shr ecx,1
jnc xchgw_ok
mov ax,[edi]
xchg ax,[esi]
stosw
add esi,2
xchgw_ok:
jz xchgd_ok
xchgd:
mov eax,[edi]
xchg eax,[esi]
stosd
add esi,4
loop xchgd
xchgd_ok:
retn
small_second_part:
mov edi,[second_write]
mov esi,edi
add edi,[first_write_length]
cmp edi,[first_write]
jbe move_second_part
mov edi,[first_write]
add edi,[first_write_length]
move_second_part:
push edi
mov ecx,[second_write_length]
lea eax,[edi+ecx]
cmp eax,[tagged_blocks]
ja out_of_memory
call move_block
mov edi,[second_write]
mov esi,[first_write]
mov ecx,[first_write_length]
call move_block
pop esi
mov ecx,[second_write_length]
call move_block
mov ecx,edi
sub ecx,[ebx+FASM_STATE.output_data]
mov [ebx+FASM_STATE.output_length],ecx
retn
display_block:
mov eax,[display_pipe]
or eax,eax
jz display_ok
invoke WriteFile,eax,esi,ecx,tmp,NULL
display_ok:
retn
make_timestamp:
invoke GetSystemTime,systime
movzx ecx,[systime.wYear]
mov eax,ecx
sub eax,1970
mov ebx,365
mul ebx
mov ebp,eax
mov eax,ecx
sub eax,1969
shr eax,2
add ebp,eax
mov eax,ecx
sub eax,1901
mov ebx,100
div ebx
sub ebp,eax
mov eax,ecx
xor edx,edx
sub eax,1601
mov ebx,400
div ebx
add ebp,eax
movzx ecx,[systime.wMonth]
mov eax,ecx
dec eax
mov ebx,30
mul ebx
add ebp,eax
cmp ecx,8
jbe months_correction
mov eax,ecx
sub eax,7
shr eax,1
add ebp,eax
mov ecx,8
months_correction:
mov eax,ecx
shr eax,1
add ebp,eax
cmp ecx,2
jbe day_correction_ok
sub ebp,2
movzx ecx,word [systime.wYear]
test ecx,11b
jnz day_correction_ok
xor edx,edx
mov eax,ecx
mov ebx,100
div ebx
or edx,edx
jnz day_correction
mov eax,ecx
mov ebx,400
div ebx
or edx,edx
jnz day_correction_ok
day_correction:
inc ebp
day_correction_ok:
movzx eax,[systime.wDay]
dec eax
add eax,ebp
mov ebx,24
mul ebx
movzx ecx,[systime.wHour]
add eax,ecx
mov ebx,60
mul ebx
movzx ecx,[systime.wMinute]
add eax,ecx
mov ebx,60
mul ebx
movzx ecx,[systime.wSecond]
add eax,ecx
retn
dump_symbols:
retn
include 'errors.inc'
include '..\preproce.inc'
include '..\parser.inc'
include '..\exprpars.inc'
include '..\exprcalc.inc'
include '..\assemble.inc'
include '..\formats.inc'
include '..\x86_64.inc'
include '..\avx.inc'
include '..\tables.inc'
include '..\version.inc'
null_byte db 0
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL'
include 'api\kernel32.inc'
section '.edata' export data readable
export 'FASM.DLL',\
fasm_GetVersion,'fasm_GetVersion',\
fasm_Assemble,'fasm_Assemble',\
fasm_AssembleFile,'fasm_AssembleFile'
section '.reloc' fixups data readable discardable
section '.rsrc' resource data readable
directory RT_VERSION,versions
resource versions,\
1,LANG_NEUTRAL,version
versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
'FileDescription','flat assembler',\
'LegalCopyright',<'Copyright ',0A9h,' 2001-2017 Tomasz Grysztar.'>,\
'FileVersion',VERSION_STRING,\
'ProductVersion',VERSION_STRING,\
'OriginalFilename','FASM.DLL'

View File

@@ -0,0 +1,195 @@
; flat editor DLL interface for Win32
; Copyright (c) 2001-2014, Tomasz Grysztar.
; All rights reserved.
format PE DLL GUI 4.0
entry DLLEntryPoint
include 'win32a.inc'
include 'fedit.ash'
section '.data' data readable writeable
_fedit_class db 'FEDIT',0
_user_library db 'USER32.DLL',0
_setgestureconfig_api db 'SetGestureConfig',0
_getgestureinfo_api db 'GetGestureInfo',0
_closegestureinfohandle_api db 'CloseGestureInfoHandle',0
align 4
SetGestureConfig dd 0
GetGestureInfo dd 0
CloseGestureInfoHandle dd 0
wheel_scroll_lines dd 3
fedit_font dd ?
char rb 4
kbstate rb 100h
line_colors rb 100h
line_buffer rb 100h
text_buffer rb 100h
upper_case_table rb 100h
wc WNDCLASS
ps PAINTSTRUCT
tm TEXTMETRIC
sc SCROLLINFO
rect RECT
section '.text' code readable executable
proc DLLEntryPoint uses ebx esi edi,hinstDLL,fdwReason,lpvReserved
cmp [fdwReason],DLL_PROCESS_ATTACH
jne .done
invoke GetModuleHandle,_user_library
or eax,eax
jz .gesture_api_unavailable
mov ebx,eax
invoke GetProcAddress,ebx,_setgestureconfig_api
or eax,eax
jz .gesture_api_unavailable
mov esi,eax
invoke GetProcAddress,ebx,_getgestureinfo_api
or eax,eax
jz .gesture_api_unavailable
mov edi,eax
invoke GetProcAddress,ebx,_closegestureinfohandle_api
or eax,eax
jz .gesture_api_unavailable
mov [CloseGestureInfoHandle],eax
mov [SetGestureConfig],esi
mov [GetGestureInfo],edi
.gesture_api_unavailable:
invoke LoadCursor,0,IDC_IBEAM
mov [wc.hCursor],eax
mov [wc.style],CS_GLOBALCLASS+CS_DBLCLKS
mov [wc.lpfnWndProc],FlatEditor
mov eax,[hinstDLL]
mov [wc.hInstance],eax
mov [wc.cbWndExtra],4
xor eax,eax
mov [wc.hbrBackground],eax
mov [wc.cbClsExtra],eax
mov [wc.lpszMenuName],eax
mov [wc.lpszClassName],_fedit_class
invoke RegisterClass,wc
or eax,eax
jz .failed
invoke CreateFont,0,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,NULL
or eax,eax
jz .failed
mov [fedit_font],eax
push ebx esi edi
mov edi,upper_case_table
xor ebx,ebx
mov esi,100h
.make_upper_case_table:
invoke CharUpper,ebx
stosb
inc bl
dec esi
jnz .make_upper_case_table
pop edi esi ebx
.done:
mov eax,TRUE
ret
.failed:
mov eax,FALSE
ret
endp
include 'fedit.inc'
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL',\
gdi,'GDI32.DLL'
import kernel,\
GetModuleHandle,'GetModuleHandleA',\
GetProcAddress,'GetProcAddress',\
GlobalAlloc,'GlobalAlloc',\
GlobalReAlloc,'GlobalReAlloc',\
GlobalLock,'GlobalLock',\
GlobalUnlock,'GlobalUnlock',\
GlobalFree,'GlobalFree',\
VirtualAlloc,'VirtualAlloc',\
VirtualFree,'VirtualFree',\
ExitProcess,'ExitProcess'
import user,\
RegisterClass,'RegisterClassA',\
CreateCaret,'CreateCaret',\
ShowCaret,'ShowCaret',\
HideCaret,'HideCaret',\
SetCaretPos,'SetCaretPos',\
DestroyCaret,'DestroyCaret',\
BeginPaint,'BeginPaint',\
EndPaint,'EndPaint',\
GetDC,'GetDC',\
GetUpdateRect,'GetUpdateRect',\
ReleaseDC,'ReleaseDC',\
GetCursorPos,'GetCursorPos',\
ClientToScreen,'ClientToScreen',\
TrackPopupMenu,'TrackPopupMenu',\
DrawText,'DrawTextA',\
FillRect,'FillRect',\
InvalidateRect,'InvalidateRect',\
GetKeyboardState,'GetKeyboardState',\
ToAscii,'ToAscii',\
GetScrollInfo,'GetScrollInfo',\
SetScrollInfo,'SetScrollInfo',\
SetCapture,'SetCapture',\
ReleaseCapture,'ReleaseCapture',\
OpenClipboard,'OpenClipboard',\
CloseClipboard,'CloseClipboard',\
EmptyClipboard,'EmptyClipboard',\
GetClipboardData,'GetClipboardData',\
SetClipboardData,'SetClipboardData',\
LoadCursor,'LoadCursorA',\
IsClipboardFormatAvailable,'IsClipboardFormatAvailable',\
CharUpper,'CharUpperA',\
GetWindowLong,'GetWindowLongA',\
SetWindowLong,'SetWindowLongA',\
DefWindowProc,'DefWindowProcA',\
GetClientRect,'GetClientRect',\
UpdateWindow,'UpdateWindow',\
SetFocus,'SetFocus',\
GetSysColor,'GetSysColor',\
MessageBox,'MessageBoxA',\
SendMessage,'SendMessageA',\
PostMessage,'PostMessageA'
import gdi,\
SetBkColor,'SetBkColor',\
SetTextColor,'SetTextColor',\
CreateSolidBrush,'CreateSolidBrush',\
CreateFont,'CreateFontA',\
GetTextMetrics,'GetTextMetricsA',\
GetTextExtentPoint32,'GetTextExtentPoint32A',\
DeleteDC,'DeleteDC',\
SelectObject,'SelectObject',\
DeleteObject,'DeleteObject'
section '.reloc' fixups data readable discardable
section '.rsrc' resource data readable
directory RT_VERSION,versions
resource versions,\
1,LANG_NEUTRAL,version
versioninfo version,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
'FileDescription','flat editor',\
'LegalCopyright',<'Copyright ',0A9h,' 1999-2014 Tomasz Grysztar.'>,\
'FileVersion',FEDIT_VERSION_STRING,\
'ProductVersion',FEDIT_VERSION_STRING,\
'OriginalFilename','FEDIT.DLL'

View File

@@ -1,3 +0,0 @@
# FASM4Delphi
Заголовки FASMDll для Delphi/Free Pascal.

192
Source/Fasm4Delphi.pas Normal file
View File

@@ -0,0 +1,192 @@
unit Fasm4Delphi platform;
{Delphi Translation&Tests:Artyom Gavrilov,Vlad Untkin.
From FASMDLL.TXT:
Short description of functions inside FASM.DLL
fasm_GetVersion()
Returns double word containg major version in lower 16 bits,
and minor version in the higher 16 bits.
fasm_Assemble(lpSource,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
Assembles the given source, using the provided memory block as a free
storage space (which is also to contain generated output).
The lpSource should contain a pointer to zero-ended source text.
The lpMemory should be a pointer to the memory block and cbMemorySize
should contain its size. In the beginning of this memory block the
FASM_STATE structure will reside (as defined in FASM.ASH). The assembler
doesn't allocate any memory beside this block, if it is not enough for
its purposes, the function returns with FASM_OUT_OF_MEMORY state.
The nPassesLimit should be a value in range from 1 to 65536, defining
the maximum number of passes the assembler can perform in order to
generate the code (the recommended value is 100). If the limit is reached,
the function returns with state FASM_CANNOT_GENERATE_CODE.
The hDisplayPipe should contain handle of the pipe, to which the output
of DISPLAY directives will be written. If this parameter is NULL, all
the display will get discarded.
If the assembly is successful, function returns FASM_OK value and fills
the output_data and output_length fields of the FASM_STATE structure
(which resides at the beginning of provided memory block) with pointer
to the generated output and count of bytes stored there.
If the assembly failed, function returns one of the other general
conditions as defined in FASM.ASH. If the condition returned is FASM_ERROR,
it means that an error caused by a specific place in source occured,
then the error_code and error_line fields of FASM_STATE are filled,
first one with detailed error code as defined in FASM.ASH, and the second
one with pointer to a structure containing data about line that caused
the error.
fasm_AssembleFile(lpSourceFile,lpMemory,cbMemorySize,nPassesLimit,hDisplayPipe)
This function performs identically to fasm_Assemble, except that it takes
the lpSourceFile parameter in place of lpSource, and it shall contain the
pointer to zero-ended path to file containing the source to assemble.
}
interface
uses
Windows;
//{$Define FasmStaticLink}
type
TFasmVersion=packed record
V1,V2:word;
end;
TLINE_HEADER=record
file_path:PAnsiChar;
line_number:cardinal;
file_offset:cardinal;
macro_calling_line:^TLINE_HEADER;
//macro_line:^TLINE_HEADER;
end;
PLINE_HEADER=^TLINE_HEADER;
TFASM_STATE=record
condition:Int32;
error_code:Int32;
error_line:PLINE_HEADER;
//output_data:pointer;
//output_length:cardinal;
end;
PFASM_STATE=^TFASM_STATE;
//{$EXTERNALSYM TFASM_STATE}
const
FASMDLLName='FASM.DLL';
// General errors and conditions
FASM_OK =0; //FASM_STATE points to output
FASM_WORKING =1;
FASM_ERROR =2; //FASM_STATE contains error code
FASM_INVALID_PARAMETER =-1;
FASM_OUT_OF_MEMORY =-2;
FASM_STACK_OVERFLOW =-3;
FASM_SOURCE_NOT_FOUND =-4;
FASM_UNEXPECTED_END_OF_SOURCE =-5;
FASM_CANNOT_GENERATE_CODE =-6;
FASM_FORMAT_LIMITATIONS_EXCEDDED =-7;
FASM_WRITE_FAILED =-8;
FASM_INVALID_DEFINITION =-9;
//Error codes for FASM_ERROR condition
FASMERR_FILE_NOT_FOUND =-101;
FASMERR_ERROR_READING_FILE =-102;
FASMERR_INVALID_FILE_FORMAT =-103;
FASMERR_INVALID_MACRO_ARGUMENTS =-104;
FASMERR_INCOMPLETE_MACRO =-105;
FASMERR_UNEXPECTED_CHARACTERS =-106;
FASMERR_INVALID_ARGUMENT =-107;
FASMERR_ILLEGAL_INSTRUCTION =-108;
FASMERR_INVALID_OPERAND =-109;
FASMERR_INVALID_OPERAND_SIZE =-110;
FASMERR_OPERAND_SIZE_NOT_SPECIFIED =-111;
FASMERR_OPERAND_SIZES_DO_NOT_MATCH =-112;
FASMERR_INVALID_ADDRESS_SIZE =-113;
FASMERR_ADDRESS_SIZES_DO_NOT_AGREE =-114;
FASMERR_DISALLOWED_COMBINATION_OF_REGISTERS =-115;
FASMERR_LONG_IMMEDIATE_NOT_ENCODABLE =-116;
FASMERR_RELATIVE_JUMP_OUT_OF_RANGE =-117;
FASMERR_INVALID_EXPRESSION =-118;
FASMERR_INVALID_ADDRESS =-119;
FASMERR_INVALID_VALUE =-120;
FASMERR_VALUE_OUT_OF_RANGE =-121;
FASMERR_UNDEFINED_SYMBOL =-122;
FASMERR_INVALID_USE_OF_SYMBOL =-123;
FASMERR_NAME_TOO_LONG =-124;
FASMERR_INVALID_NAME =-125;
FASMERR_RESERVED_WORD_USED_AS_SYMBOL =-126;
FASMERR_SYMBOL_ALREADY_DEFINED =-127;
FASMERR_MISSING_END_QUOTE =-128;
FASMERR_MISSING_END_DIRECTIVE =-129;
FASMERR_UNEXPECTED_INSTRUCTION =-130;
FASMERR_EXTRA_CHARACTERS_ON_LINE =-131;
FASMERR_SECTION_NOT_ALIGNED_ENOUGH =-132;
FASMERR_SETTING_ALREADY_SPECIFIED =-133;
FASMERR_DATA_ALREADY_DEFINED =-134;
FASMERR_TOO_MANY_REPEATS =-135;
FASMERR_SYMBOL_OUT_OF_SCOPE =-136;
FASMERR_USER_ERROR =-140;
FASMERR_ASSERTION_FAILED =-141;
{$IFDEF FasmStaticLink}
function fasm_GetVersion:TFasmVersion;stdcall;external FASMDLLName;
function fasm_Assemble(lpSource:PAnsiChar;lpMemory:pointer;cbMemorySize:cardinal;
nPassesLimit:word=100;hDisplayPipe:DWord=0):Int32;stdcall;external FASMDLLName;
function fasm_AssembleFile(lpSourceFile:PAnsiChar;lpMemory:pointer;cbMemorySize:cardinal;
nPassesLimit:word=100;hDisplayPipe:DWord=0):Int32;stdcall;external FASMDLLName;
{$ELSE}
var
fasm_GetVersion:function:TFasmVersion;stdcall;
fasm_Assemble:function(lpSource:PAnsiChar;lpMemory:pointer;cbMemorySize:cardinal;nPassesLimit:word=100;hDisplayPipe:DWord=0):Int32;stdcall;
fasm_AssembleFile:function(lpSourceFile:PAnsiChar;lpMemory:pointer;cbMemorySize:cardinal;nPassesLimit:word=100;hDisplayPipe:DWord=0):Int32;stdcall;
{$ENDIF}
{$IFNDEF FasmStaticLink}
procedure LoadFASM(Name:string);
procedure FreeFASM;
{$ENDIF}
implementation
{$IFNDEF FasmStaticLink}
var
&Library:THandle=0;
procedure LoadFASM(Name:string);
begin
if &Library<>0 then
FreeFasm;
&Library:=LoadLibrary(PWideChar(Name));
fasm_GetVersion:=GetProcAddress(&Library,'fasm_GetVersion');
fasm_Assemble:=GetProcAddress(&Library,'fasm_Assemble');
fasm_AssembleFile:=GetProcAddress(&Library,'fasm_AssembleFile');
end;
procedure FreeFASM;
begin
if &Library=0 then
exit;
fasm_GetVersion:=nil;
fasm_Assemble:=nil;
fasm_AssembleFile:=nil;
&Library:=0;
end;
{$ENDIF}
end.

2
Tests/Test1.asm Normal file
View File

@@ -0,0 +1,2 @@
a db 0
cmp [a],0

60
Tests/Tester.dpr Normal file
View File

@@ -0,0 +1,60 @@
program Tester;
{$IFNDEF TESTINSIGHT}
{$APPTYPE CONSOLE}
{$ENDIF}{$STRONGLINKTYPES ON}
uses
System.SysUtils,
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX,
{$ENDIF }
DUnitX.Loggers.Console,
DUnitX.Loggers.Xml.NUnit,
DUnitX.TestFramework,
TesterMain in 'TesterMain.pas',
Fasm4Delphi in '..\Source\Fasm4Delphi.pas';
var
runner : ITestRunner;
results : IRunResults;
logger : ITestLogger;
nunitLogger : ITestLogger;
begin
{$IFDEF TESTINSIGHT}
TestInsight.DUnitX.RunRegisteredTests;
exit;
{$ENDIF}
try
//Check command line options, will exit if invalid
TDUnitX.CheckCommandLine;
//Create the test runner
runner := TDUnitX.CreateRunner;
//Tell the runner to use RTTI to find Fixtures
runner.UseRTTI := True;
//tell the runner how we will log things
//Log to the console window
logger := TDUnitXConsoleLogger.Create(true);
runner.AddLogger(logger);
//Generate an NUnit compatible XML File
nunitLogger := TDUnitXXMLNUnitFileLogger.Create(TDUnitX.Options.XMLOutputFile);
runner.AddLogger(nunitLogger);
runner.FailsOnNoAsserts := False; //When true, Assertions must be made during tests;
//Run tests
results := runner.Execute;
if not results.AllPassed then
System.ExitCode := EXIT_ERRORS;
{$IFNDEF CI}
//We don't want this happening when running under CI.
if TDUnitX.Options.ExitBehavior = TDUnitXExitBehavior.Pause then
begin
System.Write('Done.. press <Enter> key to quit.');
System.Readln;
end;
{$ENDIF}
except
on E: Exception do
System.Writeln(E.ClassName, ': ', E.Message);
end;
end.

562
Tests/Tester.dproj Normal file
View File

@@ -0,0 +1,562 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{4DB29771-5426-49E7-B0D8-B77F95D4EDCE}</ProjectGuid>
<ProjectVersion>18.2</ProjectVersion>
<FrameworkType>None</FrameworkType>
<MainSource>Tester.dpr</MainSource>
<Base>True</Base>
<Config Condition="'$(Config)'==''">Debug</Config>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<TargetedPlatforms>1</TargetedPlatforms>
<AppType>Console</AppType>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Base' or '$(Base)'!=''">
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Android' and '$(Base)'=='true') or '$(Base_Android)'!=''">
<Base_Android>true</Base_Android>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='iOSDevice32' and '$(Base)'=='true') or '$(Base_iOSDevice32)'!=''">
<Base_iOSDevice32>true</Base_iOSDevice32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='iOSDevice64' and '$(Base)'=='true') or '$(Base_iOSDevice64)'!=''">
<Base_iOSDevice64>true</Base_iOSDevice64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='iOSSimulator' and '$(Base)'=='true') or '$(Base_iOSSimulator)'!=''">
<Base_iOSSimulator>true</Base_iOSSimulator>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Linux64' and '$(Base)'=='true') or '$(Base_Linux64)'!=''">
<Base_Linux64>true</Base_Linux64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='OSX32' and '$(Base)'=='true') or '$(Base_OSX32)'!=''">
<Base_OSX32>true</Base_OSX32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Base)'=='true') or '$(Base_Win32)'!=''">
<Base_Win32>true</Base_Win32>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win64' and '$(Base)'=='true') or '$(Base_Win64)'!=''">
<Base_Win64>true</Base_Win64>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Debug' or '$(Cfg_1)'!=''">
<Cfg_1>true</Cfg_1>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="('$(Platform)'=='Win32' and '$(Cfg_1)'=='true') or '$(Cfg_1_Win32)'!=''">
<Cfg_1_Win32>true</Cfg_1_Win32>
<CfgParent>Cfg_1</CfgParent>
<Cfg_1>true</Cfg_1>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Config)'=='Release' or '$(Cfg_2)'!=''">
<Cfg_2>true</Cfg_2>
<CfgParent>Base</CfgParent>
<Base>true</Base>
</PropertyGroup>
<PropertyGroup Condition="'$(Base)'!=''">
<DCC_DcuOutput>.\$(Platform)\$(Config)</DCC_DcuOutput>
<DCC_ExeOutput>.\$(Platform)\$(Config)</DCC_ExeOutput>
<DCC_E>false</DCC_E>
<DCC_N>false</DCC_N>
<DCC_S>false</DCC_S>
<DCC_F>false</DCC_F>
<DCC_K>false</DCC_K>
<DCC_UsePackage>RESTComponents;emsclientfiredac;FireDACIBDriver;emsclient;FireDACCommon;RESTBackendComponents;soapserver;CloudService;FireDACCommonDriver;inet;FireDAC;FireDACSqliteDriver;soaprtl;soapmidas;$(DCC_UsePackage)</DCC_UsePackage>
<DCC_Namespace>System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace)</DCC_Namespace>
<UsingDelphiRTL>true</UsingDelphiRTL>
<Icon_MainIcon>$(BDS)\bin\delphi_PROJECTICON.ico</Icon_MainIcon>
<Icns_MainIcns>$(BDS)\bin\delphi_PROJECTICNS.icns</Icns_MainIcns>
<DCC_UnitSearchPath>$(DUnitX);$(DCC_UnitSearchPath)</DCC_UnitSearchPath>
<SanitizedProjectName>Tester</SanitizedProjectName>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Android)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;DataSnapFireDAC;tethering;bindcompfmx;FmxTeeUI;fmx;FireDACDBXDriver;dbexpress;IndyCore;dsnap;DataSnapCommon;bindengine;DataSnapClient;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;ibmonitor;FMXTee;DbxCommonDriver;ibxpress;xmlrtl;DataSnapNativeClient;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;$(DCC_UsePackage)</DCC_UsePackage>
<EnabledSysJars>android-support-v4.dex.jar;cloud-messaging.dex.jar;fmx.dex.jar;google-analytics-v2.dex.jar;google-play-billing.dex.jar;google-play-licensing.dex.jar;google-play-services.dex.jar</EnabledSysJars>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_iOSDevice32)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;DataSnapFireDAC;tethering;bindcompfmx;FmxTeeUI;fmx;FireDACDBXDriver;dbexpress;IndyCore;dsnap;DataSnapCommon;bindengine;DataSnapClient;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;ibmonitor;FMXTee;DbxCommonDriver;ibxpress;xmlrtl;DataSnapNativeClient;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_iOSDevice64)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;DataSnapFireDAC;tethering;bindcompfmx;FmxTeeUI;fmx;FireDACDBXDriver;dbexpress;IndyCore;dsnap;DataSnapCommon;bindengine;DataSnapClient;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;ibmonitor;FMXTee;DbxCommonDriver;ibxpress;xmlrtl;DataSnapNativeClient;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_iOSSimulator)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DBXInterBaseDriver;DataSnapFireDAC;tethering;bindcompfmx;FmxTeeUI;fmx;FireDACDBXDriver;dbexpress;IndyCore;dsnap;DataSnapCommon;bindengine;DataSnapClient;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;ibmonitor;FMXTee;DbxCommonDriver;ibxpress;xmlrtl;DataSnapNativeClient;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;CustomIPTransport;bindcomp;IndyIPClient;dbxcds;dsnapxml;DataSnapProviderClient;dbrtl;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Linux64)'!=''">
<DCC_UsePackage>DataSnapServerMidas;FireDACADSDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;inetdb;emsedge;IndyCore;dsnap;DataSnapCommon;DataSnapConnectors;bindengine;FireDACOracleDriver;FireDACMySQLDriver;FireDACCommonODBC;DataSnapClient;IndySystem;FireDACDb2Driver;FireDACInfxDriver;emshosting;FireDACPgDriver;FireDACASADriver;FireDACTDataDriver;DbxCommonDriver;DataSnapServer;xmlrtl;DataSnapNativeClient;rtl;DbxClientDriver;CustomIPTransport;bindcomp;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;dbrtl;FireDACMongoDBDriver;IndyProtocols;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_OSX32)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DataSnapServerMidas;DBXInterBaseDriver;DataSnapFireDAC;tethering;FireDACMSSQLDriver;bindcompfmx;DBXOracleDriver;inetdb;FmxTeeUI;emsedge;fmx;fmxdae;FireDACDBXDriver;dbexpress;IndyCore;dsnap;DataSnapCommon;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;DataSnapClient;bindcompdbx;IndyIPCommon;IndyIPServer;IndySystem;fmxFireDAC;emshosting;FireDACPgDriver;ibmonitor;FireDACASADriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;ibxpress;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;bindcomp;DBXInformixDriver;IndyIPClient;dbxcds;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win32)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;DataSnapFireDAC;svnui;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;svn;Intraweb;DBXOracleDriver;inetdb;RaizeComponentsVcl;FmxTeeUI;emsedge;RaizeComponentsVclDb;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;DataSnapCommon;DataSnapConnectors;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;DataSnapClient;bindcompdbx;IndyIPCommon;vcl;DBXSybaseASEDriver;IndyIPServer;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;emshosting;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;vclwinx;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;CodeSiteExpressPkg;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)</DCC_Namespace>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
</PropertyGroup>
<PropertyGroup Condition="'$(Base_Win64)'!=''">
<DCC_UsePackage>DBXSqliteDriver;DataSnapServerMidas;DBXDb2Driver;DBXInterBaseDriver;vclactnband;vclFireDAC;DataSnapFireDAC;tethering;FireDACADSDriver;DBXMSSQLDriver;DatasnapConnectorsFreePascal;FireDACMSSQLDriver;vcltouch;vcldb;bindcompfmx;Intraweb;DBXOracleDriver;inetdb;RaizeComponentsVcl;FmxTeeUI;emsedge;RaizeComponentsVclDb;fmx;fmxdae;vclib;FireDACDBXDriver;dbexpress;IndyCore;vclx;dsnap;DataSnapCommon;DataSnapConnectors;VCLRESTComponents;vclie;bindengine;DBXMySQLDriver;FireDACOracleDriver;FireDACMySQLDriver;DBXFirebirdDriver;FireDACCommonODBC;DataSnapClient;bindcompdbx;IndyIPCommon;vcl;DBXSybaseASEDriver;IndyIPServer;IndySystem;FireDACDb2Driver;dsnapcon;FireDACMSAccDriver;fmxFireDAC;FireDACInfxDriver;vclimg;TeeDB;emshosting;FireDACPgDriver;ibmonitor;FireDACASADriver;DBXOdbcDriver;FireDACTDataDriver;FMXTee;DbxCommonDriver;ibxpress;Tee;DataSnapServer;xmlrtl;DataSnapNativeClient;fmxobj;vclwinx;ibxbindings;rtl;FireDACDSDriver;DbxClientDriver;DBXSybaseASADriver;CustomIPTransport;vcldsnap;bindcomp;appanalytics;DBXInformixDriver;IndyIPClient;bindcompvcl;TeeUI;dbxcds;VclSmp;adortl;FireDACODBCDriver;DataSnapIndy10ServerTransport;dsnapxml;DataSnapProviderClient;dbrtl;inetdbxpress;FireDACMongoDBDriver;IndyProtocols;fmxase;$(DCC_UsePackage)</DCC_UsePackage>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1)'!=''">
<DCC_Define>DEBUG;$(DCC_Define)</DCC_Define>
<DCC_DebugDCUs>true</DCC_DebugDCUs>
<DCC_Optimize>false</DCC_Optimize>
<DCC_GenerateStackFrames>true</DCC_GenerateStackFrames>
<DCC_DebugInfoInExe>true</DCC_DebugInfoInExe>
<DCC_RemoteDebug>true</DCC_RemoteDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_1_Win32)'!=''">
<DCC_RemoteDebug>false</DCC_RemoteDebug>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2)'!=''">
<DCC_LocalDebugSymbols>false</DCC_LocalDebugSymbols>
<DCC_Define>RELEASE;$(DCC_Define)</DCC_Define>
<DCC_SymbolReferenceInfo>0</DCC_SymbolReferenceInfo>
<DCC_DebugInformation>0</DCC_DebugInformation>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="TesterMain.pas"/>
<DCCReference Include="..\Source\Fasm4Delphi.pas"/>
<BuildConfiguration Include="Release">
<Key>Cfg_2</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
<BuildConfiguration Include="Debug">
<Key>Cfg_1</Key>
<CfgParent>Base</CfgParent>
</BuildConfiguration>
</ItemGroup>
<ProjectExtensions>
<Borland.Personality>Delphi.Personality.12</Borland.Personality>
<Borland.ProjectType>Console</Borland.ProjectType>
<BorlandProject>
<Delphi.Personality>
<Source>
<Source Name="MainSource">Tester.dpr</Source>
</Source>
</Delphi.Personality>
<Deployment Version="3">
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="OSX32">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libcgunwind.1.0.dylib" Class="DependencyModule">
<Platform Name="iOSSimulator">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\iossimulator\libPCRE.dylib" Class="DependencyModule">
<Platform Name="iOSSimulator">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="$(BDS)\Redist\osx32\libcgsqlite3.dylib" Class="DependencyModule">
<Platform Name="OSX32">
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployFile LocalName="Win32\Debug\Tester.exe" Configuration="Debug" Class="ProjectOutput">
<Platform Name="Win32">
<RemoteName>Tester.exe</RemoteName>
<Overwrite>true</Overwrite>
</Platform>
</DeployFile>
<DeployClass Name="AdditionalDebugSymbols">
<Platform Name="OSX32">
<Operation>1</Operation>
</Platform>
<Platform Name="Win32">
<RemoteDir>Contents\MacOS</RemoteDir>
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidClassesDexFile">
<Platform Name="Android">
<RemoteDir>classes</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidGDBServer">
<Platform Name="Android">
<RemoteDir>library\lib\armeabi-v7a</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidLibnativeArmeabiFile">
<Platform Name="Android">
<RemoteDir>library\lib\armeabi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidLibnativeMipsFile">
<Platform Name="Android">
<RemoteDir>library\lib\mips</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidServiceOutput">
<Platform Name="Android">
<RemoteDir>library\lib\armeabi-v7a</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashImageDef">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="AndroidSplashStyles">
<Platform Name="Android">
<RemoteDir>res\values</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_DefaultAppIcon">
<Platform Name="Android">
<RemoteDir>res\drawable</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon144">
<Platform Name="Android">
<RemoteDir>res\drawable-xxhdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon36">
<Platform Name="Android">
<RemoteDir>res\drawable-ldpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon48">
<Platform Name="Android">
<RemoteDir>res\drawable-mdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon72">
<Platform Name="Android">
<RemoteDir>res\drawable-hdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_LauncherIcon96">
<Platform Name="Android">
<RemoteDir>res\drawable-xhdpi</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_SplashImage426">
<Platform Name="Android">
<RemoteDir>res\drawable-small</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_SplashImage470">
<Platform Name="Android">
<RemoteDir>res\drawable-normal</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_SplashImage640">
<Platform Name="Android">
<RemoteDir>res\drawable-large</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="Android_SplashImage960">
<Platform Name="Android">
<RemoteDir>res\drawable-xlarge</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DebugSymbols">
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
<Platform Name="OSX32">
<Operation>1</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DependencyFramework">
<Platform Name="OSX32">
<Operation>1</Operation>
<Extensions>.framework</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="DependencyModule">
<Platform Name="OSX32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.dll;.bpl</Extensions>
</Platform>
</DeployClass>
<DeployClass Required="true" Name="DependencyPackage">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="OSX32">
<Operation>1</Operation>
<Extensions>.dylib</Extensions>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
<Extensions>.bpl</Extensions>
</Platform>
</DeployClass>
<DeployClass Name="File">
<Platform Name="Android">
<Operation>0</Operation>
</Platform>
<Platform Name="iOSDevice32">
<Operation>0</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>0</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>0</Operation>
</Platform>
<Platform Name="OSX32">
<Operation>0</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPad_Launch1024">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPad_Launch1536">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPad_Launch2048">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPad_Launch768">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPhone_Launch320">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPhone_Launch640">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="iPhone_Launch640x1136">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectAndroidManifest">
<Platform Name="Android">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectiOSDeviceDebug">
<Platform Name="iOSDevice32">
<RemoteDir>..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<RemoteDir>..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectiOSDeviceResourceRules"/>
<DeployClass Name="ProjectiOSEntitlements"/>
<DeployClass Name="ProjectiOSInfoPList"/>
<DeployClass Name="ProjectiOSResource">
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectOSXEntitlements"/>
<DeployClass Name="ProjectOSXInfoPList"/>
<DeployClass Name="ProjectOSXResource">
<Platform Name="OSX32">
<RemoteDir>Contents\Resources</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Required="true" Name="ProjectOutput">
<Platform Name="Android">
<RemoteDir>library\lib\armeabi-v7a</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice32">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSDevice64">
<Operation>1</Operation>
</Platform>
<Platform Name="iOSSimulator">
<Operation>1</Operation>
</Platform>
<Platform Name="Linux64">
<Operation>1</Operation>
</Platform>
<Platform Name="OSX32">
<Operation>1</Operation>
</Platform>
<Platform Name="Win32">
<Operation>0</Operation>
</Platform>
</DeployClass>
<DeployClass Name="ProjectUWPManifest">
<Platform Name="Win32">
<Operation>1</Operation>
</Platform>
<Platform Name="Win64">
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="UWP_DelphiLogo150">
<Platform Name="Win32">
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Win64">
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<DeployClass Name="UWP_DelphiLogo44">
<Platform Name="Win32">
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
<Platform Name="Win64">
<RemoteDir>Assets</RemoteDir>
<Operation>1</Operation>
</Platform>
</DeployClass>
<ProjectRoot Platform="iOSDevice64" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Win64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSDevice32" Name="$(PROJECTNAME).app"/>
<ProjectRoot Platform="Linux64" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Win32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="OSX32" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="Android" Name="$(PROJECTNAME)"/>
<ProjectRoot Platform="iOSSimulator" Name="$(PROJECTNAME).app"/>
</Deployment>
<Platforms>
<Platform value="Android">False</Platform>
<Platform value="iOSDevice32">False</Platform>
<Platform value="iOSDevice64">False</Platform>
<Platform value="iOSSimulator">False</Platform>
<Platform value="Linux64">False</Platform>
<Platform value="OSX32">False</Platform>
<Platform value="Win32">True</Platform>
<Platform value="Win64">False</Platform>
</Platforms>
</BorlandProject>
<ProjectFileVersion>12</ProjectFileVersion>
</ProjectExtensions>
<Import Project="$(BDS)\Bin\CodeGear.Delphi.Targets" Condition="Exists('$(BDS)\Bin\CodeGear.Delphi.Targets')"/>
<Import Project="$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj" Condition="Exists('$(APPDATA)\Embarcadero\$(BDSAPPDATABASEDIR)\$(PRODUCTVERSION)\UserTools.proj')"/>
<Import Project="$(MSBuildProjectName).deployproj" Condition="Exists('$(MSBuildProjectName).deployproj')"/>
</Project>

BIN
Tests/Tester.res Normal file

Binary file not shown.

73
Tests/TesterMain.pas Normal file
View File

@@ -0,0 +1,73 @@
unit TesterMain;
interface
uses
DUnitX.TestFramework,Fasm4Delphi,SysUtils;
type
[TestFixture]
TMyTestObject = class(TObject)
public
[Setup]
procedure Setup;
[TearDown]
procedure TearDown;
[Test]
procedure Test1;
[Test]
procedure Test2;
[Test]
procedure Test3;
[Test]
procedure Test4;
end;
const
CompliterMemSize=$10000;
var
CompliterMem:PFASM_STATE;
implementation
procedure TMyTestObject.Setup;
begin
end;
procedure TMyTestObject.TearDown;
begin
end;
procedure TMyTestObject.Test1;
begin
if fasm_AssembleFile('..\..\Test1.ASM',CompliterMem,CompliterMemSize)<>FASM_OK then
raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+
'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak);
end;
procedure TMyTestObject.Test2;
begin
if fasm_Assemble('add eax,0',CompliterMem,CompliterMemSize)<>FASM_OK then
raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+
'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak);
end;
procedure TMyTestObject.Test3;
begin
if fasm_AssembleFile('..\..\..\FasmDll\FASM.ASH',CompliterMem,CompliterMemSize)=FASM_OK then
raise Exception.Create('FASM is compiling something that it is can not compile at all.');
end;
procedure TMyTestObject.Test4;
begin
if fasm_Assemble('call -100',CompliterMem,CompliterMemSize)<>FASM_OK then
raise Exception.Create('Condition: '+CompliterMem^.condition.ToString+sLineBreak+
'Error Code: '+CompliterMem^.error_code.ToString+sLineBreak);
end;
initialization
TDUnitX.RegisterTestFixture(TMyTestObject);
LoadFASM('..\..\..\FasmDll\FASM.DLL');
GetMem(CompliterMem,CompliterMemSize);
end.

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<test-results name="W:\Fasm4Delphi\Tests\Win32\Debug\Tester.exe" total="4" errors="0" failures="0" ignored="0" inconclusive="0" not-run="0" skipped="0" invalid="0" date="2018-02-11" time="0.001">
<culture-info current-culture="en" current-uiculture="en" />
<test-suite type="Assembly" name="Tester.exe" executed="true" result="Success" success="True" time="0.001" asserts="0">
<results>
<test-suite type="Namespace" name="TesterMain" executed="true" result="Success" success="True" time="0.001" asserts="0" >
<results>
<test-suite type="Fixture" name="TMyTestObject" executed="True" result="Success" success="True" time="0.001" >
<results>
<test-case name="Test1" executed="True" result="Success" success="True" time="0.000" asserts="0" />
<test-case name="Test2" executed="True" result="Success" success="True" time="0.000" asserts="0" />
<test-case name="Test3" executed="True" result="Success" success="True" time="0.000" asserts="0" />
<test-case name="Test4" executed="True" result="Success" success="True" time="0.000" asserts="0" />
</results>
</test-suite>
</results>
</test-suite>
</results>
</test-suite>
</test-results>