[fpc-devel] Adding a new assembler to Free Pascal Compiler
Skybuck Flying
skybuck2000 at hotmail.com
Tue Apr 5 02:09:30 CEST 2011
Hello,
I would like to experiment with the pascal programming language at the
binary/assembler/machine level.
For example compile pascal sources to virtual machine instruction sets.
I took a look at the free pascal sources and there seem to be some
assemblers inside the folders.
I see classes with names like TExternalAssember and TInternalAssember
I also see files called: aasmcpu, aasmtai.
Some processor architectures seem to derive from TExternalAssembler but then
still implement lot's of stuff themselfes inside the class instead of
calling a real external assembler (perhaps a trick ? ;))
This is confusing me a little bit so I have some question about what free
pascal exaclty is, how it functions and what it does and can do or cannot
do:
So some questions:
1. Are all assemblers compiled into the final free pascal executable ? Or is
only one assembler possible which is selected by conditional defines ?
Suppose the answer to question 1 is: yes, multiple assemblers are supported.
(This seems to be the case since free pascal has the -a and -A directive
with different asm output options... (?!?))
Then my next question is 2:
2. This would mean free pascal is by default a cross compiler, which can
cross-compile to any assembly/intermediate code.
So then my main/subject question: How to add a new assember to free pascal
compiler makes sense...
Assuming it makes sense I continue my story:
I searched the documentation about how to do this... but there seems to be
no documentation for this ?
So if somebody could create some (short?) documentation for this or some
tips how/where to start and how to proceed that would be helpfull.
Perhaps a simple dummy assembler or template might be nice... concerning
this adding for a new assembler my main question would be where to add this
unit, how to make free pascal notice it and use it and such ? Where to add
the compiler directive and perhaps initialization and finalization of
classes/create/destroy that sort of thing.
3. Assuming free pascal is a cross compiler, and looking at the code... it
seems free pascal actually compiles pascal code into an abstract assembler
structure, is this indeed correct ? Can free pascal be considered a "pascal
to abstract assembler compiler ?" (which would be pretty cool) (which
ultimately gets assembled into real assembler...)
So in short what I am looking for is a pascal compiler which takes care of
all the work like "lexing/tokenizing/parsing/parse tree/syntax tree/symantec
checks/perhaps even optimizing the intermediate code" and gives me something
to work with like a syntax tree or some form of abstract assembler
(structures) like free pascal seems to do...
To me it seems free pascal could be the correct choice... either by
modifieing it or by extending it... So if I have to modify it... I would for
example modify the intel or powerpc or sparc source code and pretend it's my
own thing... but it would probably be better if I can stuff my own
assembler/platform/units into it to start from scratch just to play nice
with free pascal and prevent confusing things later on...
So I think I need to some help with: is this possible and how to do
it/documentation/short tutorial/some tips ?!?
Bye,
Skybuck.
More information about the fpc-devel
mailing list