rappcgas.pas 28 KB

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