* Install the tools on every build, so a distclean isn't necessary if the tool

source changes now
* Basically rewrote the lcc Makefile to be more sane
* Removed various bits of lcc that weren't built/needed
This commit is contained in:
Tim Angus 2005-11-06 16:50:58 +00:00
parent 590988222f
commit f20cca46e8
14 changed files with 112 additions and 2530 deletions

View file

@ -1,4 +0,0 @@
#!/bin/sh
export BUILDDIR=.\\out
mkdir out
nmake -f makefile.nt all

View file

@ -1,475 +0,0 @@
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* bprint [ -c | -Idir... | -f | -b | -n ] [ file... ]
* annotate listings of files with prof.out data
*/
#define NDIRS (sizeof dirs/sizeof dirs[0] - 1)
#define NEW(p,a) ((p) = alloc(sizeof *(p)))
#define newarray(m,n,a) alloc((m)*(n))
#define NELEMS(a) ((int)(sizeof (a)/sizeof ((a)[0])))
#define MAXTOKEN 64
struct count { /* count data: */
int x, y; /* source coordinate */
int count; /* associated execution count */
};
char *progname;
int number;
char *dirs[20];
int fcount;
struct file { /* per-file prof.out data: */
struct file *link; /* link to next file */
char *name; /* file name */
int size; /* size of counts[] */
int count; /* counts[0..count-1] hold valid data */
struct count *counts; /* count data */
struct func { /* function data: */
struct func *link; /* link to next function */
char *name; /* function name */
struct count count; /* total number of calls */
struct caller { /* caller data: */
struct caller *link; /* link to next caller */
char *name; /* caller's name */
char *file; /* call site: file, x, y */
int x, y;
int count; /* number of calls from this site */
} *callers;
} *funcs; /* list of functions */
} *filelist;
FILE *fp;
extern int process(char *);
extern int findfunc(char *, char *);
extern int findcount(char *, int, int);
void *alloc(unsigned);
char *string(char *);
int process(char *);
void emitdata(char *);
void printfile(struct file *, int);
void printfuncs(struct file *, int);
/* alloc - allocate n bytes or die */
void *alloc(unsigned n) {
void *new = malloc(n);
assert(new);
return new;
}
/* emitdata - write prof.out data to file */
void emitdata(char *file) {
FILE *fp;
if ((fp = fopen(file, "w"))) {
struct file *p;
for (p = filelist; p; p = p->link) {
int i;
struct func *q;
struct caller *r;
fprintf(fp, "1\n%s\n", p->name);
for (i = 0, q = p->funcs; q; i++, q = q->link)
if ((r = q->callers))
for (i--; r; r = r->link)
i++;
fprintf(fp, "%d\n", i);
for (q = p->funcs; q; q = q->link)
if (q->count.count == 0 || !q->callers)
fprintf(fp, "%s 1 %d %d %d ? ? 0 0\n", q->name, q->count.x,
q->count.y, q->count.count);
else
for (r = q->callers; r; r = r->link)
fprintf(fp, "%s 1 %d %d %d %s %s %d %d\n", q->name, q->count.x,
q->count.y, r->count, r->name, r->file, r->x, r->y);
fprintf(fp, "%d\n", p->count);
for (i = 0; i < p->count; i++)
fprintf(fp, "1 %d %d %d\n", p->counts[i].x,
p->counts[i].y, p->counts[i].count);
}
fclose(fp);
} else
fprintf(stderr, "%s: can't create `%s'\n", progname, file);
}
/* openfile - open name for reading, searching -I directories */
FILE *openfile(char *name) {
int i;
FILE *fp;
if (*name != '/')
for (i = 0; dirs[i]; i++) {
char buf[200];
sprintf(buf, "%s/%s", dirs[i], name);
if ((fp = fopen(buf, "r")))
return fp;
}
return fopen(name, "r");
}
/* printfile - print annotated listing for p */
void printfile(struct file *p, int nf) {
int lineno;
FILE *fp;
char *s, buf[512];
struct count *u = p->counts, *r, *uend;
if (u == 0 || p->count <= 0)
return;
uend = &p->counts[p->count];
if ((fp = openfile(p->name)) == NULL) {
fprintf(stderr, "%s: can't open `%s'\n", progname, p->name);
return;
}
if (nf)
printf("%s%s:\n\n", nf == 1 ? "" : "\f", p->name);
for (lineno = 1; fgets(buf, sizeof buf, fp); lineno++) {
if (number)
printf("%d\t", lineno);
while (u < uend && u->y < lineno)
u++;
for (s = buf; *s; ) {
char *t = s + 1;
while (u < uend && u->y == lineno && u->x < s - buf)
u++;
if (isalnum(*s) || *s == '_')
while (isalnum(*t) || *t == '_')
t++;
while (u < uend && u->y == lineno && u->x < t - buf) {
printf("<%d>", u->count);
for (r = u++; u < uend && u->x == r->x && u->y == r->y && u->count == r->count; u++)
;
}
while (s < t)
putchar(*s++);
}
if (*s)
printf("%s", s);
}
fclose(fp);
}
/* printfuncs - summarize data for functions in p */
void printfuncs(struct file *p, int nf) {
struct func *q;
if (nf)
printf("%s:\n", p->name);
for (q = p->funcs; q; q = q->link)
if (fcount <= 1 || q->count.count == 0 || !q->callers)
printf("%d\t%s\n", q->count.count, q->name);
else {
struct caller *r;
for (r = q->callers; r; r = r->link)
printf("%d\t%s\tfrom %s\tin %s:%d.%d\n", r->count, q->name, r->name,
r->file, r->y, r->x + 1);
}
}
/* string - save a copy of str, if necessary */
char *string(char *str) {
static struct string { struct string *link; char str[1]; } *list;
struct string *p;
for (p = list; p; p = p->link)
if (strcmp(p->str, str) == 0)
return p->str;
p = (struct string *)alloc(strlen(str) + sizeof *p);
strcpy(p->str, str);
p->link = list;
list = p;
return p->str;
}
/* acaller - add caller and site (file,x,y) to callee's callers list */
static void acaller(char *caller, char *file, int x, int y, int count, struct func *callee) {
struct caller *q;
assert(callee);
for (q = callee->callers; q && (caller != q->name
|| file != q->file || x != q->x || y != q->y); q = q->link)
;
if (!q) {
struct caller **r;
NEW(q, PERM);
q->name = caller;
q->file = file;
q->x = x;
q->y = y;
q->count = 0;
for (r = &callee->callers; *r && (strcmp(q->name, (*r)->name) > 0
|| strcmp(q->file, (*r)->file) > 0 || q->y > (*r)->y || q->y > (*r)->y); r = &(*r)->link)
;
q->link = *r;
*r = q;
}
q->count += count;
}
/* compare - return <0, 0, >0 if a<b, a==b, a>b, resp. */
static int compare(struct count *a, struct count *b) {
if (a->y == b->y)
return a->x - b->x;
return a->y - b->y;
}
/* findfile - return file name's file list entry, or 0 */
static struct file *findfile(char *name) {
struct file *p;
for (p = filelist; p; p = p->link)
if (p->name == name)
return p;
return 0;
}
/* afunction - add function name and its data to file's function list */
static struct func *afunction(char *name, char *file, int x, int y, int count) {
struct file *p = findfile(file);
struct func *q;
assert(p);
for (q = p->funcs; q && name != q->name; q = q->link)
;
if (!q) {
struct func **r;
NEW(q, PERM);
q->name = name;
q->count.x = x;
q->count.y = y;
q->count.count = 0;
q->callers = 0;
for (r = &p->funcs; *r && compare(&q->count, &(*r)->count) > 0; r = &(*r)->link)
;
q->link = *r;
*r = q;
}
q->count.count += count;
return q;
}
/* apoint - append execution point i to file's data */
static void apoint(int i, char *file, int x, int y, int count) {
struct file *p = findfile(file);
assert(p);
if (i >= p->size) {
int j;
if (p->size == 0) {
p->size = i >= 200 ? 2*i : 200;
p->counts = newarray(p->size, sizeof *p->counts, PERM);
} else {
struct count *new;
p->size = 2*i;
new = newarray(p->size, sizeof *new, PERM);
for (j = 0; j < p->count; j++)
new[j] = p->counts[j];
p->counts = new;
}
for (j = p->count; j < p->size; j++) {
static struct count z;
p->counts[j] = z;
}
}
p->counts[i].x = x;
p->counts[i].y = y;
p->counts[i].count += count;
if (i >= p->count)
p->count = i + 1;
}
/* findcount - return count associated with (file,x,y) or -1 */
int findcount(char *file, int x, int y) {
static struct file *cursor;
if (cursor == 0 || cursor->name != file)
cursor = findfile(file);
if (cursor) {
int l, u;
struct count *c = cursor->counts;
for (l = 0, u = cursor->count - 1; l <= u; ) {
int k = (l + u)/2;
if (c[k].y > y || (c[k].y == y && c[k].x > x))
u = k - 1;
else if (c[k].y < y || (c[k].y == y && c[k].x < x))
l = k + 1;
else
return c[k].count;
}
}
return -1;
}
/* findfunc - return count associated with function name in file or -1 */
int findfunc(char *name, char *file) {
static struct file *cursor;
if (cursor == 0 || cursor->name != file)
cursor = findfile(file);
if (cursor) {
struct func *p;
for (p = cursor->funcs; p; p = p->link)
if (p->name == name)
return p->count.count;
}
return -1;
}
/* getd - read a nonnegative number */
static int getd(void) {
int c, n = 0;
while ((c = getc(fp)) != EOF && (c == ' ' || c == '\n' || c == '\t'))
;
if (c >= '0' && c <= '9') {
do
n = 10*n + (c - '0');
while ((c = getc(fp)) >= '0' && c <= '9');
return n;
}
return -1;
}
/* getstr - read a string */
static char *getstr(void) {
int c;
char buf[MAXTOKEN], *s = buf;
while ((c = getc(fp)) != EOF && c != ' ' && c != '\n' && c != '\t')
if (s - buf < (int)sizeof buf - 2)
*s++ = c;
*s = 0;
return s == buf ? (char *)0 : string(buf);
}
/* gather - read prof.out data from fd */
static int gather(void) {
int i, nfiles, nfuncs, npoints;
char *files[64];
if ((nfiles = getd()) < 0)
return 0;
assert(nfiles < NELEMS(files));
for (i = 0; i < nfiles; i++) {
if ((files[i] = getstr()) == 0)
return -1;
if (!findfile(files[i])) {
struct file *new;
NEW(new, PERM);
new->name = files[i];
new->size = new->count = 0;
new->counts = 0;
new->funcs = 0;
new->link = filelist;
filelist = new;
}
}
if ((nfuncs = getd()) < 0)
return -1;
for (i = 0; i < nfuncs; i++) {
struct func *q;
char *name, *file;
int f, x, y, count;
if ((name = getstr()) == 0 || (f = getd()) <= 0
|| (x = getd()) < 0 || (y = getd()) < 0 || (count = getd()) < 0)
return -1;
q = afunction(name, files[f-1], x, y, count);
if ((name = getstr()) == 0 || (file = getstr()) == 0
|| (x = getd()) < 0 || (y = getd()) < 0)
return -1;
if (*name != '?')
acaller(name, file, x, y, count, q);
}
if ((npoints = getd()) < 0)
return -1;
for (i = 0; i < npoints; i++) {
int f, x, y, count;
if ((f = getd()) < 0 || (x = getd()) < 0 || (y = getd()) < 0
|| (count = getd()) < 0)
return -1;
if (f)
apoint(i, files[f-1], x, y, count);
}
return 1;
}
/* process - read prof.out data from file */
int process(char *file) {
int more;
if ((fp = fopen(file, "r")) != NULL) {
struct file *p;
while ((more = gather()) > 0)
;
fclose(fp);
if (more < 0)
return more;
for (p = filelist; p; p = p->link)
qsort(p->counts, p->count, sizeof *p->counts,
(int (*)(const void *, const void *))
compare);
return 1;
}
return 0;
}
int main(int argc, char *argv[]) {
int i;
struct file *p;
void (*f)(struct file *, int) = printfile;
progname = argv[0];
if ((i = process("prof.out")) <= 0) {
fprintf(stderr, "%s: can't %s `%s'\n", progname,
i == 0 ? "open" : "interpret", "prof.out");
exit(1);
}
for (i = 1; i < argc && *argv[i] == '-'; i++)
if (strcmp(argv[i], "-c") == 0) {
emitdata("prof.out");
exit(0);
} else if (strcmp(argv[i], "-b") == 0)
f = printfile;
else if (strcmp(argv[i], "-f") == 0) {
fcount++;
f = printfuncs;
} else if (strcmp(argv[i], "-n") == 0)
number++;
else if (strncmp(argv[i], "-I", 2) == 0) {
int j;
for (j = 0; j < NDIRS && dirs[j]; j++)
;
if (j < NDIRS)
dirs[j] = &argv[i][2];
else
fprintf(stderr, "%s: too many -I options\n", progname);
} else {
fprintf(stderr, "usage: %s [ -c | -b | -n | -f | -Idir... ] [ file... ]\n", progname);
exit(1);
}
for (p = filelist; p; p = p->link)
qsort(p->counts, p->count, sizeof *p->counts,
(int (*)(const void *, const void *))compare);
if (i < argc) {
int nf = i < argc - 1 ? 1 : 0;
for ( ; i < argc; i++, nf ? nf++ : 0)
if ((p = findfile(string(argv[i]))))
(*f)(p, nf);
else
fprintf(stderr, "%s: no data for `%s'\n", progname, argv[i]);
} else {
int nf = filelist && filelist->link ? 1 : 0;
for (p = filelist; p; p = p->link, nf ? nf++ : 0)
(*f)(p, nf);
}
return 0;
}

