obj.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. #define EXTERN
  2. #include "l.h"
  3. #include <ar.h>
  4. #ifndef DEFAULT
  5. #define DEFAULT '9'
  6. #endif
  7. char *noname = "<none>";
  8. char symname[] = SYMDEF;
  9. char thechar = '8';
  10. char *thestring = "386";
  11. /*
  12. * -H0 -T0x40004C -D0x10000000 is garbage unix
  13. * -H1 -T0xd0 -R4 is unix coff
  14. * -H2 -T4128 -R4096 is plan9 format
  15. * -H3 -Tx -Rx is MS-DOS .COM
  16. * -H4 -Tx -Rx is fake MS-DOS .EXE
  17. * -H5 -T0x80100020 -R4096 is ELF
  18. */
  19. static int
  20. isobjfile(char *f)
  21. {
  22. int n, v;
  23. Biobuf *b;
  24. char buf1[5], buf2[SARMAG];
  25. b = Bopen(f, OREAD);
  26. if(b == nil)
  27. return 0;
  28. n = Bread(b, buf1, 5);
  29. if(n == 5 && (buf1[2] == 1 && buf1[3] == '<' || buf1[3] == 1 && buf1[4] == '<'))
  30. v = 1; /* good enough for our purposes */
  31. else{
  32. Bseek(b, 0, 0);
  33. n = Bread(b, buf2, SARMAG);
  34. v = n == SARMAG && strncmp(buf2, ARMAG, SARMAG) == 0;
  35. }
  36. Bterm(b);
  37. return v;
  38. }
  39. void
  40. main(int argc, char *argv[])
  41. {
  42. int i, c;
  43. char *a;
  44. Binit(&bso, 1, OWRITE);
  45. cout = -1;
  46. listinit();
  47. memset(debug, 0, sizeof(debug));
  48. nerrors = 0;
  49. outfile = "8.out";
  50. HEADTYPE = -1;
  51. INITTEXT = -1;
  52. INITDAT = -1;
  53. INITRND = -1;
  54. INITENTRY = 0;
  55. ARGBEGIN {
  56. default:
  57. c = ARGC();
  58. if(c >= 0 && c < sizeof(debug))
  59. debug[c]++;
  60. break;
  61. case 'o': /* output to (next arg) */
  62. outfile = ARGF();
  63. break;
  64. case 'E':
  65. a = ARGF();
  66. if(a)
  67. INITENTRY = a;
  68. break;
  69. case 'H':
  70. a = ARGF();
  71. if(a)
  72. HEADTYPE = atolwhex(a);
  73. break;
  74. case 'T':
  75. a = ARGF();
  76. if(a)
  77. INITTEXT = atolwhex(a);
  78. break;
  79. case 'D':
  80. a = ARGF();
  81. if(a)
  82. INITDAT = atolwhex(a);
  83. break;
  84. case 'R':
  85. a = ARGF();
  86. if(a)
  87. INITRND = atolwhex(a);
  88. break;
  89. case 'x': /* produce export table */
  90. doexp = 1;
  91. if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
  92. readundefs(ARGF(), SEXPORT);
  93. break;
  94. case 'u': /* produce dynamically loadable module */
  95. dlm = 1;
  96. debug['l']++;
  97. if(argv[1] != nil && argv[1][0] != '-' && !isobjfile(argv[1]))
  98. readundefs(ARGF(), SIMPORT);
  99. break;
  100. } ARGEND
  101. USED(argc);
  102. if(*argv == 0) {
  103. diag("usage: 8l [-options] objects");
  104. errorexit();
  105. }
  106. if(!debug['9'] && !debug['U'] && !debug['B'])
  107. debug[DEFAULT] = 1;
  108. if(HEADTYPE == -1) {
  109. if(debug['U'])
  110. HEADTYPE = 1;
  111. if(debug['B'])
  112. HEADTYPE = 2;
  113. if(debug['9'])
  114. HEADTYPE = 2;
  115. }
  116. switch(HEADTYPE) {
  117. default:
  118. diag("unknown -H option");
  119. errorexit();
  120. case 0: /* this is garbage */
  121. HEADR = 20L+56L;
  122. if(INITTEXT == -1)
  123. INITTEXT = 0x40004CL;
  124. if(INITDAT == -1)
  125. INITDAT = 0x10000000L;
  126. if(INITRND == -1)
  127. INITRND = 0;
  128. break;
  129. case 1: /* is unix coff */
  130. HEADR = 0xd0L;
  131. if(INITTEXT == -1)
  132. INITTEXT = 0xd0;
  133. if(INITDAT == -1)
  134. INITDAT = 0x400000;
  135. if(INITRND == -1)
  136. INITRND = 0;
  137. break;
  138. case 2: /* plan 9 */
  139. HEADR = 32L;
  140. if(INITTEXT == -1)
  141. INITTEXT = 4096+32;
  142. if(INITDAT == -1)
  143. INITDAT = 0;
  144. if(INITRND == -1)
  145. INITRND = 4096;
  146. break;
  147. case 3: /* MS-DOS .COM */
  148. HEADR = 0;
  149. if(INITTEXT == -1)
  150. INITTEXT = 0x0100;
  151. if(INITDAT == -1)
  152. INITDAT = 0;
  153. if(INITRND == -1)
  154. INITRND = 4;
  155. break;
  156. case 4: /* fake MS-DOS .EXE */
  157. HEADR = 0x200;
  158. if(INITTEXT == -1)
  159. INITTEXT = 0x0100;
  160. if(INITDAT == -1)
  161. INITDAT = 0;
  162. if(INITRND == -1)
  163. INITRND = 4;
  164. HEADR += (INITTEXT & 0xFFFF);
  165. if(debug['v'])
  166. Bprint(&bso, "HEADR = 0x%ld\n", HEADR);
  167. break;
  168. case 5: /* elf executable */
  169. HEADR = rnd(52L+3*32L, 16);
  170. if(INITTEXT == -1)
  171. INITTEXT = 0x80100020L;
  172. if(INITDAT == -1)
  173. INITDAT = 0;
  174. if(INITRND == -1)
  175. INITRND = 4096;
  176. break;
  177. }
  178. if(INITDAT != 0 && INITRND != 0)
  179. print("warning: -D0x%lux is ignored because of -R0x%lux\n",
  180. INITDAT, INITRND);
  181. if(debug['v'])
  182. Bprint(&bso, "HEADER = -H0x%ld -T0x%lux -D0x%lux -R0x%lux\n",
  183. HEADTYPE, INITTEXT, INITDAT, INITRND);
  184. Bflush(&bso);
  185. for(i=1; optab[i].as; i++)
  186. if(i != optab[i].as) {
  187. diag("phase error in optab: %d", i);
  188. errorexit();
  189. }
  190. for(i=0; i<Ymax; i++)
  191. ycover[i*Ymax + i] = 1;
  192. ycover[Yi0*Ymax + Yi8] = 1;
  193. ycover[Yi1*Ymax + Yi8] = 1;
  194. ycover[Yi0*Ymax + Yi32] = 1;
  195. ycover[Yi1*Ymax + Yi32] = 1;
  196. ycover[Yi8*Ymax + Yi32] = 1;
  197. ycover[Yal*Ymax + Yrb] = 1;
  198. ycover[Ycl*Ymax + Yrb] = 1;
  199. ycover[Yax*Ymax + Yrb] = 1;
  200. ycover[Ycx*Ymax + Yrb] = 1;
  201. ycover[Yrx*Ymax + Yrb] = 1;
  202. ycover[Yax*Ymax + Yrx] = 1;
  203. ycover[Ycx*Ymax + Yrx] = 1;
  204. ycover[Yax*Ymax + Yrl] = 1;
  205. ycover[Ycx*Ymax + Yrl] = 1;
  206. ycover[Yrx*Ymax + Yrl] = 1;
  207. ycover[Yf0*Ymax + Yrf] = 1;
  208. ycover[Yal*Ymax + Ymb] = 1;
  209. ycover[Ycl*Ymax + Ymb] = 1;
  210. ycover[Yax*Ymax + Ymb] = 1;
  211. ycover[Ycx*Ymax + Ymb] = 1;
  212. ycover[Yrx*Ymax + Ymb] = 1;
  213. ycover[Yrb*Ymax + Ymb] = 1;
  214. ycover[Ym*Ymax + Ymb] = 1;
  215. ycover[Yax*Ymax + Yml] = 1;
  216. ycover[Ycx*Ymax + Yml] = 1;
  217. ycover[Yrx*Ymax + Yml] = 1;
  218. ycover[Yrl*Ymax + Yml] = 1;
  219. ycover[Ym*Ymax + Yml] = 1;
  220. for(i=0; i<D_NONE; i++) {
  221. reg[i] = -1;
  222. if(i >= D_AL && i <= D_BH)
  223. reg[i] = (i-D_AL) & 7;
  224. if(i >= D_AX && i <= D_DI)
  225. reg[i] = (i-D_AX) & 7;
  226. if(i >= D_F0 && i <= D_F0+7)
  227. reg[i] = (i-D_F0) & 7;
  228. }
  229. zprg.link = P;
  230. zprg.pcond = P;
  231. zprg.back = 2;
  232. zprg.as = AGOK;
  233. zprg.from.type = D_NONE;
  234. zprg.from.index = D_NONE;
  235. zprg.from.scale = 1;
  236. zprg.to = zprg.from;
  237. pcstr = "%.6lux ";
  238. nuxiinit();
  239. histgen = 0;
  240. textp = P;
  241. datap = P;
  242. edatap = P;
  243. pc = 0;
  244. dtype = 4;
  245. cout = create(outfile, 1, 0775);
  246. if(cout < 0) {
  247. diag("cannot create %s", outfile);
  248. errorexit();
  249. }
  250. version = 0;
  251. cbp = buf.cbuf;
  252. cbc = sizeof(buf.cbuf);
  253. firstp = prg();
  254. lastp = firstp;
  255. if(INITENTRY == 0) {
  256. INITENTRY = "_main";
  257. if(debug['p'])
  258. INITENTRY = "_mainp";
  259. if(!debug['l'])
  260. lookup(INITENTRY, 0)->type = SXREF;
  261. } else
  262. lookup(INITENTRY, 0)->type = SXREF;
  263. while(*argv)
  264. objfile(*argv++);
  265. if(!debug['l'])
  266. loadlib();
  267. firstp = firstp->link;
  268. if(firstp == P)
  269. errorexit();
  270. if(doexp || dlm){
  271. EXPTAB = "_exporttab";
  272. zerosig(EXPTAB);
  273. zerosig("etext");
  274. zerosig("edata");
  275. zerosig("end");
  276. if(dlm){
  277. import();
  278. HEADTYPE = 2;
  279. INITTEXT = INITDAT = 0;
  280. INITRND = 8;
  281. INITENTRY = EXPTAB;
  282. }
  283. export();
  284. }
  285. patch();
  286. follow();
  287. dodata();
  288. dostkoff();
  289. if(debug['p'])
  290. if(debug['1'])
  291. doprof1();
  292. else
  293. doprof2();
  294. span();
  295. doinit();
  296. asmb();
  297. undef();
  298. if(debug['v']) {
  299. Bprint(&bso, "%5.2f cpu time\n", cputime());
  300. Bprint(&bso, "%ld symbols\n", nsymbol);
  301. Bprint(&bso, "%ld memory used\n", thunk);
  302. Bprint(&bso, "%d sizeof adr\n", sizeof(Adr));
  303. Bprint(&bso, "%d sizeof prog\n", sizeof(Prog));
  304. }
  305. Bflush(&bso);
  306. errorexit();
  307. }
  308. void
  309. loadlib(void)
  310. {
  311. int i;
  312. long h;
  313. Sym *s;
  314. loop:
  315. xrefresolv = 0;
  316. for(i=0; i<libraryp; i++) {
  317. if(debug['v'])
  318. Bprint(&bso, "%5.2f autolib: %s (from %s)\n", cputime(), library[i], libraryobj[i]);
  319. objfile(library[i]);
  320. }
  321. if(xrefresolv)
  322. for(h=0; h<nelem(hash); h++)
  323. for(s = hash[h]; s != S; s = s->link)
  324. if(s->type == SXREF)
  325. goto loop;
  326. }
  327. void
  328. errorexit(void)
  329. {
  330. if(nerrors) {
  331. if(cout >= 0)
  332. remove(outfile);
  333. exits("error");
  334. }
  335. exits(0);
  336. }
  337. void
  338. objfile(char *file)
  339. {
  340. long off, esym, cnt, l;
  341. int f, work;
  342. Sym *s;
  343. char magbuf[SARMAG];
  344. char name[100], pname[150];
  345. struct ar_hdr arhdr;
  346. char *e, *start, *stop;
  347. if(file[0] == '-' && file[1] == 'l') {
  348. if(debug['9'])
  349. sprint(name, "/%s/lib/lib", thestring);
  350. else
  351. sprint(name, "/usr/%clib/lib", thechar);
  352. strcat(name, file+2);
  353. strcat(name, ".a");
  354. file = name;
  355. }
  356. if(debug['v'])
  357. Bprint(&bso, "%5.2f ldobj: %s\n", cputime(), file);
  358. Bflush(&bso);
  359. f = open(file, 0);
  360. if(f < 0) {
  361. diag("cannot open file: %s", file);
  362. errorexit();
  363. }
  364. l = read(f, magbuf, SARMAG);
  365. if(l != SARMAG || strncmp(magbuf, ARMAG, SARMAG)){
  366. /* load it as a regular file */
  367. l = seek(f, 0L, 2);
  368. seek(f, 0L, 0);
  369. ldobj(f, l, file);
  370. close(f);
  371. return;
  372. }
  373. l = read(f, &arhdr, SAR_HDR);
  374. if(l != SAR_HDR) {
  375. diag("%s: short read on archive file symbol header", file);
  376. goto out;
  377. }
  378. if(strncmp(arhdr.name, symname, strlen(symname))) {
  379. diag("%s: first entry not symbol header", file);
  380. goto out;
  381. }
  382. esym = SARMAG + SAR_HDR + atolwhex(arhdr.size);
  383. off = SARMAG + SAR_HDR;
  384. /*
  385. * just bang the whole symbol file into memory
  386. */
  387. seek(f, off, 0);
  388. cnt = esym - off;
  389. start = malloc(cnt + 10);
  390. cnt = read(f, start, cnt);
  391. if(cnt <= 0){
  392. close(f);
  393. return;
  394. }
  395. stop = &start[cnt];
  396. memset(stop, 0, 10);
  397. work = 1;
  398. while(work) {
  399. if(debug['v'])
  400. Bprint(&bso, "%5.2f library pass: %s\n", cputime(), file);
  401. Bflush(&bso);
  402. work = 0;
  403. for(e = start; e < stop; e = strchr(e+5, 0) + 1) {
  404. s = lookup(e+5, 0);
  405. if(s->type != SXREF)
  406. continue;
  407. sprint(pname, "%s(%s)", file, s->name);
  408. if(debug['v'])
  409. Bprint(&bso, "%5.2f library: %s\n", cputime(), pname);
  410. Bflush(&bso);
  411. l = e[1] & 0xff;
  412. l |= (e[2] & 0xff) << 8;
  413. l |= (e[3] & 0xff) << 16;
  414. l |= (e[4] & 0xff) << 24;
  415. seek(f, l, 0);
  416. l = read(f, &arhdr, SAR_HDR);
  417. if(l != SAR_HDR)
  418. goto bad;
  419. if(strncmp(arhdr.fmag, ARFMAG, sizeof(arhdr.fmag)))
  420. goto bad;
  421. l = atolwhex(arhdr.size);
  422. ldobj(f, l, pname);
  423. if(s->type == SXREF) {
  424. diag("%s: failed to load: %s", file, s->name);
  425. errorexit();
  426. }
  427. work = 1;
  428. xrefresolv = 1;
  429. }
  430. }
  431. return;
  432. bad:
  433. diag("%s: bad or out of date archive", file);
  434. out:
  435. close(f);
  436. }
  437. int
  438. zaddr(uchar *p, Adr *a, Sym *h[])
  439. {
  440. int c, t, i;
  441. long l;
  442. Sym *s;
  443. Auto *u;
  444. t = p[0];
  445. c = 1;
  446. if(t & T_INDEX) {
  447. a->index = p[c];
  448. a->scale = p[c+1];
  449. c += 2;
  450. } else {
  451. a->index = D_NONE;
  452. a->scale = 0;
  453. }
  454. a->offset = 0;
  455. if(t & T_OFFSET) {
  456. a->offset = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
  457. c += 4;
  458. }
  459. a->sym = S;
  460. if(t & T_SYM) {
  461. a->sym = h[p[c]];
  462. c++;
  463. }
  464. a->type = D_NONE;
  465. if(t & T_FCONST) {
  466. a->ieee.l = p[c] | (p[c+1]<<8) | (p[c+2]<<16) | (p[c+3]<<24);
  467. a->ieee.h = p[c+4] | (p[c+5]<<8) | (p[c+6]<<16) | (p[c+7]<<24);
  468. c += 8;
  469. a->type = D_FCONST;
  470. } else
  471. if(t & T_SCONST) {
  472. for(i=0; i<NSNAME; i++)
  473. a->scon[i] = p[c+i];
  474. c += NSNAME;
  475. a->type = D_SCONST;
  476. }
  477. if(t & T_TYPE) {
  478. a->type = p[c];
  479. c++;
  480. }
  481. s = a->sym;
  482. if(s == S)
  483. return c;
  484. t = a->type;
  485. if(t != D_AUTO && t != D_PARAM)
  486. return c;
  487. l = a->offset;
  488. for(u=curauto; u; u=u->link) {
  489. if(u->asym == s)
  490. if(u->type == t) {
  491. if(u->aoffset > l)
  492. u->aoffset = l;
  493. return c;
  494. }
  495. }
  496. while(nhunk < sizeof(Auto))
  497. gethunk();
  498. u = (Auto*)hunk;
  499. nhunk -= sizeof(Auto);
  500. hunk += sizeof(Auto);
  501. u->link = curauto;
  502. curauto = u;
  503. u->asym = s;
  504. u->aoffset = l;
  505. u->type = t;
  506. return c;
  507. }
  508. void
  509. addlib(char *obj)
  510. {
  511. char name[1024], comp[256], *p;
  512. int i;
  513. if(histfrogp <= 0)
  514. return;
  515. if(histfrog[0]->name[1] == '/') {
  516. sprint(name, "");
  517. i = 1;
  518. } else
  519. if(histfrog[0]->name[1] == '.') {
  520. sprint(name, ".");
  521. i = 0;
  522. } else {
  523. if(debug['9'])
  524. sprint(name, "/%s/lib", thestring);
  525. else
  526. sprint(name, "/usr/%clib", thechar);
  527. i = 0;
  528. }
  529. for(; i<histfrogp; i++) {
  530. snprint(comp, sizeof comp, histfrog[i]->name+1);
  531. for(;;) {
  532. p = strstr(comp, "$O");
  533. if(p == 0)
  534. break;
  535. memmove(p+1, p+2, strlen(p+2)+1);
  536. p[0] = thechar;
  537. }
  538. for(;;) {
  539. p = strstr(comp, "$M");
  540. if(p == 0)
  541. break;
  542. if(strlen(comp)+strlen(thestring)-2+1 >= sizeof comp) {
  543. diag("library component too long");
  544. return;
  545. }
  546. memmove(p+strlen(thestring), p+2, strlen(p+2)+1);
  547. memmove(p, thestring, strlen(thestring));
  548. }
  549. if(strlen(name) + strlen(comp) + 3 >= sizeof(name)) {
  550. diag("library component too long");
  551. return;
  552. }
  553. strcat(name, "/");
  554. strcat(name, comp);
  555. }
  556. for(i=0; i<libraryp; i++)
  557. if(strcmp(name, library[i]) == 0)
  558. return;
  559. if(libraryp == nelem(library)){
  560. diag("too many autolibs; skipping %s", name);
  561. return;
  562. }
  563. p = malloc(strlen(name) + 1);
  564. strcpy(p, name);
  565. library[libraryp] = p;
  566. p = malloc(strlen(obj) + 1);
  567. strcpy(p, obj);
  568. libraryobj[libraryp] = p;
  569. libraryp++;
  570. }
  571. void
  572. addhist(long line, int type)
  573. {
  574. Auto *u;
  575. Sym *s;
  576. int i, j, k;
  577. u = malloc(sizeof(Auto));
  578. s = malloc(sizeof(Sym));
  579. s->name = malloc(2*(histfrogp+1) + 1);
  580. u->asym = s;
  581. u->type = type;
  582. u->aoffset = line;
  583. u->link = curhist;
  584. curhist = u;
  585. j = 1;
  586. for(i=0; i<histfrogp; i++) {
  587. k = histfrog[i]->value;
  588. s->name[j+0] = k>>8;
  589. s->name[j+1] = k;
  590. j += 2;
  591. }
  592. }
  593. void
  594. histtoauto(void)
  595. {
  596. Auto *l;
  597. while(l = curhist) {
  598. curhist = l->link;
  599. l->link = curauto;
  600. curauto = l;
  601. }
  602. }
  603. void
  604. collapsefrog(Sym *s)
  605. {
  606. int i;
  607. /*
  608. * bad encoding of path components only allows
  609. * MAXHIST components. if there is an overflow,
  610. * first try to collapse xxx/..
  611. */
  612. for(i=1; i<histfrogp; i++)
  613. if(strcmp(histfrog[i]->name+1, "..") == 0) {
  614. memmove(histfrog+i-1, histfrog+i+1,
  615. (histfrogp-i-1)*sizeof(histfrog[0]));
  616. histfrogp--;
  617. goto out;
  618. }
  619. /*
  620. * next try to collapse .
  621. */
  622. for(i=0; i<histfrogp; i++)
  623. if(strcmp(histfrog[i]->name+1, ".") == 0) {
  624. memmove(histfrog+i, histfrog+i+1,
  625. (histfrogp-i-1)*sizeof(histfrog[0]));
  626. goto out;
  627. }
  628. /*
  629. * last chance, just truncate from front
  630. */
  631. memmove(histfrog+0, histfrog+1,
  632. (histfrogp-1)*sizeof(histfrog[0]));
  633. out:
  634. histfrog[histfrogp-1] = s;
  635. }
  636. void
  637. nopout(Prog *p)
  638. {
  639. p->as = ANOP;
  640. p->from.type = D_NONE;
  641. p->to.type = D_NONE;
  642. }
  643. uchar*
  644. readsome(int f, uchar *buf, uchar *good, uchar *stop, int max)
  645. {
  646. int n;
  647. n = stop - good;
  648. memmove(buf, good, stop - good);
  649. stop = buf + n;
  650. n = MAXIO - n;
  651. if(n > max)
  652. n = max;
  653. n = read(f, stop, n);
  654. if(n <= 0)
  655. return 0;
  656. return stop + n;
  657. }
  658. void
  659. ldobj(int f, long c, char *pn)
  660. {
  661. long ipc;
  662. Prog *p, *t;
  663. uchar *bloc, *bsize, *stop;
  664. int v, o, r, skip;
  665. Sym *h[NSYM], *s, *di;
  666. ulong sig;
  667. static int files;
  668. static char **filen;
  669. char **nfilen;
  670. if((files&15) == 0){
  671. nfilen = malloc((files+16)*sizeof(char*));
  672. memmove(nfilen, filen, files*sizeof(char*));
  673. free(filen);
  674. filen = nfilen;
  675. }
  676. filen[files++] = strdup(pn);
  677. bsize = buf.xbuf;
  678. bloc = buf.xbuf;
  679. di = S;
  680. newloop:
  681. memset(h, 0, sizeof(h));
  682. version++;
  683. histfrogp = 0;
  684. ipc = pc;
  685. skip = 0;
  686. loop:
  687. if(c <= 0)
  688. goto eof;
  689. r = bsize - bloc;
  690. if(r < 100 && r < c) { /* enough for largest prog */
  691. bsize = readsome(f, buf.xbuf, bloc, bsize, c);
  692. if(bsize == 0)
  693. goto eof;
  694. bloc = buf.xbuf;
  695. goto loop;
  696. }
  697. o = bloc[0] | (bloc[1] << 8);
  698. if(o <= AXXX || o >= ALAST) {
  699. if(o < 0)
  700. goto eof;
  701. diag("%s: opcode out of range %d", pn, o);
  702. print(" probably not a .8 file\n");
  703. errorexit();
  704. }
  705. if(o == ANAME || o == ASIGNAME) {
  706. sig = 0;
  707. if(o == ASIGNAME) {
  708. sig = bloc[2] | (bloc[3]<<8) | (bloc[4]<<16) | (bloc[5]<<24);
  709. bloc += 4;
  710. c -= 4;
  711. }
  712. stop = memchr(&bloc[4], 0, bsize-&bloc[4]);
  713. if(stop == 0){
  714. bsize = readsome(f, buf.xbuf, bloc, bsize, c);
  715. if(bsize == 0)
  716. goto eof;
  717. bloc = buf.xbuf;
  718. stop = memchr(&bloc[4], 0, bsize-&bloc[4]);
  719. if(stop == 0){
  720. fprint(2, "%s: name too long\n", pn);
  721. errorexit();
  722. }
  723. }
  724. v = bloc[2]; /* type */
  725. o = bloc[3]; /* sym */
  726. bloc += 4;
  727. c -= 4;
  728. r = 0;
  729. if(v == D_STATIC)
  730. r = version;
  731. s = lookup((char*)bloc, r);
  732. c -= &stop[1] - bloc;
  733. bloc = stop + 1;
  734. if(debug['S'] && r == 0)
  735. sig = 1729;
  736. if(sig != 0){
  737. if(s->sig != 0 && s->sig != sig)
  738. diag("incompatible type signatures %lux(%s) and %lux(%s) for %s", s->sig, filen[s->file], sig, pn, s->name);
  739. s->sig = sig;
  740. s->file = files-1;
  741. }
  742. if(debug['W'])
  743. print(" ANAME %s\n", s->name);
  744. h[o] = s;
  745. if((v == D_EXTERN || v == D_STATIC) && s->type == 0)
  746. s->type = SXREF;
  747. if(v == D_FILE) {
  748. if(s->type != SFILE) {
  749. histgen++;
  750. s->type = SFILE;
  751. s->value = histgen;
  752. }
  753. if(histfrogp < MAXHIST) {
  754. histfrog[histfrogp] = s;
  755. histfrogp++;
  756. } else
  757. collapsefrog(s);
  758. }
  759. goto loop;
  760. }
  761. while(nhunk < sizeof(Prog))
  762. gethunk();
  763. p = (Prog*)hunk;
  764. nhunk -= sizeof(Prog);
  765. hunk += sizeof(Prog);
  766. p->as = o;
  767. p->line = bloc[2] | (bloc[3] << 8) | (bloc[4] << 16) | (bloc[5] << 24);
  768. p->back = 2;
  769. r = zaddr(bloc+6, &p->from, h) + 6;
  770. r += zaddr(bloc+r, &p->to, h);
  771. bloc += r;
  772. c -= r;
  773. if(debug['W'])
  774. print("%P\n", p);
  775. switch(p->as) {
  776. case AHISTORY:
  777. if(p->to.offset == -1) {
  778. addlib(pn);
  779. histfrogp = 0;
  780. goto loop;
  781. }
  782. addhist(p->line, D_FILE); /* 'z' */
  783. if(p->to.offset)
  784. addhist(p->to.offset, D_FILE1); /* 'Z' */
  785. histfrogp = 0;
  786. goto loop;
  787. case AEND:
  788. histtoauto();
  789. if(curtext != P)
  790. curtext->to.autom = curauto;
  791. curauto = 0;
  792. curtext = P;
  793. if(c)
  794. goto newloop;
  795. return;
  796. case AGLOBL:
  797. s = p->from.sym;
  798. if(s->type == 0 || s->type == SXREF) {
  799. s->type = SBSS;
  800. s->value = 0;
  801. }
  802. if(s->type != SBSS) {
  803. diag("%s: redefinition: %s in %s",
  804. pn, s->name, TNAME);
  805. s->type = SBSS;
  806. s->value = 0;
  807. }
  808. if(p->to.offset > s->value)
  809. s->value = p->to.offset;
  810. goto loop;
  811. case ADYNT:
  812. if(p->to.sym == S) {
  813. diag("DYNT without a sym\n%P", p);
  814. break;
  815. }
  816. di = p->to.sym;
  817. p->from.scale = 4;
  818. if(di->type == SXREF) {
  819. if(debug['z'])
  820. Bprint(&bso, "%P set to %d\n", p, dtype);
  821. di->type = SCONST;
  822. di->value = dtype;
  823. dtype += 4;
  824. }
  825. if(p->from.sym == S)
  826. break;
  827. p->from.offset = di->value;
  828. p->from.sym->type = SDATA;
  829. if(curtext == P) {
  830. diag("DYNT not in text: %P", p);
  831. break;
  832. }
  833. p->to.sym = curtext->from.sym;
  834. p->to.type = D_ADDR;
  835. p->to.index = D_EXTERN;
  836. goto data;
  837. case AINIT:
  838. if(p->from.sym == S) {
  839. diag("INIT without a sym\n%P", p);
  840. break;
  841. }
  842. if(di == S) {
  843. diag("INIT without previous DYNT\n%P", p);
  844. break;
  845. }
  846. p->from.offset = di->value;
  847. p->from.sym->type = SDATA;
  848. goto data;
  849. case ADATA:
  850. data:
  851. if(edatap == P)
  852. datap = p;
  853. else
  854. edatap->link = p;
  855. edatap = p;
  856. p->link = P;
  857. goto loop;
  858. case AGOK:
  859. diag("%s: GOK opcode in %s", pn, TNAME);
  860. pc++;
  861. goto loop;
  862. case ATEXT:
  863. if(curtext != P) {
  864. histtoauto();
  865. curtext->to.autom = curauto;
  866. curauto = 0;
  867. }
  868. skip = 0;
  869. curtext = p;
  870. s = p->from.sym;
  871. if(s == S) {
  872. diag("%s: no TEXT symbol: %P", pn, p);
  873. errorexit();
  874. }
  875. if(s->type != 0 && s->type != SXREF) {
  876. if(p->from.scale & DUPOK) {
  877. skip = 1;
  878. goto casdef;
  879. }
  880. diag("%s: redefinition: %s\n%P", pn, s->name, p);
  881. }
  882. s->type = STEXT;
  883. s->value = pc;
  884. lastp->link = p;
  885. lastp = p;
  886. p->pc = pc;
  887. pc++;
  888. if(textp == P) {
  889. textp = p;
  890. etextp = p;
  891. goto loop;
  892. }
  893. etextp->pcond = p;
  894. etextp = p;
  895. goto loop;
  896. case AFMOVF:
  897. case AFADDF:
  898. case AFSUBF:
  899. case AFSUBRF:
  900. case AFMULF:
  901. case AFDIVF:
  902. case AFDIVRF:
  903. case AFCOMF:
  904. case AFCOMFP:
  905. if(skip)
  906. goto casdef;
  907. if(p->from.type == D_FCONST) {
  908. /* size sb 9 max */
  909. sprint(literal, "$%lux", ieeedtof(&p->from.ieee));
  910. s = lookup(literal, 0);
  911. if(s->type == 0) {
  912. s->type = SBSS;
  913. s->value = 4;
  914. t = prg();
  915. t->as = ADATA;
  916. t->line = p->line;
  917. t->from.type = D_EXTERN;
  918. t->from.sym = s;
  919. t->from.scale = 4;
  920. t->to = p->from;
  921. if(edatap == P)
  922. datap = t;
  923. else
  924. edatap->link = t;
  925. edatap = t;
  926. t->link = P;
  927. }
  928. p->from.type = D_EXTERN;
  929. p->from.sym = s;
  930. p->from.offset = 0;
  931. }
  932. goto casdef;
  933. case AFMOVD:
  934. case AFADDD:
  935. case AFSUBD:
  936. case AFSUBRD:
  937. case AFMULD:
  938. case AFDIVD:
  939. case AFDIVRD:
  940. case AFCOMD:
  941. case AFCOMDP:
  942. if(skip)
  943. goto casdef;
  944. if(p->from.type == D_FCONST) {
  945. /* size sb 18 max */
  946. sprint(literal, "$%lux.%lux",
  947. p->from.ieee.l, p->from.ieee.h);
  948. s = lookup(literal, 0);
  949. if(s->type == 0) {
  950. s->type = SBSS;
  951. s->value = 8;
  952. t = prg();
  953. t->as = ADATA;
  954. t->line = p->line;
  955. t->from.type = D_EXTERN;
  956. t->from.sym = s;
  957. t->from.scale = 8;
  958. t->to = p->from;
  959. if(edatap == P)
  960. datap = t;
  961. else
  962. edatap->link = t;
  963. edatap = t;
  964. t->link = P;
  965. }
  966. p->from.type = D_EXTERN;
  967. p->from.sym = s;
  968. p->from.offset = 0;
  969. }
  970. goto casdef;
  971. casdef:
  972. default:
  973. if(skip)
  974. nopout(p);
  975. if(p->to.type == D_BRANCH)
  976. p->to.offset += ipc;
  977. lastp->link = p;
  978. lastp = p;
  979. p->pc = pc;
  980. pc++;
  981. goto loop;
  982. }
  983. goto loop;
  984. eof:
  985. diag("truncated object file: %s", pn);
  986. }
  987. Sym*
  988. lookup(char *symb, int v)
  989. {
  990. Sym *s;
  991. char *p;
  992. long h;
  993. int l, c;
  994. h = v;
  995. for(p=symb; c = *p; p++)
  996. h = h+h+h + c;
  997. l = (p - symb) + 1;
  998. if(h < 0)
  999. h = ~h;
  1000. h %= NHASH;
  1001. for(s = hash[h]; s != S; s = s->link)
  1002. if(s->version == v)
  1003. if(memcmp(s->name, symb, l) == 0)
  1004. return s;
  1005. while(nhunk < sizeof(Sym))
  1006. gethunk();
  1007. s = (Sym*)hunk;
  1008. nhunk -= sizeof(Sym);
  1009. hunk += sizeof(Sym);
  1010. s->name = malloc(l + 1);
  1011. memmove(s->name, symb, l);
  1012. s->link = hash[h];
  1013. s->type = 0;
  1014. s->version = v;
  1015. s->value = 0;
  1016. s->sig = 0;
  1017. hash[h] = s;
  1018. nsymbol++;
  1019. return s;
  1020. }
  1021. Prog*
  1022. prg(void)
  1023. {
  1024. Prog *p;
  1025. while(nhunk < sizeof(Prog))
  1026. gethunk();
  1027. p = (Prog*)hunk;
  1028. nhunk -= sizeof(Prog);
  1029. hunk += sizeof(Prog);
  1030. *p = zprg;
  1031. return p;
  1032. }
  1033. Prog*
  1034. copyp(Prog *q)
  1035. {
  1036. Prog *p;
  1037. p = prg();
  1038. *p = *q;
  1039. return p;
  1040. }
  1041. Prog*
  1042. appendp(Prog *q)
  1043. {
  1044. Prog *p;
  1045. p = prg();
  1046. p->link = q->link;
  1047. q->link = p;
  1048. p->line = q->line;
  1049. return p;
  1050. }
  1051. void
  1052. gethunk(void)
  1053. {
  1054. char *h;
  1055. long nh;
  1056. nh = NHUNK;
  1057. if(thunk >= 5L*NHUNK) {
  1058. nh = 5L*NHUNK;
  1059. if(thunk >= 25L*NHUNK)
  1060. nh = 25L*NHUNK;
  1061. }
  1062. h = mysbrk(nh);
  1063. if(h == (char*)-1) {
  1064. diag("out of memory");
  1065. errorexit();
  1066. }
  1067. hunk = h;
  1068. nhunk = nh;
  1069. thunk += nh;
  1070. }
  1071. void
  1072. doprof1(void)
  1073. {
  1074. Sym *s;
  1075. long n;
  1076. Prog *p, *q;
  1077. if(debug['v'])
  1078. Bprint(&bso, "%5.2f profile 1\n", cputime());
  1079. Bflush(&bso);
  1080. s = lookup("__mcount", 0);
  1081. n = 1;
  1082. for(p = firstp->link; p != P; p = p->link) {
  1083. if(p->as == ATEXT) {
  1084. q = prg();
  1085. q->line = p->line;
  1086. q->link = datap;
  1087. datap = q;
  1088. q->as = ADATA;
  1089. q->from.type = D_EXTERN;
  1090. q->from.offset = n*4;
  1091. q->from.sym = s;
  1092. q->from.scale = 4;
  1093. q->to = p->from;
  1094. q->to.type = D_CONST;
  1095. q = prg();
  1096. q->line = p->line;
  1097. q->pc = p->pc;
  1098. q->link = p->link;
  1099. p->link = q;
  1100. p = q;
  1101. p->as = AADDL;
  1102. p->from.type = D_CONST;
  1103. p->from.offset = 1;
  1104. p->to.type = D_EXTERN;
  1105. p->to.sym = s;
  1106. p->to.offset = n*4 + 4;
  1107. n += 2;
  1108. continue;
  1109. }
  1110. }
  1111. q = prg();
  1112. q->line = 0;
  1113. q->link = datap;
  1114. datap = q;
  1115. q->as = ADATA;
  1116. q->from.type = D_EXTERN;
  1117. q->from.sym = s;
  1118. q->from.scale = 4;
  1119. q->to.type = D_CONST;
  1120. q->to.offset = n;
  1121. s->type = SBSS;
  1122. s->value = n*4;
  1123. }
  1124. void
  1125. doprof2(void)
  1126. {
  1127. Sym *s2, *s4;
  1128. Prog *p, *q, *ps2, *ps4;
  1129. if(debug['v'])
  1130. Bprint(&bso, "%5.2f profile 2\n", cputime());
  1131. Bflush(&bso);
  1132. s2 = lookup("_profin", 0);
  1133. s4 = lookup("_profout", 0);
  1134. if(s2->type != STEXT || s4->type != STEXT) {
  1135. diag("_profin/_profout not defined");
  1136. return;
  1137. }
  1138. ps2 = P;
  1139. ps4 = P;
  1140. for(p = firstp; p != P; p = p->link) {
  1141. if(p->as == ATEXT) {
  1142. if(p->from.sym == s2) {
  1143. p->from.scale = 1;
  1144. ps2 = p;
  1145. }
  1146. if(p->from.sym == s4) {
  1147. p->from.scale = 1;
  1148. ps4 = p;
  1149. }
  1150. }
  1151. }
  1152. for(p = firstp; p != P; p = p->link) {
  1153. if(p->as == ATEXT) {
  1154. curtext = p;
  1155. if(p->from.scale & NOPROF) { /* dont profile */
  1156. for(;;) {
  1157. q = p->link;
  1158. if(q == P)
  1159. break;
  1160. if(q->as == ATEXT)
  1161. break;
  1162. p = q;
  1163. }
  1164. continue;
  1165. }
  1166. /*
  1167. * JMPL profin
  1168. */
  1169. q = prg();
  1170. q->line = p->line;
  1171. q->pc = p->pc;
  1172. q->link = p->link;
  1173. p->link = q;
  1174. p = q;
  1175. p->as = ACALL;
  1176. p->to.type = D_BRANCH;
  1177. p->pcond = ps2;
  1178. p->to.sym = s2;
  1179. continue;
  1180. }
  1181. if(p->as == ARET) {
  1182. /*
  1183. * RET
  1184. */
  1185. q = prg();
  1186. q->as = ARET;
  1187. q->from = p->from;
  1188. q->to = p->to;
  1189. q->link = p->link;
  1190. p->link = q;
  1191. /*
  1192. * JAL profout
  1193. */
  1194. p->as = ACALL;
  1195. p->from = zprg.from;
  1196. p->to = zprg.to;
  1197. p->to.type = D_BRANCH;
  1198. p->pcond = ps4;
  1199. p->to.sym = s4;
  1200. p = q;
  1201. continue;
  1202. }
  1203. }
  1204. }
  1205. void
  1206. nuxiinit(void)
  1207. {
  1208. int i, c;
  1209. for(i=0; i<4; i++) {
  1210. c = find1(0x04030201L, i+1);
  1211. if(i < 2)
  1212. inuxi2[i] = c;
  1213. if(i < 1)
  1214. inuxi1[i] = c;
  1215. inuxi4[i] = c;
  1216. fnuxi4[i] = c;
  1217. fnuxi8[i] = c;
  1218. fnuxi8[i+4] = c+4;
  1219. }
  1220. if(debug['v']) {
  1221. Bprint(&bso, "inuxi = ");
  1222. for(i=0; i<1; i++)
  1223. Bprint(&bso, "%d", inuxi1[i]);
  1224. Bprint(&bso, " ");
  1225. for(i=0; i<2; i++)
  1226. Bprint(&bso, "%d", inuxi2[i]);
  1227. Bprint(&bso, " ");
  1228. for(i=0; i<4; i++)
  1229. Bprint(&bso, "%d", inuxi4[i]);
  1230. Bprint(&bso, "\nfnuxi = ");
  1231. for(i=0; i<4; i++)
  1232. Bprint(&bso, "%d", fnuxi4[i]);
  1233. Bprint(&bso, " ");
  1234. for(i=0; i<8; i++)
  1235. Bprint(&bso, "%d", fnuxi8[i]);
  1236. Bprint(&bso, "\n");
  1237. }
  1238. Bflush(&bso);
  1239. }
  1240. int
  1241. find1(long l, int c)
  1242. {
  1243. char *p;
  1244. int i;
  1245. p = (char*)&l;
  1246. for(i=0; i<4; i++)
  1247. if(*p++ == c)
  1248. return i;
  1249. return 0;
  1250. }
  1251. int
  1252. find2(long l, int c)
  1253. {
  1254. short *p;
  1255. int i;
  1256. p = (short*)&l;
  1257. for(i=0; i<4; i+=2) {
  1258. if(((*p >> 8) & 0xff) == c)
  1259. return i;
  1260. if((*p++ & 0xff) == c)
  1261. return i+1;
  1262. }
  1263. return 0;
  1264. }
  1265. long
  1266. ieeedtof(Ieee *e)
  1267. {
  1268. int exp;
  1269. long v;
  1270. if(e->h == 0)
  1271. return 0;
  1272. exp = (e->h>>20) & ((1L<<11)-1L);
  1273. exp -= (1L<<10) - 2L;
  1274. v = (e->h & 0xfffffL) << 3;
  1275. v |= (e->l >> 29) & 0x7L;
  1276. if((e->l >> 28) & 1) {
  1277. v++;
  1278. if(v & 0x800000L) {
  1279. v = (v & 0x7fffffL) >> 1;
  1280. exp++;
  1281. }
  1282. }
  1283. if(exp <= -126 || exp >= 130)
  1284. diag("double fp to single fp overflow");
  1285. v |= ((exp + 126) & 0xffL) << 23;
  1286. v |= e->h & 0x80000000L;
  1287. return v;
  1288. }
  1289. double
  1290. ieeedtod(Ieee *ieeep)
  1291. {
  1292. Ieee e;
  1293. double fr;
  1294. int exp;
  1295. if(ieeep->h & (1L<<31)) {
  1296. e.h = ieeep->h & ~(1L<<31);
  1297. e.l = ieeep->l;
  1298. return -ieeedtod(&e);
  1299. }
  1300. if(ieeep->l == 0 && ieeep->h == 0)
  1301. return 0;
  1302. fr = ieeep->l & ((1L<<16)-1L);
  1303. fr /= 1L<<16;
  1304. fr += (ieeep->l>>16) & ((1L<<16)-1L);
  1305. fr /= 1L<<16;
  1306. fr += (ieeep->h & (1L<<20)-1L) | (1L<<20);
  1307. fr /= 1L<<21;
  1308. exp = (ieeep->h>>20) & ((1L<<11)-1L);
  1309. exp -= (1L<<10) - 2L;
  1310. return ldexp(fr, exp);
  1311. }
  1312. void
  1313. undefsym(Sym *s)
  1314. {
  1315. int n;
  1316. n = imports;
  1317. if(s->value != 0)
  1318. diag("value != 0 on SXREF");
  1319. if(n >= 1<<Rindex)
  1320. diag("import index %d out of range", n);
  1321. s->value = n<<Roffset;
  1322. s->type = SUNDEF;
  1323. imports++;
  1324. }
  1325. void
  1326. zerosig(char *sp)
  1327. {
  1328. Sym *s;
  1329. s = lookup(sp, 0);
  1330. s->sig = 0;
  1331. }
  1332. void
  1333. readundefs(char *f, int t)
  1334. {
  1335. int i, n;
  1336. Sym *s;
  1337. Biobuf *b;
  1338. char *l, buf[256], *fields[64];
  1339. if(f == nil)
  1340. return;
  1341. b = Bopen(f, OREAD);
  1342. if(b == nil){
  1343. diag("could not open %s: %r", f);
  1344. errorexit();
  1345. }
  1346. while((l = Brdline(b, '\n')) != nil){
  1347. n = Blinelen(b);
  1348. if(n >= sizeof(buf)){
  1349. diag("%s: line too long", f);
  1350. errorexit();
  1351. }
  1352. memmove(buf, l, n);
  1353. buf[n-1] = '\0';
  1354. n = getfields(buf, fields, nelem(fields), 1, " \t\r\n");
  1355. if(n == nelem(fields)){
  1356. diag("%s: bad format", f);
  1357. errorexit();
  1358. }
  1359. for(i = 0; i < n; i++){
  1360. s = lookup(fields[i], 0);
  1361. s->type = SXREF;
  1362. s->subtype = t;
  1363. if(t == SIMPORT)
  1364. nimports++;
  1365. else
  1366. nexports++;
  1367. }
  1368. }
  1369. Bterm(b);
  1370. }