rappcgas.pas 22 KB

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