// TODO this looks like a dup of newConstProxySym? Symbol * newConstSymFromProxy(int lvl, char * id, ProxySymbol * proxySym) { Symbol * newConstSym = NULL; /* Error checking */ if (!proxySym) { /* Record error */ return NULL; } if (proxySym->kind != CONST_KIND) { /* Error: trying to declare constant with non-constant kind */ return NULL; } newConstSym = calloc(1, sizeof(Symbol)); if (!newConstSym) { err(1, "Failed to allocate memory for new const symbol!"); exit(1); } setSymbolName(newConstSym, id); newConstSym->kind = CONST_KIND; allocateKindPtr(newConstSym); setInnerTypeSymbol(newConstSym, getTypeSym(proxySym)); copyConstVal(&(newConstSym->kindPtr.ConstKind->value), getConstVal(proxySym), getType(proxySym)); newConstSym->lvl = lvl; return newConstSym; }
ProxySymbol * newProxySymFromSym(Symbol *s) { ProxySymbol *ps = NULL; if (!s) return NULL; ps = calloc(1, sizeof(ProxySymbol)); if (s->name) { setSymbolName((Symbol *)ps, s->name); } ps->kind = s->kind; ps->kindPtr = s->kindPtr; ps->typeOriginator = 0; ps->lvl = s->lvl; ps->offset = s->offset; ps->size = s->size; if (s->isAddress) { /* The old symbol sheds the flag of isAddress, this is for * protection in the case that s is a type symbol */ ps->isAddress = 1; s->isAddress = 0; } if (s->isRecordHead) ps->isRecordHead = 1; return ps; }
/* Main function */ int main(int argc, char **argv) { int i; /* Index to process commandline arguments */ /* Scan for a -h or --help option */ for (i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { /* Print command line arguments help and exit immediately */ printf("%s", commandLineHelp); return EXIT_SUCCESS; } } /* Scan for a -v or --version option */ for (i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version")) { /* Print version information and exit immediately */ printf("%s", versionInfo); return EXIT_SUCCESS; } } /* Process command line arguments */ for (i = 1; i < argc; ++i) { /* Check if it's an option or file name */ if (argv[i][0] == '-') { /* Process the option */ switch (argv[i][1]) { case '-': /* Long options */ if (!strcmp(argv[i], "--output")) { /* Name an output file */ openOutputFile(argv[i+1]); ++i; } else if (!strcmp(argv[i], "--header")) { /* Name a header file */ openHeaderFile(argv[i+1]); ++i; } else if (!strcmp(argv[i], "--macro")) { /* Create a macro for the size definition */ createMacro = true; } else if (!strcmp(argv[i], "--name")) { /* Name the symbol */ setSymbolName(argv[i+1]); ++i; } else { /* Unknown option */ handleUnknownOption(argv[i]); } break; case 'o': /* Name an output file */ openOutputFile(argv[i+1]); ++i; break; case 'd': /* Name a header file */ openHeaderFile(argv[i+1]); ++i; break; case 'm': /* Create a macro for the size definition */ createMacro = true; break; case 'n': /* Name the symbol */ setSymbolName(argv[i+1]); ++i; break; default: /* Unknown option */ handleUnknownOption(argv[i]); } } else { /* Process the file */ processFile(argv[i], 0, -1); } } /* Close any remaining output files */ if (headerFile) { header("\n#endif /* __%s_included */\n", headerSymbol); free(headerSymbol); headerSymbol = 0; check(!fclose(headerFile), cantClose, headerFileName); } if (outputFile) { check(!fclose(outputFile), cantClose, outputFileName); } return EXIT_SUCCESS; }