View file

@ -1,190 +0,0 @@
#include "c.h"
/* ops [ {csilhfdxp}=n ]...
* prints lcc dag operator set for a given set of type sizes.
*/
static char list[] = { 'c', 's', 'i', 'l', 'h', 'f', 'd', 'x', 'p', 0 };
static int sizes[] = { 1, 2, 4, 4, 8, 4, 8, 16, 8 };
static int doop(int op, int type, const char *sz, const char *opname) {
int count = 0;
static int last;
if (op == LOAD)
return 0;
if (last != 0 && last != op)
printf("\n");
last = op;
if (type == B || type == V) {
printf(" %s=%d", opname, op + type);
count++;
} else {
int i, done = 0;
const char *s;
for (i = 0; sz[i] != '\0' && (s = strchr(list, sz[i])) != NULL; i++) {
int n = sizes[s-list];
if ((done&(1<<n)) == 0) {
printf(" %s%d=%d", opname, n, op + type + sizeop(n));
count++;
}
done |= 1<<n;
}
}
printf("\n");
return count;
}
int main(int argc, char *argv[]) {
int i, count = 0;
for (i = 1; i < argc; i++) {
char c, *s;
int n;
if (sscanf(argv[i], "%c=%d", &c, &n) == 2
&& n > 0 && (s = strchr(list, c)) != NULL)
sizes[s-list] = n;
else {
fprintf(stderr, "usage: %s [ {csilhfdxp}=n ]...\n", argv[0]);
exit(EXIT_FAILURE);
}
}
#define gop(x,n)
#define op(x,t,s) count += doop(x,t,#s,#x #t);
gop(CNST,1)
op(CNST,F,fdx)
op(CNST,I,csilh)
op(CNST,P,p)
op(CNST,U,csilh)
gop(ARG,2)
op(ARG,B,-)
op(ARG,F,fdx)
op(ARG,I,ilh)
op(ARG,P,p)
op(ARG,U,ilh)
gop(ASGN,3)
op(ASGN,B,-)
op(ASGN,F,fdx)
op(ASGN,I,csilh)
op(ASGN,P,p)
op(ASGN,U,csilh)
gop(INDIR,4)
op(INDIR,B,-)
op(INDIR,F,fdx)
op(INDIR,I,csilh)
op(INDIR,P,p)
op(INDIR,U,csilh)
gop(CVF,7)
op(CVF,F,fdx)
op(CVF,I,ilh)
gop(CVI,8)
op(CVI,F,fdx)
op(CVI,I,csilh)
op(CVI,U,csilhp)
gop(CVP,9)
op(CVP,U,p)
gop(CVU,11)
op(CVU,I,csilh)
op(CVU,P,p)
op(CVU,U,csilh)
gop(NEG,12)
op(NEG,F,fdx)
op(NEG,I,ilh)
gop(CALL,13)
op(CALL,B,-)
op(CALL,F,fdx)
op(CALL,I,ilh)
op(CALL,P,p)
op(CALL,U,ilh)
op(CALL,V,-)
gop(RET,15)
op(RET,F,fdx)
op(RET,I,ilh)
op(RET,P,p)
op(RET,U,ilh)
op(RET,V,-)
gop(ADDRG,16)
op(ADDRG,P,p)
gop(ADDRF,17)
op(ADDRF,P,p)
gop(ADDRL,18)
op(ADDRL,P,p)
gop(ADD,19)
op(ADD,F,fdx)
op(ADD,I,ilh)
op(ADD,P,p)
op(ADD,U,ilhp)
gop(SUB,20)
op(SUB,F,fdx)
op(SUB,I,ilh)
op(SUB,P,p)
op(SUB,U,ilhp)
gop(LSH,21)
op(LSH,I,ilh)
op(LSH,U,ilh)
gop(MOD,22)
op(MOD,I,ilh)
op(MOD,U,ilh)
gop(RSH,23)
op(RSH,I,ilh)
op(RSH,U,ilh)
gop(BAND,24)
op(BAND,I,ilh)
op(BAND,U,ilh)
gop(BCOM,25)
op(BCOM,I,ilh)
op(BCOM,U,ilh)
gop(BOR,26)
op(BOR,I,ilh)
op(BOR,U,ilh)
gop(BXOR,27)
op(BXOR,I,ilh)
op(BXOR,U,ilh)
gop(DIV,28)
op(DIV,F,fdx)
op(DIV,I,ilh)
op(DIV,U,ilh)
gop(MUL,29)
op(MUL,F,fdx)
op(MUL,I,ilh)
op(MUL,U,ilh)
gop(EQ,30)
op(EQ,F,fdx)
op(EQ,I,ilh)
op(EQ,U,ilhp)
gop(GE,31)
op(GE,F,fdx)
op(GE,I,ilh)
op(GE,U,ilhp)
gop(GT,32)
op(GT,F,fdx)
op(GT,I,ilh)
op(GT,U,ilhp)
gop(LE,33)
op(LE,F,fdx)
op(LE,I,ilh)
op(LE,U,ilhp)
gop(LT,34)
op(LT,F,fdx)
op(LT,I,ilh)
op(LT,U,ilhp)
gop(NE,35)
op(NE,F,fdx)
op(NE,I,ilh)
op(NE,U,ilhp)
gop(JUMP,36)
op(JUMP,V,-)
gop(LABEL,37)
op(LABEL,V,-)
gop(LOAD,14)
op(LOAD,B,-)
op(LOAD,F,fdx)
op(LOAD,I,csilh)
op(LOAD,P,p)
op(LOAD,U,csilhp)
#undef gop
#undef op
fprintf(stderr, "%d operators\n", count);
return EXIT_SUCCESS;
}

View file

@ -1,15 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
int _assert(char *e, char *file, int line) {
fprintf(stderr, "assertion failed:");
if (e)
fprintf(stderr, " %s", e);
if (file)
fprintf(stderr, " file %s", file);
fprintf(stderr, " line %d\n", line);
fflush(stderr);
abort();
return 0;
}

View file

@ -1,123 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
struct callsite {
char *file, *name;
union coordinate {
struct { unsigned int index:6,x:10,y:16; } be;
struct { unsigned int y:16,x:10,index:6; } le;
unsigned int coord;
} u;
} *_caller;
static struct _bbdata {
struct _bbdata *link;
unsigned npoints, *counts;
union coordinate *coords;
char **files;
struct func {
struct func *link;
struct caller {
struct caller *link;
struct callsite *caller;
unsigned count;
} *callers;
char *name;
union coordinate src;
} *funcs;
} tail, *_bblist = &tail;
static void unpack(unsigned int coord, int *index, int *x, int *y) {
static union { int x; char endian; } little = { 1 };
union coordinate u;
u.coord = coord;
if (little.endian) {
*index = u.le.index;
*x = u.le.x;
*y = u.le.y;
} else {
*index = u.be.index;
*x = u.be.x;
*y = u.be.y;
}
}
static void profout(struct _bbdata *p, FILE *fp) {
int i, index, x, y;
struct func *f;
struct caller *q;
for (i = 0; p->files[i]; i++)
;
fprintf(fp, "%d\n", i);
for (i = 0; p->files[i]; i++)
fprintf(fp, "%s\n", p->files[i]);
for (i = 0, f = p->funcs; f; i++, f = f->link)
if ((q = f->callers))
for (i--; q; q = q->link)
i++;
fprintf(fp, "%d\n", i);
for (f = p->funcs; f; f = f->link) {
int n = 0;
for (q = f->callers; q; n += q->count, q = q->link) {
unpack(f->src.coord, &index, &x, &y);
fprintf(fp, "%s %d %d %d %d", f->name, index, x, y, q->count);
if (q->caller) {
unpack(q->caller->u.coord, &index, &x, &y);
fprintf(fp, " %s %s %d %d\n", q->caller->name, q->caller->file, x, y);
} else
fprintf(fp, " ? ? 0 0\n");
}
if (n == 0) {
unpack(f->src.coord, &index, &x, &y);
fprintf(fp, "%s %d %d %d 0 ? ? 0 0\n", f->name, index, x, y);
}
}
fprintf(fp, "%d\n", p->npoints);
for (i = 0; i < p->npoints; i++) {
unpack(p->coords[i].coord, &index, &x, &y);
fprintf(fp, "%d %d %d %d\n", index, x, y, p->counts[i]);
}
}
static void bbexit(void) {
FILE *fp;
if (_bblist != &tail && (fp = fopen("prof.out", "a"))) {
for ( ; _bblist != &tail; _bblist = _bblist->link)
profout(_bblist, fp);
fclose(fp);
}
}
void _epilogue(struct func *callee) {
_caller = 0;
}
void _prologue(struct func *callee, struct _bbdata *yylink) {
static struct caller callers[4096];
static int next;
struct caller *p;
if (!yylink->link) {
yylink->link = _bblist;
_bblist = yylink;
if (next == 0)
atexit(bbexit);
}
for (p = callee->callers; p; p = p->link)
if (p->caller == _caller) {
p->count++;
break;
}
if (!p && next < sizeof callers/sizeof callers[0]) {
p = &callers[next++];
p->caller = _caller;
p->count = 1;
p->link = callee->callers;
callee->callers = p;
}
_caller = 0;
}

View file

@ -1,12 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
void _YYnull(char *file, int line) {
fprintf(stderr, "null pointer dereferenced:");
if (file)
fprintf(stderr, " file %s,", file);
fprintf(stderr, " line %d\n", line);
fflush(stderr);
abort();
}

View file

