lex.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. #define EXTERN
  2. #include "a.h"
  3. #include "y.tab.h"
  4. #include <ctype.h>
  5. void
  6. main(int argc, char *argv[])
  7. {
  8. char *p;
  9. int nout, nproc, status, i, c;
  10. thechar = 'q';
  11. thestring = "power";
  12. memset(debug, 0, sizeof(debug));
  13. cinit();
  14. outfile = 0;
  15. include[ninclude++] = ".";
  16. ARGBEGIN {
  17. default:
  18. c = ARGC();
  19. if(c >= 0 || c < sizeof(debug))
  20. debug[c] = 1;
  21. break;
  22. case 'o':
  23. outfile = ARGF();
  24. break;
  25. case 'D':
  26. p = ARGF();
  27. if(p)
  28. Dlist[nDlist++] = p;
  29. break;
  30. case 'I':
  31. p = ARGF();
  32. setinclude(p);
  33. break;
  34. } ARGEND
  35. if(*argv == 0) {
  36. print("usage: %ca [-options] file.s\n", thechar);
  37. errorexit();
  38. }
  39. if(argc > 1 && systemtype(Windows)){
  40. print("can't assemble multiple files on windows\n");
  41. errorexit();
  42. }
  43. if(argc > 1) {
  44. nproc = 1;
  45. if(p = getenv("NPROC"))
  46. nproc = atol(p);
  47. c = 0;
  48. nout = 0;
  49. for(;;) {
  50. while(nout < nproc && argc > 0) {
  51. i = myfork();
  52. if(i < 0) {
  53. i = mywait(&status);
  54. if(i < 0)
  55. errorexit();
  56. if(status)
  57. c++;
  58. nout--;
  59. continue;
  60. }
  61. if(i == 0) {
  62. print("%s:\n", *argv);
  63. if(assemble(*argv))
  64. errorexit();
  65. exits(0);
  66. }
  67. nout++;
  68. argc--;
  69. argv++;
  70. }
  71. i = mywait(&status);
  72. if(i < 0) {
  73. if(c)
  74. errorexit();
  75. exits(0);
  76. }
  77. if(status)
  78. c++;
  79. nout--;
  80. }
  81. }
  82. if(assemble(argv[0]))
  83. errorexit();
  84. exits(0);
  85. }
  86. int
  87. assemble(char *file)
  88. {
  89. char ofile[100], incfile[20], *p;
  90. int i, of;
  91. strcpy(ofile, file);
  92. if(p = strrchr(ofile, pathchar())) {
  93. include[0] = ofile;
  94. *p++ = 0;
  95. } else
  96. p = ofile;
  97. if(outfile == 0) {
  98. outfile = p;
  99. if(p = strrchr(outfile, '.'))
  100. if(p[1] == 's' && p[2] == 0)
  101. p[0] = 0;
  102. p = strrchr(outfile, 0);
  103. p[0] = '.';
  104. p[1] = thechar;
  105. p[2] = 0;
  106. }
  107. p = getenv("INCLUDE");
  108. if(p) {
  109. setinclude(p);
  110. } else {
  111. if(systemtype(Plan9)) {
  112. sprint(incfile,"/%s/include", thestring);
  113. setinclude(strdup(incfile));
  114. }
  115. }
  116. of = mycreat(outfile, 0664);
  117. if(of < 0) {
  118. yyerror("%ca: cannot create %s", thechar, outfile);
  119. errorexit();
  120. }
  121. Binit(&obuf, of, OWRITE);
  122. pass = 1;
  123. nosched = 0;
  124. pinit(file);
  125. for(i=0; i<nDlist; i++)
  126. dodefine(Dlist[i]);
  127. yyparse();
  128. if(nerrors) {
  129. cclean();
  130. return nerrors;
  131. }
  132. pass = 2;
  133. nosched = 0;
  134. outhist();
  135. pinit(file);
  136. for(i=0; i<nDlist; i++)
  137. dodefine(Dlist[i]);
  138. yyparse();
  139. cclean();
  140. return nerrors;
  141. }
  142. struct
  143. {
  144. char *name;
  145. ushort type;
  146. ushort value;
  147. } itab[] =
  148. {
  149. "SP", LSP, D_AUTO,
  150. "SB", LSB, D_EXTERN,
  151. "FP", LFP, D_PARAM,
  152. "PC", LPC, D_BRANCH,
  153. "LR", LLR, D_LR,
  154. "CTR", LCTR, D_CTR,
  155. "XER", LSPREG, D_XER,
  156. "MSR", LMSR, D_MSR,
  157. "FPSCR", LFPSCR, D_FPSCR,
  158. "SPR", LSPR, D_SPR,
  159. "DCR", LDCR, D_DCR,
  160. "SEG", LSEG, D_SREG,
  161. "CR", LCR, 0,
  162. "CR0", LCREG, 0,
  163. "CR1", LCREG, 1,
  164. "CR2", LCREG, 2,
  165. "CR3", LCREG, 3,
  166. "CR4", LCREG, 4,
  167. "CR5", LCREG, 5,
  168. "CR6", LCREG, 6,
  169. "CR7", LCREG, 7,
  170. "R", LR, 0,
  171. "R0", LREG, 0,
  172. "R1", LREG, 1,
  173. "R2", LREG, 2,
  174. "R3", LREG, 3,
  175. "R4", LREG, 4,
  176. "R5", LREG, 5,
  177. "R6", LREG, 6,
  178. "R7", LREG, 7,
  179. "R8", LREG, 8,
  180. "R9", LREG, 9,
  181. "R10", LREG, 10,
  182. "R11", LREG, 11,
  183. "R12", LREG, 12,
  184. "R13", LREG, 13,
  185. "R14", LREG, 14,
  186. "R15", LREG, 15,
  187. "R16", LREG, 16,
  188. "R17", LREG, 17,
  189. "R18", LREG, 18,
  190. "R19", LREG, 19,
  191. "R20", LREG, 20,
  192. "R21", LREG, 21,
  193. "R22", LREG, 22,
  194. "R23", LREG, 23,
  195. "R24", LREG, 24,
  196. "R25", LREG, 25,
  197. "R26", LREG, 26,
  198. "R27", LREG, 27,
  199. "R28", LREG, 28,
  200. "R29", LREG, 29,
  201. "R30", LREG, 30,
  202. "R31", LREG, 31,
  203. "F", LF, 0,
  204. "F0", LFREG, 0,
  205. "F1", LFREG, 1,
  206. "F2", LFREG, 2,
  207. "F3", LFREG, 3,
  208. "F4", LFREG, 4,
  209. "F5", LFREG, 5,
  210. "F6", LFREG, 6,
  211. "F7", LFREG, 7,
  212. "F8", LFREG, 8,
  213. "F9", LFREG, 9,
  214. "F10", LFREG, 10,
  215. "F11", LFREG, 11,
  216. "F12", LFREG, 12,
  217. "F13", LFREG, 13,
  218. "F14", LFREG, 14,
  219. "F15", LFREG, 15,
  220. "F16", LFREG, 16,
  221. "F17", LFREG, 17,
  222. "F18", LFREG, 18,
  223. "F19", LFREG, 19,
  224. "F20", LFREG, 20,
  225. "F21", LFREG, 21,
  226. "F22", LFREG, 22,
  227. "F23", LFREG, 23,
  228. "F24", LFREG, 24,
  229. "F25", LFREG, 25,
  230. "F26", LFREG, 26,
  231. "F27", LFREG, 27,
  232. "F28", LFREG, 28,
  233. "F29", LFREG, 29,
  234. "F30", LFREG, 30,
  235. "F31", LFREG, 31,
  236. "CREQV", LCROP, ACREQV,
  237. "CRXOR", LCROP, ACRXOR,
  238. "CRAND", LCROP, ACRAND,
  239. "CROR", LCROP, ACROR,
  240. "CRANDN", LCROP, ACRANDN,
  241. "CRORN", LCROP, ACRORN,
  242. "CRNAND", LCROP, ACRNAND,
  243. "CRNOR", LCROP, ACRNOR,
  244. "ADD", LADDW, AADD,
  245. "ADDV", LADDW, AADDV,
  246. "ADDCC", LADDW, AADDCC,
  247. "ADDVCC", LADDW, AADDVCC,
  248. "ADDC", LADDW, AADDC,
  249. "ADDCV", LADDW, AADDCV,
  250. "ADDCCC", LADDW, AADDCCC,
  251. "ADDCVCC", LADDW, AADDCVCC,
  252. "ADDE", LLOGW, AADDE,
  253. "ADDEV", LLOGW, AADDEV,
  254. "ADDECC", LLOGW, AADDECC,
  255. "ADDEVCC", LLOGW, AADDEVCC,
  256. "ADDME", LABS, AADDME,
  257. "ADDMEV", LABS, AADDMEV,
  258. "ADDMECC", LABS, AADDMECC,
  259. "ADDMEVCC", LABS, AADDMEVCC,
  260. "ADDZE", LABS, AADDZE,
  261. "ADDZEV", LABS, AADDZEV,
  262. "ADDZECC", LABS, AADDZECC,
  263. "ADDZEVCC", LABS, AADDZEVCC,
  264. "SUB", LADDW, ASUB,
  265. "SUBV", LADDW, ASUBV,
  266. "SUBCC", LADDW, ASUBCC,
  267. "SUBVCC", LADDW, ASUBVCC,
  268. "SUBE", LLOGW, ASUBE,
  269. "SUBECC", LLOGW, ASUBECC,
  270. "SUBEV", LLOGW, ASUBEV,
  271. "SUBEVCC", LLOGW, ASUBEVCC,
  272. "SUBC", LADDW, ASUBC,
  273. "SUBCCC", LADDW, ASUBCCC,
  274. "SUBCV", LADDW, ASUBCV,
  275. "SUBCVCC", LADDW, ASUBCVCC,
  276. "SUBME", LABS, ASUBME,
  277. "SUBMEV", LABS, ASUBMEV,
  278. "SUBMECC", LABS, ASUBMECC,
  279. "SUBMEVCC", LABS, ASUBMEVCC,
  280. "SUBZE", LABS, ASUBZE,
  281. "SUBZEV", LABS, ASUBZEV,
  282. "SUBZECC", LABS, ASUBZECC,
  283. "SUBZEVCC", LABS, ASUBZEVCC,
  284. "AND", LADDW, AAND,
  285. "ANDCC", LADDW, AANDCC, /* includes andil & andiu */
  286. "ANDN", LLOGW, AANDN,
  287. "ANDNCC", LLOGW, AANDNCC,
  288. "EQV", LLOGW, AEQV,
  289. "EQVCC", LLOGW, AEQVCC,
  290. "NAND", LLOGW, ANAND,
  291. "NANDCC", LLOGW, ANANDCC,
  292. "NOR", LLOGW, ANOR,
  293. "NORCC", LLOGW, ANORCC,
  294. "OR", LADDW, AOR, /* includes oril & oriu */
  295. "ORCC", LADDW, AORCC,
  296. "ORN", LLOGW, AORN,
  297. "ORNCC", LLOGW, AORNCC,
  298. "XOR", LADDW, AXOR, /* includes xoril & xoriu */
  299. "XORCC", LLOGW, AXORCC,
  300. "EXTSB", LABS, AEXTSB,
  301. "EXTSBCC", LABS, AEXTSBCC,
  302. "EXTSH", LABS, AEXTSH,
  303. "EXTSHCC", LABS, AEXTSHCC,
  304. "CNTLZW", LABS, ACNTLZW,
  305. "CNTLZWCC", LABS, ACNTLZWCC,
  306. "RLWMI", LRLWM, ARLWMI,
  307. "RLWMICC", LRLWM, ARLWMICC,
  308. "RLWNM", LRLWM, ARLWNM,
  309. "RLWNMCC", LRLWM, ARLWNMCC,
  310. "SLW", LSHW, ASLW,
  311. "SLWCC", LSHW, ASLWCC,
  312. "SRW", LSHW, ASRW,
  313. "SRWCC", LSHW, ASRWCC,
  314. "SRAW", LSHW, ASRAW,
  315. "SRAWCC", LSHW, ASRAWCC,
  316. "BR", LBRA, ABR,
  317. "BC", LBRA, ABC,
  318. "BCL", LBRA, ABC,
  319. "BL", LBRA, ABL,
  320. "BEQ", LBRA, ABEQ,
  321. "BNE", LBRA, ABNE,
  322. "BGT", LBRA, ABGT,
  323. "BGE", LBRA, ABGE,
  324. "BLT", LBRA, ABLT,
  325. "BLE", LBRA, ABLE,
  326. "BVC", LBRA, ABVC,
  327. "BVS", LBRA, ABVS,
  328. "CMP", LCMP, ACMP,
  329. "CMPU", LCMP, ACMPU,
  330. "DIVW", LLOGW, ADIVW,
  331. "DIVWV", LLOGW, ADIVWV,
  332. "DIVWCC", LLOGW, ADIVWCC,
  333. "DIVWVCC", LLOGW, ADIVWVCC,
  334. "DIVWU", LLOGW, ADIVWU,
  335. "DIVWUV", LLOGW, ADIVWUV,
  336. "DIVWUCC", LLOGW, ADIVWUCC,
  337. "DIVWUVCC", LLOGW, ADIVWUVCC,
  338. "FABS", LFCONV, AFABS,
  339. "FABSCC", LFCONV, AFABSCC,
  340. "FNEG", LFCONV, AFNEG,
  341. "FNEGCC", LFCONV, AFNEGCC,
  342. "FNABS", LFCONV, AFNABS,
  343. "FNABSCC", LFCONV, AFNABSCC,
  344. "FADD", LFADD, AFADD,
  345. "FADDCC", LFADD, AFADDCC,
  346. "FSUB", LFADD, AFSUB,
  347. "FSUBCC", LFADD, AFSUBCC,
  348. "FMUL", LFADD, AFMUL,
  349. "FMULCC", LFADD, AFMULCC,
  350. "FDIV", LFADD, AFDIV,
  351. "FDIVCC", LFADD, AFDIVCC,
  352. "FRSP", LFCONV, AFRSP,
  353. "FRSPCC", LFCONV, AFRSPCC,
  354. "FMADD", LFMA, AFMADD,
  355. "FMADDCC", LFMA, AFMADDCC,
  356. "FMSUB", LFMA, AFMSUB,
  357. "FMSUBCC", LFMA, AFMSUBCC,
  358. "FNMADD", LFMA, AFNMADD,
  359. "FNMADDCC", LFMA, AFNMADDCC,
  360. "FNMSUB", LFMA, AFNMSUB,
  361. "FNMSUBCC", LFMA, AFNMSUBCC,
  362. "FMADDS", LFMA, AFMADDS,
  363. "FMADDSCC", LFMA, AFMADDSCC,
  364. "FMSUBS", LFMA, AFMSUBS,
  365. "FMSUBSCC", LFMA, AFMSUBSCC,
  366. "FNMADDS", LFMA, AFNMADDS,
  367. "FNMADDSCC", LFMA, AFNMADDSCC,
  368. "FNMSUBS", LFMA, AFNMSUBS,
  369. "FNMSUBSCC", LFMA, AFNMSUBSCC,
  370. "FCMPU", LFCMP, AFCMPU,
  371. "FCMPO", LFCMP, AFCMPO,
  372. "MTFSB0", LMTFSB, AMTFSB0,
  373. "MTFSB1", LMTFSB, AMTFSB1,
  374. "FMOVD", LFMOV, AFMOVD,
  375. "FMOVS", LFMOV, AFMOVS,
  376. "FMOVDCC", LFCONV, AFMOVDCC, /* fmr. */
  377. "GLOBL", LTEXT, AGLOBL,
  378. "MOVB", LMOVB, AMOVB,
  379. "MOVBZ", LMOVB, AMOVBZ,
  380. "MOVBU", LMOVB, AMOVBU,
  381. "MOVBZU", LMOVB, AMOVBZU,
  382. "MOVH", LMOVB, AMOVH,
  383. "MOVHZ", LMOVB, AMOVHZ,
  384. "MOVHU", LMOVB, AMOVHU,
  385. "MOVHZU", LMOVB, AMOVHZU,
  386. "MOVHBR", LXMV, AMOVHBR,
  387. "MOVWBR", LXMV, AMOVWBR,
  388. "MOVW", LMOVW, AMOVW,
  389. "MOVWU", LMOVW, AMOVWU,
  390. "MOVMW", LMOVMW, AMOVMW,
  391. "MOVFL", LMOVW, AMOVFL,
  392. "MULLW", LADDW, AMULLW, /* includes multiply immediate 10-139 */
  393. "MULLWV", LLOGW, AMULLWV,
  394. "MULLWCC", LLOGW, AMULLWCC,
  395. "MULLWVCC", LLOGW, AMULLWVCC,
  396. "MULHW", LLOGW, AMULHW,
  397. "MULHWCC", LLOGW, AMULHWCC,
  398. "MULHWU", LLOGW, AMULHWU,
  399. "MULHWUCC", LLOGW, AMULHWUCC,
  400. "NEG", LABS, ANEG,
  401. "NEGV", LABS, ANEGV,
  402. "NEGCC", LABS, ANEGCC,
  403. "NEGVCC", LABS, ANEGVCC,
  404. "NOP", LNOP, ANOP, /* ori 0,0,0 */
  405. "SYSCALL", LNOP, ASYSCALL,
  406. "RETURN", LRETRN, ARETURN,
  407. "RFI", LRETRN, ARFI,
  408. "RFCI", LRETRN, ARFCI,
  409. "DATA", LDATA, ADATA,
  410. "END", LEND, AEND,
  411. "TEXT", LTEXT, ATEXT,
  412. /* IBM powerpc embedded */
  413. "MACCHW", LMA, AMACCHW,
  414. "MACCHWCC", LMA, AMACCHWCC,
  415. "MACCHWS", LMA, AMACCHWS,
  416. "MACCHWSCC", LMA, AMACCHWSCC,
  417. "MACCHWSU", LMA, AMACCHWSU,
  418. "MACCHWSUCC", LMA, AMACCHWSUCC,
  419. "MACCHWSUV", LMA, AMACCHWSUV,
  420. "MACCHWSUVCC", LMA, AMACCHWSUVCC,
  421. "MACCHWSV", LMA, AMACCHWSV,
  422. "MACCHWSVCC", LMA, AMACCHWSVCC,
  423. "MACCHWU", LMA, AMACCHWU,
  424. "MACCHWUCC", LMA, AMACCHWUCC,
  425. "MACCHWUV", LMA, AMACCHWUV,
  426. "MACCHWUVCC", LMA, AMACCHWUVCC,
  427. "MACCHWV", LMA, AMACCHWV,
  428. "MACCHWVCC", LMA, AMACCHWVCC,
  429. "MACHHW", LMA, AMACHHW,
  430. "MACHHWCC", LMA, AMACHHWCC,
  431. "MACHHWS", LMA, AMACHHWS,
  432. "MACHHWSCC", LMA, AMACHHWSCC,
  433. "MACHHWSU", LMA, AMACHHWSU,
  434. "MACHHWSUCC", LMA, AMACHHWSUCC,
  435. "MACHHWSUV", LMA, AMACHHWSUV,
  436. "MACHHWSUVCC", LMA, AMACHHWSUVCC,
  437. "MACHHWSV", LMA, AMACHHWSV,
  438. "MACHHWSVCC", LMA, AMACHHWSVCC,
  439. "MACHHWU", LMA, AMACHHWU,
  440. "MACHHWUCC", LMA, AMACHHWUCC,
  441. "MACHHWUV", LMA, AMACHHWUV,
  442. "MACHHWUVCC", LMA, AMACHHWUVCC,
  443. "MACHHWV", LMA, AMACHHWV,
  444. "MACHHWVCC", LMA, AMACHHWVCC,
  445. "MACLHW", LMA, AMACLHW,
  446. "MACLHWCC", LMA, AMACLHWCC,
  447. "MACLHWS", LMA, AMACLHWS,
  448. "MACLHWSCC", LMA, AMACLHWSCC,
  449. "MACLHWSU", LMA, AMACLHWSU,
  450. "MACLHWSUCC", LMA, AMACLHWSUCC,
  451. "MACLHWSUV", LMA, AMACLHWSUV,
  452. "MACLHWSUVCC", LMA, AMACLHWSUVCC,
  453. "MACLHWSV", LMA, AMACLHWSV,
  454. "MACLHWSVCC", LMA, AMACLHWSVCC,
  455. "MACLHWU", LMA, AMACLHWU,
  456. "MACLHWUCC", LMA, AMACLHWUCC,
  457. "MACLHWUV", LMA, AMACLHWUV,
  458. "MACLHWUVCC", LMA, AMACLHWUVCC,
  459. "MACLHWV", LMA, AMACLHWV,
  460. "MACLHWVCC", LMA, AMACLHWVCC,
  461. "MULCHW", LLOGW, AMULCHW,
  462. "MULCHWCC", LLOGW, AMULCHWCC,
  463. "MULCHWU", LLOGW, AMULCHWU,
  464. "MULCHWUCC", LLOGW, AMULCHWUCC,
  465. "MULHHW", LLOGW, AMULHHW,
  466. "MULHHWCC", LLOGW, AMULHHWCC,
  467. "MULHHWU", LLOGW, AMULHHWU,
  468. "MULHHWUCC", LLOGW, AMULHHWUCC,
  469. "MULLHW", LLOGW, AMULLHW,
  470. "MULLHWCC", LLOGW, AMULLHWCC,
  471. "MULLHWU", LLOGW, AMULLHWU,
  472. "MULLHWUCC", LLOGW, AMULLHWUCC,
  473. "NMACCHW", LMA, ANMACCHW,
  474. "NMACCHWCC", LMA, ANMACCHWCC,
  475. "NMACCHWS", LMA, ANMACCHWS,
  476. "NMACCHWSCC", LMA, ANMACCHWSCC,
  477. "NMACCHWSV", LMA, ANMACCHWSV,
  478. "NMACCHWSVCC", LMA, ANMACCHWSVCC,
  479. "NMACCHWV", LMA, ANMACCHWV,
  480. "NMACCHWVCC", LMA, ANMACCHWVCC,
  481. "NMACHHW", LMA, ANMACHHW,
  482. "NMACHHWCC", LMA, ANMACHHWCC,
  483. "NMACHHWS", LMA, ANMACHHWS,
  484. "NMACHHWSCC", LMA, ANMACHHWSCC,
  485. "NMACHHWSV", LMA, ANMACHHWSV,
  486. "NMACHHWSVCC", LMA, ANMACHHWSVCC,
  487. "NMACHHWV", LMA, ANMACHHWV,
  488. "NMACHHWVCC", LMA, ANMACHHWVCC,
  489. "NMACLHW", LMA, ANMACLHW,
  490. "NMACLHWCC", LMA, ANMACLHWCC,
  491. "NMACLHWS", LMA, ANMACLHWS,
  492. "NMACLHWSCC", LMA, ANMACLHWSCC,
  493. "NMACLHWSV", LMA, ANMACLHWSV,
  494. "NMACLHWSVCC", LMA, ANMACLHWSVCC,
  495. "NMACLHWV", LMA, ANMACLHWV,
  496. "NMACLHWVCC", LMA, ANMACLHWVCC,
  497. /* optional on 32-bit */
  498. "FRES", LFCONV, AFRES,
  499. "FRESCC", LFCONV, AFRESCC,
  500. "FRSQRTE", LFCONV, AFRSQRTE,
  501. "FRSQRTECC", LFCONV, AFRSQRTECC,
  502. "FSEL", LFMA, AFSEL,
  503. "FSELCC", LFMA, AFSELCC,
  504. "FSQRT", LFCONV, AFSQRT,
  505. "FSQRTCC", LFCONV, AFSQRTCC,
  506. "FSQRTS", LFCONV, AFSQRTS,
  507. "FSQRTSCC", LFCONV, AFSQRTSCC,
  508. /* parallel, cross, and secondary (fp2) */
  509. "FPSEL", LFMA, AFPSEL,
  510. "FPMUL", LFADD, AFPMUL,
  511. "FXMUL", LFADD, AFXMUL,
  512. "FXPMUL", LFADD, AFXPMUL,
  513. "FXSMUL", LFADD, AFXSMUL,
  514. "FPADD", LFADD, AFPADD,
  515. "FPSUB", LFADD, AFPSUB,
  516. "FPRE", LFCONV, AFPRE,
  517. "FPRSQRTE", LFCONV, AFPRSQRTE,
  518. "FPMADD", LFMA, AFPMADD,
  519. "FXMADD", LFMA, AFXMADD,
  520. "FXCPMADD", LFMA, AFXCPMADD,
  521. "FXCSMADD", LFMA, AFXCSMADD,
  522. "FPNMADD", LFMA, AFPNMADD,
  523. "FXNMADD", LFMA, AFXNMADD,
  524. "FXCPNMADD", LFMA, AFXCPNMADD,
  525. "FXCSNMADD", LFMA, AFXCSNMADD,
  526. "FPMSUB", LFMA, AFPMSUB,
  527. "FXMSUB", LFMA, AFXMSUB,
  528. "FXCPMSUB", LFMA, AFXCPMSUB,
  529. "FXCSMSUB", LFMA, AFXCSMSUB,
  530. "FPNMSUB", LFMA, AFPNMSUB,
  531. "FXNMSUB", LFMA, AFXNMSUB,
  532. "FXCPNMSUB", LFMA, AFXCPNMSUB,
  533. "FXCSNMSUB", LFMA, AFXCSNMSUB,
  534. "FPABS", LFCONV, AFPABS,
  535. "FPNEG", LFCONV, AFPNEG,
  536. "FPRSP", LFCONV, AFPRSP,
  537. "FPNABS", LFCONV, AFPNABS,
  538. "FSMOVD", LFMOV, AFSMOVD,
  539. "FSCMP", LFCMP, AFSCMP,
  540. "FSABS", LFCONV, AFSABS,
  541. "FSNEG", LFCONV, AFSNEG,
  542. "FSNABS", LFCONV, AFSNABS,
  543. "FPCTIW", LFCONV, AFPCTIW,
  544. "FPCTIWZ", LFCONV, AFPCTIWZ,
  545. "FMOVSPD", LFCONV, AFMOVSPD,
  546. "FMOVPSD", LFCONV, AFMOVPSD,
  547. "FXCPNPMA", LFMA, AFXCPNPMA,
  548. "FXCSNPMA", LFMA, AFXCSNPMA,
  549. "FXCPNSMA", LFMA, AFXCPNSMA,
  550. "FXCSNSMA", LFMA, AFXCSNSMA,
  551. "FXCXNPMA", LFMA, AFXCXNPMA,
  552. "FXCXNSMA", LFMA, AFXCXNSMA,
  553. "FXCXMA", LFMA, AFXCXMA,
  554. "FXCXNMS", LFMA, AFXCXNMS,
  555. /* parallel, cross, and secondary load and store (fp2) */
  556. "FSMOVS", LFMOVX, AFSMOVS,
  557. "FSMOVSU", LFMOVX, AFSMOVSU,
  558. "FSMOVD", LFMOVX, AFSMOVD,
  559. "FSMOVDU", LFMOVX, AFSMOVDU,
  560. "FXMOVS", LFMOVX, AFXMOVS,
  561. "FXMOVSU", LFMOVX, AFXMOVSU,
  562. "FXMOVD", LFMOVX, AFXMOVD,
  563. "FXMOVDU", LFMOVX, AFXMOVDU,
  564. "FPMOVS", LFMOVX, AFPMOVS,
  565. "FPMOVSU", LFMOVX, AFPMOVSU,
  566. "FPMOVD", LFMOVX, AFPMOVD,
  567. "FPMOVDU", LFMOVX, AFPMOVDU,
  568. "FPMOVIW", LFMOVX, AFPMOVIW,
  569. "AFMOVSPD", LFMOV, AFMOVSPD,
  570. "AFMOVPSD", LFMOV, AFMOVPSD,
  571. /* special instructions */
  572. "DCBF", LXOP, ADCBF,
  573. "DCBI", LXOP, ADCBI,
  574. "DCBST", LXOP, ADCBST,
  575. "DCBT", LXOP, ADCBT,
  576. "DCBTST", LXOP, ADCBTST,
  577. "DCBZ", LXOP, ADCBZ,
  578. "ICBI", LXOP, AICBI,
  579. "ECIWX", LXLD, AECIWX,
  580. "ECOWX", LXST, AECOWX,
  581. "LWAR", LXLD, ALWAR,
  582. "STWCCC", LXST, ASTWCCC,
  583. "EIEIO", LRETRN, AEIEIO,
  584. "TLBIE", LNOP, ATLBIE,
  585. "LSW", LXLD, ALSW,
  586. "STSW", LXST, ASTSW,
  587. "ISYNC", LRETRN, AISYNC,
  588. "SYNC", LRETRN, ASYNC,
  589. /* "TW", LADDW, ATW,*/
  590. "WORD", LWORD, AWORD,
  591. "SCHED", LSCHED, 0,
  592. "NOSCHED", LSCHED, 0x80,
  593. 0
  594. };
  595. void
  596. cinit(void)
  597. {
  598. Sym *s;
  599. int i;
  600. nullgen.sym = S;
  601. nullgen.offset = 0;
  602. nullgen.type = D_NONE;
  603. nullgen.name = D_NONE;
  604. nullgen.reg = NREG;
  605. nullgen.xreg = NREG;
  606. if(FPCHIP)
  607. nullgen.dval = 0;
  608. for(i=0; i<sizeof(nullgen.sval); i++)
  609. nullgen.sval[i] = 0;
  610. nerrors = 0;
  611. iostack = I;
  612. iofree = I;
  613. peekc = IGN;
  614. nhunk = 0;
  615. for(i=0; i<NHASH; i++)
  616. hash[i] = S;
  617. for(i=0; itab[i].name; i++) {
  618. s = slookup(itab[i].name);
  619. s->type = itab[i].type;
  620. s->value = itab[i].value;
  621. }
  622. ALLOCN(pathname, 0, 100);
  623. if(mygetwd(pathname, 99) == 0) {
  624. ALLOCN(pathname, 100, 900);
  625. if(mygetwd(pathname, 999) == 0)
  626. strcpy(pathname, "/?");
  627. }
  628. }
  629. void
  630. syminit(Sym *s)
  631. {
  632. s->type = LNAME;
  633. s->value = 0;
  634. }
  635. void
  636. cclean(void)
  637. {
  638. outcode(AEND, &nullgen, NREG, &nullgen);
  639. Bflush(&obuf);
  640. }
  641. void
  642. zname(char *n, int t, int s)
  643. {
  644. Bputc(&obuf, ANAME);
  645. Bputc(&obuf, ANAME>>8);
  646. Bputc(&obuf, t); /* type */
  647. Bputc(&obuf, s); /* sym */
  648. while(*n) {
  649. Bputc(&obuf, *n);
  650. n++;
  651. }
  652. Bputc(&obuf, 0);
  653. }
  654. void
  655. zaddr(Gen *a, int s)
  656. {
  657. long l;
  658. int i;
  659. char *n;
  660. Ieee e;
  661. Bputc(&obuf, a->type);
  662. Bputc(&obuf, a->reg);
  663. Bputc(&obuf, s);
  664. Bputc(&obuf, a->name);
  665. switch(a->type) {
  666. default:
  667. print("unknown type %d\n", a->type);
  668. exits("arg");
  669. case D_NONE:
  670. case D_REG:
  671. case D_FREG:
  672. case D_CREG:
  673. case D_FPSCR:
  674. case D_MSR:
  675. case D_SREG:
  676. case D_OPT:
  677. break;
  678. case D_DCR:
  679. case D_SPR:
  680. case D_OREG:
  681. case D_CONST:
  682. case D_BRANCH:
  683. l = a->offset;
  684. Bputc(&obuf, l);
  685. Bputc(&obuf, l>>8);
  686. Bputc(&obuf, l>>16);
  687. Bputc(&obuf, l>>24);
  688. break;
  689. case D_SCONST:
  690. n = a->sval;
  691. for(i=0; i<NSNAME; i++) {
  692. Bputc(&obuf, *n);
  693. n++;
  694. }
  695. break;
  696. case D_FCONST:
  697. ieeedtod(&e, a->dval);
  698. Bputc(&obuf, e.l);
  699. Bputc(&obuf, e.l>>8);
  700. Bputc(&obuf, e.l>>16);
  701. Bputc(&obuf, e.l>>24);
  702. Bputc(&obuf, e.h);
  703. Bputc(&obuf, e.h>>8);
  704. Bputc(&obuf, e.h>>16);
  705. Bputc(&obuf, e.h>>24);
  706. break;
  707. }
  708. }
  709. int
  710. outsim(Gen *g)
  711. {
  712. Sym *s;
  713. int sno, t;
  714. s = g->sym;
  715. if(s == S)
  716. return 0;
  717. sno = s->sym;
  718. if(sno < 0 || sno >= NSYM)
  719. sno = 0;
  720. t = g->name;
  721. if(h[sno].type == t && h[sno].sym == s)
  722. return sno;
  723. zname(s->name, t, sym);
  724. s->sym = sym;
  725. h[sym].sym = s;
  726. h[sym].type = t;
  727. sno = sym;
  728. sym++;
  729. if(sym >= NSYM)
  730. sym = 1;
  731. return sno;
  732. }
  733. void
  734. outcode(int a, Gen *g1, int reg, Gen *g2)
  735. {
  736. int sf, st;
  737. if(a != AGLOBL && a != ADATA)
  738. pc++;
  739. if(pass == 1)
  740. return;
  741. if(g1->xreg != NREG) {
  742. if(reg != NREG || g2->xreg != NREG)
  743. yyerror("bad addressing modes");
  744. reg = g1->xreg;
  745. } else
  746. if(g2->xreg != NREG) {
  747. if(reg != NREG)
  748. yyerror("bad addressing modes");
  749. reg = g2->xreg;
  750. }
  751. do {
  752. sf = outsim(g1);
  753. st = outsim(g2);
  754. } while(sf != 0 && st == sf);
  755. Bputc(&obuf, a);
  756. Bputc(&obuf, a>>8);
  757. Bputc(&obuf, reg|nosched);
  758. Bputc(&obuf, lineno);
  759. Bputc(&obuf, lineno>>8);
  760. Bputc(&obuf, lineno>>16);
  761. Bputc(&obuf, lineno>>24);
  762. zaddr(g1, sf);
  763. zaddr(g2, st);
  764. }
  765. void
  766. outgcode(int a, Gen *g1, int reg, Gen *g2, Gen *g3)
  767. {
  768. int s1, s2, s3, flag;
  769. if(a != AGLOBL && a != ADATA)
  770. pc++;
  771. if(pass == 1)
  772. return;
  773. do {
  774. s1 = outsim(g1);
  775. s2 = outsim(g2);
  776. s3 = outsim(g3);
  777. } while(s1 && (s2 && s1 == s2 || s3 && s1 == s3) || s2 && (s3 && s2 == s3));
  778. flag = 0;
  779. if(g2->type != D_NONE)
  780. flag = 0x40; /* flags extra operand */
  781. Bputc(&obuf, a);
  782. Bputc(&obuf, a>>8);
  783. Bputc(&obuf, reg | nosched | flag);
  784. Bputc(&obuf, lineno);
  785. Bputc(&obuf, lineno>>8);
  786. Bputc(&obuf, lineno>>16);
  787. Bputc(&obuf, lineno>>24);
  788. zaddr(g1, s1);
  789. if(flag)
  790. zaddr(g2, s2);
  791. zaddr(g3, s3);
  792. }
  793. void
  794. outhist(void)
  795. {
  796. Gen g;
  797. Hist *h;
  798. char *p, *q, *op, c;
  799. int n;
  800. g = nullgen;
  801. c = pathchar();
  802. for(h = hist; h != H; h = h->link) {
  803. p = h->name;
  804. op = 0;
  805. /* on windows skip drive specifier in pathname */
  806. if(systemtype(Windows) && p && p[1] == ':'){
  807. p += 2;
  808. c = *p;
  809. }
  810. if(p && p[0] != c && h->offset == 0 && pathname){
  811. /* on windows skip drive specifier in pathname */
  812. if(systemtype(Windows) && pathname[1] == ':') {
  813. op = p;
  814. p = pathname+2;
  815. c = *p;
  816. } else if(pathname[0] == c){
  817. op = p;
  818. p = pathname;
  819. }
  820. }
  821. while(p) {
  822. q = strchr(p, c);
  823. if(q) {
  824. n = q-p;
  825. if(n == 0){
  826. n = 1; /* leading "/" */
  827. *p = '/'; /* don't emit "\" on windows */
  828. }
  829. q++;
  830. } else {
  831. n = strlen(p);
  832. q = 0;
  833. }
  834. if(n) {
  835. Bputc(&obuf, ANAME);
  836. Bputc(&obuf, ANAME>>8);
  837. Bputc(&obuf, D_FILE); /* type */
  838. Bputc(&obuf, 1); /* sym */
  839. Bputc(&obuf, '<');
  840. Bwrite(&obuf, p, n);
  841. Bputc(&obuf, 0);
  842. }
  843. p = q;
  844. if(p == 0 && op) {
  845. p = op;
  846. op = 0;
  847. }
  848. }
  849. g.offset = h->offset;
  850. Bputc(&obuf, AHISTORY);
  851. Bputc(&obuf, AHISTORY>>8);
  852. Bputc(&obuf, 0);
  853. Bputc(&obuf, h->line);
  854. Bputc(&obuf, h->line>>8);
  855. Bputc(&obuf, h->line>>16);
  856. Bputc(&obuf, h->line>>24);
  857. zaddr(&nullgen, 0);
  858. zaddr(&g, 0);
  859. }
  860. }
  861. #include "../cc/lexbody"
  862. #include "../cc/macbody"