rappcgas.pas 23 KB

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