@ -1,4 +1,3 @@
# $Id: makefile 145 2001-10-17 21:53:10Z timo $
PLATFORM=$(shell uname|sed -e s/_.*//|tr A-Z a-z)
TEMPDIR=/tmp
A=.a
@ -11,7 +10,7 @@ else
endif
CC=gcc
LCC_CFLAGS=-O2 -Wall -fno-strict-aliasing
LCC_CFLAGS=-O2 -Wall -fno-strict-aliasing -MMD
LDFLAGS=
LD=gcc
AR=ar
@ -22,211 +21,135 @@ RM=rm -f
RMDIR=rmdir
BUILDDIR=build
BD=$(BUILDDIR)/
ifeq ($(PLATFORM),SunOS)
INSTALL=ginstall
else
INSTALL=install
endif
# $Id: makefile 145 2001-10-17 21:53:10Z timo $
what:
-@echo make all q3rcc lburg q3cpp q3lcc bprint liblcc triple clean clobber
makedirs:
@if [ ! -d $(BD) ];then mkdir $(BD);fi
all:: q3rcc lburg q3cpp q3lcc bprint liblcc
all: q3rcc lburg q3cpp q3lcc
q3rcc: makedirs $(BD)q3rcc$(E)
lburg: makedirs $(BD)lburg$(E)
q3cpp: makedirs $(BD)q3cpp$(E)
q3lcc: makedirs $(BD)q3lcc$(E)
bprint: makedirs $(BD)bprint$(E)
liblcc: makedirs $(BD)liblcc$(A)
RCCOBJS=$(BD)alloc$(O) \
$(BD)bind$(O) \
$(BD)dag$(O) \
$(BD)dagcheck$(O) \
$(BD)decl$(O) \
$(BD)enode$(O) \
$(BD)error$(O) \
$(BD)expr$(O) \
$(BD)event$(O) \
$(BD)init$(O) \
$(BD)inits$(O) \
$(BD)input$(O) \
$(BD)lex$(O) \
$(BD)list$(O) \
$(BD)main$(O) \
$(BD)output$(O) \
$(BD)prof$(O) \
$(BD)profio$(O) \
$(BD)simp$(O) \
$(BD)stmt$(O) \
$(BD)string$(O) \
$(BD)sym$(O) \
$(BD)trace$(O) \
$(BD)tree$(O) \
$(BD)types$(O) \
$(BD)null$(O) \
$(BD)symbolic$(O) \
$(BD)gen$(O) \
$(BD)bytecode$(O)
makedirs:
@if [ ! -d $(BD) ];then mkdir $(BD);fi
@if [ ! -d $(BD)/etc ];then mkdir $(BD)/etc;fi
@if [ ! -d $(BD)/rcc ];then mkdir $(BD)/rcc;fi
@if [ ! -d $(BD)/cpp ];then mkdir $(BD)/cpp;fi
@if [ ! -d $(BD)/lburg ];then mkdir $(BD)/lburg;fi
$(BD)q3rcc$(E):: $(BD)main$(O) $(BD)librcc$(A) $(EXTRAOBJS)
$(LD) $(LDFLAGS) -o $@ $(BD)main$(O) $(EXTRAOBJS) $(BD)librcc$(A) $(EXTRALIBS)
# ===== RCC =====
RCCOBJS= \
$(BD)rcc/alloc$(O) \
$(BD)rcc/bind$(O) \
$(BD)rcc/bytecode$(O) \
$(BD)rcc/dag$(O) \
$(BD)rcc/dagcheck$(O) \
$(BD)rcc/decl$(O) \
$(BD)rcc/enode$(O) \
$(BD)rcc/error$(O) \
$(BD)rcc/event$(O) \
$(BD)rcc/expr$(O) \
$(BD)rcc/gen$(O) \
$(BD)rcc/init$(O) \
$(BD)rcc/inits$(O) \
$(BD)rcc/input$(O) \
$(BD)rcc/lex$(O) \
$(BD)rcc/list$(O) \
$(BD)rcc/main$(O) \
$(BD)rcc/null$(O) \
$(BD)rcc/output$(O) \
$(BD)rcc/prof$(O) \
$(BD)rcc/profio$(O) \
$(BD)rcc/simp$(O) \
$(BD)rcc/stmt$(O) \
$(BD)rcc/string$(O) \
$(BD)rcc/sym$(O) \
$(BD)rcc/symbolic$(O) \
$(BD)rcc/trace$(O) \
$(BD)rcc/tree$(O) \
$(BD)rcc/types$(O)
$(BD)librcc$(A): $(RCCOBJS)
$(AR) $(ARFLAGS) $@ $(RCCOBJS); $(RANLIB) $@ || true
$(BD)q3rcc$(E): $(RCCOBJS)
$(LD) $(LDFLAGS) -o $@ $(RCCOBJS)
$(RCCOBJS): src/c.h src/token.h src/config.h
$(BD)rcc/%$(O): src/%.c
$(CC) $(LCC_CFLAGS) -c -Isrc -o $@ $<
$(BD)alloc$(O): src/alloc.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/alloc.c
$(BD)bind$(O): src/bind.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/bind.c
$(BD)dag$(O): src/dag.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/dag.c
$(BD)decl$(O): src/decl.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/decl.c
$(BD)enode$(O): src/enode.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/enode.c
$(BD)error$(O): src/error.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/error.c
$(BD)event$(O): src/event.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/event.c
$(BD)expr$(O): src/expr.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/expr.c
$(BD)gen$(O): src/gen.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/gen.c
$(BD)init$(O): src/init.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/init.c
$(BD)inits$(O): src/inits.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/inits.c
$(BD)input$(O): src/input.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/input.c
$(BD)lex$(O): src/lex.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/lex.c
$(BD)list$(O): src/list.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/list.c
$(BD)main$(O): src/main.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/main.c
$(BD)null$(O): src/null.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/null.c
$(BD)output$(O): src/output.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/output.c
$(BD)prof$(O): src/prof.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/prof.c
$(BD)profio$(O): src/profio.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/profio.c
$(BD)simp$(O): src/simp.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/simp.c
$(BD)stmt$(O): src/stmt.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/stmt.c
$(BD)string$(O): src/string.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/string.c
$(BD)sym$(O): src/sym.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/sym.c
$(BD)symbolic$(O): src/symbolic.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/symbolic.c
$(BD)bytecode$(O): src/bytecode.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/bytecode.c
$(BD)trace$(O): src/trace.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/trace.c
$(BD)tree$(O): src/tree.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/tree.c
$(BD)types$(O): src/types.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/types.c
$(BD)stab$(O): src/stab.c src/stab.h; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ src/stab.c
$(BD)rcc/dagcheck$(O): $(BD)rcc/dagcheck.c
$(CC) $(LCC_CFLAGS) -Wno-unused -c -Isrc -o $@ $<
$(BD)dagcheck$(O): $(BD)dagcheck.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ $(BD)dagcheck.c
$(BD)rcc/dagcheck.c: $(BD)lburg/lburg$(E) src/dagcheck.md
$(BD)lburg/lburg$(E) src/dagcheck.md $@
$(BD)dagcheck.c: $(BD)lburg$(E) src/dagcheck.md; $(BD)lburg src/dagcheck.md $@
$(BD)q3rcc.h: src/rcc.asdl; $(ASDL_HOME)/bin/asdlGen --c -d $(BD) src/rcc.asdl
$(BD)q3rcc$(O): $(BD)rcc.h; $(CC) $(LCC_CFLAGS) -c -Isrc -I$(BD) -I$(ASDL_HOME)/include/asdlGen -o $@ $(BD)rcc.c
$(BD)asdl$(O): src/asdl.c $(BD)rcc.h src/c.h; $(CC) $(LCC_CFLAGS) -c -Isrc -I$(BD) -I$(ASDL_HOME)/include/asdlGen -o $@ src/asdl.c
$(BD)2html$(O): src/2html.c $(BD)rcc.h src/c.h; $(CC) $(LCC_CFLAGS) -c -Isrc -I$(BD) -I$(ASDL_HOME)/include/asdlGen -o $@ src/2html.c
# ===== LBURG =====
LBURGOBJS= \
$(BD)lburg/lburg$(O) \
$(BD)lburg/gram$(O)
$(BD)2html$(E): $(BD)2html$(O) $(BD)q3rcc$(O); $(LD) $(LDFLAGS) -o $@ $(BD)2html$(O) $(BD)q3rcc$(O) $(EXTRALIBS)
$(BD)lburg/lburg$(E): $(LBURGOBJS)
$(LD) $(LDFLAGS) -o $@ $(LBURGOBJS)
$(BD)bprint$(E): $(BD)bprint$(O); $(LD) $(LDFLAGS) -o $@ $(BD)bprint$(O)
$(BD)lburg/%$(O): lburg/%.c
$(CC) $(LCC_CFLAGS) -c -Ilburg -o $@ $<
$(BD)bprint$(O): etc/bprint.c; $(CC) $(LCC_CFLAGS) -c -Isrc -o $@ etc/bprint.c
$(BD)q3lcc$(E): $(BD)q3lcc$(O) $(BD)host$(O); $(LD) $(LDFLAGS) -o $@ $(BD)q3lcc$(O) $(BD)host$(O)
$(BD)q3lcc$(O): etc/lcc.c; $(CC) $(LCC_CFLAGS) -c -DTEMPDIR=\"$(TEMPDIR)\" -o $@ etc/lcc.c
$(BD)host$(O): etc/bytecode.c; $(CC) $(LCC_CFLAGS) -c -DSYSTEM=\"\" -o $@ etc/bytecode.c
LIBOBJS=$(BD)assert$(O) $(BD)bbexit$(O) $(BD)yynull$(O)
$(BD)liblcc$(A): $(LIBOBJS); $(AR) $(ARFLAGS) $@ $(BD)assert$(O) $(BD)bbexit$(O) $(BD)yynull$(O); $(RANLIB) $@ || true
$(BD)assert$(O): lib/assert.c; $(CC) $(LCC_CFLAGS) -c -o $@ lib/assert.c
$(BD)yynull$(O): lib/yynull.c; $(CC) $(LCC_CFLAGS) -c -o $@ lib/yynull.c
$(BD)bbexit$(O): lib/bbexit.c; $(CC) $(LCC_CFLAGS) -c -o $@ lib/bbexit.c
$(BD)lburg$(E): $(BD)lburg$(O) $(BD)gram$(O); $(LD) $(LDFLAGS) -o $@ $(BD)lburg$(O) $(BD)gram$(O)
$(BD)lburg$(O) $(BD)gram$(O): lburg/lburg.h
$(BD)lburg$(O): lburg/lburg.c; $(CC) $(LCC_CFLAGS) -c -Ilburg -o $@ lburg/lburg.c
$(BD)gram$(O): lburg/gram.c; $(CC) $(LCC_CFLAGS) -c -Ilburg -o $@ lburg/gram.c
CPPOBJS=$(BD)q3cpp$(O) $(BD)lexer$(O) $(BD)nlist$(O) $(BD)tokens$(O) $(BD)macro$(O) $(BD)eval$(O) \
$(BD)include$(O) $(BD)hideset$(O) $(BD)getopt$(O) $(BD)unix$(O)
# ===== CPP =====
CPPOBJS= \
$(BD)cpp/cpp$(O) \
$(BD)cpp/lex$(O) \
$(BD)cpp/nlist$(O) \
$(BD)cpp/tokens$(O) \
$(BD)cpp/macro$(O) \
$(BD)cpp/eval$(O) \
$(BD)cpp/include$(O) \
$(BD)cpp/hideset$(O) \
$(BD)cpp/getopt$(O) \
$(BD)cpp/unix$(O)
$(BD)q3cpp$(E): $(CPPOBJS)
$(LD) $(LDFLAGS) -o $@ $(CPPOBJS)
$(CPPOBJS): cpp/cpp.h
$(BD)cpp/%$(O): cpp/%.c
$(CC) $(LCC_CFLAGS) -c -Icpp -o $@ $<
$(BD)q3cpp$(O): cpp/cpp.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/cpp.c
$(BD)lexer$(O): cpp/lex.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/lex.c
$(BD)nlist$(O): cpp/nlist.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/nlist.c
$(BD)tokens$(O): cpp/tokens.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/tokens.c
$(BD)macro$(O): cpp/macro.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/macro.c
$(BD)eval$(O): cpp/eval.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/eval.c
$(BD)include$(O): cpp/include.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/include.c
$(BD)hideset$(O): cpp/hideset.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/hideset.c
$(BD)getopt$(O): cpp/getopt.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/getopt.c
$(BD)unix$(O): cpp/unix.c; $(CC) $(LCC_CFLAGS) -c -Icpp -o $@ cpp/unix.c
install:: all
# ===== LCC =====
LCCOBJS= \
$(BD)etc/lcc$(O) \
$(BD)etc/bytecode$(O)
$(BD)q3lcc$(E): $(LCCOBJS)
$(LD) $(LDFLAGS) -o $@ $(LCCOBJS)
$(BD)etc/%$(O): etc/%.c
$(CC) $(LCC_CFLAGS) -DTEMPDIR=\"$(TEMPDIR)\" -DSYSTEM=\"\" -c -Isrc -o $@ $<
install: q3lcc q3cpp q3rcc
$(INSTALL) -s -m 0755 $(BD)q3lcc$(E) ../
$(INSTALL) -s -m 0755 $(BD)q3cpp$(E) ../
$(INSTALL) -s -m 0755 $(BD)q3rcc$(E) ../
uninstall::
uninstall:
-$(RM) ../q3lcc$(E)
-$(RM) ../q3cpp$(E)
-$(RM) ../q3rcc$(E)
clean::
$(RM) $(BD)*$(O)
$(RM) $(BD)dagcheck.c $(BD)gram.c
$(RM) $(BD)rcc.c $(BD)rcc.h
$(RM) $(BD)rcc1$(E) $(BD)rcc1$(E) $(BD)1rcc$(E) $(BD)2rcc$(E)
$(RM) $(BD)*.ilk
clean:
if [ -d $(BD) ];then (find $(BD) -name '*.d' -exec rm {} \;)fi
$(RM) $(RCCOBJS) $(LBURGOBJS) $(CPPOBJS) $(LCCOBJS)
$(RM) $(BD)rcc/dagcheck.c $(BD)lburg/lburg$(E)
$(RM) $(BD)q3lcc$(E) $(BD)q3cpp$(E) $(BD)q3rcc$(E)
$(RM) -r $(BD)
clobber:: clean
$(RM) $(BD)q3rcc$(E) $(BD)2html$(E) $(BD)lburg$(E) $(BD)q3cpp$(E) $(BD)q3lcc$(E) $(BD)bprint$(E) $(BD)*$(A)
$(RM) $(BD)*.pdb $(BD)*.pch
D_FILES=$(shell find . -name '*.d')
RCCSRCS=src/alloc.c \
src/bind.c \
src/dag.c \
src/decl.c \
src/enode.c \
src/error.c \
src/expr.c \
src/event.c \
src/init.c \
src/inits.c \
src/input.c \
src/lex.c \
src/list.c \
src/main.c \
src/output.c \
src/prof.c \
src/profio.c \
src/simp.c \
src/stmt.c \
src/string.c \
src/sym.c \
src/trace.c \
src/tree.c \
src/types.c \
src/null.c \
src/symbolic.c \
src/bytecode.c \
src/gen.c \
src/stab.c \
$(BD)dagcheck.c
C=$(BD)q3lcc -A -d0.6 -Wo-lccdir=$(BUILDDIR) -Isrc -I$(BUILDDIR)
triple: $(BD)q3rcc$(E) $(BD)q3lcc$(E) $(BD)q3cpp$(E)
$C -o $(BD)1rcc$(E) -B$(BD) $(RCCSRCS)
$C -o $(BD)2rcc$(E) -B$(BD)1 $(RCCSRCS)
strip $(BD)1rcc$(E) $(BD)2rcc$(E)
dd if=$(BD)1rcc$(E) of=$(BD)rcc1$(E) bs=512 skip=1
dd if=$(BD)2rcc$(E) of=$(BD)rcc2$(E) bs=512 skip=1
if cmp $(BD)rcc1$(E) $(BD)rcc2$(E); then \
mv $(BD)2rcc$(E) $(BD)q3rcc$(E); \
$(RM) $(BD)1rcc$(E) $(BD)q3rcc[12]$(E); fi
ifneq ($(strip $(D_FILES)),)
include $(D_FILES)
endif

View file

@ -1,555 +0,0 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "c.h"
#include "rcc.h"
#if WIN32
#include <fcntl.h>
#include <io.h>
#endif
static void do_int(int x) {
printf("%d", x);
}
static void do_scope(int x) {
#define xx(c) if (x == c) { printf(#c); return; }
xx(CONSTANTS)
xx(LABELS)
xx(GLOBAL)
xx(PARAM)
xx(LOCAL)
#undef xx
if (x > LOCAL)
printf("LOCAL+%d", x-LOCAL);
else
do_int(x);
}
static void do_sclass(int x) {
#define xx(c) if (x == c) { printf(#c); return; }
xx(REGISTER)
xx(AUTO)
xx(EXTERN)
xx(STATIC)
xx(TYPEDEF)
#undef xx
do_int(x);
}
static void do_flags(int x) {
char *bar = "";
#define xx(f,n) if ((x>>n)&1) { printf("%s" #f, bar); bar = "|"; }
xx(structarg,0)
xx(addressed,1)
xx(computed,2)
xx(temporary,3)
xx(generated,4)
#undef xx
if (*bar == '\0')
do_int(x);
}
static void do_seg(int x) {
#define xx(s) if (x == s) { printf(#s); return; }
xx(CODE)
xx(BSS)
xx(DATA)
xx(LIT)
#undef xx
do_int(x);
}
#define xx(ptr,field,type) do { printf("<li>" #field " = "); do_##type(ptr->field); printf("</li>\n"); } while (0)
static void do_op(int x) {
static char *opnames[] = {
"",
"CNST",
"ARG",
"ASGN",
"INDIR",
"CVC",
"CVD",
"CVF",
"CVI",
"CVP",
"CVS",
"CVU",
"NEG",
"CALL",
"*LOAD*",
"RET",
"ADDRG",
"ADDRF",
"ADDRL",
"ADD",
"SUB",
"LSH",
"MOD",
"RSH",
"BAND",
"BCOM",
"BOR",
"BXOR",
"DIV",
"MUL",
"EQ",
"GE",
"GT",
"LE",
"LT",
"NE",
"JUMP",
"LABEL",
"AND",
"NOT",
"OR",
"COND",
"RIGHT",
"FIELD"
};
int op = opindex(x);
if (op < 1 || op >= sizeof opnames/sizeof opnames[0])
printf("%d", x);
else
printf("%s", opnames[op]);
}
static void do_define_uid(int x) {
printf("<strong id=uid%d>%d</strong>", x, x);
}
static void do_define_label(int x) {
printf("<strong id=ll%d>%d</strong>", x, x);
}
static void do_uid(int x) {
printf("<a href='#%d'>%d</a>", x, x, x);
}
static void do_label(int x) {
printf("<a href='#L%d'>%d</a>", x, x, x);
}
static int nextid;
static void do_list(list_ty x, void do_one(void *), char *type, char *listhtml, char *separator) {
int count = Seq_length(x);
if (count == 0)
printf("<em>empty %s list</em>\n", type);
else {
int i;
printf("<em>%s list</em>", type);
if (listhtml != NULL)
printf("<%s>\n", listhtml);
for (i = 0; i < count; i++) {
if (listhtml != NULL)
printf("<li>");
printf(separator);
do_one(Seq_get(x, i));
if (listhtml != NULL)
printf("</li>\n");
}
if (listhtml != NULL)
printf("</%s>\n", listhtml);
}
}
static void do_uid_list(list_ty x) {
int i, count = Seq_length(x);
if (count == 0)
printf("<em>empty int list</em>\n");
else {
int i;
printf("<em>int list</em>");
for (i= 0; i < count; i++) {
printf(" ");
do_uid(*(int *)Seq_get(x, i));
}
}
}
static void do_identifier(const char *x) {
printf("%s", x);
}
static void do_real(rcc_real_ty x) {
double d;
unsigned *p = (unsigned *)&d;
static union { int x; char endian; } little = { 1 };
p[1-little.endian] = x->msb;
p[little.endian] = x->lsb;
printf("(%#X,%#X) = %g", x->msb, x->lsb, d);
}
static void do_suffix(int x) {
static char suffixes[] = "0F234IUPVB";
if (x < 0 || x >= (sizeof suffixes/sizeof suffixes[0]) - 1)
printf("%d", x);
else
printf("%c", suffixes[x]);
}
static void do_enum(void *x) {
rcc_enum__ty e = x;
do_identifier(e->id);
printf("=");
do_int(e->value);
}
static void do_enum_list(list_ty x) {
do_list(x, do_enum, "enum", NULL, " ");
}
static void do_field(void *x) {
rcc_field_ty f = x;
printf("<em>field</em><ul>\n");
xx(f,id,identifier);
xx(f,type,uid);
xx(f,offset,int);
xx(f,bitsize,int);
xx(f,lsb,int);
printf("</ul>\n");
}
static void do_field_list(list_ty x) {
do_list(x, do_field, "field", "ol", "");
}
static void do_symbol(rcc_symbol_ty x) {
printf("<em>symbol</em><ul>\n");
xx(x,id,identifier);
xx(x,type,uid);
xx(x,scope,scope);
xx(x,sclass,sclass);
xx(x,ref,int);
xx(x,flags,flags);
printf("</ul>\n");
}
#define caselabel(kind) case rcc_##kind##_enum: \
printf("<strong>" #kind "</strong> : <em>%s</em>", typename); \
printf("<ul>\n"); attributes
#define yy(kind,field,type) xx((&x->v.rcc_##kind),field,type)
static void do_type(rcc_type_ty x) {
#define attributes xx(x,size,int); xx(x,align,int)
switch (x->kind) {
static char *typename = "type";
caselabel(INT); break;
caselabel(UNSIGNED); break;
caselabel(FLOAT); break;
caselabel(VOID); break;
caselabel(POINTER);
yy(POINTER,type,uid);
break;
caselabel(ENUM);
yy(ENUM,tag,identifier);
yy(ENUM,ids,enum_list);
break;
caselabel(STRUCT);
yy(STRUCT,tag,identifier);
yy(STRUCT,fields,field_list);
break;
caselabel(UNION);
yy(UNION,tag,identifier);
yy(UNION,fields,field_list);
break;
caselabel(ARRAY);
yy(ARRAY,type,uid);
break;
caselabel(FUNCTION);
yy(FUNCTION,type,uid);
yy(FUNCTION,formals,uid_list);
break;
caselabel(CONST);
yy(CONST,type,uid);
break;
caselabel(VOLATILE);
yy(VOLATILE,type,uid);
break;
default: assert(0);
}
#undef attributes
printf("</ul>\n");
}
static void do_item(rcc_item_ty x) {
printf("<a name='%d'>", x->uid);
#define attributes xx(x,uid,define_uid)
printf("</a>");
switch (x->kind) {
static char *typename = "item";
caselabel(Symbol);
yy(Symbol,symbol,symbol);
break;
caselabel(Type);
yy(Type,type,type);
break;
default: assert(0);
}
#undef attributes
printf("</ul>\n");
}
static void do_item_list(list_ty x) {
int count = Seq_length(x);
if (count == 0)
printf("<em>empty item list</em>\n");
else {
int i;
printf("<em>item list</em>");
printf("<ol>\n");
for (i = 0; i < count; i++) {
rcc_item_ty item = Seq_get(x, i);
printf("<li value=%d>", item->uid);
do_item(item);
printf("</li>\n");
}
printf("</ol>\n");
}
}
static void do_string(string_ty x) {
printf("%d,<code>'%s'</code>", x.len, x.str);
}
static void do_generic_string(void *x) {
do_string(*(string_ty *)x);
}
static void do_string_list(list_ty x) {
do_list(x, do_generic_string, "string", "ol", "");
}
static void do_node(void *y) {
rcc_node_ty x = y;
if (x->kind == rcc_LABEL_enum)
printf("<a name='L%d'></a>", x->v.rcc_LABEL.label);
#define attributes xx(x,suffix,suffix); xx(x,size,int)
switch (x->kind) {
static char *typename = "node";
caselabel(CNST);
yy(CNST,value,int);
break;
caselabel(CNSTF);
yy(CNSTF,value,real);
break;
caselabel(ARG);
yy(ARG,left,node);
yy(ARG,len,int);
yy(ARG,align,int);
break;
caselabel(ASGN);
yy(ASGN,left,node);
yy(ASGN,right,node);
yy(ASGN,len,int);
yy(ASGN,align,int);
break;
caselabel(CVT);
yy(CVT,op,op);
yy(CVT,left,node);
yy(CVT,fromsize,int);
break;
caselabel(CALL);
yy(CALL,left,node);
yy(CALL,type,uid);
break;
caselabel(CALLB);
yy(CALLB,left,node);
yy(CALLB,right,node);
yy(CALLB,type,uid);
break;
caselabel(RET); break;
caselabel(ADDRG);
yy(ADDRG,uid,uid);
break;
caselabel(ADDRL);
yy(ADDRL,uid,uid);
break;
caselabel(ADDRF);
yy(ADDRF,uid,uid);
break;
caselabel(Unary);
yy(Unary,op,op);
yy(Unary,left,node);
break;
caselabel(Binary);
yy(Binary,op,op);
yy(Binary,left,node);
yy(Binary,right,node);
break;
caselabel(Compare);
yy(Compare,op,op);
yy(Compare,left,node);
yy(Compare,right,node);
yy(Compare,label,label);
break;
caselabel(LABEL);
yy(LABEL,label,define_label);
break;
caselabel(BRANCH);
yy(BRANCH,label,label);
break;
caselabel(CSE);
yy(CSE,uid,uid);
yy(CSE,node,node);
break;
default: assert(0);
}
#undef attributes
printf("</ul>");
}
static void do_node_list(list_ty x) {
do_list(x, do_node, "node", "ol", "");
}
static void do_interface(void *);
static void do_interface_list(list_ty x) {
do_list(x, do_interface, "interface", "ol", "");
}
static void do_interface(void *y) {
rcc_interface_ty x = y;
if (x->kind == rcc_Address_enum)
printf("<a name='%d'></a>", x->v.rcc_Address.uid);
else if (x->kind == rcc_Local_enum)
printf("<a name='%d'></a>", x->v.rcc_Local.uid);
#define attributes
switch (x->kind) {
static char *typename = "interface";
caselabel(Export);
yy(Export,p,uid);
break;
caselabel(Import);
yy(Import,p,uid);
break;
caselabel(Global);
yy(Global,p,uid);
yy(Global,seg,seg);
break;
caselabel(Local);
yy(Local,uid,define_uid);
yy(Local,p,symbol);
break;
caselabel(Address);
yy(Address,uid,define_uid);
yy(Address,q,symbol);
yy(Address,p,uid);
yy(Address,n,int);
break;
caselabel(Segment);
yy(Segment,seg,seg);
break;
caselabel(Defaddress);
yy(Defaddress,p,uid);
break;
caselabel(Deflabel);
yy(Deflabel,label,label);
break;
caselabel(Defconst);
yy(Defconst,suffix,suffix);
yy(Defconst,size,int);
yy(Defconst,value,int);
break;
caselabel(Defconstf);
yy(Defconstf,size,int);
yy(Defconstf,value,real);
break;
caselabel(Defstring);
yy(Defstring,s,string);
break;
caselabel(Space);
yy(Space,n,int);
break;
caselabel(Function);
yy(Function,f,uid);
yy(Function,caller,uid_list);
yy(Function,callee,uid_list);
yy(Function,ncalls,int);
yy(Function,codelist,interface_list);
break;
caselabel(Forest);
yy(Forest,nodes,node_list);
break;
case rcc_Blockbeg_enum: printf("<strong>Blockbeg</strong> : <em>%s</em>", typename); return;
case rcc_Blockend_enum: printf("<strong>Blockend</strong> : <em>%s</em>", typename); return;
default: assert(0);
}
#undef attributes
printf("</ul>\n");
}
static void do_program(rcc_program_ty x) {
printf("<ul>\n");
xx(x,nuids,int);
xx(x,nlabels,int);
xx(x,items,item_list);
xx(x,interfaces,interface_list);
xx(x,argc,int);
xx(x,argv,string_list);
printf("</ul>\n");
}
int main(int argc, char *argv[]) {
int i, version;
float stamp = (assert(strstr(rcsid, ",v")), strtod(strstr(rcsid, ",v")+2, NULL))
;
char *infile = NULL, *outfile = NULL;
rcc_program_ty pickle;
for (i = 1; i < argc; i++)
if (*argv[i] != '-' || strcmp(argv[i], "-") == 0) {
if (infile == NULL)
infile = argv[i];
else if (outfile == NULL)
outfile = argv[i];
}
if (infile != NULL && strcmp(infile, "-") != 0
&& freopen(infile, "rb", stdin) == NULL) {
fprintf(stderr, "%s: can't read `%s'\n", argv[0], infile);
exit(EXIT_FAILURE);
}
if (infile == NULL || strcmp(infile, "-") == 0)
infile = "Standard Input";
#if WIN32
else
_setmode(_fileno(stdin), _O_BINARY);
#endif
if (outfile != NULL && strcmp(outfile, "-") != 0
&& freopen(outfile, "w", stdout) == NULL) {
fprintf(stderr, "%s: can't write `%s'\n", argv[0], outfile);
exit(EXIT_FAILURE);
}
version = read_int(stdin);
assert(version/100 == (int)stamp);
pickle = rcc_read_program(stdin);
printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\"\n");
printf("<html><head><title>%s</title>\n"
"<link rev=made href=\"mailto:drh@microsoft.com\">\n"
"</head><body>\n<h1>%s</h1>\n", infile, infile);
printf("<p>version = %d.%d</p>", version/100, version%100);
do_program(pickle);
{
time_t t;
time(&t);
printf("<hr><address>%s</address>\n", ctime(&t));
}
printf("</body></html>\n");
return EXIT_SUCCESS;
}

View file

@ -1,399 +0,0 @@
#include "c.h"
#include "rcc.h"
#if WIN32
#include <fcntl.h>
#include <io.h>
#endif
static list_ty interfaces;
static rcc_program_ty pickle;
char *string(const char *str) {
return (char *)Atom_string(str);
}
char *stringd(long n) {
return (char *)Atom_int(n);
}
char *stringn(const char *str, int len) {
return (char *)Atom_new(str, len);
}
static void put(rcc_interface_ty node) {
Seq_addhi(interfaces, node);
}
static int typeuid(Type ty) {
rcc_type_ty type;
assert(ty);
if (ty->x.typeno != 0)
return ty->x.typeno;
ty->x.typeno = pickle->nuids++;
switch (ty->op) {
#define xx(op) case op: type = rcc_##op(ty->size, ty->align); break
xx(INT);
xx(UNSIGNED);
xx(FLOAT);
xx(VOID);
#undef xx
#define xx(op) case op: type = rcc_##op(ty->size, ty->align, typeuid(ty->type)); break
xx(POINTER);
xx(ARRAY);
xx(CONST);
xx(VOLATILE);
#undef xx
case CONST+VOLATILE:
type = rcc_CONST(ty->size, ty->align, typeuid(ty->type));
break;
case ENUM: {
list_ty ids = Seq_new(0);
int i;
for (i = 0; ty->u.sym->u.idlist[i] != NULL; i++)
Seq_addhi(ids, rcc_enum_(ty->u.sym->u.idlist[i]->name,
ty->u.sym->u.idlist[i]->u.value));
assert(i > 0);
type = rcc_ENUM(ty->size, ty->align, ty->u.sym->name, ids);
break;
}
case STRUCT: case UNION: {
list_ty fields = Seq_new(0);
Field p = fieldlist(ty);
for ( ; p != NULL; p = p->link)
Seq_addhi(fields, rcc_field(p->name, typeuid(p->type), p->offset, p->bitsize, p->lsb));
if (ty->op == STRUCT)
type = rcc_STRUCT(ty->size, ty->align, ty->u.sym->name, fields);
else
type = rcc_UNION (ty->size, ty->align, ty->u.sym->name, fields);
break;
}
case FUNCTION: {
list_ty formals = Seq_new(0);
if (ty->u.f.proto != NULL && ty->u.f.proto[0] != NULL) {
int i;
for (i = 0; ty->u.f.proto[i] != NULL; i++)
Seq_addhi(formals, to_generic_int(typeuid(ty->u.f.proto[i])));
} else if (ty->u.f.proto != NULL && ty->u.f.proto[0] == NULL)
Seq_addhi(formals, to_generic_int(typeuid(voidtype)));
type = rcc_FUNCTION(ty->size, ty->align, typeuid(ty->type), formals);
break;
}
default: assert(0);
}
Seq_addhi(pickle->items, rcc_Type(ty->x.typeno, type));
return ty->x.typeno;
}
static int symboluid(Symbol p) {
assert(p);
assert(p->scope != CONSTANTS && p->scope != LABELS);
if (p->x.offset == 0)
p->x.offset = pickle->nuids++;
return p->x.offset;
}
static rcc_symbol_ty mk_symbol(Symbol p) {
int flags = 0, ref = 10000*p->ref;
if (p->ref > 0 && ref == 0)
ref++;
#define xx(f,n) flags |= p->f<<n;
xx(structarg,0)
xx(addressed,1)
xx(computed,2)
xx(temporary,3)
xx(generated,4)
#undef xx
return rcc_symbol(p->name, typeuid(p->type), p->scope, p->sclass, ref, flags);
}
static rcc_real_ty mk_real(int size, Value v) {
unsigned *p = (unsigned *)&v.d;
return rcc_real(p[swap], p[1-swap]);
}
static void asdl_segment(int n) {
static int cseg;
if (cseg != n)
put(rcc_Segment(cseg = n));
}
static void asdl_address(Symbol q, Symbol p, long n) {
assert(q->x.offset == 0);
put(rcc_Address(symboluid(q), mk_symbol(q), symboluid(p), n));
}
static void asdl_blockbeg(Env *e) {
put(rcc_Blockbeg());
}
static void asdl_blockend(Env *e) {
put(rcc_Blockend());
}
static void asdl_defaddress(Symbol p) {
if (p->scope == LABELS)
put(rcc_Deflabel(p->u.l.label));
else
put(rcc_Defaddress(symboluid(p)));
}
static void asdl_defconst(int suffix, int size, Value v) {
switch (suffix) {
case I: put(rcc_Defconst(suffix, size, v.i)); return;
case U: put(rcc_Defconst(suffix, size, v.u)); return;
case P: put(rcc_Defconst(suffix, size, (unsigned long)v.p)); return; /* FIXME */
case F: put(rcc_Defconstf(size, mk_real(size, v))); return;
assert(0);
}
}
static void asdl_defstring(int len, char *str) {
put(rcc_Defstring(Text_box(stringn(str, len), len)));
}
static void asdl_defsymbol(Symbol p) {
if (p->scope >= GLOBAL)
symboluid(p);
}
static Symbol temps;
static rcc_node_ty visit(Node p) {
Symbol q;
rcc_node_ty left = NULL, right = NULL;
int suffix = optype(p->op), size = opsize(p->op);
assert(p);
for (q = temps; q; q = q->u.t.next)
if (q->u.t.cse == p) {
q->u.t.cse = NULL;
return rcc_CSE(0, 0, symboluid(q), visit(p));
}
if (p->kids[0] != NULL)
left = visit(p->kids[0]);
if (p->kids[1] != NULL)
right = visit(p->kids[1]);
switch (specific(p->op)) {
case CNST+F:
assert(p->syms[0]);
return rcc_CNSTF(suffix, size, mk_real(size, p->syms[0]->u.c.v));
case CALL+B:
assert(p->syms[0]);
assert(p->syms[0]->type);
return rcc_CALLB(suffix, size, left, right, typeuid(p->syms[0]->type));
case RET+V:
return rcc_RET(suffix, size);
case LABEL+V:
assert(p->syms[0]);
return rcc_LABEL(suffix, size, p->syms[0]->u.l.label);
}
switch (generic(p->op)) {
case CNST:
assert(p->syms[0]);
return rcc_CNST(suffix, size, p->syms[0]->u.c.v.i); /* FIXME */
case ARG:
assert(p->syms[0]);
return rcc_ARG(suffix, size, left, p->syms[0]->u.c.v.i, p->syms[1]->u.c.v.i);
case ASGN:
assert(p->syms[0]);
assert(p->syms[1]);
return rcc_ASGN(suffix, size, left, right, p->syms[0]->u.c.v.i, p->syms[1]->u.c.v.i);
case CVF: case CVI: case CVP: case CVU:
assert(p->syms[0]);
return rcc_CVT(suffix, size, generic(p->op), left, p->syms[0]->u.c.v.i);
case CALL:
assert(p->syms[0]);
assert(p->syms[0]->type);
return rcc_CALL(suffix, size, left, typeuid(p->syms[0]->type));
#define xx(op) case op: return rcc_##op(suffix, size, symboluid(p->syms[0]))
xx(ADDRG);
xx(ADDRF);
#undef xx
case ADDRL:
if (!p->syms[0]->defined)
(*IR->local)(p->syms[0]);
p->syms[0]->defined = 1;
return rcc_ADDRL(suffix, size, symboluid(p->syms[0]));
case JUMP:
if (p->syms[0] != NULL)
return rcc_BRANCH(suffix, size, p->syms[0]->u.l.label);
return rcc_Unary(suffix, size, generic(p->op), left);
case INDIR: case RET: case NEG: case BCOM:
return rcc_Unary(suffix, size, generic(p->op), left);
case BOR: case BAND: case BXOR: case RSH: case LSH:
case ADD: case SUB: case DIV: case MUL: case MOD:
return rcc_Binary(suffix, size, generic(p->op), left, right);
case EQ: case NE: case GT: case GE: case LE: case LT:
assert(p->syms[0]);
return rcc_Compare(suffix, size, generic(p->op), left, right, p->syms[0]->u.l.label);
}
assert(0);
return NULL;
}
static void asdl_emit(Node p) {}
static void asdl_local(Symbol p) {
assert(p->x.offset == 0);
put(rcc_Local(symboluid(p), mk_symbol(p)));
if (p->temporary && p->u.t.cse) {
p->u.t.next = temps;
temps = p;
}
}
static Symbol pending = NULL;
static void dopending(Symbol p) {
if (pending != NULL) {
int uid = symboluid(pending);
rcc_symbol_ty symbol = mk_symbol(pending);
Seq_addhi(pickle->items, rcc_Symbol(uid, symbol));
}
pending = p;
}
static void asdl_export(Symbol p) {
put(rcc_Export(symboluid(p)));
}
static void asdl_function(Symbol f, Symbol caller[], Symbol callee[], int ncalls) {
list_ty codelist = Seq_new(0), save, calleelist = Seq_new(0), callerlist = Seq_new(0);
int i;
dopending(f);
for (i = 0; caller[i] != NULL; i++) {
asdl_local(caller[i]);
Seq_addhi(callerlist, to_generic_int(symboluid(caller[i])));
}
for (i = 0; callee[i] != NULL; i++) {
asdl_local(callee[i]);
Seq_addhi(calleelist, to_generic_int(symboluid(callee[i])));
}
save = interfaces;
interfaces = codelist;
gencode(caller, callee);
asdl_segment(CODE);
emitcode();
interfaces = save;
put(rcc_Function(symboluid(f), callerlist, calleelist, ncalls, codelist));
}
static Node asdl_gen(Node p) {
Node q;
list_ty forest = Seq_new(0);
for (q = p; p != NULL; p = p->link)
if (specific(p->op) == JUMP+V && specific(p->kids[0]->op) == ADDRG+P
&& p->kids[0]->syms[0]->scope == LABELS) {
p->syms[0] = p->kids[0]->syms[0];
p->kids[0] = NULL;
}
for (p = q; p != NULL; p = p->link)
Seq_addhi(forest, visit(p));
put(rcc_Forest(forest));
temps = NULL;
return q;
}
static void asdl_global(Symbol p) {
dopending(p);
put(rcc_Global(symboluid(p), p->u.seg));
}
static void asdl_import(Symbol p) {
dopending(p);
put(rcc_Import(symboluid(p)));
}
static void asdl_progbeg(int argc, char *argv[]) {
int i;
#if WIN32
_setmode(_fileno(stdout), _O_BINARY);
#endif
pickle = rcc_program(1, 0, Seq_new(0), Seq_new(0), argc, Seq_new(0));
for (i = 0; i < argc; i++)
Seq_addhi(pickle->argv, to_generic_string(Text_box(argv[i], strlen(argv[i]) + 1)));
interfaces = pickle->interfaces;
}
static int checkuid(list_ty list) {
int i, n = 0, count = Seq_length(list);
for (i = 0; i < count; i++) {
rcc_interface_ty in = Seq_get(list, i);
if (in->kind == rcc_Local_enum
|| in->kind == rcc_Address_enum)
n++;
else if (in->kind == rcc_Function_enum)
n += checkuid(in->v.rcc_Function.codelist);
}
return n;
}
static void asdl_progend(void) {
dopending(NULL);
{
int n = checkuid(pickle->interfaces) + Seq_length(pickle->items);
if (n != pickle->nuids - 1)
fprintf(stderr, "?bogus uid count: have %d should have %d\n",
n, pickle->nuids-1);
}
pickle->nlabels = genlabel(0);
write_int((int)(100*(assert(strstr(rcsid, ",v")), strtod(strstr(rcsid, ",v")+2, NULL))
), stdout);
rcc_write_program(pickle, stdout);
}
static void asdl_space(int n) {
put(rcc_Space(n));
}
void asdl_init(int argc, char *argv[]) {
int i;
static int inited;
if (inited)
return;
inited = 1;
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "-asdl") == 0) {
#define xx(f) IR->f = asdl_##f
xx(address);
xx(blockbeg);
xx(blockend);
xx(defaddress);
xx(defconst);
xx(defstring);
xx(defsymbol);
xx(emit);
xx(export);
xx(function);
xx(gen);
xx(global);
xx(import);
xx(local);
xx(progbeg);
xx(progend);
xx(segment);
xx(space);
#undef xx
#define xx(f) IR->f = 0
xx(stabblock);
xx(stabend);
xx(stabfend);
xx(stabinit);
xx(stabline);
xx(stabsym);
xx(stabtype);
#undef xx
IR->wants_dag = 0;
prunetemps = 0; /* pass2 prunes useless temps */
assignargs = 0; /* pass2 generates caller to callee assignments */
}
}

