rappcgas.pas 27 KB

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