rappcgas.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. {
  2. $Id: rappcgas.pas,v 1.19 2005/02/14 17:13:10 peter Exp $
  3. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  4. Does the parsing for the PowerPC GNU AS styled inline assembler.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit rappcgas;
  19. {$I fpcdefs.inc}
  20. interface
  21. uses
  22. raatt, rappc;
  23. type
  24. tppcattreader = class(tattreader)
  25. function is_asmopcode(const s: string): boolean; override;
  26. procedure handleopcode; override;
  27. procedure BuildReference(oper: tppcoperand);
  28. procedure BuildOperand(oper: tppcoperand);
  29. procedure BuildOpCode(instr: tppcinstruction);
  30. procedure ReadAt(oper: tppcoperand);
  31. procedure ReadSym(oper: tppcoperand);
  32. procedure ConvertCalljmp(instr: tppcinstruction);
  33. end;
  34. implementation
  35. uses
  36. { helpers }
  37. cutils,
  38. { global }
  39. globtype, verbose,
  40. systems,
  41. { aasm }
  42. cpubase, aasmbase, aasmtai,aasmdata, aasmcpu,
  43. { symtable }
  44. symconst, symsym,
  45. { parser }
  46. procinfo,
  47. rabase, rautils,
  48. cgbase, cgobj
  49. ;
  50. procedure tppcattreader.ReadSym(oper: tppcoperand);
  51. var
  52. tempstr, mangledname: string;
  53. typesize, l, k: aint;
  54. begin
  55. tempstr := actasmpattern;
  56. Consume(AS_ID);
  57. { typecasting? }
  58. if (actasmtoken = AS_LPAREN) and
  59. SearchType(tempstr, typesize) then
  60. begin
  61. oper.hastype := true;
  62. Consume(AS_LPAREN);
  63. BuildOperand(oper);
  64. Consume(AS_RPAREN);
  65. if oper.opr.typ in [OPR_REFERENCE, OPR_LOCAL] then
  66. oper.SetSize(typesize, true);
  67. end
  68. else if not oper.SetupVar(tempstr, false) then
  69. Message1(sym_e_unknown_id, tempstr);
  70. { record.field ? }
  71. if actasmtoken = AS_DOT then
  72. begin
  73. BuildRecordOffsetSize(tempstr, l, k, mangledname, false);
  74. if (mangledname<>'') then
  75. Message(asmr_e_invalid_reference_syntax);
  76. inc(oper.opr.ref.offset, l);
  77. end;
  78. end;
  79. procedure tppcattreader.ReadAt(oper: tppcoperand);
  80. begin
  81. { check for ...@ }
  82. if actasmtoken = AS_AT then
  83. begin
  84. if (oper.opr.ref.symbol = nil) and
  85. (oper.opr.ref.offset = 0) then
  86. Message(asmr_e_invalid_reference_syntax);
  87. Consume(AS_AT);
  88. if actasmtoken = AS_ID then
  89. begin
  90. if upper(actasmpattern) = 'L' then
  91. oper.opr.ref.refaddr := addr_low
  92. else if upper(actasmpattern) = 'HA' then
  93. oper.opr.ref.refaddr := addr_higha
  94. else if upper(actasmpattern) = 'H' then
  95. oper.opr.ref.refaddr := addr_high
  96. else if upper(actasmpattern) = 'HIGHERA' then
  97. oper.opr.ref.refaddr := addr_highera
  98. else if upper(actasmpattern) = 'HIGHESTA' then
  99. oper.opr.ref.refaddr := addr_highesta
  100. else if upper(actasmpattern) = 'HIGHER' then
  101. oper.opr.ref.refaddr := addr_higher
  102. else if upper(actasmpattern) = 'HIGHEST' then
  103. oper.opr.ref.refaddr := addr_highest
  104. else
  105. Message(asmr_e_invalid_reference_syntax);
  106. Consume(AS_ID);
  107. end
  108. else
  109. Message(asmr_e_invalid_reference_syntax);
  110. end;
  111. end;
  112. procedure tppcattreader.BuildReference(oper: tppcoperand);
  113. procedure Consume_RParen;
  114. begin
  115. if actasmtoken <> AS_RPAREN then
  116. begin
  117. Message(asmr_e_invalid_reference_syntax);
  118. RecoverConsume(true);
  119. end
  120. else
  121. begin
  122. Consume(AS_RPAREN);
  123. if not (actasmtoken in [AS_COMMA, AS_SEPARATOR, AS_END]) then
  124. begin
  125. Message(asmr_e_invalid_reference_syntax);
  126. RecoverConsume(true);
  127. end;
  128. end;
  129. end;
  130. var
  131. l: aint;
  132. begin
  133. Consume(AS_LPAREN);
  134. case actasmtoken of
  135. AS_INTNUM,
  136. AS_MINUS,
  137. AS_PLUS:
  138. begin
  139. { offset(offset) is invalid }
  140. if oper.opr.Ref.Offset <> 0 then
  141. begin
  142. Message(asmr_e_invalid_reference_syntax);
  143. RecoverConsume(true);
  144. end
  145. else
  146. begin
  147. oper.opr.Ref.Offset := BuildConstExpression(false, true);
  148. Consume(AS_RPAREN);
  149. if actasmtoken = AS_AT then
  150. ReadAt(oper);
  151. end;
  152. exit;
  153. end;
  154. AS_REGISTER: { (reg ... }
  155. begin
  156. if ((oper.opr.typ = OPR_REFERENCE) and (oper.opr.ref.base <> NR_NO)) or
  157. ((oper.opr.typ = OPR_LOCAL) and (oper.opr.localsym.localloc.loc <>
  158. LOC_REGISTER)) then
  159. message(asmr_e_cannot_index_relative_var);
  160. oper.opr.ref.base := actasmregister;
  161. Consume(AS_REGISTER);
  162. { can either be a register or a right parenthesis }
  163. { (reg) }
  164. if actasmtoken = AS_RPAREN then
  165. begin
  166. Consume_RParen;
  167. exit;
  168. end;
  169. { (reg,reg .. }
  170. Consume(AS_COMMA);
  171. if (actasmtoken = AS_REGISTER) and
  172. (oper.opr.Ref.Offset = 0) then
  173. begin
  174. oper.opr.ref.index := actasmregister;
  175. Consume(AS_REGISTER);
  176. Consume_RParen;
  177. end
  178. else
  179. begin
  180. Message(asmr_e_invalid_reference_syntax);
  181. RecoverConsume(false);
  182. end;
  183. end; {end case }
  184. AS_ID:
  185. begin
  186. ReadSym(oper);
  187. { add a constant expression? }
  188. if (actasmtoken = AS_PLUS) then
  189. begin
  190. l := BuildConstExpression(true, true);
  191. case oper.opr.typ of
  192. OPR_CONSTANT:
  193. inc(oper.opr.val, l);
  194. OPR_LOCAL:
  195. inc(oper.opr.localsymofs, l);
  196. OPR_REFERENCE:
  197. inc(oper.opr.ref.offset, l);
  198. else
  199. internalerror(200309202);
  200. end;
  201. end;
  202. Consume(AS_RPAREN);
  203. if actasmtoken = AS_AT then
  204. ReadAt(oper);
  205. end;
  206. AS_COMMA: { (, ... can either be scaling, or index }
  207. begin
  208. Consume(AS_COMMA);
  209. { Index }
  210. if (actasmtoken = AS_REGISTER) then
  211. begin
  212. oper.opr.ref.index := actasmregister;
  213. Consume(AS_REGISTER);
  214. { check for scaling ... }
  215. Consume_RParen;
  216. end
  217. else
  218. begin
  219. Message(asmr_e_invalid_reference_syntax);
  220. RecoverConsume(false);
  221. end;
  222. end;
  223. else
  224. begin
  225. Message(asmr_e_invalid_reference_syntax);
  226. RecoverConsume(false);
  227. end;
  228. end;
  229. end;
  230. procedure tppcattreader.BuildOperand(oper: tppcoperand);
  231. var
  232. expr: string;
  233. typesize, l: aint;
  234. procedure AddLabelOperand(hl: tasmlabel);
  235. begin
  236. if not (actasmtoken in [AS_PLUS, AS_MINUS, AS_LPAREN]) and
  237. is_calljmp(actopcode) then
  238. begin
  239. oper.opr.typ := OPR_SYMBOL;
  240. oper.opr.symbol := hl;
  241. end
  242. else
  243. begin
  244. oper.InitRef;
  245. oper.opr.ref.symbol := hl;
  246. end;
  247. end;
  248. procedure MaybeRecordOffset;
  249. var
  250. mangledname : string;
  251. hasdot: boolean;
  252. l,
  253. toffset,
  254. tsize: aint;
  255. begin
  256. if not (actasmtoken in [AS_DOT, AS_PLUS, AS_MINUS]) then
  257. exit;
  258. l := 0;
  259. hasdot := (actasmtoken = AS_DOT);
  260. if hasdot then
  261. begin
  262. if expr <> '' then
  263. begin
  264. BuildRecordOffsetSize(expr, toffset, tsize, mangledname, false);
  265. if (oper.opr.typ<>OPR_CONSTANT) and
  266. (mangledname<>'') then
  267. Message(asmr_e_wrong_sym_type);
  268. inc(l, toffset);
  269. oper.SetSize(tsize, true);
  270. end;
  271. end;
  272. if actasmtoken in [AS_PLUS, AS_MINUS] then
  273. inc(l, BuildConstExpression(true, false));
  274. case oper.opr.typ of
  275. OPR_LOCAL:
  276. begin
  277. { don't allow direct access to fields of parameters, because that
  278. will generate buggy code. Allow it only for explicit typecasting }
  279. if hasdot and
  280. (not oper.hastype) and
  281. (tabstractvarsym(oper.opr.localsym).owner.symtabletype =
  282. parasymtable) and
  283. (current_procinfo.procdef.proccalloption <> pocall_register) then
  284. Message(asmr_e_cannot_access_field_directly_for_parameters);
  285. inc(oper.opr.localsymofs, l)
  286. end;
  287. OPR_CONSTANT:
  288. if (mangledname<>'') then
  289. begin
  290. if (oper.opr.val<>0) then
  291. Message(asmr_e_wrong_sym_type);
  292. oper.opr.typ:=OPR_SYMBOL;
  293. oper.opr.symbol:=current_asmdata.RefAsmSymbol(mangledname);
  294. end
  295. else
  296. inc(oper.opr.val,l);
  297. OPR_REFERENCE:
  298. inc(oper.opr.ref.offset, l);
  299. OPR_SYMBOL:
  300. Message(asmr_e_invalid_symbol_ref);
  301. else
  302. internalerror(200309221);
  303. end;
  304. end;
  305. function MaybeBuildReference: boolean;
  306. { Try to create a reference, if not a reference is found then false
  307. is returned }
  308. begin
  309. MaybeBuildReference := true;
  310. case actasmtoken of
  311. AS_INTNUM,
  312. AS_MINUS,
  313. AS_PLUS:
  314. begin
  315. oper.opr.ref.offset := BuildConstExpression(True, False);
  316. if actasmtoken <> AS_LPAREN then
  317. Message(asmr_e_invalid_reference_syntax)
  318. else
  319. BuildReference(oper);
  320. end;
  321. AS_LPAREN:
  322. BuildReference(oper);
  323. AS_ID: { only a variable is allowed ... }
  324. begin
  325. ReadSym(oper);
  326. case actasmtoken of
  327. AS_END,
  328. AS_SEPARATOR,
  329. AS_COMMA: ;
  330. AS_LPAREN:
  331. BuildReference(oper);
  332. else
  333. begin
  334. Message(asmr_e_invalid_reference_syntax);
  335. Consume(actasmtoken);
  336. end;
  337. end; {end case }
  338. end;
  339. else
  340. MaybeBuildReference := false;
  341. end; { end case }
  342. end;
  343. var
  344. tempreg: tregister;
  345. hl: tasmlabel;
  346. ofs: aint;
  347. begin
  348. expr := '';
  349. case actasmtoken of
  350. AS_LPAREN: { Memory reference or constant expression }
  351. begin
  352. oper.InitRef;
  353. BuildReference(oper);
  354. end;
  355. AS_INTNUM,
  356. AS_MINUS,
  357. AS_PLUS:
  358. begin
  359. { Constant memory offset }
  360. { This must absolutely be followed by ( }
  361. oper.InitRef;
  362. oper.opr.ref.offset := BuildConstExpression(True, False);
  363. if actasmtoken <> AS_LPAREN then
  364. begin
  365. ofs := oper.opr.ref.offset;
  366. BuildConstantOperand(oper);
  367. inc(oper.opr.val, ofs);
  368. end
  369. else
  370. BuildReference(oper);
  371. end;
  372. AS_ID: { A constant expression, or a Variable ref. }
  373. begin
  374. { Local Label ? }
  375. if is_locallabel(actasmpattern) then
  376. begin
  377. CreateLocalLabel(actasmpattern, hl, false);
  378. Consume(AS_ID);
  379. AddLabelOperand(hl);
  380. end
  381. else
  382. { Check for label } if SearchLabel(actasmpattern, hl, false) then
  383. begin
  384. Consume(AS_ID);
  385. AddLabelOperand(hl);
  386. end
  387. else
  388. { probably a variable or normal expression }
  389. { or a procedure (such as in CALL ID) }
  390. begin
  391. { is it a constant ? }
  392. if SearchIConstant(actasmpattern, l) then
  393. begin
  394. if not (oper.opr.typ in [OPR_NONE, OPR_CONSTANT]) then
  395. Message(asmr_e_invalid_operand_type);
  396. BuildConstantOperand(oper);
  397. end
  398. else
  399. begin
  400. expr := actasmpattern;
  401. Consume(AS_ID);
  402. { typecasting? }
  403. if (actasmtoken = AS_LPAREN) and
  404. SearchType(expr, typesize) then
  405. begin
  406. oper.hastype := true;
  407. Consume(AS_LPAREN);
  408. BuildOperand(oper);
  409. Consume(AS_RPAREN);
  410. if oper.opr.typ in [OPR_REFERENCE, OPR_LOCAL] then
  411. oper.SetSize(typesize, true);
  412. end
  413. else
  414. begin
  415. if oper.SetupVar(expr, false) then
  416. ReadAt(oper)
  417. else
  418. begin
  419. { look for special symbols ... }
  420. if expr = '__HIGH' then
  421. begin
  422. consume(AS_LPAREN);
  423. if not oper.setupvar('high' + actasmpattern, false) then
  424. Message1(sym_e_unknown_id, 'high' + actasmpattern);
  425. consume(AS_ID);
  426. consume(AS_RPAREN);
  427. end
  428. else if expr = '__RESULT' then
  429. oper.SetUpResult
  430. else if expr = '__SELF' then
  431. oper.SetupSelf
  432. else if expr = '__OLDEBP' then
  433. oper.SetupOldEBP
  434. else
  435. Message1(sym_e_unknown_id, expr);
  436. end;
  437. end;
  438. end;
  439. if actasmtoken = AS_DOT then
  440. MaybeRecordOffset;
  441. { add a constant expression? }
  442. if (actasmtoken = AS_PLUS) then
  443. begin
  444. l := BuildConstExpression(true, false);
  445. case oper.opr.typ of
  446. OPR_CONSTANT:
  447. inc(oper.opr.val, l);
  448. OPR_LOCAL:
  449. inc(oper.opr.localsymofs, l);
  450. OPR_REFERENCE:
  451. inc(oper.opr.ref.offset, l);
  452. else
  453. internalerror(200309202);
  454. end;
  455. end
  456. end;
  457. { Do we have a indexing reference, then parse it also }
  458. if actasmtoken = AS_LPAREN then
  459. BuildReference(oper);
  460. end;
  461. AS_REGISTER: { Register, a variable reference or a constant reference }
  462. begin
  463. { save the type of register used. }
  464. tempreg := actasmregister;
  465. Consume(AS_REGISTER);
  466. if (actasmtoken in [AS_END, AS_SEPARATOR, AS_COMMA]) then
  467. if is_condreg(tempreg) and
  468. ((actopcode = A_BC) or
  469. (actopcode = A_BCCTR) or
  470. (actopcode = A_BCLR) or
  471. (actopcode = A_TW) or
  472. (actopcode = A_TWI)) then
  473. begin
  474. { it isn't a real operand, everything is stored in the condition }
  475. oper.opr.typ := OPR_NONE;
  476. actcondition.cr := getsupreg(tempreg);
  477. end
  478. else
  479. begin
  480. if not (oper.opr.typ in [OPR_NONE, OPR_REGISTER]) then
  481. Message(asmr_e_invalid_operand_type);
  482. oper.opr.typ := OPR_REGISTER;
  483. oper.opr.reg := tempreg;
  484. end
  485. else if is_condreg(tempreg) then
  486. begin
  487. if not (actcondition.cond in [C_T..C_DZF]) then
  488. Message(asmr_e_syn_operand);
  489. if actasmtoken = AS_STAR then
  490. begin
  491. consume(AS_STAR);
  492. if (actasmtoken = AS_INTNUM) then
  493. begin
  494. consume(AS_INTNUM);
  495. if actasmtoken = AS_PLUS then
  496. begin
  497. consume(AS_PLUS);
  498. if (actasmtoken = AS_ID) then
  499. begin
  500. oper.opr.typ := OPR_NONE;
  501. if actasmpattern = 'LT' then
  502. actcondition.crbit := (getsupreg(tempreg) - (RS_CR0)) * 4
  503. else if actasmpattern = 'GT' then
  504. actcondition.crbit := (getsupreg(tempreg) - (RS_CR0)) * 4 + 1
  505. else if actasmpattern = 'EQ' then
  506. actcondition.crbit := (getsupreg(tempreg) - (RS_CR0)) * 4 + 2
  507. else if actasmpattern = 'SO' then
  508. actcondition.crbit := (getsupreg(tempreg) - (RS_CR0)) * 4 + 3
  509. else
  510. Message(asmr_e_syn_operand);
  511. consume(AS_ID);
  512. end
  513. else
  514. Message(asmr_e_syn_operand);
  515. end
  516. else
  517. Message(asmr_e_syn_operand);
  518. end
  519. else
  520. Message(asmr_e_syn_operand);
  521. end
  522. else
  523. Message(asmr_e_syn_operand);
  524. end
  525. else
  526. Message(asmr_e_syn_operand);
  527. end;
  528. AS_END,
  529. AS_SEPARATOR,
  530. AS_COMMA: ;
  531. else
  532. begin
  533. Message(asmr_e_syn_operand);
  534. Consume(actasmtoken);
  535. end;
  536. end; { end case }
  537. end;
  538. {*****************************************************************************
  539. tppcattreader
  540. *****************************************************************************}
  541. procedure tppcattreader.BuildOpCode(instr: tppcinstruction);
  542. var
  543. operandnum: longint;
  544. begin
  545. { opcode }
  546. if (actasmtoken <> AS_OPCODE) then
  547. begin
  548. Message(asmr_e_invalid_or_missing_opcode);
  549. RecoverConsume(true);
  550. exit;
  551. end;
  552. { Fill the instr object with the current state }
  553. with instr do
  554. begin
  555. Opcode := ActOpcode;
  556. condition := ActCondition;
  557. end;
  558. { We are reading operands, so opcode will be an AS_ID }
  559. operandnum := 1;
  560. Consume(AS_OPCODE);
  561. { Zero operand opcode ? }
  562. if actasmtoken in [AS_SEPARATOR, AS_END] then
  563. begin
  564. operandnum := 0;
  565. exit;
  566. end;
  567. { Read the operands }
  568. repeat
  569. case actasmtoken of
  570. AS_COMMA: { Operand delimiter }
  571. begin
  572. if operandnum > Max_Operands then
  573. Message(asmr_e_too_many_operands)
  574. else
  575. begin
  576. { condition operands doesn't set the operand but write to the
  577. condition field of the instruction
  578. }
  579. if instr.Operands[operandnum].opr.typ <> OPR_NONE then
  580. Inc(operandnum);
  581. end;
  582. Consume(AS_COMMA);
  583. end;
  584. AS_SEPARATOR,
  585. AS_END: { End of asm operands for this opcode }
  586. begin
  587. break;
  588. end;
  589. else
  590. BuildOperand(instr.Operands[operandnum] as tppcoperand);
  591. end; { end case }
  592. until false;
  593. if (operandnum = 1) and (instr.Operands[operandnum].opr.typ = OPR_NONE) then
  594. dec(operandnum);
  595. instr.Ops := operandnum;
  596. end;
  597. function tppcattreader.is_asmopcode(const s: string): boolean;
  598. var
  599. cond: tasmcondflag;
  600. hs: string;
  601. begin
  602. { making s a value parameter would break other assembler readers }
  603. hs := s;
  604. is_asmopcode := false;
  605. { clear op code }
  606. actopcode := A_None;
  607. { clear condition }
  608. fillchar(actcondition, sizeof(actcondition), 0);
  609. { check for direction hint }
  610. if hs[length(s)] = '-' then
  611. begin
  612. dec(ord(hs[0]));
  613. actcondition.dirhint := DH_Minus;
  614. end
  615. else if hs[length(s)] = '+' then
  616. begin
  617. dec(ord(hs[0]));
  618. actcondition.dirhint := DH_Plus;
  619. end;
  620. actopcode := tasmop(ptrint(iasmops.Find(hs)));
  621. if actopcode <> A_NONE then
  622. begin
  623. if actcondition.dirhint <> DH_None then
  624. message1(asmr_e_unknown_opcode, actasmpattern);
  625. actasmtoken := AS_OPCODE;
  626. is_asmopcode := true;
  627. exit;
  628. end;
  629. { not found, check branch instructions }
  630. if hs[1] = 'B' then
  631. begin
  632. { we can search here without an extra table which is sorted by string length
  633. because we take the whole remaining string without the leading B }
  634. if copy(hs, length(s) - 1, 2) = 'LR' then
  635. begin
  636. actopcode := A_BCLR;
  637. setlength(hs, length(hs) - 2)
  638. end
  639. else if copy(hs, length(s) - 2, 3) = 'CTR' then
  640. begin
  641. actopcode := A_BCCTR;
  642. setlength(hs, length(hs) - 3)
  643. end
  644. else
  645. actopcode := A_BC;
  646. for cond := low(TAsmCondFlag) to high(TAsmCondFlag) do
  647. if copy(hs, 2, length(s) - 1) = UpperAsmCondFlag2Str[cond] then
  648. begin
  649. actcondition.simple := true;
  650. actcondition.cond := cond;
  651. if (cond in [C_LT, C_LE, C_EQ, C_GE, C_GT, C_NL, C_NE, C_NG, C_SO, C_NS,
  652. C_UN, C_NU]) then
  653. actcondition.cr := RS_CR0;
  654. actasmtoken := AS_OPCODE;
  655. is_asmopcode := true;
  656. exit;
  657. end;
  658. end;
  659. end;
  660. procedure tppcattreader.ConvertCalljmp(instr: tppcinstruction);
  661. begin
  662. if instr.Operands[1].opr.typ = OPR_CONSTANT then begin
  663. if (instr.operands[1].opr.val > 31) or
  664. (instr.operands[2].opr.typ <> OPR_CONSTANT) or
  665. (instr.operands[2].opr.val > 31) or
  666. not(instr.operands[3].opr.typ in [OPR_REFERENCE,OPR_SYMBOL]) then
  667. Message(asmr_e_syn_operand);
  668. { BO/BI notation }
  669. instr.condition.simple := false;
  670. instr.condition.bo := instr.operands[1].opr.val;
  671. instr.condition.bi := instr.operands[2].opr.val;
  672. instr.operands[1].free;
  673. instr.operands[2].free;
  674. instr.operands[2] := nil;
  675. instr.operands[1] := instr.operands[3];
  676. instr.operands[3] := nil;
  677. instr.ops := 1;
  678. end;
  679. if instr.Operands[1].opr.typ = OPR_REFERENCE then begin
  680. instr.Operands[1].opr.ref.refaddr:=addr_full;
  681. if (instr.Operands[1].opr.ref.base<>NR_NO) or
  682. (instr.Operands[1].opr.ref.index<>NR_NO) then
  683. Message(asmr_e_syn_operand);
  684. end;
  685. end;
  686. procedure tppcattreader.handleopcode;
  687. var
  688. instr: tppcinstruction;
  689. begin
  690. instr := TPPCInstruction.Create(TPPCOperand);
  691. BuildOpcode(instr);
  692. instr.condition := actcondition;
  693. if is_calljmp(instr.opcode) then
  694. ConvertCalljmp(instr);
  695. {
  696. instr.AddReferenceSizes;
  697. instr.SetInstructionOpsize;
  698. instr.CheckOperandSizes;
  699. }
  700. instr.ConcatInstruction(curlist);
  701. instr.Free;
  702. end;
  703. {*****************************************************************************
  704. Initialize
  705. *****************************************************************************}
  706. const
  707. asmmode_ppc_att_info: tasmmodeinfo =
  708. (
  709. id: asmmode_ppc_gas;
  710. idtxt: 'GAS';
  711. casmreader: tppcattreader;
  712. );
  713. asmmode_ppc_standard_info: tasmmodeinfo =
  714. (
  715. id: asmmode_standard;
  716. idtxt: 'STANDARD';
  717. casmreader: tppcattreader;
  718. );
  719. initialization
  720. RegisterAsmMode(asmmode_ppc_att_info);
  721. RegisterAsmMode(asmmode_ppc_standard_info);
  722. end.