View file

@ -1,70 +0,0 @@
-- lcc IR
-- $Id: rcc.asdl 145 2001-10-17 21:53:10Z timo $
module rcc {
-- Pickles start with an int version number, followed by rcc.program
program = (int nuids,int nlabels,item* items,interface* interfaces,int argc,string *argv)
real = (int msb,int lsb)
item = Symbol(symbol symbol)
| Type(type type)
attributes(int uid)
symbol = (identifier id,int type,int scope,int sclass,int ref,int flags)
field = (identifier id,int type,int offset,int bitsize,int lsb)
enum = (identifier id,int value)
type = INT
| UNSIGNED
| FLOAT
| VOID
| POINTER(int type)
| ENUM(identifier tag,enum* ids)
| STRUCT(identifier tag,field* fields)
| UNION(identifier tag,field* fields)
| ARRAY(int type)
| FUNCTION(int type,int* formals)
| CONST(int type)
| VOLATILE(int type)
attributes(int size,int align)
interface = Export(int p)
| Import(int p)
| Global(int p,int seg)
| Local(int uid,symbol p) -- includes formals
| Address(int uid,symbol q,int p,int n)
| Segment(int seg)
| Defaddress(int p)
| Deflabel(int label)
| Defconst(int suffix,int size,int value)
| Defconstf(int size,real value)
| Defstring(string s)
| Space(int n)
| Function(int f,int* caller,int* callee,int ncalls,interface* codelist)
| Blockbeg
| Blockend
| Forest(node* nodes)
node = CNST(int value)
| CNSTF(real value)
| ARG(node left,int len,int align)
| ASGN(node left,node right,int len,int align)
| CVT(int op,node left,int fromsize)
| CALL(node left,int type)
| CALLB(node left,node right,int type)
| RET
| ADDRG(int uid)
| ADDRL(int uid)
| ADDRF(int uid)
| Unary(int op,node left) -- INDIR RET JUMP NEG BCOM
| Binary(int op,node left,node right) -- ADD SUB DIV MUL MOD BOR BAND BXOR RSH LSH
| Compare(int op,node left,node right,int label) -- EQ NE GT GE LE LT
| LABEL(int label)
| BRANCH(int label)
| CSE(int uid,node node)
attributes(int suffix,int size)
}

