Re: Front End for a C compiler

"Chris Fraser" <cwfraser@microsoft.com>
1 Apr 2000 14:19:57 -0500

          From comp.compilers

Related articles
Front End for a C compiler Rohit.Bodas@motorola.com (Rohit Bodas) (2000-03-23)
Re: Front End for a C compiler leupers@ls12sr.cs.uni-dortmund.de (Rainer Leupers) (2000-03-23)
Re: Front End for a C compiler thp@roam-thp2.cs.ucr.edu (Tom Payne) (2000-03-23)
Re: Front End for a C compiler cwfraser@microsoft.com (Chris Fraser) (2000-04-01)
| List of all articles for this month |
From: "Chris Fraser" <cwfraser@microsoft.com>
Newsgroups: comp.compilers
Date: 1 Apr 2000 14:19:57 -0500
Organization: Microsoft Corp.
References: 00-03-099
Keywords: C, lcc, parse

"Rohit Bodas" <Rohit.Bodas@motorola.com> wrote in message news:00-03-099@com
p.compilers...
> Can anyone tell me where I can get a front end for a C compiler
> giving out 3 address intermediate code.
> [You might be able to get lcc to do what you want. -John]


lcc is a good match IF its intermediate represention (see Chapter 5 of
the l cc book) suits your application without complex changes. I
started writing text to explain how I 'd do the job, but it proved
faster to simply do the job, so if you think that the lcc IR is right
for you:


1. Install lcc 4.1 from http://www.cs.princeton.edu/software/lcc/
2. Replace the routine dumptree(p) in bytecode.c with the text below.
3. Compile src/*.c
4. Run the resulting binary with the command-line argument "-target=bytecode
" and with
preprocessed C on stdin.


Good luck...Chris


---CUT HERE---
static int dumptree(Node p) {
                int n = genlabel(1);
                switch (specific(p->op)) { /* special cases */
                case ASGN+B:
                                print("%s %d, T%d, T%d\n", opname(p->op), p->syms[0]->u.c.v.
u, dumptree(p->kids[0]), dumptree(p->kids[1]));
                                return -1;
                case RET+V:
                                print("%s\n", opname(p->op));
                                return -1;
                }
                switch (generic(p->op)) { /* everything else */
                case LABEL:
                                print("L%s:\n", p->syms[0]->x.name);
                                return -1;
                case ADDRG: case ADDRF: case ADDRL: case CNST:
                                print("T%d = %s(%s)\n", n, opname(p->op), p->syms[0]->x.name
);
                                return n;
                case ARG: case JUMP: case RET:
                                print("T%d = %s(T%d)\n", n, opname(p->op), dumptree(p->kids[
0]));
                                return -1;
                case BCOM: case CALL: case CVF: case CVI: case CVP: case CVU: case N
EG: case INDIR:
                                print("T%d = %s(T%d)\n", n, opname(p->op), dumptree(p->kids[
0]));
                                return n;
                case ASGN: case BOR: case BAND: case BXOR: case RSH: case LSH:
                case ADD: case SUB: case DIV: case MUL: case MOD:
                                print("T%d = %s(T%d, T%d)\n", n, opname(p->op), dumptree(p->
kids[0]), dumptree(p->kids[1]));
                                return n;
                case EQ: case NE: case GT: case GE: case LE: case LT:
                                print("%s(T%d, T%d, %s)\n", opname(p->op), dumptree(p->kids[
0]), dumptree(p->kids[1]), p->syms[0]->x.name);
                                return -1;
                }
                return -1; /* stifle warnings about missing return value */
}
---CUT HERE---


Post a followup to this message

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