a.y 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. %{
  2. #include "a.h"
  3. %}
  4. %union
  5. {
  6. Sym *sym;
  7. long lval;
  8. double dval;
  9. char sval[8];
  10. Gen gen;
  11. }
  12. %left '|'
  13. %left '^'
  14. %left '&'
  15. %left '<' '>'
  16. %left '+' '-'
  17. %left '*' '/' '%'
  18. %token <lval> LMOVW LMOVB LABS LLOGW LSHW LADDW LCMP LCROP
  19. %token <lval> LBRA LFMOV LFCONV LFCMP LFADD LFMA LTRAP LXORW
  20. %token <lval> LNOP LEND LRETT LWORD LTEXT LDATA LRETRN
  21. %token <lval> LCONST LSP LSB LFP LPC LCREG LFLUSH
  22. %token <lval> LREG LFREG LR LCR LF LFPSCR
  23. %token <lval> LLR LCTR LSPR LSPREG LSEG LMSR LDCR
  24. %token <lval> LSCHED LXLD LXST LXOP LXMV
  25. %token <lval> LRLWM LMOVMW LMOVEM LMOVFL LMTFSB LMA LFMOVX
  26. %token <dval> LFCONST
  27. %token <sval> LSCONST
  28. %token <sym> LNAME LLAB LVAR
  29. %type <lval> con expr pointer offset sreg
  30. %type <gen> addr rreg regaddr name creg freg xlreg lr ctr
  31. %type <gen> imm ximm fimm rel psr lcr cbit fpscr fpscrf seg msr mask
  32. %%
  33. prog:
  34. | prog line
  35. line:
  36. LLAB ':'
  37. {
  38. if($1->value != pc)
  39. yyerror("redeclaration of %s", $1->name);
  40. $1->value = pc;
  41. }
  42. line
  43. | LNAME ':'
  44. {
  45. $1->type = LLAB;
  46. $1->value = pc;
  47. }
  48. line
  49. | LNAME '=' expr ';'
  50. {
  51. $1->type = LVAR;
  52. $1->value = $3;
  53. }
  54. | LVAR '=' expr ';'
  55. {
  56. if($1->value != $3)
  57. yyerror("redeclaration of %s", $1->name);
  58. $1->value = $3;
  59. }
  60. | LSCHED ';'
  61. {
  62. nosched = $1;
  63. }
  64. | ';'
  65. | inst ';'
  66. | error ';'
  67. inst:
  68. /*
  69. * load ints and bytes
  70. */
  71. LMOVW rreg ',' rreg
  72. {
  73. outcode($1, &$2, NREG, &$4);
  74. }
  75. | LMOVW addr ',' rreg
  76. {
  77. outcode($1, &$2, NREG, &$4);
  78. }
  79. | LMOVW regaddr ',' rreg
  80. {
  81. outcode($1, &$2, NREG, &$4);
  82. }
  83. | LMOVB rreg ',' rreg
  84. {
  85. outcode($1, &$2, NREG, &$4);
  86. }
  87. | LMOVB addr ',' rreg
  88. {
  89. outcode($1, &$2, NREG, &$4);
  90. }
  91. | LMOVB regaddr ',' rreg
  92. {
  93. outcode($1, &$2, NREG, &$4);
  94. }
  95. /*
  96. * load and store floats
  97. */
  98. | LFMOV addr ',' freg
  99. {
  100. outcode($1, &$2, NREG, &$4);
  101. }
  102. | LFMOV regaddr ',' freg
  103. {
  104. outcode($1, &$2, NREG, &$4);
  105. }
  106. | LFMOV fimm ',' freg
  107. {
  108. outcode($1, &$2, NREG, &$4);
  109. }
  110. | LFMOV freg ',' freg
  111. {
  112. outcode($1, &$2, NREG, &$4);
  113. }
  114. | LFMOV freg ',' addr
  115. {
  116. outcode($1, &$2, NREG, &$4);
  117. }
  118. | LFMOV freg ',' regaddr
  119. {
  120. outcode($1, &$2, NREG, &$4);
  121. }
  122. /*
  123. * load and store floats, indexed only
  124. */
  125. | LFMOVX regaddr ',' freg
  126. {
  127. outcode($1, &$2, NREG, &$4);
  128. }
  129. | LFMOVX freg ',' regaddr
  130. {
  131. outcode($1, &$2, NREG, &$4);
  132. }
  133. /*
  134. * store ints and bytes
  135. */
  136. | LMOVW rreg ',' addr
  137. {
  138. outcode($1, &$2, NREG, &$4);
  139. }
  140. | LMOVW rreg ',' regaddr
  141. {
  142. outcode($1, &$2, NREG, &$4);
  143. }
  144. | LMOVB rreg ',' addr
  145. {
  146. outcode($1, &$2, NREG, &$4);
  147. }
  148. | LMOVB rreg ',' regaddr
  149. {
  150. outcode($1, &$2, NREG, &$4);
  151. }
  152. /*
  153. * store floats
  154. */
  155. | LMOVW freg ',' addr
  156. {
  157. outcode($1, &$2, NREG, &$4);
  158. }
  159. | LMOVW freg ',' regaddr
  160. {
  161. outcode($1, &$2, NREG, &$4);
  162. }
  163. /*
  164. * floating point status
  165. */
  166. | LMOVW fpscr ',' freg
  167. {
  168. outcode($1, &$2, NREG, &$4);
  169. }
  170. | LMOVW freg ',' fpscr
  171. {
  172. outcode($1, &$2, NREG, &$4);
  173. }
  174. | LMOVW freg ',' imm ',' fpscr
  175. {
  176. outgcode($1, &$2, NREG, &$4, &$6);
  177. }
  178. | LMOVW fpscr ',' creg
  179. {
  180. outcode($1, &$2, NREG, &$4);
  181. }
  182. | LMOVW imm ',' fpscrf
  183. {
  184. outcode($1, &$2, NREG, &$4);
  185. }
  186. | LMTFSB imm ',' con
  187. {
  188. outcode($1, &$2, $4, &nullgen);
  189. }
  190. /*
  191. * field moves (mtcrf)
  192. */
  193. | LMOVW rreg ',' imm ',' lcr
  194. {
  195. outgcode($1, &$2, NREG, &$4, &$6);
  196. }
  197. | LMOVW rreg ',' creg
  198. {
  199. outcode($1, &$2, NREG, &$4);
  200. }
  201. | LMOVW rreg ',' lcr
  202. {
  203. outcode($1, &$2, NREG, &$4);
  204. }
  205. /*
  206. * integer operations
  207. * logical instructions
  208. * shift instructions
  209. * unary instructions
  210. */
  211. | LADDW rreg ',' sreg ',' rreg
  212. {
  213. outcode($1, &$2, $4, &$6);
  214. }
  215. | LADDW imm ',' sreg ',' rreg
  216. {
  217. outcode($1, &$2, $4, &$6);
  218. }
  219. | LADDW rreg ',' imm ',' rreg
  220. {
  221. outgcode($1, &$2, NREG, &$4, &$6);
  222. }
  223. | LADDW rreg ',' rreg
  224. {
  225. outcode($1, &$2, NREG, &$4);
  226. }
  227. | LADDW imm ',' rreg
  228. {
  229. outcode($1, &$2, NREG, &$4);
  230. }
  231. | LLOGW rreg ',' sreg ',' rreg
  232. {
  233. outcode($1, &$2, $4, &$6);
  234. }
  235. | LLOGW rreg ',' rreg
  236. {
  237. outcode($1, &$2, NREG, &$4);
  238. }
  239. | LSHW rreg ',' sreg ',' rreg
  240. {
  241. outcode($1, &$2, $4, &$6);
  242. }
  243. | LSHW rreg ',' rreg
  244. {
  245. outcode($1, &$2, NREG, &$4);
  246. }
  247. | LSHW imm ',' sreg ',' rreg
  248. {
  249. outcode($1, &$2, $4, &$6);
  250. }
  251. | LSHW imm ',' rreg
  252. {
  253. outcode($1, &$2, NREG, &$4);
  254. }
  255. | LABS rreg ',' rreg
  256. {
  257. outcode($1, &$2, NREG, &$4);
  258. }
  259. | LABS rreg
  260. {
  261. outcode($1, &$2, NREG, &$2);
  262. }
  263. /*
  264. * multiply-accumulate
  265. */
  266. | LMA rreg ',' sreg ',' rreg
  267. {
  268. outcode($1, &$2, $4, &$6);
  269. }
  270. /*
  271. * move immediate: macro for cau+or, addi, addis, and other combinations
  272. */
  273. | LMOVW imm ',' rreg
  274. {
  275. outcode($1, &$2, NREG, &$4);
  276. }
  277. | LMOVW ximm ',' rreg
  278. {
  279. outcode($1, &$2, NREG, &$4);
  280. }
  281. /*
  282. * condition register operations
  283. */
  284. | LCROP cbit ',' cbit
  285. {
  286. outcode($1, &$2, $4.reg, &$4);
  287. }
  288. | LCROP cbit ',' con ',' cbit
  289. {
  290. outcode($1, &$2, $4, &$6);
  291. }
  292. /*
  293. * condition register moves
  294. * move from machine state register
  295. */
  296. | LMOVW creg ',' creg
  297. {
  298. outcode($1, &$2, NREG, &$4);
  299. }
  300. | LMOVW psr ',' creg
  301. {
  302. outcode($1, &$2, NREG, &$4);
  303. }
  304. | LMOVW lcr ',' rreg
  305. {
  306. outcode($1, &$2, NREG, &$4);
  307. }
  308. | LMOVW psr ',' rreg
  309. {
  310. outcode($1, &$2, NREG, &$4);
  311. }
  312. | LMOVW seg ',' rreg
  313. {
  314. int r;
  315. r = $2.offset;
  316. $2.offset = 0;
  317. outcode($1, &$2, r, &$4);
  318. }
  319. | LMOVW rreg ',' seg
  320. {
  321. int r;
  322. r = $4.offset;
  323. $4.offset = 0;
  324. outcode($1, &$2, r, &$4);
  325. }
  326. | LMOVW xlreg ',' rreg
  327. {
  328. outcode($1, &$2, NREG, &$4);
  329. }
  330. | LMOVW rreg ',' xlreg
  331. {
  332. outcode($1, &$2, NREG, &$4);
  333. }
  334. | LMOVW creg ',' psr
  335. {
  336. outcode($1, &$2, NREG, &$4);
  337. }
  338. | LMOVW rreg ',' psr
  339. {
  340. outcode($1, &$2, NREG, &$4);
  341. }
  342. /*
  343. * branch, branch conditional
  344. * branch conditional register
  345. * branch conditional to count register
  346. */
  347. | LBRA rel
  348. {
  349. outcode($1, &nullgen, NREG, &$2);
  350. }
  351. | LBRA addr
  352. {
  353. outcode($1, &nullgen, NREG, &$2);
  354. }
  355. | LBRA '(' xlreg ')'
  356. {
  357. outcode($1, &nullgen, NREG, &$3);
  358. }
  359. | LBRA ',' rel
  360. {
  361. outcode($1, &nullgen, NREG, &$3);
  362. }
  363. | LBRA ',' addr
  364. {
  365. outcode($1, &nullgen, NREG, &$3);
  366. }
  367. | LBRA ',' '(' xlreg ')'
  368. {
  369. outcode($1, &nullgen, NREG, &$4);
  370. }
  371. | LBRA creg ',' rel
  372. {
  373. outcode($1, &$2, NREG, &$4);
  374. }
  375. | LBRA creg ',' addr
  376. {
  377. outcode($1, &$2, NREG, &$4);
  378. }
  379. | LBRA creg ',' '(' xlreg ')'
  380. {
  381. outcode($1, &$2, NREG, &$5);
  382. }
  383. | LBRA con ',' rel
  384. {
  385. outcode($1, &nullgen, $2, &$4);
  386. }
  387. | LBRA con ',' addr
  388. {
  389. outcode($1, &nullgen, $2, &$4);
  390. }
  391. | LBRA con ',' '(' xlreg ')'
  392. {
  393. outcode($1, &nullgen, $2, &$5);
  394. }
  395. | LBRA con ',' con ',' rel
  396. {
  397. Gen g;
  398. g = nullgen;
  399. g.type = D_CONST;
  400. g.offset = $2;
  401. outcode($1, &g, $4, &$6);
  402. }
  403. | LBRA con ',' con ',' addr
  404. {
  405. Gen g;
  406. g = nullgen;
  407. g.type = D_CONST;
  408. g.offset = $2;
  409. outcode($1, &g, $4, &$6);
  410. }
  411. | LBRA con ',' con ',' '(' xlreg ')'
  412. {
  413. Gen g;
  414. g = nullgen;
  415. g.type = D_CONST;
  416. g.offset = $2;
  417. outcode($1, &g, $4, &$7);
  418. }
  419. /*
  420. * conditional trap
  421. */
  422. | LTRAP rreg ',' sreg
  423. {
  424. outcode($1, &$2, $4, &nullgen);
  425. }
  426. | LTRAP imm ',' sreg
  427. {
  428. outcode($1, &$2, $4, &nullgen);
  429. }
  430. | LTRAP rreg comma
  431. {
  432. outcode($1, &$2, NREG, &nullgen);
  433. }
  434. | LTRAP comma
  435. {
  436. outcode($1, &nullgen, NREG, &nullgen);
  437. }
  438. /*
  439. * floating point operate
  440. */
  441. | LFCONV freg ',' freg
  442. {
  443. outcode($1, &$2, NREG, &$4);
  444. }
  445. | LFADD freg ',' freg
  446. {
  447. outcode($1, &$2, NREG, &$4);
  448. }
  449. | LFADD freg ',' freg ',' freg
  450. {
  451. outcode($1, &$2, $4.reg, &$6);
  452. }
  453. | LFMA freg ',' freg ',' freg ',' freg
  454. {
  455. outgcode($1, &$2, $4.reg, &$6, &$8);
  456. }
  457. | LFCMP freg ',' freg
  458. {
  459. outcode($1, &$2, NREG, &$4);
  460. }
  461. | LFCMP freg ',' freg ',' creg
  462. {
  463. outcode($1, &$2, $6.reg, &$4);
  464. }
  465. /*
  466. * CMP
  467. */
  468. | LCMP rreg ',' rreg
  469. {
  470. outcode($1, &$2, NREG, &$4);
  471. }
  472. | LCMP rreg ',' imm
  473. {
  474. outcode($1, &$2, NREG, &$4);
  475. }
  476. | LCMP rreg ',' rreg ',' creg
  477. {
  478. outcode($1, &$2, $6.reg, &$4);
  479. }
  480. | LCMP rreg ',' imm ',' creg
  481. {
  482. outcode($1, &$2, $6.reg, &$4);
  483. }
  484. /*
  485. * rotate and mask
  486. */
  487. | LRLWM imm ',' rreg ',' imm ',' rreg
  488. {
  489. outgcode($1, &$2, $4.reg, &$6, &$8);
  490. }
  491. | LRLWM imm ',' rreg ',' mask ',' rreg
  492. {
  493. outgcode($1, &$2, $4.reg, &$6, &$8);
  494. }
  495. | LRLWM rreg ',' rreg ',' imm ',' rreg
  496. {
  497. outgcode($1, &$2, $4.reg, &$6, &$8);
  498. }
  499. | LRLWM rreg ',' rreg ',' mask ',' rreg
  500. {
  501. outgcode($1, &$2, $4.reg, &$6, &$8);
  502. }
  503. /*
  504. * load/store multiple
  505. */
  506. | LMOVMW addr ',' rreg
  507. {
  508. outcode($1, &$2, NREG, &$4);
  509. }
  510. | LMOVMW rreg ',' addr
  511. {
  512. outcode($1, &$2, NREG, &$4);
  513. }
  514. /*
  515. * various indexed load/store
  516. * indexed unary (eg, cache clear)
  517. */
  518. | LXLD regaddr ',' rreg
  519. {
  520. outcode($1, &$2, NREG, &$4);
  521. }
  522. | LXLD regaddr ',' imm ',' rreg
  523. {
  524. outgcode($1, &$2, NREG, &$4, &$6);
  525. }
  526. | LXST rreg ',' regaddr
  527. {
  528. outcode($1, &$2, NREG, &$4);
  529. }
  530. | LXST rreg ',' imm ',' regaddr
  531. {
  532. outgcode($1, &$2, NREG, &$4, &$6);
  533. }
  534. | LXMV regaddr ',' rreg
  535. {
  536. outcode($1, &$2, NREG, &$4);
  537. }
  538. | LXMV rreg ',' regaddr
  539. {
  540. outcode($1, &$2, NREG, &$4);
  541. }
  542. | LXOP regaddr
  543. {
  544. outcode($1, &$2, NREG, &nullgen);
  545. }
  546. /*
  547. * NOP
  548. */
  549. | LNOP comma
  550. {
  551. outcode($1, &nullgen, NREG, &nullgen);
  552. }
  553. | LNOP rreg comma
  554. {
  555. outcode($1, &$2, NREG, &nullgen);
  556. }
  557. | LNOP freg comma
  558. {
  559. outcode($1, &$2, NREG, &nullgen);
  560. }
  561. | LNOP ',' rreg
  562. {
  563. outcode($1, &nullgen, NREG, &$3);
  564. }
  565. | LNOP ',' freg
  566. {
  567. outcode($1, &nullgen, NREG, &$3);
  568. }
  569. /*
  570. * word
  571. */
  572. | LWORD imm comma
  573. {
  574. outcode($1, &$2, NREG, &nullgen);
  575. }
  576. | LWORD ximm comma
  577. {
  578. outcode($1, &$2, NREG, &nullgen);
  579. }
  580. /*
  581. * END
  582. */
  583. | LEND comma
  584. {
  585. outcode($1, &nullgen, NREG, &nullgen);
  586. }
  587. /*
  588. * TEXT/GLOBL
  589. */
  590. | LTEXT name ',' imm
  591. {
  592. outcode($1, &$2, NREG, &$4);
  593. }
  594. | LTEXT name ',' con ',' imm
  595. {
  596. outcode($1, &$2, $4, &$6);
  597. }
  598. | LTEXT name ',' imm ':' imm
  599. {
  600. outgcode($1, &$2, NREG, &$6, &$4);
  601. }
  602. | LTEXT name ',' con ',' imm ':' imm
  603. {
  604. outgcode($1, &$2, $4, &$8, &$6);
  605. }
  606. /*
  607. * DATA
  608. */
  609. | LDATA name '/' con ',' imm
  610. {
  611. outcode($1, &$2, $4, &$6);
  612. }
  613. | LDATA name '/' con ',' ximm
  614. {
  615. outcode($1, &$2, $4, &$6);
  616. }
  617. | LDATA name '/' con ',' fimm
  618. {
  619. outcode($1, &$2, $4, &$6);
  620. }
  621. /*
  622. * RETURN
  623. */
  624. | LRETRN comma
  625. {
  626. outcode($1, &nullgen, NREG, &nullgen);
  627. }
  628. rel:
  629. con '(' LPC ')'
  630. {
  631. $$ = nullgen;
  632. $$.type = D_BRANCH;
  633. $$.offset = $1 + pc;
  634. }
  635. | LNAME offset
  636. {
  637. $$ = nullgen;
  638. if(pass == 2)
  639. yyerror("undefined label: %s", $1->name);
  640. $$.type = D_BRANCH;
  641. $$.sym = $1;
  642. $$.offset = $2;
  643. }
  644. | LLAB offset
  645. {
  646. $$ = nullgen;
  647. $$.type = D_BRANCH;
  648. $$.sym = $1;
  649. $$.offset = $1->value + $2;
  650. }
  651. rreg:
  652. sreg
  653. {
  654. $$ = nullgen;
  655. $$.type = D_REG;
  656. $$.reg = $1;
  657. }
  658. xlreg:
  659. lr
  660. | ctr
  661. lr:
  662. LLR
  663. {
  664. $$ = nullgen;
  665. $$.type = D_SPR;
  666. $$.offset = $1;
  667. }
  668. lcr:
  669. LCR
  670. {
  671. $$ = nullgen;
  672. $$.type = D_CREG;
  673. $$.reg = NREG; /* whole register */
  674. }
  675. ctr:
  676. LCTR
  677. {
  678. $$ = nullgen;
  679. $$.type = D_SPR;
  680. $$.offset = $1;
  681. }
  682. msr:
  683. LMSR
  684. {
  685. $$ = nullgen;
  686. $$.type = D_MSR;
  687. }
  688. psr:
  689. LSPREG
  690. {
  691. $$ = nullgen;
  692. $$.type = D_SPR;
  693. $$.offset = $1;
  694. }
  695. | LSPR '(' con ')'
  696. {
  697. $$ = nullgen;
  698. $$.type = $1;
  699. $$.offset = $3;
  700. }
  701. | LDCR '(' con ')'
  702. {
  703. $$ = nullgen;
  704. $$.type = $1;
  705. $$.offset = $3;
  706. }
  707. | LDCR '(' sreg ')'
  708. {
  709. $$ = nullgen;
  710. $$.type = $1;
  711. $$.reg = $3;
  712. $$.offset = 0;
  713. }
  714. | msr
  715. seg:
  716. LSEG '(' con ')'
  717. {
  718. if($3 < 0 || $3 > 15)
  719. yyerror("segment register number out of range");
  720. $$ = nullgen;
  721. $$.type = D_SREG;
  722. $$.reg = $3;
  723. $$.offset = NREG;
  724. }
  725. | LSEG '(' sreg ')'
  726. {
  727. $$ = nullgen;
  728. $$.type = D_SREG;
  729. $$.reg = NREG;
  730. $$.offset = $3;
  731. }
  732. fpscr:
  733. LFPSCR
  734. {
  735. $$ = nullgen;
  736. $$.type = D_FPSCR;
  737. $$.reg = NREG;
  738. }
  739. fpscrf:
  740. LFPSCR '(' con ')'
  741. {
  742. $$ = nullgen;
  743. $$.type = D_FPSCR;
  744. $$.reg = $3;
  745. }
  746. freg:
  747. LFREG
  748. {
  749. $$ = nullgen;
  750. $$.type = D_FREG;
  751. $$.reg = $1;
  752. }
  753. | LF '(' con ')'
  754. {
  755. $$ = nullgen;
  756. $$.type = D_FREG;
  757. $$.reg = $3;
  758. }
  759. creg:
  760. LCREG
  761. {
  762. $$ = nullgen;
  763. $$.type = D_CREG;
  764. $$.reg = $1;
  765. }
  766. | LCR '(' con ')'
  767. {
  768. $$ = nullgen;
  769. $$.type = D_CREG;
  770. $$.reg = $3;
  771. }
  772. cbit: con
  773. {
  774. $$ = nullgen;
  775. $$.type = D_REG;
  776. $$.reg = $1;
  777. }
  778. mask:
  779. con ',' con
  780. {
  781. int mb, me;
  782. ulong v;
  783. $$ = nullgen;
  784. $$.type = D_CONST;
  785. mb = $1;
  786. me = $3;
  787. if(mb < 0 || mb > 31 || me < 0 || me > 31){
  788. yyerror("illegal mask start/end value(s)");
  789. mb = me = 0;
  790. }
  791. if(mb <= me)
  792. v = ((ulong)~0L>>mb) & (~0L<<(31-me));
  793. else
  794. v = ~(((ulong)~0L>>(me+1)) & (~0L<<(31-(mb-1))));
  795. $$.offset = v;
  796. }
  797. ximm:
  798. '$' addr
  799. {
  800. $$ = $2;
  801. $$.type = D_CONST;
  802. }
  803. | '$' LSCONST
  804. {
  805. $$ = nullgen;
  806. $$.type = D_SCONST;
  807. memcpy($$.sval, $2, sizeof($$.sval));
  808. }
  809. fimm:
  810. '$' LFCONST
  811. {
  812. $$ = nullgen;
  813. $$.type = D_FCONST;
  814. $$.dval = $2;
  815. }
  816. | '$' '-' LFCONST
  817. {
  818. $$ = nullgen;
  819. $$.type = D_FCONST;
  820. $$.dval = -$3;
  821. }
  822. imm: '$' con
  823. {
  824. $$ = nullgen;
  825. $$.type = D_CONST;
  826. $$.offset = $2;
  827. }
  828. sreg:
  829. LREG
  830. | LR '(' con ')'
  831. {
  832. if($$ < 0 || $$ >= NREG)
  833. print("register value out of range\n");
  834. $$ = $3;
  835. }
  836. regaddr:
  837. '(' sreg ')'
  838. {
  839. $$ = nullgen;
  840. $$.type = D_OREG;
  841. $$.reg = $2;
  842. $$.offset = 0;
  843. }
  844. | '(' sreg '+' sreg ')'
  845. {
  846. $$ = nullgen;
  847. $$.type = D_OREG;
  848. $$.reg = $2;
  849. $$.xreg = $4;
  850. $$.offset = 0;
  851. }
  852. addr:
  853. name
  854. | con '(' sreg ')'
  855. {
  856. $$ = nullgen;
  857. $$.type = D_OREG;
  858. $$.reg = $3;
  859. $$.offset = $1;
  860. }
  861. name:
  862. con '(' pointer ')'
  863. {
  864. $$ = nullgen;
  865. $$.type = D_OREG;
  866. $$.name = $3;
  867. $$.sym = S;
  868. $$.offset = $1;
  869. }
  870. | LNAME offset '(' pointer ')'
  871. {
  872. $$ = nullgen;
  873. $$.type = D_OREG;
  874. $$.name = $4;
  875. $$.sym = $1;
  876. $$.offset = $2;
  877. }
  878. | LNAME '<' '>' offset '(' LSB ')'
  879. {
  880. $$ = nullgen;
  881. $$.type = D_OREG;
  882. $$.name = D_STATIC;
  883. $$.sym = $1;
  884. $$.offset = $4;
  885. }
  886. comma:
  887. | ','
  888. offset:
  889. {
  890. $$ = 0;
  891. }
  892. | '+' con
  893. {
  894. $$ = $2;
  895. }
  896. | '-' con
  897. {
  898. $$ = -$2;
  899. }
  900. pointer:
  901. LSB
  902. | LSP
  903. | LFP
  904. con:
  905. LCONST
  906. | LVAR
  907. {
  908. $$ = $1->value;
  909. }
  910. | '-' con
  911. {
  912. $$ = -$2;
  913. }
  914. | '+' con
  915. {
  916. $$ = $2;
  917. }
  918. | '~' con
  919. {
  920. $$ = ~$2;
  921. }
  922. | '(' expr ')'
  923. {
  924. $$ = $2;
  925. }
  926. expr:
  927. con
  928. | expr '+' expr
  929. {
  930. $$ = $1 + $3;
  931. }
  932. | expr '-' expr
  933. {
  934. $$ = $1 - $3;
  935. }
  936. | expr '*' expr
  937. {
  938. $$ = $1 * $3;
  939. }
  940. | expr '/' expr
  941. {
  942. $$ = $1 / $3;
  943. }
  944. | expr '%' expr
  945. {
  946. $$ = $1 % $3;
  947. }
  948. | expr '<' '<' expr
  949. {
  950. $$ = $1 << $4;
  951. }
  952. | expr '>' '>' expr
  953. {
  954. $$ = $1 >> $4;
  955. }
  956. | expr '&' expr
  957. {
  958. $$ = $1 & $3;
  959. }
  960. | expr '^' expr
  961. {
  962. $$ = $1 ^ $3;
  963. }
  964. | expr '|' expr
  965. {
  966. $$ = $1 | $3;
  967. }