int main() { struct nlist *curr = NULL; // Give passwords to all of them install("meyling", "chickens"); install("ching", "cows"); install("robert", "poop"); install("meyling", "chickeneggs"); // Look them up curr = lookup("ching"); printf("ching's password: %s\n", curr->defn); curr = lookup("meyling"); printf("meyling's password: %s\n", curr->defn); curr = lookup("robert"); printf("robert's password: %s\n", curr->defn); // Remove some stuff undef("meyling"); curr = lookup("meyling"); if (curr == NULL) printf("Successfully removed meyling\n"); return 0; }
char * test_nlist() { unsigned ui; struct nlist *nl; /* ui = hash("how"); printf("how -> %u\n", ui); ui = hash("are"); printf("are -> %u\n", ui); ui = hash("you"); printf("you -> %u\n", ui); */ nl = install("how", "how"); nl = install("are", "are"); nl = install("you", "you"); nl = lookup("how"); mu_assert(nl != NULL, "did not find 'how'"); mu_assert(strcmp(nl->name, "how") == 0, "name is not 'how'"); mu_assert(strcmp(nl->defn, "how") == 0, "defn is not 'how'"); undef("how"); nl = lookup("how"); mu_assert(nl == NULL, "still find 'how'"); releaselist(); return NULL; }
int main() { char *test_input = "MAXSIZE"; char *test_output = "100"; struct nlist *np; install(test_input, test_output); np = lookup(test_input); printf("%s\n", np->defn); undef(test_input); np = lookup(test_input); if (np != NULL) printf("%s\n", np->defn); else printf("not found\n"); install(test_input, "200"); np = lookup(test_input); if (np != NULL) printf("%s\n", np->defn); else printf("not found\n"); }
void MongoStatusInfo::fromStatus(JSContext* cx, Status status, JS::MutableHandleValue value) { auto scope = getScope(cx); JS::RootedValue undef(cx); undef.setUndefined(); JS::AutoValueArray<1> args(cx); ValueReader(cx, args[0]).fromStringData(status.reason()); JS::RootedObject error(cx); scope->getProto<ErrorInfo>().newInstance(args, &error); JS::RootedObject thisv(cx); scope->getProto<MongoStatusInfo>().newObjectWithProto(&thisv, error); ObjectWrapper thisvObj(cx, thisv); thisvObj.defineProperty( InternedString::code, undef, JSPROP_ENUMERATE | JSPROP_SHARED, smUtils::wrapConstrainedMethod<Functions::code, false, MongoStatusInfo>); thisvObj.defineProperty( InternedString::reason, undef, JSPROP_ENUMERATE | JSPROP_SHARED, smUtils::wrapConstrainedMethod<Functions::reason, false, MongoStatusInfo>); JS_SetPrivate(thisv, scope->trackedNew<Status>(std::move(status))); value.setObjectOrNull(thisv); }
void install(wchar_t *nam, wchar_t *val, int mode) { struct nlist *np; wchar_t *cp; int l; if (mode == PUSH) (void) lookup(nam); /* lookup sets hshval */ else while (undef(nam)) /* undef calls lookup */ ; np = xcalloc(1, sizeof (*np)); np->name = wstrdup(nam); np->next = hshtab[hshval]; hshtab[hshval] = np; cp = xcalloc((l = wcslen(val))+1, sizeof (*val)); np->def = cp; cp = &cp[l]; while (*val) *--cp = *val++; }
extern void do_set (void) { char *mac; char c; char temp[64]; mac = read_ident(); if (! mac) { err_head(); fprintf(stderr, "@set: missing/illegal macro name\n"); return ; } if (! in_false_if()) { char *cp; c = getnonspace(); if (c != '(') { err_head(); fprintf(stderr, "@set must have ()s\n"); Push(c); return ; } os_sprintf(temp, "%d", eval_expr(0, 1)); undef(mac); cp = copyofstr(temp); check_os_malloc(cp); define(mac, -1, (unsigned char *) cp, DEF_DEFINE); } os_free(mac); }
void getdef(void) { int c, i; char def[MAXWORD], dir[MAXWORD], name[MAXWORD]; skipblanks(); if (!isalpha(getword(dir, MAXWORD))) error(dir[0], "getdef: expecting a directive after #"); else if (strcmp(dir, "define") == 0) { skipblanks(); if (!isalpha(getword(name, MAXWORD))) error(name[0], "getdef: non-alpha name expected"); else { skipblanks(); for (i = 0; i < MAXWORD; i++) if ((def[i] = getch()) == EOF || def[i] == '\n') break; def[i] = '\0'; if (i <= 0) error('\n', "getdef: incomplete define"); else install(name, def); } } else if (strcmp(dir, "undef") == 0) { skipblanks(); if (!isalpha(getword(name, MAXWORD))) error(name[0], "getdef: non-alpha in undef"); else undef(name); } else error(dir[0], "getdef: expecting a directive after #"); }
void define(const std::string& key, const std::string& value = "") { undef(key); m_defines[key] = value; m_defineHashValid = false; m_memHashValid = false; }
int main(int argc, char **argv) { install("one", "1"); install("thirty-two", "32"); printdef(); undef("one"); printdef(); return; }
int main(){ struct nlist* p; int c, i; for (i = 0; i < HASHSIZE; i++) hashtab[i] = NULL; char test[] = "Ralf"; char test2[] = "Rolf"; install(test, "1"); install(test2, "2"); printf("hash values: %d %d\n", hash("Ralf"), hash("Rolf")); p = lookup("Ralf"); if (p != NULL) printf("hash value of Ralf: %u, defn of Ralf: %s\n", hash(p->name), p->defn); c = undef("Anton"); if (c == -1) printf("Error: trying to undefine name that was never defined.\n"); c = undef("Ralf"); if (c == 0) printf("Undefined Ralf\n"); else printf("Error: can't undefine Ralf.\n"); p = lookup("Ralf"); if (p == NULL) printf("Error: trying to look up name that is not defined.\n"); install("Ralf", "7"); p = lookup("Ralf"); if (p != NULL) printf("%s is re-defined to now equal %s\n", p->name, p->defn); return 0; }
extern void autodef_file (const char * f) { int i; i = strlen (f); temp = os_malloc (i + 2 + 1); check_os_malloc (temp); os_sprintf ((char*) temp, "\"%s\"", f); undef ("__FILE__"); define ("__FILE__", -1, temp, DEF_DEFINE); }
void V3PreProcImp::define(FileLine* fl, const string& name, const string& value, const string& params, bool cmdline) { UINFO(4,"DEFINE '"<<name<<"' as '"<<value<<"' params '"<<params<<"'"<<endl); if (defExists(name)) { if (!(defValue(name)==value && defParams(name)==params)) { // Duplicate defs are OK fl->v3warn(REDEFMACRO,"Redefining existing define: "<<name<<", with different value: "<<value<<" "<<params); defFileline(name)->v3warn(REDEFMACRO,"Previous definition is here, with value: "<<defValue(name)<<" "<<defParams(name)); } undef(name); } m_defines.insert(make_pair(name, V3Define(fl, value, params, cmdline))); }
int main(void) { char *line = malloc(sizeof(char[STRLEN])); char directive[STRLEN]; char key[STRLEN]; char value[STRLEN]; while (fgets(line, STRLEN, stdin) != NULL) { if (line[0] != '#') { // Look up a defined key getword(&line, key); nlist *np; char **args; int numvars; if ((np = lookup(key)) == NULL) printf("Couldn't find a key name '%s'\n", key); else { if ((numvars = checkargs(&line, &args)) == 0) { for (np; np != NULL; np = np->next) if (strcmp(np->name, key) == 0) { printf("\t%s\n", np->defn); break; } } else printf("\t%s\n", insertargs(np->defn, np->args, args, np->numvars)); } } else if (getword(&line, directive) > 0) { // Execute a directive if (strcmp(directive, DEFINE) == 0) { char **args; int numvars; getword(&line, key); numvars = checkargs(&line, &args); trim(&line); strcpy(value, line); install(key, value, args, numvars); } else if (strcmp(directive, UNDEF) == 0) { getword(&line, key); undef(key); } else { printf("ERROR: Unknown directive '%s'\n", directive); } } } printf("\n"); system("pause"); return 0; }
main() { install("min", "100"); install("max", "1000"); struct nlist *p; p = lookup("min"); printf(p->defn); undef("min"); if (lookup("min") == NULL) printf("no found"); }
void OIDInfo::postInstall(JSContext* cx, JS::HandleObject global, JS::HandleObject proto) { JS::RootedValue undef(cx); undef.setUndefined(); if (!JS_DefinePropertyById(cx, proto, getScope(cx)->getInternedStringId(InternedString::str), undef, JSPROP_ENUMERATE | JSPROP_SHARED, smUtils::wrapConstrainedMethod<Functions::getter, true, OIDInfo>, nullptr)) { uasserted(ErrorCodes::JSInterpreterFailure, "Failed to JS_DefinePropertyById"); } }
int main(int argc, char *argv[]) { struct nlist *table[4] = { (install("key", "value")), (install("key1", "value1")), (install("key2", "value2")), (install("key3", "value3")) }; int i; for (i=0; i < 4; i++) { printf("%s->%s\n", table[i]->name, table[i]->defn); } undef("key"); undef("key3"); struct nlist *result; char *keys[4] = { "key", "key1", "key2", "key3" }; for (i = 0; i < 4; i++) { if ((result = lookup(keys[i])) == NULL) { printf("key not found\n"); } else { printf("%s->%s\n", result->name, result->defn); } } return 0; }
int main(void) { install("A", "1"); install("Y", "1"); install("Z", "1"); install("IN", "1"); install("OUT", "0"); install("MAXLINE", "1000"); install("SIZZ", "100"); install("SIZA", "12345"); print(); undef("SIZZ"); print(); return 0; }
// procdefn: process #define or #undef statement int procdefn(void) { char word[MAXWORD], val[MAXTOKEN]; int c, def; while ((c=getch()) != '#' && c != EOF); if (c == '#' && (c=getword(word,MAXWORD)) != EOF) if ((!strcmp(word,"define")||!strcmp(word,"undef"))) { def = word[0] == 'd'; if ((c=getword(word,MAXWORD)) != EOF) { c = gettoken(val,MAXTOKEN); if (def) install(word, *val != '\0' ? val : ""); else free((void *) undef(word)); } } return c; }
int main(int argc, char **argv) { install("hrishikesh", "barua"); install("hrishikesh1", "barua1"); // install("2hrishikesh", "barua2"); // install("3hrishikesh", "barua3"); // install("hrishikesh4", "barua4"); struct lnode *res = lookup("hrishikesh"); printf("%s\n", res == NULL ? "null" : res->value); undef("hrishikesh"); res = lookup("hrishikesh"); printf("%s\n", res == NULL ? "null" : res->value); // printf("%s\n", res); // res = lookup("hrishikesh1"); // printf("%s\n", res == NULL ? "null" : res->value); // res = lookup("2hrishikesh"); // printf("%s\n", res == NULL ? "null" : res->value); // res = lookup("3hrishikesh"); // printf("%s\n", res == NULL ? "null" : res->value); }
void getdef(){ char c; char dir[MAXWORD], name[MAXWORD], defn[MAXWORD]; skipblanks(); c = getword(dir, MAXWORD); if(!isalpha(dir[0])){ error(c, "getdef: expecting a directive after #"); } if(strcmp(dir, "define") == 0){ skipblanks(); c = getword(name, MAXWORD); if(!isalpha(name[0])){ error(c, "getdef: non-alpha - name expected"); }else{ skipblanks(); int i; for(i = 0; i < MAXWORD - 1; i++){ defn[i] = getch(); if(defn[i] == '\n' || defn[i] == EOF){ break; } } defn[i] = '\0'; if(i == 0){ error(c, "getdef: non-alpha - incompleted define"); }else{ install(name, defn); } } }else if(strcmp(dir, "undef") == 0){ skipblanks(); c = getword(name, MAXWORD); if(!isalpha(c)){ error(c, "getdef: non-alpha - in undef"); }else{ undef(name); } }else{ //error(c, "getdef: expecting a directive after #"); } }
void testmain(void) { print("macros"); special(); include(); predefined(); simple(); loop(); undef(); cond_incl(); const_expr(); defined(); ifdef(); funclike(); empty(); noarg(); line(); null(); counter(); gnuext(); }
/* main program */ int main( int argc, char **argv ) { char word[ MAX_WORD_LEN ]; Node node; char def[ MAX_WORD_LEN ]; while ( 1 ) { if ( isalpha( getword(word, MAX_WORD_LEN) ) ) { getword(def, MAX_WORD_LEN); if ( (node = install( word, def )) == NULL ) { printf( "error: low memory\n" ); break; } else { printf( "installed '%s -- %s'\n", node->name, node->def ); } } else { break; /* time for undef */ } } printf( "after install, the hashtable looks like:\n" ); hashwalk(); Node tmp = (Node) malloc( sizeof( *tmp ) ); while ( getword(word, MAX_WORD_LEN) != EOF ) { if ( lookup( word ) != NULL ) { printf( "macro '%s' is in the table\n", word ); } else { printf( "macro '%s' is not in the table\n", word ); } printf( "removing macro '%s'\n", word ); undef( word, tmp ); if ( strcmp( tmp->name, "####" ) == 0 ) { printf( "Whoops: No such macro '%s'\n", word ); } else { printf( "macro '%s' -- '%s', has been removed\n", tmp->name, tmp->def ); } } printf( "after undef, the hashtable looks like:\n" ); hashwalk(); free( tmp ); hashfree(); return 0; }
extern void do_undef (int sharp) { char *mac; if (! in_false_if()) { mac = read_ident(); if (! mac) { err_head(); fprintf(stderr, "missing/illegal macro name\n"); } else { undef (mac); } } if (sharp) { flush_sharp_line(); } }
void main(int argc, char *argv[]) { int c; Binit(&bso, 1, OWRITE); cout = -1; listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': /* output to (next arg) */ outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); break; case 'I': interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND if(argc != 1) usage(); mywhatsys(); // get goos if(HEADTYPE == -1) HEADTYPE = headtype(goos); if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = "8.out.exe"; else outfile = "8.out"; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hgarbunix: /* this is garbage */ HEADR = 20L+56L; if(INITTEXT == -1) INITTEXT = 0x40004CL; if(INITDAT == -1) INITDAT = 0x10000000L; if(INITRND == -1) INITRND = 0; break; case Hunixcoff: /* is unix coff */ HEADR = 0xd0L; if(INITTEXT == -1) INITTEXT = 0xd0; if(INITDAT == -1) INITDAT = 0x400000; if(INITRND == -1) INITRND = 0; break; case Hplan9x32: /* plan 9 */ tlsoffset = -8; HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4096+32; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hmsdoscom: /* MS-DOS .COM */ HEADR = 0; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hmsdosexe: /* fake MS-DOS .EXE */ HEADR = 0x200; if(INITTEXT == -1) INITTEXT = 0x0100; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; HEADR += (INITTEXT & 0xFFFF); if(debug['v']) Bprint(&bso, "HEADR = 0x%d\n", HEADR); break; case Hdarwin: /* apple MACH */ /* * OS X system constant - offset from %gs to our TLS. * Explained in ../../libcgo/darwin_386.c. */ tlsoffset = 0x468; machoinit(); HEADR = INITIAL_MACHO_HEADR; if(INITTEXT == -1) INITTEXT = 4096+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hlinux: /* elf32 executable */ case Hfreebsd: /* * ELF uses TLS offsets negative from %gs. * Translate 0(GS) and 4(GS) into -8(GS) and -4(GS). * Also known to ../../pkg/runtime/linux/386/sys.s * and ../../libcgo/linux_386.c. */ tlsoffset = -8; elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x08048000+HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hwindows: /* PE executable */ peinit(); HEADR = PEFILEHEADR; if(INITTEXT == -1) INITTEXT = PEBASE+PESECTHEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = PESECTALIGN; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); instinit(); zprg.link = P; zprg.pcond = P; zprg.back = 2; zprg.as = AGOK; zprg.from.type = D_NONE; zprg.from.index = D_NONE; zprg.from.scale = 1; zprg.to = zprg.from; pcstr = "%.6ux "; nuxiinit(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); deadcode(); patch(); follow(); doelf(); if(HEADTYPE == Hdarwin) domacho(); if(HEADTYPE == Hwindows) dope(); dostkoff(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); span(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { int c; char *p, *name, *val; Binit(&bso, 1, OWRITE); listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; nuxiinit(); p = getenv("GOARM"); if(p != nil && strcmp(p, "5") == 0) debug['F'] = 1; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'I': debug['I'] = 1; // denote cmdline interpreter override interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); case 'X': name = EARGF(usage()); val = EARGF(usage()); addstrdata(name, val); break; } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(HEADTYPE == -1) HEADTYPE = Hlinux; switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hnetbsd: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ debug['d'] = 0; // with dynamic linking tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m // this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing if(debug['F']) mark(rlookup("_sfloat", 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); noops(); dostkcheck(); span(); addexport(); // textaddress() functionality is handled in span() pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void define (const String& key, const String& value = "") { undef(key); m_defines.add(key, value); m_defineHashValid = false; m_memHashValid = false; }
void main(int argc, char *argv[]) { int c, i; char *p; Binit(&bso, 1, OWRITE); cout = -1; listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; p = getenv("GOARM"); if(p != nil && strcmp(p, "5") == 0) debug['F'] = 1; ARGBEGIN { default: c = ARGC(); if(c == 'l') usage(); if(c >= 0 && c < sizeof(debug)) debug[c]++; break; case 'o': outfile = EARGF(usage()); break; case 'E': INITENTRY = EARGF(usage()); break; case 'I': interpreter = EARGF(usage()); break; case 'L': Lflag(EARGF(usage())); break; case 'T': INITTEXT = atolwhex(EARGF(usage())); break; case 'D': INITDAT = atolwhex(EARGF(usage())); break; case 'R': INITRND = atolwhex(EARGF(usage())); break; case 'r': rpath = EARGF(usage()); break; case 'H': HEADTYPE = headtype(EARGF(usage())); /* do something about setting INITTEXT */ break; case 'V': print("%cl version %s\n", thechar, getgoversion()); errorexit(); } ARGEND USED(argc); if(argc != 1) usage(); libinit(); if(!debug['9'] && !debug['U'] && !debug['B']) debug[DEFAULT] = 1; if(HEADTYPE == -1) { if(debug['U']) HEADTYPE = Hnoheader; if(debug['B']) HEADTYPE = Hrisc; if(debug['9']) HEADTYPE = Hplan9x32; HEADTYPE = Hlinux; } switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hnetbsd: /* boot for NetBSD */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 0xF0000020L; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ debug['d'] = 1; // no dynamic linking elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; nuxiinit(); version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing // TODO(kaib): this doesn't work, the prog can't be found in runtime for(i=0; i<nelem(linkername); i++) mark(lookup(linkername[i], 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); noops(); dostkcheck(); span(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { char *p; Sym *s; Binit(&bso, 1, OWRITE); listinit(); nerrors = 0; outfile = "5.out"; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; linkmode = LinkAuto; nuxiinit(); p = getgoarm(); if(p != nil) goarm = atoi(p); else goarm = 6; if(goarm == 5) debug['F'] = 1; flagcount("1", "use alternate profiling code", &debug['1']); flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo); flagstr("E", "sym: entry symbol", &INITENTRY); flagint32("D", "addr: data address", &INITDAT); flagcount("G", "debug pseudo-ops", &debug['G']); flagfn1("I", "interp: set ELF interp", setinterp); flagfn1("L", "dir: add dir to library path", Lflag); flagfn1("H", "head: header type", setheadtype); flagcount("K", "add stack underflow checks", &debug['K']); flagcount("M", "disable software div/mod", &debug['M']); flagcount("O", "print pc-line tables", &debug['O']); flagcount("P", "debug code generation", &debug['P']); flagint32("R", "rnd: address rounding", &INITRND); flagint32("T", "addr: text address", &INITTEXT); flagfn0("V", "print version and exit", doversion); flagcount("W", "disassemble input", &debug['W']); flagfn2("X", "name value: define string data", addstrdata); flagcount("Z", "clear stack frame on entry", &debug['Z']); flagcount("a", "disassemble output", &debug['a']); flagcount("c", "dump call graph", &debug['c']); flagcount("d", "disable dynamic executable", &debug['d']); flagstr("extld", "linker to run in external mode", &extld); flagstr("extldflags", "flags for external linker", &extldflags); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); flagstr("k", "sym: set field tracking symbol", &tracksym); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagcount("n", "dump symbol table", &debug['n']); flagstr("o", "outfile: set output file", &outfile); flagcount("p", "insert profiling code", &debug['p']); flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); flagcount("race", "enable race detector", &flag_race); flagcount("s", "disable symbol table", &debug['s']); flagcount("shared", "generate shared object (implies -linkmode external)", &flag_shared); flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); flagcount("u", "reject unsafe packages", &debug['u']); flagcount("v", "print link trace", &debug['v']); flagcount("w", "disable DWARF generation", &debug['w']); flagparse(&argc, &argv, usage); if(argc != 1) usage(); if(flag_shared) linkmode = LinkExternal; mywhatsys(); if(HEADTYPE == -1) HEADTYPE = headtype(goos); // getgoextlinkenabled is based on GO_EXTLINK_ENABLED when // Go was built; see ../../make.bash. if(linkmode == LinkAuto && strcmp(getgoextlinkenabled(), "0") == 0) linkmode = LinkInternal; switch(HEADTYPE) { default: if(linkmode == LinkAuto) linkmode = LinkInternal; if(linkmode == LinkExternal && strcmp(getgoextlinkenabled(), "1") != 0) sysfatal("cannot use -linkmode=external with -H %s", headstr(HEADTYPE)); break; case Hlinux: break; } libinit(); switch(HEADTYPE) { default: diag("unknown -H option"); errorexit(); case Hnoheader: /* no header */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hrisc: /* aif for risc os */ HEADR = 128L; if(INITTEXT == -1) INITTEXT = 0x10005000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hplan9x32: /* plan 9 */ HEADR = 32L; if(INITTEXT == -1) INITTEXT = 4128; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; case Hixp1200: /* boot for IXP1200 */ HEADR = 0L; if(INITTEXT == -1) INITTEXT = 0x0; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4; break; case Hipaq: /* boot for ipaq */ HEADR = 16L; if(INITTEXT == -1) INITTEXT = 0xC0008010; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 1024; break; case Hlinux: /* arm elf */ case Hfreebsd: case Hnetbsd: debug['d'] = 0; // with dynamic linking tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m // this number is known to ../../pkg/runtime/rt0_*_arm.s elfinit(); HEADR = ELFRESERVE; if(INITTEXT == -1) INITTEXT = 0x10000 + HEADR; if(INITDAT == -1) INITDAT = 0; if(INITRND == -1) INITRND = 4096; break; } if(INITDAT != 0 && INITRND != 0) print("warning: -D0x%ux is ignored because of -R0x%ux\n", INITDAT, INITRND); if(debug['v']) Bprint(&bso, "HEADER = -H0x%d -T0x%ux -D0x%ux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); zprg.as = AGOK; zprg.scond = 14; zprg.reg = NREG; zprg.from.name = D_NONE; zprg.from.type = D_NONE; zprg.from.reg = NREG; zprg.to = zprg.from; buildop(); histgen = 0; pc = 0; dtype = 4; version = 0; cbp = buf.cbuf; cbc = sizeof(buf.cbuf); // embed goarm to runtime.goarm s = lookup("runtime.goarm", 0); s->dupok = 1; adduint8(s, goarm); addlibpath("command line", "command line", argv[0], "main"); loadlib(); // mark some functions that are only referenced after linker code editing if(debug['F']) mark(rlookup("_sfloat", 0)); mark(lookup("runtime.read_tls_fallback", 0)); deadcode(); if(textp == nil) { diag("no code"); errorexit(); } patch(); if(debug['p']) if(debug['1']) doprof1(); else doprof2(); doelf(); follow(); softfloat(); // 5l -Z means zero the stack frame on entry. // This slows down function calls but can help avoid // false positives in garbage collection. if(debug['Z']) dozerostk(); noops(); // generate stack split prolog, handle div/mod, etc. dostkcheck(); span(); addexport(); // textaddress() functionality is handled in span() pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); hostlink(); if(debug['c']) print("ARM size = %d\n", armsize); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d sizeof adr\n", sizeof(Adr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); } Bflush(&bso); errorexit(); }
void main(int argc, char *argv[]) { linkarchinit(); ctxt = linknew(thelinkarch); ctxt->thechar = thechar; ctxt->thestring = thestring; ctxt->diag = diag; ctxt->bso = &bso; Binit(&bso, 1, OWRITE); listinit(); memset(debug, 0, sizeof(debug)); nerrors = 0; outfile = nil; HEADTYPE = -1; INITTEXT = -1; INITDAT = -1; INITRND = -1; INITENTRY = 0; linkmode = LinkAuto; nuxiinit(); if(thechar == '5' && ctxt->goarm == 5) debug['F'] = 1; flagcount("1", "use alternate profiling code", &debug['1']); if(thechar == '6') flagcount("8", "assume 64-bit addresses", &debug['8']); flagfn1("B", "info: define ELF NT_GNU_BUILD_ID note", addbuildinfo); flagint64("D", "addr: data address", &INITDAT); flagstr("E", "sym: entry symbol", &INITENTRY); if(thechar == '5') flagcount("G", "debug pseudo-ops", &debug['G']); flagfn1("I", "interp: set ELF interp", setinterp); flagfn1("L", "dir: add dir to library path", Lflag); flagfn1("H", "head: header type", setheadtype); flagcount("K", "add stack underflow checks", &debug['K']); if(thechar == '5') flagcount("M", "disable software div/mod", &debug['M']); flagcount("O", "print pc-line tables", &debug['O']); flagcount("Q", "debug byte-register code gen", &debug['Q']); if(thechar == '5') flagcount("P", "debug code generation", &debug['P']); flagint32("R", "rnd: address rounding", &INITRND); flagcount("S", "check type signatures", &debug['S']); flagint64("T", "addr: text address", &INITTEXT); flagfn0("V", "print version and exit", doversion); flagcount("W", "disassemble input", &debug['W']); flagfn2("X", "name value: define string data", addstrdata); flagcount("Z", "clear stack frame on entry", &debug['Z']); flagcount("a", "disassemble output", &debug['a']); flagcount("c", "dump call graph", &debug['c']); flagcount("d", "disable dynamic executable", &debug['d']); flagstr("extld", "linker to run in external mode", &extld); flagstr("extldflags", "flags for external linker", &extldflags); flagcount("f", "ignore version mismatch", &debug['f']); flagcount("g", "disable go package data checks", &debug['g']); flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix); flagstr("k", "sym: set field tracking symbol", &tracksym); flagfn1("linkmode", "mode: set link mode (internal, external, auto)", setlinkmode); flagcount("n", "dump symbol table", &debug['n']); flagstr("o", "outfile: set output file", &outfile); flagstr("r", "dir1:dir2:...: set ELF dynamic linker search path", &rpath); flagcount("race", "enable race detector", &flag_race); flagcount("s", "disable symbol table", &debug['s']); if(thechar == '5' || thechar == '6') flagcount("shared", "generate shared object (implies -linkmode external)", &flag_shared); flagstr("tmpdir", "leave temporary files in this directory", &tmpdir); flagcount("u", "reject unsafe packages", &debug['u']); flagcount("v", "print link trace", &debug['v']); flagcount("w", "disable DWARF generation", &debug['w']); flagparse(&argc, &argv, usage); ctxt->bso = &bso; ctxt->debugdivmod = debug['M']; ctxt->debugfloat = debug['F']; ctxt->debughist = debug['O']; ctxt->debugpcln = debug['O']; ctxt->debugread = debug['W']; ctxt->debugstack = debug['K']; ctxt->debugvlog = debug['v']; if(argc != 1) usage(); if(outfile == nil) { if(HEADTYPE == Hwindows) outfile = smprint("%c.out.exe", thechar); else outfile = smprint("%c.out", thechar); } libinit(); // creates outfile if(HEADTYPE == -1) HEADTYPE = headtype(goos); ctxt->headtype = HEADTYPE; if (headstring == nil) headstring = headstr(HEADTYPE); archinit(); ctxt->debugfloat = debug['F']; if(debug['v']) Bprint(&bso, "HEADER = -H%d -T0x%llux -D0x%llux -R0x%ux\n", HEADTYPE, INITTEXT, INITDAT, INITRND); Bflush(&bso); cbp = buf.cbuf; cbc = sizeof(buf.cbuf); addlibpath(ctxt, "command line", "command line", argv[0], "main"); loadlib(); if(thechar == '5') { // mark some functions that are only referenced after linker code editing if(debug['F']) mark(linkrlookup(ctxt, "_sfloat", 0)); mark(linklookup(ctxt, "runtime.read_tls_fallback", 0)); } deadcode(); callgraph(); paramspace = "SP"; /* (FP) now (SP) on output */ doelf(); if(HEADTYPE == Hdarwin) domacho(); dostkcheck(); if(HEADTYPE == Hwindows) dope(); addexport(); textaddress(); pclntab(); symtab(); dodata(); address(); doweak(); reloc(); asmb(); undef(); hostlink(); if(debug['v']) { Bprint(&bso, "%5.2f cpu time\n", cputime()); Bprint(&bso, "%d symbols\n", ctxt->nsymbol); Bprint(&bso, "%d sizeof adr\n", sizeof(Addr)); Bprint(&bso, "%d sizeof prog\n", sizeof(Prog)); Bprint(&bso, "%lld liveness data\n", liveness); } Bflush(&bso); errorexit(); }
int main() { int i; char name[] = "AAA"; struct nlist *np; /* initilize the hash table */ for (i = 0; i < HASHSIZE; i++) { hashtab[i] = NULL; } while (1) { install(name, name); name[2]++; if (name[2] == 'Z'+1) { if (name[1] == 'Z') { if (name[0] == 'Z') { break; } name[0]++; name[1] = 'A'; name[2] = 'A'; } else { name[1]++; name[2] = 'A'; } } } strcpy(name, "AAA"); while (1) { if (lookup(name) == NULL) { printf("%s was NOT found\n", name); } else { printf("%s was found\n", name); } name[2]++; if (name[2] == 'Z'+1) { if (name[1] == 'Z') { if (name[0] == 'Z') { break; } name[0]++; name[1] = 'A'; name[2] = 'A'; } else { name[1]++; name[2] = 'A'; } } } undef("CCC"); /* remove a random name */ undef("---"); /* remove a name that does not exist */ undef("AAA"); /* remove a node in hashtab */ strcpy(name, "AAA"); while (1) { if (lookup(name) == NULL) { printf("%s was NOT found\n", name); } else { printf("%s was found\n", name); } name[2]++; if (name[2] == 'Z'+1) { if (name[1] == 'Z') { if (name[0] == 'Z') { break; } name[0]++; name[1] = 'A'; name[2] = 'A'; } else { name[1]++; name[2] = 'A'; } } } return (0); }