View file

@ -1,51 +0,0 @@
#!/bin/sh
# run .../target/os/tst/foo.s [ remotehost ]
# set -x
target=`echo $1 | awk -F/ '{ print $(NF-3) }'`
os=`echo $1 | awk -F/ '{ print $(NF-2) }'`
dir=$target/$os
case "$1" in
*symbolic/irix*) idir=include/mips/irix; remotehost=noexecute ;;
*symbolic/osf*) idir=include/alpha/osf; remotehost=noexecute ;;
*) idir=include/$dir; remotehost=${2-$REMOTEHOST} ;;
esac
if [ ! -d "$target/$os" -o ! -d "$idir" ]; then
echo 2>&1 $0: unknown combination '"'$target/$os'"'
exit 1
fi
C=`basename $1 .s`
BUILDDIR=${BUILDDIR-.} LCC="${LCC-${BUILDDIR}/lcc} -Wo-lccdir=$BUILDDIR"
TSTDIR=${TSTDIR-${BUILDDIR}/$dir/tst}
if [ ! -d $TSTDIR ]; then mkdir -p $TSTDIR; fi
echo ${BUILDDIR}/rcc$EXE -target=$target/$os $1: 1>&2
$LCC -S -I$idir -Ualpha -Usun -Uvax -Umips -Ux86 \
-Wf-errout=$TSTDIR/$C.2 -D$target -Wf-g0 \
-Wf-target=$target/$os -o $1 tst/$C.c
if [ $? != 0 ]; then remotehost=noexecute; fi
if [ -r $dir/tst/$C.2bk ]; then
diff $dir/tst/$C.2bk $TSTDIR/$C.2
fi
if [ -r $dir/tst/$C.sbk ]; then
if diff $dir/tst/$C.sbk $TSTDIR/$C.s; then exit 0; fi
fi
case "$remotehost" in
noexecute) exit 0 ;;
""|"-") $LCC -o $TSTDIR/$C$EXE $1; $TSTDIR/$C$EXE <tst/$C.0 >$TSTDIR/$C.1 ;;
*) rcp $1 $remotehost:
if expr "$remotehost" : '.*@' >/dev/null ; then
remotehost="`expr $remotehost : '.*@\(.*\)'` -l `expr $remotehost : '\(.*\)@'`"
fi
rsh $remotehost "cc -o $C$EXE $C.s -lm;./$C$EXE;rm -f $C$EXE $C.[so]" <tst/$C.0 >$TSTDIR/$C.1
;;
esac
if [ -r $dir/tst/$C.1bk ]; then
diff $dir/tst/$C.1bk $TSTDIR/$C.1
exit $?
fi
exit 0

