#include "c.h"
#include "rcc.h"
Include dependency graph for pass2.c:

Go to the source code of this file.
Data Structures | |
| struct | block |
Defines | |
| #define | T(x) rcc_##x##_enum |
| #define | VERBOSE(n, arg) (verbose >= n ? (void)(arg):(void)0) |
| #define | xx(s) |
| #define | xx(s) 0, |
| #define | xx(s) static void do##s(rcc_interface_ty); |
| #define | xx(f, n) p->f = symbol->flags>>n; |
Functions | |
| void | doAddress (rcc_interface_ty in) |
| void | doBlockbeg (rcc_interface_ty in) |
| void | doBlockend (rcc_interface_ty in) |
| void | doDefaddress (rcc_interface_ty in) |
| void | doDefconst (rcc_interface_ty in) |
| void | doDefconstf (rcc_interface_ty in) |
| void | doDeflabel (rcc_interface_ty in) |
| void | doDefstring (rcc_interface_ty in) |
| void | doExport (rcc_interface_ty in) |
| void | doForest (rcc_interface_ty in) |
| void | doFunction (rcc_interface_ty in) |
| void | doGlobal (rcc_interface_ty in) |
| void | doImport (rcc_interface_ty in) |
| void | doLocal (rcc_interface_ty in) |
| void | doSegment (rcc_interface_ty in) |
| void | doSpace (rcc_interface_ty in) |
| void | init (int argc, char *argv[]) |
| void | interface (rcc_interface_ty in) |
| int | main (int argc, char *argv[]) |
| void | main_init (int argc, char *argv[]) |
| Symbol | uid2symbol (int uid) |
| void * | uid2type (int uid) |
| Node | visit (rcc_node_ty node) |
| xx (Export) | |
Variables | |
| int | Aflag |
| block * | blockstack |
| int | glevel |
| Interface * | IR = NULL |
| void ** | itemmap |
| rcc_item_ty * | items |
| int | nuids |
| int | Pflag |
| int | verbose = 1 |
| int | xref |
| Symbol | YYcheck |
| Symbol | YYnull |
|
|
Referenced by BadCond(), EmitBrushPrimitTextureCoordinates(), main(), PtrList::Ptr(), StrPtr::Ptr(), PtrList::Ref(), StrPtr::Ref(), TstCond(), and visit(). |
|
|
|
|
|
Value: |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 256 of file pass2.c. References code::addr, interface::address, assert, code::base, code(), Code, cp, GLOBAL, in, IR, items, nuids, NULL, code::offset, p, symbol::sclass, symbol::scope, code::sym, Symbol, code::u, uid2symbol(), and symbol::v. 00256 {
00257 int uid = in->v.rcc_Address.uid;
00258 Symbol p = uid2symbol(in->v.rcc_Address.p);
00259
00260 assert(uid >= 0 && uid < nuids);
00261 assert(items[uid] == NULL);
00262 items[uid] = rcc_Symbol(uid, in->v.rcc_Address.q);
00263 if (p->scope == GLOBAL || p->sclass == STATIC || p->sclass == EXTERN)
00264 (*IR->address)(uid2symbol(uid), p, in->v.rcc_Address.n);
00265 else {
00266 Code cp = code(Address);
00267 cp->u.addr.sym = uid2symbol(uid);
00268 cp->u.addr.base = p;
00269 cp->u.addr.offset = in->v.rcc_Address.n;
00270 }
00271 }
|
Here is the call graph for this function:

|
|
Definition at line 368 of file pass2.c. References b, block::begin, code::block, blockstack, code(), Code, cp, enterscope(), FUNC, code::identifiers, code::level, code::locals, NEW, newarray, block::prev, code::types, and code::u. 00368 {
00369 struct block *b;
00370 Code cp = code(Blockbeg);
00371
00372 enterscope();
00373 cp->u.block.level = level;
00374 cp->u.block.locals = newarray(1, sizeof *cp->u.block.locals, FUNC);
00375 cp->u.block.locals[0] = NULL;
00376 cp->u.block.identifiers = NULL;
00377 cp->u.block.types = NULL;
00378 NEW(b, FUNC);
00379 b->begin = cp;
00380 b->prev = blockstack;
00381 blockstack = b;
00382 }
|
Here is the call graph for this function:

|
|
Definition at line 384 of file pass2.c. References assert, block::begin, code::begin, blockstack, code(), exitscope(), block::prev, and code::u. 00384 {
00385 assert(blockstack);
00386 code(Blockend)->u.begin = blockstack->begin;
00387 blockstack = blockstack->prev;
00388 exitscope();
00389 }
|
Here is the call graph for this function:

|
|
Definition at line 277 of file pass2.c. References interface::defaddress, in, IR, and uid2symbol(). 00277 {
00278 (*IR->defaddress)(uid2symbol(in->v.rcc_Defaddress.p));
00279 }
|
Here is the call graph for this function:

|
|
Definition at line 285 of file pass2.c. References interface::defconst, value::i, in, IR, v, and Value. 00285 {
00286 Value v;
00287
00288 v.i = in->v.rcc_Defconst.value;
00289 (*IR->defconst)(in->v.rcc_Defconst.suffix, in->v.rcc_Defconst.size, v);
00290 }
|
|
|
Definition at line 292 of file pass2.c. References value::d, interface::defconst, free(), in, IR, p, v, and Value. 00292 {
00293 Value v;
00294 unsigned *p = (unsigned *)&v.d;
00295
00296 p[swap] = in->v.rcc_Defconstf.value->msb;
00297 p[1-swap] = in->v.rcc_Defconstf.value->lsb;
00298 (*IR->defconst)(F, in->v.rcc_Defconstf.size, v);
00299 free(in->v.rcc_Defconstf.value);
00300 }
|
Here is the call graph for this function:

|
|
Definition at line 281 of file pass2.c. References interface::defaddress, findlabel(), in, and IR. 00281 {
00282 (*IR->defaddress)(findlabel(in->v.rcc_Deflabel.label));
00283 }
|
Here is the call graph for this function:

|
|
Definition at line 302 of file pass2.c. References interface::defstring, free(), in, and IR. 00302 {
00303 (*IR->defstring)(in->v.rcc_Defstring.s.len, (char *)in->v.rcc_Defstring.s.str);
00304 free((char *)in->v.rcc_Defstring.s.str);
00305 }
|
Here is the call graph for this function:

|
|
Definition at line 227 of file pass2.c. References interface::export, in, IR, and uid2symbol(). 00227 {
00228 (*IR->export)(uid2symbol(in->v.rcc_Export.p));
00229 }
|
Here is the call graph for this function:

|
|
Definition at line 498 of file pass2.c. References assert, code(), code::forest, i, in, node::link, n, Node, code::u, and visit(). 00498 {
00499 Node *tail = &code(Gen)->u.forest;
00500 int i, n = Seq_length(in->v.rcc_Forest.nodes);
00501
00502 for (i = 0; i < n; i++) {
00503 *tail = visit(Seq_remlo(in->v.rcc_Forest.nodes));
00504 assert(*tail);
00505 tail = &(*tail)->link;
00506 }
00507 *tail = NULL;
00508 Seq_free(&in->v.rcc_Forest.nodes);
00509 }
|
Here is the call graph for this function:

|
|
Definition at line 311 of file pass2.c. References symbol::callee, cfunc, codelist, symbol::defined, enterscope(), exitscope(), symbol::f, free(), FUNC, interface::function, i, in, interface(), IR, LABELS, labels, n, newarray, code::next, NULL, Symbol, table(), symbol::u, and uid2symbol(). 00311 {
00312 int i, n;
00313 Symbol *caller, *callee;
00314
00315 /*
00316 Initialize:
00317 define the function symbol,
00318 initialize callee and caller arrays.
00319 */
00320 cfunc = uid2symbol(in->v.rcc_Function.f);
00321 labels = table(NULL, LABELS);
00322 enterscope();
00323 n = Seq_length(in->v.rcc_Function.caller);
00324 caller = newarray(n + 1, sizeof *caller, FUNC);
00325 for (i = 0; i < n; i++) {
00326 int *uid = Seq_remlo(in->v.rcc_Function.caller);
00327 caller[i] = uid2symbol(*uid);
00328 free(uid);
00329 }
00330 caller[i] = NULL;
00331 Seq_free(&in->v.rcc_Function.caller);
00332 callee = newarray(n + 1, sizeof *callee, FUNC);
00333 for (i = 0; i < n; i++) {
00334 int *uid = Seq_remlo(in->v.rcc_Function.callee);
00335 callee[i] = uid2symbol(*uid);
00336 free(uid);
00337 }
00338 callee[i] = NULL;
00339 Seq_free(&in->v.rcc_Function.callee);
00340 cfunc->u.f.callee = callee;
00341 cfunc->defined = 1;
00342 /*
00343 Initialize the code list,
00344 traverse the interfaces inside the function;
00345 each call appends code list entries.
00346 */
00347 codelist = &codehead;
00348 codelist->next = NULL;
00349 n = Seq_length(in->v.rcc_Function.codelist);
00350 for (i = 0; i < n; i++)
00351 interface(Seq_remlo(in->v.rcc_Function.codelist));
00352 Seq_free(&in->v.rcc_Function.codelist);
00353 /*
00354 Call the back end,
00355 Wrap-up.
00356 */
00357 exitscope();
00358 (*IR->function)(cfunc, caller, callee, in->v.rcc_Function.ncalls);
00359 cfunc = NULL;
00360 labels = NULL;
00361 }
|
Here is the call graph for this function:

|
|
Definition at line 238 of file pass2.c. References symbol::defined, interface::global, in, IR, p, symbol::seg, Symbol, symbol::u, uid2symbol(), and symbol::v. 00238 {
00239 Symbol p = uid2symbol(in->v.rcc_Global.p);
00240
00241 p->u.seg = in->v.rcc_Global.seg;
00242 (*IR->global)(p);
00243 p->defined = 1;
00244 }
|
Here is the call graph for this function:

|
|
Definition at line 231 of file pass2.c. References symbol::defined, interface::import, in, IR, p, Symbol, and uid2symbol(). 00231 {
00232 Symbol p = uid2symbol(in->v.rcc_Export.p);
00233
00234 (*IR->import)(p);
00235 p->defined = 1;
00236 }
|
Here is the call graph for this function:

|
|
Definition at line 246 of file pass2.c. References addlocal(), assert, in, items, nuids, NULL, uid2symbol(), and symbol::v. 00246 {
00247 int uid = in->v.rcc_Local.uid;
00248
00249 assert(uid >= 0 && uid < nuids);
00250 assert(items[uid] == NULL);
00251 items[uid] = rcc_Symbol(uid, in->v.rcc_Local.p);
00252 if (in->v.rcc_Local.p->scope >= LOCAL)
00253 addlocal(uid2symbol(uid));
00254 }
|
Here is the call graph for this function:

|
|
Definition at line 273 of file pass2.c. References in, IR, and interface::segment.
|
|
|
Definition at line 307 of file pass2.c. References in, IR, and interface::space.
|
|
||||||||||||
|
Definition at line 659 of file pass2.c. References argc, argv, main_init(), prof_init(), trace_init(), and type_init(). Referenced by Draw_ClearWindow(), Eclass_ForName(), main(), SV_RankBegin(), SV_RankUserCreate(), SV_RankUserLogin(), SV_RankUserValidate(), and UI_HeadCountByTeam(). 00659 {
00660 {extern void main_init(int, char *[]); main_init(argc, argv);}
00661 {extern void prof_init(int, char *[]); prof_init(argc, argv);}
00662 {extern void trace_init(int, char *[]); trace_init(argc, argv);}
00663 {extern void type_init(int, char *[]); type_init(argc, argv);}
00664 {extern void x86linux_init(int, char *[]); x86linux_init(argc, argv);}
00665 }
|
Here is the call graph for this function:

|
|
Definition at line 221 of file pass2.c. References assert, free(), and in. Referenced by doFunction(), and main().
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 511 of file pass2.c. References argc, argv, assert, bindings, count, deallocate(), errcnt, exit(), EXIT_FAILURE, fprint(), free(), freopen(), genlabel(), i, init(), interface(), IR, binding::ir, itemmap, items, j, level, name, binding::name, newarray, nuids, NULL, PERM, interface::progbeg, interface::progend, rcsid, stderr, stdin, stdout, strcmp(), strncmp(), strstr(), strtod(), interface::wants_dag, and xx. 00511 {
00512 int i, version;
00513 float stamp = (assert(strstr(rcsid, ",v")), strtod(strstr(rcsid, ",v")+2, NULL))
00514 ;
00515 char *infile = NULL, *outfile = NULL;
00516 rcc_program_ty pickle;
00517
00518 for (i = 1; i < argc; i++)
00519 if (*argv[i] != '-' || strcmp(argv[i], "-") == 0) {
00520 if (infile == NULL)
00521 infile = argv[i];
00522 else if (outfile == NULL)
00523 outfile = argv[i];
00524 }
00525 if (infile != NULL && strcmp(infile, "-") != 0
00526 && freopen(infile, "rb", stdin) == NULL) {
00527 fprint(stderr, "%s: can't read `%s'\n", argv[0], infile);
00528 exit(EXIT_FAILURE);
00529 }
00530 #if WIN32
00531 else
00532 _setmode(_fileno(stdin), _O_BINARY);
00533 #endif
00534 if (outfile != NULL && strcmp(outfile, "-") != 0
00535 && freopen(outfile, "w", stdout) == NULL) {
00536 fprint(stderr, "%s: can't write `%s'\n", argv[0], outfile);
00537 exit(EXIT_FAILURE);
00538 }
00539 version = read_int(stdin);
00540 assert(version/100 == (int)stamp);
00541 pickle = rcc_read_program(stdin);
00542 argc = pickle->argc;
00543 argv = newarray(argc + 1, sizeof *argv, PERM);
00544 {
00545 for (i = 0; i < argc; i++) {
00546 string_ty *arg = Seq_remlo(pickle->argv);
00547 argv[i] = (char *)arg->str;
00548 free(arg);
00549 }
00550 argv[i] = NULL;
00551 assert(i == argc);
00552 Seq_free(&pickle->argv);
00553 }
00554 for (i = argc - 1; i > 0; i--)
00555 if (strncmp(argv[i], "-target=", 8) == 0)
00556 break;
00557 if (i > 0) {
00558 int j;
00559 for (j = 0; bindings[j].name && bindings[j].ir; j++)
00560 if (strcmp(&argv[i][8], bindings[j].name) == 0) {
00561 IR = bindings[j].ir;
00562 break;
00563 }
00564 }
00565 if (!IR) {
00566 fprint(stderr, "%s: unknown target", argv[0]);
00567 if (i > 0)
00568 fprint(stderr, " `%s'", &argv[i][8]);
00569 fprint(stderr, "; must specify one of\n");
00570 for (i = 0; bindings[i].name; i++)
00571 fprint(stderr, "\t-target=%s\n", bindings[i].name);
00572 exit(EXIT_FAILURE);
00573 }
00574 IR->wants_dag = 0; /* pickle's hold trees */
00575 init(argc, argv);
00576 genlabel(pickle->nlabels);
00577 level = GLOBAL;
00578 {
00579 int i, count;
00580 nuids = pickle->nuids;
00581 items = newarray(nuids, sizeof *items, PERM);
00582 itemmap = newarray(nuids, sizeof *items, PERM);
00583 for (i = 0; i < nuids; i++) {
00584 itemmap[i] = NULL;
00585 items[i] = NULL;
00586 }
00587 (*IR->progbeg)(argc, argv);
00588 count = Seq_length(pickle->items);
00589 for (i = 0; i < count; i++) {
00590 rcc_item_ty item = Seq_remlo(pickle->items);
00591 int uid = item->uid;
00592 assert(uid >= 0 && uid < nuids);
00593 assert(items[uid] == NULL);
00594 items[uid] = item;
00595 }
00596 Seq_free(&pickle->items);
00597 #define xx(s) assert(rcc_##s##_enum < sizeof doX/sizeof doX[0] && doX[rcc_##s##_enum]==0); \
00598 doX[rcc_##s##_enum] = do##s;
00599 xx(Export)
00600 xx(Import)
00601 xx(Global)
00602 xx(Local)
00603 xx(Address)
00604 xx(Segment)
00605 xx(Defaddress)
00606 xx(Deflabel)
00607 xx(Defconst)
00608 xx(Defconstf)
00609 xx(Defstring)
00610 xx(Space)
00611 xx(Function)
00612 xx(Blockbeg)
00613 xx(Blockend)
00614 xx(Forest)
00615 #undef xx
00616 count = Seq_length(pickle->interfaces);
00617 for (i = 0; i < count; i++)
00618 interface(Seq_remlo(pickle->interfaces));
00619 Seq_free(&pickle->interfaces);
00620 free(pickle);
00621 (*IR->progend)();
00622 }
00623 deallocate(PERM);
00624 return errcnt > 0;
00625 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 628 of file pass2.c. References argv, assert, errlimit, exit(), EXIT_FAILURE, f, fclose(), fopen(), fprint(), freopen(), glevel, i, NULL, rcsid, stderr, strcmp(), strncmp(), strtol(), verbose, wflag, and x. Referenced by init(), and input_init(). 00628 {
00629 int i;
00630 static int inited;
00631
00632 if (inited)
00633 return;
00634 inited = 1;
00635 for (i = 1; i < argc; i++)
00636 if (strcmp(argv[i], "-g") == 0 || strcmp(argv[i], "-g2") == 0)
00637 glevel = 2;
00638 else if (strcmp(argv[i], "-w") == 0)
00639 wflag++;
00640 else if (strcmp(argv[i], "-v") == 0) {
00641 fprint(stderr, "%s %s\n", argv[0], rcsid);
00642 verbose++;
00643 } else if (strncmp(argv[i], "-errout=", 8) == 0) {
00644 FILE *f = fopen(argv[i]+8, "w");
00645 if (f == NULL) {
00646 fprint(stderr, "%s: can't write errors to `%s'\n", argv[0], argv[i]+8);
00647 exit(EXIT_FAILURE);
00648 }
00649 fclose(f);
00650 f = freopen(argv[i]+8, "w", stderr);
00651 assert(f);
00652 } else if (strncmp(argv[i], "-e", 2) == 0) {
00653 int x;
00654 if ((x = strtol(&argv[i][2], NULL, 0)) > 0)
00655 errlimit = x;
00656 }
00657 }
|
Here is the call graph for this function:

|
|
Definition at line 147 of file pass2.c. References assert, CONSTANTS, interface::defsymbol, free(), GLOBAL, IR, itemmap, items, kind, LABELS, symbol::name, NEW0, nuids, p, PERM, symbol::ref, symbol::sclass, symbol::scope, Symbol, temporary(), symbol::type, uid2type(), symbol::v, and xx. Referenced by doAddress(), doDefaddress(), doExport(), doFunction(), doGlobal(), doImport(), doLocal(), and visit(). 00147 {
00148 assert(uid >= 0 && uid < nuids);
00149 if (itemmap[uid] == NULL) {
00150 Symbol p;
00151 rcc_symbol_ty symbol;
00152 assert(items[uid]);
00153 assert(items[uid]->uid == uid);
00154 assert(items[uid]->kind == rcc_Symbol_enum);
00155 symbol = items[uid]->v.rcc_Symbol.symbol;
00156 assert(symbol);
00157 NEW0(p, PERM);
00158 p->name = (char *)symbol->id;
00159 p->scope = symbol->scope;
00160 p->sclass = symbol->sclass;
00161 p->type = uid2type(symbol->type);
00162 #define xx(f,n) p->f = symbol->flags>>n;
00163 xx(structarg,0)
00164 xx(addressed,1)
00165 xx(computed,2)
00166 xx(temporary,3)
00167 xx(generated,4)
00168 #undef xx
00169 p->ref = symbol->ref/10000.0;
00170 assert(p->scope != CONSTANTS && p->scope != LABELS);
00171 if (p->scope == GLOBAL || p->sclass == STATIC || p->sclass == EXTERN)
00172 (*IR->defsymbol)(p);
00173 itemmap[uid] = p;
00174 free(symbol);
00175 free(items[uid]);
00176 items[uid] = NULL;
00177 }
00178 return itemmap[uid];
00179 }
|
Here is the call graph for this function:

|
|
Definition at line 23 of file pass2.c. References type::align, array(), assert, btot(), symbol::cfields, CONST, e, ENUM, field(), Field, fields, symbol::flist, FLOAT, free(), func(), GLOBAL, i, identifiers, symbol::idlist, install(), INT, isconst, isvolatile, itemmap, items, kind, field::link, n, field::name, NEW0, newarray, newstruct(), nuids, NULL, p, PERM, ptr(), qual(), symbol::s, symbol::sclass, type::size, string(), STRUCT, type::sym, Symbol, tree::type, symbol::type, type::type, type, Type, symbol::u, type::u, UNION, UNSIGNED, symbol::value, symbol::vfields, and VOLATILE. Referenced by uid2symbol(), and visit(). 00023 {
00024 assert(uid >= 0 && uid < nuids);
00025 if (itemmap[uid] == NULL) {
00026 Type ty;
00027 rcc_type_ty type = (void *)items[uid];
00028 assert(items[uid]);
00029 assert(items[uid]->uid == uid);
00030 assert(items[uid]->kind == rcc_Type_enum);
00031 type = items[uid]->v.rcc_Type.type;
00032 assert(type);
00033 switch (type->kind) {
00034 case rcc_INT_enum:
00035 ty = btot(INT, type->size);
00036 assert(ty->align == type->align);
00037 break;
00038 case rcc_UNSIGNED_enum:
00039 ty = btot(UNSIGNED, type->size);
00040 assert(ty->align == type->align);
00041 break;
00042 case rcc_FLOAT_enum:
00043 ty = btot(FLOAT, type->size);
00044 assert(ty->align == type->align);
00045 break;
00046 case rcc_VOID_enum:
00047 ty = voidtype;
00048 break;
00049 case rcc_POINTER_enum:
00050 ty = ptr(uid2type(type->v.rcc_POINTER.type));
00051 break;
00052 case rcc_ARRAY_enum:
00053 ty = uid2type(type->v.rcc_ARRAY.type);
00054 assert(ty->size > 0);
00055 ty = array(ty, type->size/ty->size, 0);
00056 break;
00057 case rcc_CONST_enum:
00058 ty = qual(CONST, uid2type(type->v.rcc_CONST.type));
00059 break;
00060 case rcc_VOLATILE_enum:
00061 ty = qual(VOLATILE, uid2type(type->v.rcc_VOLATILE.type));
00062 break;
00063 case rcc_ENUM_enum: {
00064 int i, n = Seq_length(type->v.rcc_ENUM.ids);
00065 ty = newstruct(ENUM, string(type->v.rcc_ENUM.tag));
00066 ty->type = inttype;
00067 ty->size = ty->type->size;
00068 ty->align = ty->type->align;
00069 ty->u.sym->u.idlist = newarray(n + 1, sizeof *ty->u.sym->u.idlist, PERM);
00070 for (i = 0; i < n; i++) {
00071 rcc_enum__ty e = Seq_remlo(type->v.rcc_ENUM.ids);
00072 Symbol |