I read a bit about RTL in the gcc info files. Would the correct
approach be to output this and pass it to gcc?
I also noticed gcc's syntactical tree is fairly similar to the tree my
parser builds when reading the input file, could this be of use?
Further, I was planning on applying constant collapsing,
tail-rescursion detection, and if/lambda optimization to the tree
myself, but if gcc automatically applies these algorithms to its tree
structure I would be very interested in using the existing routines.
Or is the optimization applied at the RTL stage so that I could output
unoptimized RTL to gcc and have it optimize?
Anyways, is this binding at all possible or should I simply make my
own intermediate stage and write a machine specific assembly
converter. (blah)
Thanks for your time.
--
Wesley Tersptra - UBC - Science One
210 Cariboo House, Place Vanier
221-9358, terp...@unixg.ubc.ca
> I have been working on a compiler for Omicron (a relatively new
> programming language) and have completed a working parser. When
> deciding what my target language should be I remembered that gcc has a
> mechanism for describing the assembly output for various machines and
> optimizing the result assembly for that target machine. Is it possible
> to make use of this with another compiler? Or is it possible to bind
> my Omicron parser into the gcc control program itself such that gcc
> could compile Omicron code with an additional command-line parameter
> or language specification?
You can make your Omicron compiler part of gcc, but this is not too
well documented (yet). There is a document in german (i've lost the
URL that was posted a few weeks ago), and I've seen a _Very_
simplistic toy language setup in english (but there, again, I've lost
the URL).
> I read a bit about RTL in the gcc info files. Would the correct
> approach be to output this and pass it to gcc?
No; the RTL code is (a bit) target-specific. (A warning against this
approach is on page 199(?) of the GCC 2.8.1 manual, I think.)
> I also noticed gcc's syntactical tree is fairly similar to the tree my
> parser builds when reading the input file, could this be of use?
Indeed, this is the way you are supposed to proceed. You generate
tree code for your expressions and call various gcc functions to
produce RTL code.
Basically, to produce a new language front-end, you make a new
subdirectory (called omicron, i guess) in the GCC source directory.
This is where you place your parser (parse.y or whatever). You also
need to make a Makefile.in and a Make-lang.in; copy these from
i.e. the cp/ subdirectory and modify as needed.
Your parser could produce tree-code directly, or it could produce some
intermediate format of your choice and have it translated into
tree-code; I guess I'd prefer the forst option.
You'll find the tree-code documented in its source files: tree.h,
tree.def and tree.c; c-parse.y[1] and friends may show you ways for a
parser to generate tree-code.
[...]
> Anyways, is this binding at all possible or should I simply make my
> own intermediate stage and write a machine specific assembly
> converter. (blah)
It should be quite feasible, assuming you don't mind reading quite
some source code. I'm not sure if it'll take any less programming
effort *initially*, i.e. for producing a working compiler for one (or
a few) target(s), but you'll get an optimising compiler producing code
for a very wide variety of targets, with essential parts debugged and
maintained by very competent people.
Please note that if you ever release your compiler using this
approach, you will have to apply the GNU General Public Licence to
it.
[1] yes, I know it's autogenerated, but i find it more readable than
c-parse.in.
--
Arvid
I have a copy at <http://www.cs.mu.oz.au/~fjh/gcc/example-front-end.shar>.
--
Fergus Henderson <f...@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger f...@128.250.37.3 | -- the last words of T. S. Garp.
> * Wesley Waylon Terpstra
>
> > I have been working on a compiler for Omicron (a relatively new
> > programming language) and have completed a working parser. When
> > deciding what my target language should be I remembered that gcc has a
> > mechanism for describing the assembly output for various machines and
> > optimizing the result assembly for that target machine. Is it possible
> > to make use of this with another compiler? Or is it possible to bind
> > my Omicron parser into the gcc control program itself such that gcc
> > could compile Omicron code with an additional command-line parameter
> > or language specification?
>
> You can make your Omicron compiler part of gcc, but this is not too
> well documented (yet). There is a document in german (i've lost the
> URL that was posted a few weeks ago), and I've seen a _Very_
> simplistic toy language setup in english (but there, again, I've lost
> the URL).
I still have a link to the german document. A notice about this document
was posted sometime in Mars this year. The URL is:
I hope you read german or at least know someone who does. It's really
helpful if you want to use gcc as a backend!
http://www.pu.informatik.tu-darmstadt.de/docs/gccpue/
:-) Espen
--
*********** Espen Jorde ****************************************************
URL: Telefon: UNIK: Hjemme: P-søk:
http://www.unik.no/~espenjo 6484 4772 2218 8538 9672 3659