View file

@ -1,326 +0,0 @@
#include <string.h>
#include <stdlib.h>
#include "c.h"
#include "stab.h"
static char *currentfile; /* current file name */
static int ntypes;
extern Interface sparcIR;
char *stabprefix = "L";
extern char *stabprefix;
extern void stabblock(int, int, Symbol*);
extern void stabend(Coordinate *, Symbol, Coordinate **, Symbol *, Symbol *);
extern void stabfend(Symbol, int);
extern void stabinit(char *, int, char *[]);
extern void stabline(Coordinate *);
extern void stabsym(Symbol);
extern void stabtype(Symbol);
static void asgncode(Type, int);
static void dbxout(Type);
static int dbxtype(Type);
static int emittype(Type, int, int);
/* asgncode - assign type code to ty */
static void asgncode(Type ty, int lev) {
if (ty->x.marked || ty->x.typeno)
return;
ty->x.marked = 1;
switch (ty->op) {
case VOLATILE: case CONST: case VOLATILE+CONST:
asgncode(ty->type, lev);
ty->x.typeno = ty->type->x.typeno;
break;
case POINTER: case FUNCTION: case ARRAY:
asgncode(ty->type, lev + 1);
/* fall thru */
case VOID: case INT: case UNSIGNED: case FLOAT:
break;
case STRUCT: case UNION: {
Field p;
for (p = fieldlist(ty); p; p = p->link)
asgncode(p->type, lev + 1);
/* fall thru */
case ENUM:
if (ty->x.typeno == 0)
ty->x.typeno = ++ntypes;
if (lev > 0 && (*ty->u.sym->name < '0' || *ty->u.sym->name > '9'))
dbxout(ty);
break;
}
default:
assert(0);
}
}
/* dbxout - output .stabs entry for type ty */
static void dbxout(Type ty) {
ty = unqual(ty);
if (!ty->x.printed) {
int col = 0;
print(".stabs \""), col += 8;
if (ty->u.sym && !(isfunc(ty) || isarray(ty) || isptr(ty)))
print("%s", ty->u.sym->name), col += strlen(ty->u.sym->name);
print(":%c", isstruct(ty) || isenum(ty) ? 'T' : 't'), col += 2;
emittype(ty, 0, col);
print("\",%d,0,0,0\n", N_LSYM);
}
}
/* dbxtype - emit a stabs entry for type ty, return type code */
static int dbxtype(Type ty) {
asgncode(ty, 0);
dbxout(ty);
return ty->x.typeno;
}
/*
* emittype - emit ty's type number, emitting its definition if necessary.
* Returns the output column number after emission; col is the approximate
* output column before emission and is used to emit continuation lines for long
* struct, union, and enum types. Continuations are not emitted for other types,
* even if the definition is long. lev is the depth of calls to emittype.
*/
static int emittype(Type ty, int lev, int col) {
int tc = ty->x.typeno;
if (isconst(ty) || isvolatile(ty)) {
col = emittype(ty->type, lev, col);
ty->x.typeno = ty->type->x.typeno;
ty->x.printed = 1;
return col;
}
if (tc == 0) {
ty->x.typeno = tc = ++ntypes;
/* fprint(2,"`%t'=%d\n", ty, tc); */
}
print("%d", tc), col += 3;
if (ty->x.printed)
return col;
ty->x.printed = 1;
switch (ty->op) {
case VOID: /* void is defined as itself */
print("=%d", tc), col += 1+3;
break;
case INT:
if (ty == chartype) /* plain char is a subrange of itself */
print("=r%d;%d;%d;", tc, ty->u.sym->u.limits.min.i, ty->u.sym->u.limits.max.i),
col += 2+3+2*2.408*ty->size+2;
else /* other signed ints are subranges of int */
print("=r1;%D;%D;", ty->u.sym->u.limits.min.i, ty->u.sym->u.limits.max.i),
col += 4+2*2.408*ty->size+2;
break;
case UNSIGNED:
if (ty == chartype) /* plain char is a subrange of itself */
print("=r%d;0;%u;", tc, ty->u.sym->u.limits.max.i),
col += 2+3+2+2.408*ty->size+1;
else /* other signed ints are subranges of int */
print("=r1;0;%U;", ty->u.sym->u.limits.max.i),
col += 4+2.408*ty->size+1;
break;
case FLOAT: /* float, double, long double get sizes, not ranges */
print("=r1;%d;0;", ty->size), col += 4+1+3;
break;
case POINTER:
print("=*"), col += 2;
col = emittype(ty->type, lev + 1, col);
break;
case FUNCTION:
print("=f"), col += 2;
col = emittype(ty->type, lev + 1, col);
break;
case ARRAY: /* array includes subscript as an int range */
if (ty->size && ty->type->size)
print("=ar1;0;%d;", ty->size/ty->type->size - 1), col += 7+3+1;
else
print("=ar1;0;-1;"), col += 10;
col = emittype(ty->type, lev + 1, col);
break;
case STRUCT: case UNION: {
Field p;
if (!ty->u.sym->defined) {
print("=x%c%s:", ty->op == STRUCT ? 's' : 'u', ty->u.sym->name);
col += 2+1+strlen(ty->u.sym->name)+1;
break;
}
if (lev > 0 && (*ty->u.sym->name < '0' || *ty->u.sym->name > '9')) {
ty->x.printed = 0;
break;
}
print("=%c%d", ty->op == STRUCT ? 's' : 'u', ty->size), col += 1+1+3;
for (p = fieldlist(ty); p; p = p->link) {
if (p->name)
print("%s:", p->name), col += strlen(p->name)+1;
else
print(":"), col += 1;
col = emittype(p->type, lev + 1, col);
if (p->lsb)
print(",%d,%d;", 8*p->offset +
(IR->little_endian ? fieldright(p) : fieldleft(p)),
fieldsize(p));
else
print(",%d,%d;", 8*p->offset, 8*p->type->size);
col += 1+3+1+3+1; /* accounts for ,%d,%d; */
if (col >= 80 && p->link) {
print("\\\\\",%d,0,0,0\n.stabs \"", N_LSYM);
col = 8;
}
}
print(";"), col += 1;
break;
}
case ENUM: {
Symbol *p;
if (lev > 0 && (*ty->u.sym->name < '0' || *ty->u.sym->name > '9')) {
ty->x.printed = 0;
break;
}
print("=e"), col += 2;
for (p = ty->u.sym->u.idlist; *p; p++) {
print("%s:%d,", (*p)->name, (*p)->u.value), col += strlen((*p)->name)+3;
if (col >= 80 && p[1]) {
print("\\\\\",%d,0,0,0\n.stabs \"", N_LSYM);
col = 8;
}
}
print(";"), col += 1;
break;
}
default:
assert(0);
}
return col;
}
/* stabblock - output a stab entry for '{' or '}' at level lev */
void stabblock(int brace, int lev, Symbol *p) {
if (brace == '{')
while (*p)
stabsym(*p++);
{
int lab = genlabel(1);
print(".stabn 0x%x,0,%d,%s%d-%s\n", brace == '{' ? N_LBRAC : N_RBRAC, lev,
stabprefix, lab, cfunc->x.name);
print("%s%d:\n", stabprefix, lab);
}
}
/* stabinit - initialize stab output */
void stabinit(char *file, int argc, char *argv[]) {
typedef void (*Closure)(Symbol, void *);
extern char *getcwd(char *, size_t);
print(".stabs \"lcc4_compiled.\",0x%x,0,0,0\n", N_OPT);
if (file && *file) {
char buf[1024], *cwd = getcwd(buf, sizeof buf);
if (cwd)
print(".stabs \"%s/\",0x%x,0,3,%stext0\n", cwd, N_SO, stabprefix);
print(".stabs \"%s\",0x%x,0,3,%stext0\n", file, N_SO, stabprefix);
(*IR->segment)(CODE);
print("%stext0:\n", stabprefix, N_SO);
currentfile = file;
}
dbxtype(inttype);
dbxtype(chartype);
dbxtype(doubletype);
dbxtype(floattype);
dbxtype(longdouble);
dbxtype(longtype);
dbxtype(longlong);
dbxtype(shorttype);
dbxtype(signedchar);
dbxtype(unsignedchar);
dbxtype(unsignedlong);
dbxtype(unsignedlonglong);
dbxtype(unsignedshort);
dbxtype(unsignedtype);
dbxtype(voidtype);
foreach(types, GLOBAL, (Closure)stabtype, NULL);
}
/* stabline - emit stab entry for source coordinate *cp */
void stabline(Coordinate *cp) {
if (cp->file && cp->file != currentfile) {
int lab = genlabel(1);
print(".stabs \"%s\",0x%x,0,0,%s%d\n", cp->file, N_SOL, stabprefix, lab);
print("%s%d:\n", stabprefix, lab);
currentfile = cp->file;
}
{
int lab = genlabel(1);
print(".stabn 0x%x,0,%d,%s%d-%s\n", N_SLINE, cp->y,
stabprefix, lab, cfunc->x.name);
print("%s%d:\n", stabprefix, lab);
}
}
/* stabsym - output a stab entry for symbol p */
void stabsym(Symbol p) {
int code, tc, sz = p->type->size;
if (p->generated || p->computed)
return;
if (isfunc(p->type)) {
print(".stabs \"%s:%c%d\",%d,0,0,%s\n", p->name,
p->sclass == STATIC ? 'f' : 'F', dbxtype(freturn(p->type)),
N_FUN, p->x.name);
return;
}
if (!IR->wants_argb && p->scope == PARAM && p->structarg) {
assert(isptr(p->type) && isstruct(p->type->type));
tc = dbxtype(p->type->type);
sz = p->type->type->size;
} else
tc = dbxtype(p->type);
if ((p->sclass == AUTO && p->scope == GLOBAL) || p->sclass == EXTERN) {
print(".stabs \"%s:G", p->name);
code = N_GSYM;
} else if (p->sclass == STATIC) {
print(".stabs \"%s:%c%d\",%d,0,0,%s\n", p->name, p->scope == GLOBAL ? 'S' : 'V',
tc, p->u.seg == BSS ? N_LCSYM : N_STSYM, p->x.name);
return;
} else if (p->sclass == REGISTER) {
if (p->x.regnode) {
int r = p->x.regnode->number;
if (p->x.regnode->set == FREG)
r += 32; /* floating point */
print(".stabs \"%s:%c%d\",%d,0,", p->name,
p->scope == PARAM ? 'P' : 'r', tc, N_RSYM);
print("%d,%d\n", sz, r);
}
return;
} else if (p->scope == PARAM) {
print(".stabs \"%s:p", p->name);
code = N_PSYM;
} else if (p->scope >= LOCAL) {
print(".stabs \"%s:", p->name);
code = N_LSYM;
} else
assert(0);
print("%d\",%d,0,0,%s\n", tc, code,
p->scope >= PARAM && p->sclass != EXTERN ? p->x.name : "0");
}
/* stabtype - output a stab entry for type *p */
void stabtype(Symbol p) {
if (p->type) {
if (p->sclass == 0)
dbxtype(p->type);
else if (p->sclass == TYPEDEF)
print(".stabs \"%s:t%d\",%d,0,0,0\n", p->name, dbxtype(p->type), N_LSYM);
}
}
/* stabend - finalize a function */
void stabfend(Symbol p, int lineno) {}
/* stabend - finalize stab output */
void stabend(Coordinate *cp, Symbol p, Coordinate **cpp, Symbol *sp, Symbol *stab) {
(*IR->segment)(CODE);
print(".stabs \"\", %d, 0, 0,%setext\n", N_SO, stabprefix);
print("%setext:\n", stabprefix);
}

