Re: Is Assembler Language essential in compiler construction?

"Bartc" <bartc@freeuk.com>
Wed, 11 Feb 2009 12:07:20 GMT

          From comp.compilers

Related articles
Is Assembler Language essential in compiler construction? marco.m.petersen@gmail.com (2009-02-09)
Re: Is Assembler Language essential in compiler construction? mburrel@uwo.ca (Mike Burrell) (2009-02-10)
Re: Is Assembler Language essential in compiler construction? rpboland@gmail.com (Ralph Boland) (2009-02-10)
Re: Is Assembler Language essential in compiler construction? bartc@freeuk.com (Bartc) (2009-02-11)
Re: Is Assembler Language essential in compiler construction? tim.d.richards@gmail.com (Tim) (2009-02-11)
Re: Is Assembler Language essential in compiler construction? walter@bytecraft.com (Walter Banks) (2009-02-11)
Re: Is Assembler Language essential in compiler construction? haberg_20080406@math.su.se (Hans Aberg) (2009-02-11)
Re: Is Assembler Language essential in compiler construction? torbenm@pc-003.diku.dk (2009-02-11)
Re: Is Assembler Language essential in compiler construction? anton@mips.complang.tuwien.ac.at (2009-02-11)
Re: Is Assembler Language essential in compiler construction? anton@mips.complang.tuwien.ac.at (2009-02-11)
[16 later articles]
| List of all articles for this month |
From: "Bartc" <bartc@freeuk.com>
Newsgroups: comp.compilers
Date: Wed, 11 Feb 2009 12:07:20 GMT
Organization: Compilers Central
References: 09-02-021 09-02-025
Keywords: assembler, practice
Posted-Date: 11 Feb 2009 10:03:03 EST

"Mike Burrell" <mburrel@uwo.ca> wrote in message
> On 2009-02-09 05:34:36 -0500, marco.m.petersen@gmail.com said:
>
>> I mean, if you wrote a program that converts code from BASIC to C++
>> then calls another compiler to do the compilation process, wouldn't
>> that be considered as a compiler?
>
> It depends on what you want to get out of your compiler. A lot of
> compilers, especially when they're in the proof-of-concept stage, will
> target another language, such as C. If your primary goal in writing
> the compiler isn't to worry about the back-end stuff (register
> allocation and all those fun things), then it's easier to just target
> C, and you get portability to boot.


I've tried targetting C and it was completely unsatisfactory.


First, there are a number of extra hoops to jump through in order to
generate C source code (syntax, formatting, creating suitable names
when your language uses namespaces perhaps).


Then, to implement certain features of your language might involve
using casting and other tricks in the generated C when it's datatypes,
and using a lot of gotos and labels when it's syntax.


Then you make the discovery that you can use casting and gotos for
nearly *all* your language constructs, meaning most features of C are
not needed: typedefs, control statements, even types: char arrays will
do nicely; in fact probably a single char array at each scope level
would work, so not even variables are needed!. Functions are still
needed, but only just.


So you end up with a target language which is a travesty of C, and
while it might be portable, won't compile to great code because the
structure the C compiler depends on is missing. (And there's the
headache of converting errors/line numbers in C source back to your
original code.)


Generating ASM source code, while it still has a few of the same
problems, is much more satisfactory.


I would suggest anyway creating some intermediate language (ASM-like,
with a linear structure and with a limited complexity per line), then
you have still have the choice of generating some stylised C from
this, or source ASM for an actual machine, or perhaps even
binary. (There are some existing ILs but sometimes it's nice to keep
100% control of your project.)
--
Bartc


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.