* 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:
parent
590988222f
commit
f20cca46e8
14 changed files with 112 additions and 2530 deletions
|
@ -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;
|
||||
}
|
|
@ -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 */
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
}
|
|
@ -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
|
|
@ -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);
|
||||
}
|
|
@ -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
|
Loading…
Add table
Add a link
Reference in a new issue