View file

@ -1,113 +0,0 @@
/* @(#)stab.h 1.11 92/05/11 SMI */
/*
* Copyright (c) 1990 by Sun Microsystems, Inc.
*/
/*
* This file gives definitions supplementing <a.out.h>
* for permanent symbol table entries.
* These must have one of the N_STAB bits on,
* and are subject to relocation according to the masks in <a.out.h>.
*/
#ifndef _STAB_H
#define _STAB_H
#if !defined(_a_out_h) && !defined(_A_OUT_H)
/* this file contains fragments of a.out.h and stab.h relevant to
* support of stabX processing within ELF files - see the
* Format of a symbol table entry
*/
struct nlist {
union {
char *n_name; /* for use when in-core */
long n_strx; /* index into file string table */
} n_un;
unsigned char n_type; /* type flag (N_TEXT,..) */
char n_other; /* unused */
short n_desc; /* see <stab.h> */
unsigned long n_value; /* value of symbol (or sdb offset) */
};
/*
* Simple values for n_type.
*/
#define N_UNDF 0x0 /* undefined */
#define N_ABS 0x2 /* absolute */
#define N_TEXT 0x4 /* text */
#define N_DATA 0x6 /* data */
#define N_BSS 0x8 /* bss */
#define N_COMM 0x12 /* common (internal to ld) */
#define N_FN 0x1f /* file name symbol */
#define N_EXT 01 /* external bit, or'ed in */
#define N_TYPE 0x1e /* mask for all the type bits */
#endif
/*
* for symbolic debugger, sdb(1):
*/
#define N_GSYM 0x20 /* global symbol: name,,0,type,0 */
#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,0 */
#define N_FUN 0x24 /* procedure: name,,0,linenumber,address */
#define N_STSYM 0x26 /* static symbol: name,,0,type,address */
#define N_LCSYM 0x28 /* .lcomm symbol: name,,0,type,address */
#define N_MAIN 0x2a /* name of main routine : name,,0,0,0 */
#define N_ROSYM 0x2c /* ro_data objects */
#define N_OBJ 0x38 /* object file path or name */
#define N_OPT 0x3c /* compiler options */
#define N_RSYM 0x40 /* register sym: name,,0,type,register */
#define N_SLINE 0x44 /* src line: 0,,0,linenumber,address */
#define N_FLINE 0x4c /* function start.end */
#define N_SSYM 0x60 /* structure elt: name,,0,type,struct_offset */
#define N_ENDM 0x62 /* last stab emitted for module */
#define N_SO 0x64 /* source file name: name,,0,0,address */
#define N_LSYM 0x80 /* local sym: name,,0,type,offset */
#define N_BINCL 0x82 /* header file: name,,0,0,0 */
#define N_SOL 0x84 /* #included file name: name,,0,0,address */
#define N_PSYM 0xa0 /* parameter: name,,0,type,offset */
#define N_EINCL 0xa2 /* end of include file */
#define N_ENTRY 0xa4 /* alternate entry: name,linenumber,address */
#define N_LBRAC 0xc0 /* left bracket: 0,,0,nesting level,address */
#define N_EXCL 0xc2 /* excluded include file */
#define N_RBRAC 0xe0 /* right bracket: 0,,0,nesting level,address */
#define N_BCOMM 0xe2 /* begin common: name,, */
#define N_ECOMM 0xe4 /* end common: name,, */
#define N_ECOML 0xe8 /* end common (local name): ,,address */
#define N_LENG 0xfe /* second stab entry with length information */
/*
* for the berkeley pascal compiler, pc(1):
*/
#define N_PC 0x30 /* global pascal symbol: name,,0,subtype,line */
#define N_WITH 0xea /* pascal with statement: type,,0,0,offset */
/*
* for code browser only
*/
#define N_BROWS 0x48 /* path to associated .cb file */
/*
* Optional langauge designations for N_SO
*/
#define N_SO_AS 1 /* Assembler */
#define N_SO_C 2 /* C */
#define N_SO_ANSI_C 3 /* ANSI C */
#define N_SO_CC 4 /* C++ */
#define N_SO_FORTRAN 5 /* Fortran 77 */
#define N_SO_PASCAL 6 /* Pascal */
/*
* Floating point type values
*/
#define NF_NONE 0 /* Undefined type */
#define NF_SINGLE 1 /* IEEE 32 bit float */
#define NF_DOUBLE 2 /* IEEE 64 bit float */
#define NF_COMPLEX 3 /* Fortran complex */
#define NF_COMPLEX16 4 /* Fortran double complex */
#define NF_COMPLEX32 5 /* Fortran complex*16 */
#define NF_LDOUBLE 6 /* Long double */
#endif

