rappcgas.pas 26 KB

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