View file

@ -1,18 +1,12 @@
#
# Quake3 Unix Makefile
#
# Currently build for the following:
# Linux i386 (full client)
# Linux Alpha (dedicated server only) (TTimo: dropped)
# FreeBSD i386 (full client)
# SGI IRIX (full client) (TTimo: who's in charge - dropped otherwise)
# Linux PPC (full client) (TTimo: dropped)
#
# Nov '98 by Zoid <zoid@idsoftware.com>
#
# Loki Hacking by Bernd Kreimeier
# and a little more by Ryan C. Gordon.
# and a little more by Rafael Barrero
# and a little more by the ioq3 cr3w
#
# GNU Make required
#
@ -541,8 +535,8 @@ DO_WINDRES=$(WINDRES) -i $< -o $@
default:build_release
debug: build_debug
release: build_release
debug: tools build_debug
release: tools build_release
build_debug: B=$(BD)
build_debug: makedirs
@ -583,10 +577,8 @@ makedirs:
Q3LCC=../tools/q3lcc$(BINEXT)
Q3ASM=../tools/q3asm$(BINEXT)
$(Q3LCC):
tools:
$(MAKE) -C ../tools/lcc install
$(Q3ASM):
$(MAKE) -C ../tools/asm install
DO_Q3LCC=$(Q3LCC) -o $@ $<
@ -1269,7 +1261,7 @@ Q3CGVMOBJ = $(Q3CGOBJ_:%.o=%.asm) $(B)/baseq3/game/bg_lib.asm
$(B)/baseq3/cgame$(ARCH).$(SHLIBEXT) : $(Q3CGOBJ)
$(CC) $(SHLIBLDFLAGS) -o $@ $(Q3CGOBJ)
$(B)/baseq3/vm/cgame.qvm: $(Q3CGVMOBJ) $(CGDIR)/cg_syscalls.asm $(Q3ASM)
$(B)/baseq3/vm/cgame.qvm: $(Q3CGVMOBJ) $(CGDIR)/cg_syscalls.asm
$(Q3ASM) -o $@ $(Q3CGVMOBJ) $(CGDIR)/cg_syscalls.asm
#############################################################################
@ -1310,7 +1302,7 @@ MPCGVMOBJ = $(MPCGOBJ_:%.o=%.asm) $(B)/missionpack/game/bg_lib.asm
$(B)/missionpack/cgame$(ARCH).$(SHLIBEXT) : $(MPCGOBJ)
$(CC) $(SHLIBLDFLAGS) -o $@ $(MPCGOBJ)
$(B)/missionpack/vm/cgame.qvm: $(MPCGVMOBJ) $(CGDIR)/cg_syscalls.asm $(Q3ASM)
$(B)/missionpack/vm/cgame.qvm: $(MPCGVMOBJ) $(CGDIR)/cg_syscalls.asm
$(Q3ASM) -o $@ $(MPCGVMOBJ) $(CGDIR)/cg_syscalls.asm
@ -1360,7 +1352,7 @@ Q3GVMOBJ = $(Q3GOBJ_:%.o=%.asm) $(B)/baseq3/game/bg_lib.asm
$(B)/baseq3/qagame$(ARCH).$(SHLIBEXT) : $(Q3GOBJ)
$(CC) $(SHLIBLDFLAGS) -o $@ $(Q3GOBJ)
$(B)/baseq3/vm/qagame.qvm: $(Q3GVMOBJ) $(GDIR)/g_syscalls.asm $(Q3ASM)
$(B)/baseq3/vm/qagame.qvm: $(Q3GVMOBJ) $(GDIR)/g_syscalls.asm
$(Q3ASM) -o $@ $(Q3GVMOBJ) $(GDIR)/g_syscalls.asm
#############################################################################
@ -1408,7 +1400,7 @@ MPGVMOBJ = $(MPGOBJ_:%.o=%.asm) $(B)/missionpack/game/bg_lib.asm
$(B)/missionpack/qagame$(ARCH).$(SHLIBEXT) : $(MPGOBJ)
$(CC) $(SHLIBLDFLAGS) -o $@ $(MPGOBJ)
$(B)/missionpack/vm/qagame.qvm: $(MPGVMOBJ) $(GDIR)/g_syscalls.asm $(Q3ASM)
$(B)/missionpack/vm/qagame.qvm: $(MPGVMOBJ) $(GDIR)/g_syscalls.asm
$(Q3ASM) -o $@ $(MPGVMOBJ) $(GDIR)/g_syscalls.asm
@ -1468,7 +1460,7 @@ Q3UIVMOBJ = $(Q3UIOBJ_:%.o=%.asm) $(B)/baseq3/game/bg_lib.asm
$(B)/baseq3/ui$(ARCH).$(SHLIBEXT) : $(Q3UIOBJ)
$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(Q3UIOBJ)
$(B)/baseq3/vm/ui.qvm: $(Q3UIVMOBJ) $(UIDIR)/ui_syscalls.asm $(Q3ASM)
$(B)/baseq3/vm/ui.qvm: $(Q3UIVMOBJ) $(UIDIR)/ui_syscalls.asm
$(Q3ASM) -o $@ $(Q3UIVMOBJ) $(UIDIR)/ui_syscalls.asm
#############################################################################
@ -1493,7 +1485,7 @@ MPUIVMOBJ = $(MPUIOBJ_:%.o=%.asm) $(B)/baseq3/game/bg_lib.asm
$(B)/missionpack/ui$(ARCH).$(SHLIBEXT) : $(MPUIOBJ)
$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(MPUIOBJ)
$(B)/missionpack/vm/ui.qvm: $(MPUIVMOBJ) $(UIDIR)/ui_syscalls.asm $(Q3ASM)
$(B)/missionpack/vm/ui.qvm: $(MPUIVMOBJ) $(UIDIR)/ui_syscalls.asm
$(Q3ASM) -o $@ $(MPUIVMOBJ) $(UIDIR)/ui_syscalls.asm
@ -1505,52 +1497,52 @@ $(B)/missionpack/vm/ui.qvm: $(MPUIVMOBJ) $(UIDIR)/ui_syscalls.asm $(Q3ASM)
$(B)/baseq3/cgame/%.o: $(CGDIR)/%.c
$(DO_SHLIB_CC)
$(B)/baseq3/cgame/%.asm: $(CGDIR)/%.c $(Q3LCC)
$(B)/baseq3/cgame/%.asm: $(CGDIR)/%.c
$(DO_Q3LCC)
$(B)/missionpack/cgame/%.o: $(CGDIR)/%.c
$(DO_SHLIB_CC) -DMISSIONPACK
$(B)/missionpack/cgame/%.asm: $(CGDIR)/%.c $(Q3LCC)
$(B)/missionpack/cgame/%.asm: $(CGDIR)/%.c
$(DO_Q3LCC) -DMISSIONPACK
$(B)/baseq3/game/%.o: $(GDIR)/%.c
$(DO_SHLIB_CC)
$(B)/baseq3/game/%.asm: $(GDIR)/%.c $(Q3LCC)
$(B)/baseq3/game/%.asm: $(GDIR)/%.c
$(DO_Q3LCC)
$(B)/missionpack/game/%.o: $(GDIR)/%.c
$(DO_SHLIB_CC) -DMISSIONPACK
$(B)/missionpack/game/%.asm: $(GDIR)/%.c $(Q3LCC)
$(B)/missionpack/game/%.asm: $(GDIR)/%.c
$(DO_Q3LCC) -DMISSIONPACK
$(B)/baseq3/ui/%.o: $(Q3UIDIR)/%.c
$(DO_SHLIB_CC)
$(B)/baseq3/ui/%.asm: $(Q3UIDIR)/%.c $(Q3LCC)
$(B)/baseq3/ui/%.asm: $(Q3UIDIR)/%.c
$(DO_Q3LCC)
$(B)/missionpack/ui/%.o: $(UIDIR)/%.c
$(DO_SHLIB_CC) -DMISSIONPACK
$(B)/missionpack/ui/%.asm: $(UIDIR)/%.c $(Q3LCC)
$(B)/missionpack/ui/%.asm: $(UIDIR)/%.c
$(DO_Q3LCC) -DMISSIONPACK
$(B)/baseq3/qcommon/%.o: $(CMDIR)/%.c
$(DO_SHLIB_CC)
$(B)/baseq3/qcommon/%.asm: $(CMDIR)/%.c $(Q3LCC)
$(B)/baseq3/qcommon/%.asm: $(CMDIR)/%.c
$(DO_Q3LCC)
$(B)/missionpack/qcommon/%.o: $(CMDIR)/%.c
$(DO_SHLIB_CC) -DMISSIONPACK
$(B)/missionpack/qcommon/%.asm: $(CMDIR)/%.c $(Q3LCC)
$(B)/missionpack/qcommon/%.asm: $(CMDIR)/%.c
$(DO_Q3LCC) -DMISSIONPACK