2
0

raarmgas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Does the parsing for the ARM 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 raarmgas;
  18. {$i fpcdefs.inc}
  19. Interface
  20. uses
  21. raatt,raarm,
  22. cpubase;
  23. type
  24. tarmattreader = class(tattreader)
  25. actoppostfix : TOpPostfix;
  26. function is_asmopcode(const s: string):boolean;override;
  27. function is_register(const s:string):boolean;override;
  28. procedure handleopcode;override;
  29. procedure BuildReference(oper : tarmoperand);
  30. procedure BuildOperand(oper : tarmoperand);
  31. function TryBuildShifterOp(oper : tarmoperand) : boolean;
  32. procedure BuildOpCode(instr : tarminstruction);
  33. procedure ReadSym(oper : tarmoperand);
  34. procedure ConvertCalljmp(instr : tarminstruction);
  35. end;
  36. Implementation
  37. uses
  38. { helpers }
  39. cutils,
  40. { global }
  41. globtype,globals,verbose,
  42. systems,
  43. { aasm }
  44. cpuinfo,aasmbase,aasmtai,aasmdata,aasmcpu,
  45. { symtable }
  46. symconst,symbase,symtype,symsym,symtable,
  47. { parser }
  48. scanner,
  49. procinfo,
  50. itcpugas,
  51. rabase,rautils,
  52. cgbase,cgobj
  53. ;
  54. function tarmattreader.is_register(const s:string):boolean;
  55. type
  56. treg2str = record
  57. name : string[2];
  58. reg : tregister;
  59. end;
  60. const
  61. extraregs : array[0..19] of treg2str = (
  62. (name: 'A1'; reg : NR_R0),
  63. (name: 'A2'; reg : NR_R1),
  64. (name: 'A3'; reg : NR_R2),
  65. (name: 'A4'; reg : NR_R3),
  66. (name: 'V1'; reg : NR_R4),
  67. (name: 'V2'; reg : NR_R5),
  68. (name: 'V3'; reg : NR_R6),
  69. (name: 'V4'; reg : NR_R7),
  70. (name: 'V5'; reg : NR_R8),
  71. (name: 'V6'; reg : NR_R9),
  72. (name: 'V7'; reg : NR_R10),
  73. (name: 'V8'; reg : NR_R11),
  74. (name: 'WR'; reg : NR_R7),
  75. (name: 'SB'; reg : NR_R9),
  76. (name: 'SL'; reg : NR_R10),
  77. (name: 'FP'; reg : NR_R11),
  78. (name: 'IP'; reg : NR_R12),
  79. (name: 'SP'; reg : NR_R13),
  80. (name: 'LR'; reg : NR_R14),
  81. (name: 'PC'; reg : NR_R15));
  82. var
  83. i : longint;
  84. begin
  85. result:=inherited is_register(s);
  86. { reg found?
  87. possible aliases are always 2 char
  88. }
  89. if result or (length(s)<>2) then
  90. exit;
  91. for i:=low(extraregs) to high(extraregs) do
  92. begin
  93. if s=extraregs[i].name then
  94. begin
  95. actasmregister:=extraregs[i].reg;
  96. result:=true;
  97. actasmtoken:=AS_REGISTER;
  98. exit;
  99. end;
  100. end;
  101. end;
  102. procedure tarmattreader.ReadSym(oper : tarmoperand);
  103. var
  104. tempstr : string;
  105. typesize,l,k : longint;
  106. begin
  107. tempstr:=actasmpattern;
  108. Consume(AS_ID);
  109. { typecasting? }
  110. if (actasmtoken=AS_LPAREN) and
  111. SearchType(tempstr,typesize) then
  112. begin
  113. oper.hastype:=true;
  114. Consume(AS_LPAREN);
  115. BuildOperand(oper);
  116. Consume(AS_RPAREN);
  117. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  118. oper.SetSize(typesize,true);
  119. end
  120. else
  121. if not oper.SetupVar(tempstr,false) then
  122. Message1(sym_e_unknown_id,tempstr);
  123. { record.field ? }
  124. if actasmtoken=AS_DOT then
  125. begin
  126. BuildRecordOffsetSize(tempstr,l,k);
  127. inc(oper.opr.ref.offset,l);
  128. end;
  129. end;
  130. Procedure tarmattreader.BuildReference(oper : tarmoperand);
  131. procedure Consume_RBracket;
  132. begin
  133. if actasmtoken<>AS_RBRACKET then
  134. Begin
  135. Message(asmr_e_invalid_reference_syntax);
  136. RecoverConsume(true);
  137. end
  138. else
  139. begin
  140. Consume(AS_RBRACKET);
  141. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  142. Begin
  143. Message(asmr_e_invalid_reference_syntax);
  144. RecoverConsume(true);
  145. end;
  146. end;
  147. end;
  148. procedure read_index;
  149. begin
  150. Consume(AS_COMMA);
  151. if actasmtoken=AS_REGISTER then
  152. Begin
  153. oper.opr.ref.index:=actasmregister;
  154. Consume(AS_REGISTER);
  155. end
  156. else if actasmtoken=AS_HASH then
  157. begin
  158. Consume(AS_HASH);
  159. inc(oper.opr.ref.offset,BuildConstExpression(false,true));
  160. end;
  161. end;
  162. begin
  163. Consume(AS_LBRACKET);
  164. if actasmtoken=AS_REGISTER then
  165. begin
  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_RBRACKET then
  171. Begin
  172. Consume_RBracket;
  173. oper.opr.ref.addressmode:=AM_POSTINDEXED;
  174. if actasmtoken=AS_COMMA then
  175. read_index;
  176. exit;
  177. end;
  178. if actasmtoken=AS_COMMA then
  179. begin
  180. read_index;
  181. Consume_RBracket;
  182. end;
  183. if actasmtoken=AS_NOT then
  184. begin
  185. consume(AS_NOT);
  186. oper.opr.ref.addressmode:=AM_PREINDEXED;
  187. end;
  188. end {end case }
  189. else
  190. Begin
  191. Message(asmr_e_invalid_reference_syntax);
  192. RecoverConsume(false);
  193. end;
  194. end;
  195. function tarmattreader.TryBuildShifterOp(oper : tarmoperand) : boolean;
  196. procedure handlepara(sm : tshiftmode);
  197. begin
  198. consume(AS_ID);
  199. fillchar(oper.opr,sizeof(oper.opr),0);
  200. oper.opr.typ:=OPR_SHIFTEROP;
  201. oper.opr.shifterop.shiftmode:=sm;
  202. if sm<>SM_RRX then
  203. begin
  204. case actasmtoken of
  205. AS_REGISTER:
  206. begin
  207. oper.opr.shifterop.rs:=actasmregister;
  208. consume(AS_REGISTER);
  209. end;
  210. AS_HASH:
  211. begin
  212. consume(AS_HASH);
  213. oper.opr.shifterop.shiftimm:=BuildConstExpression(false,false);
  214. end;
  215. else
  216. Message(asmr_e_illegal_shifterop_syntax);
  217. end;
  218. end;
  219. end;
  220. begin
  221. result:=true;
  222. if (actasmtoken=AS_ID) then
  223. begin
  224. if (actasmpattern='LSL') then
  225. handlepara(SM_LSL)
  226. else if (actasmpattern='LSR') then
  227. handlepara(SM_LSR)
  228. else if (actasmpattern='ASR') then
  229. handlepara(SM_ASR)
  230. else if (actasmpattern='ROR') then
  231. handlepara(SM_ROR)
  232. else if (actasmpattern='RRX') then
  233. handlepara(SM_ROR)
  234. else
  235. result:=false;
  236. end
  237. else
  238. result:=false;
  239. end;
  240. Procedure tarmattreader.BuildOperand(oper : tarmoperand);
  241. var
  242. expr : string;
  243. typesize,l : longint;
  244. procedure AddLabelOperand(hl:tasmlabel);
  245. begin
  246. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  247. is_calljmp(actopcode) then
  248. begin
  249. oper.opr.typ:=OPR_SYMBOL;
  250. oper.opr.symbol:=hl;
  251. end
  252. else
  253. begin
  254. oper.InitRef;
  255. oper.opr.ref.symbol:=hl;
  256. end;
  257. end;
  258. procedure MaybeRecordOffset;
  259. var
  260. hasdot : boolean;
  261. l,
  262. toffset,
  263. tsize : longint;
  264. begin
  265. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  266. exit;
  267. l:=0;
  268. hasdot:=(actasmtoken=AS_DOT);
  269. if hasdot then
  270. begin
  271. if expr<>'' then
  272. begin
  273. BuildRecordOffsetSize(expr,toffset,tsize);
  274. inc(l,toffset);
  275. oper.SetSize(tsize,true);
  276. end;
  277. end;
  278. if actasmtoken in [AS_PLUS,AS_MINUS] then
  279. inc(l,BuildConstExpression(true,false));
  280. case oper.opr.typ of
  281. OPR_LOCAL :
  282. begin
  283. { don't allow direct access to fields of parameters, because that
  284. will generate buggy code. Allow it only for explicit typecasting }
  285. if hasdot and
  286. (not oper.hastype) and
  287. (tabstractnormalvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  288. (current_procinfo.procdef.proccalloption<>pocall_register) then
  289. Message(asmr_e_cannot_access_field_directly_for_parameters);
  290. inc(oper.opr.localsymofs,l)
  291. end;
  292. OPR_CONSTANT :
  293. inc(oper.opr.val,l);
  294. OPR_REFERENCE :
  295. inc(oper.opr.ref.offset,l);
  296. else
  297. internalerror(200309221);
  298. end;
  299. end;
  300. function MaybeBuildReference:boolean;
  301. { Try to create a reference, if not a reference is found then false
  302. is returned }
  303. begin
  304. MaybeBuildReference:=true;
  305. case actasmtoken of
  306. AS_INTNUM,
  307. AS_MINUS,
  308. AS_PLUS:
  309. Begin
  310. oper.opr.ref.offset:=BuildConstExpression(True,False);
  311. if actasmtoken<>AS_LPAREN then
  312. Message(asmr_e_invalid_reference_syntax)
  313. else
  314. BuildReference(oper);
  315. end;
  316. AS_LPAREN:
  317. BuildReference(oper);
  318. AS_ID: { only a variable is allowed ... }
  319. Begin
  320. ReadSym(oper);
  321. case actasmtoken of
  322. AS_END,
  323. AS_SEPARATOR,
  324. AS_COMMA: ;
  325. AS_LPAREN:
  326. BuildReference(oper);
  327. else
  328. Begin
  329. Message(asmr_e_invalid_reference_syntax);
  330. Consume(actasmtoken);
  331. end;
  332. end; {end case }
  333. end;
  334. else
  335. MaybeBuildReference:=false;
  336. end; { end case }
  337. end;
  338. var
  339. tempreg : tregister;
  340. ireg : tsuperregister;
  341. hl : tasmlabel;
  342. ofs : longint;
  343. registerset : tcpuregisterset;
  344. Begin
  345. expr:='';
  346. case actasmtoken of
  347. AS_LBRACKET: { Memory reference or constant expression }
  348. Begin
  349. oper.InitRef;
  350. BuildReference(oper);
  351. end;
  352. AS_HASH: { Constant expression }
  353. Begin
  354. Consume(AS_HASH);
  355. BuildConstantOperand(oper);
  356. end;
  357. (*
  358. AS_INTNUM,
  359. AS_MINUS,
  360. AS_PLUS:
  361. Begin
  362. { Constant memory offset }
  363. { This must absolutely be followed by ( }
  364. oper.InitRef;
  365. oper.opr.ref.offset:=BuildConstExpression(True,False);
  366. if actasmtoken<>AS_LPAREN then
  367. begin
  368. ofs:=oper.opr.ref.offset;
  369. BuildConstantOperand(oper);
  370. inc(oper.opr.val,ofs);
  371. end
  372. else
  373. BuildReference(oper);
  374. end;
  375. *)
  376. AS_ID: { A constant expression, or a Variable ref. }
  377. Begin
  378. { Local Label ? }
  379. if is_locallabel(actasmpattern) then
  380. begin
  381. CreateLocalLabel(actasmpattern,hl,false);
  382. Consume(AS_ID);
  383. AddLabelOperand(hl);
  384. end
  385. else
  386. { Check for label }
  387. if SearchLabel(actasmpattern,hl,false) then
  388. begin
  389. Consume(AS_ID);
  390. AddLabelOperand(hl);
  391. end
  392. else
  393. { probably a variable or normal expression }
  394. { or a procedure (such as in CALL ID) }
  395. Begin
  396. { is it a constant ? }
  397. if SearchIConstant(actasmpattern,l) then
  398. Begin
  399. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  400. Message(asmr_e_invalid_operand_type);
  401. BuildConstantOperand(oper);
  402. end
  403. else
  404. begin
  405. expr:=actasmpattern;
  406. Consume(AS_ID);
  407. { typecasting? }
  408. if (actasmtoken=AS_LPAREN) and
  409. SearchType(expr,typesize) then
  410. begin
  411. oper.hastype:=true;
  412. Consume(AS_LPAREN);
  413. BuildOperand(oper);
  414. Consume(AS_RPAREN);
  415. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  416. oper.SetSize(typesize,true);
  417. end
  418. else
  419. begin
  420. if not(oper.SetupVar(expr,false)) then
  421. Begin
  422. { look for special symbols ... }
  423. if expr= '__HIGH' then
  424. begin
  425. consume(AS_LPAREN);
  426. if not oper.setupvar('high'+actasmpattern,false) then
  427. Message1(sym_e_unknown_id,'high'+actasmpattern);
  428. consume(AS_ID);
  429. consume(AS_RPAREN);
  430. end
  431. else
  432. if expr = '__RESULT' then
  433. oper.SetUpResult
  434. else
  435. if expr = '__SELF' then
  436. oper.SetupSelf
  437. else
  438. if expr = '__OLDEBP' then
  439. oper.SetupOldEBP
  440. else
  441. Message1(sym_e_unknown_id,expr);
  442. end;
  443. end;
  444. end;
  445. if actasmtoken=AS_DOT then
  446. MaybeRecordOffset;
  447. { add a constant expression? }
  448. if (actasmtoken=AS_PLUS) then
  449. begin
  450. l:=BuildConstExpression(true,false);
  451. case oper.opr.typ of
  452. OPR_CONSTANT :
  453. inc(oper.opr.val,l);
  454. OPR_LOCAL :
  455. inc(oper.opr.localsymofs,l);
  456. OPR_REFERENCE :
  457. inc(oper.opr.ref.offset,l);
  458. else
  459. internalerror(200309202);
  460. end;
  461. end
  462. end;
  463. { Do we have a indexing reference, then parse it also }
  464. if actasmtoken=AS_LPAREN then
  465. BuildReference(oper);
  466. end;
  467. { Register, a variable reference or a constant reference }
  468. AS_REGISTER:
  469. Begin
  470. { save the type of register used. }
  471. tempreg:=actasmregister;
  472. Consume(AS_REGISTER);
  473. if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  474. Begin
  475. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  476. Message(asmr_e_invalid_operand_type);
  477. oper.opr.typ:=OPR_REGISTER;
  478. oper.opr.reg:=tempreg;
  479. end
  480. else if (actasmtoken=AS_NOT) and (actopcode in [A_LDM,A_STM]) then
  481. begin
  482. consume(AS_NOT);
  483. oper.opr.typ:=OPR_REFERENCE;
  484. oper.opr.ref.addressmode:=AM_PREINDEXED;
  485. oper.opr.ref.index:=tempreg;
  486. end
  487. else
  488. Message(asmr_e_syn_operand);
  489. end;
  490. { Registerset }
  491. AS_LSBRACKET:
  492. begin
  493. consume(AS_LSBRACKET);
  494. registerset:=[];
  495. while true do
  496. begin
  497. if actasmtoken=AS_REGISTER then
  498. begin
  499. include(registerset,getsupreg(actasmregister));
  500. tempreg:=actasmregister;
  501. consume(AS_REGISTER);
  502. if actasmtoken=AS_MINUS then
  503. begin
  504. consume(AS_MINUS);
  505. for ireg:=getsupreg(tempreg) to getsupreg(actasmregister) do
  506. include(registerset,ireg);
  507. consume(AS_REGISTER);
  508. end;
  509. end
  510. else
  511. consume(AS_REGISTER);
  512. if actasmtoken=AS_COMMA then
  513. consume(AS_COMMA)
  514. else
  515. break;
  516. end;
  517. consume(AS_RSBRACKET);
  518. oper.opr.typ:=OPR_REGSET;
  519. oper.opr.regset:=registerset;
  520. end;
  521. AS_END,
  522. AS_SEPARATOR,
  523. AS_COMMA: ;
  524. else
  525. Begin
  526. Message(asmr_e_syn_operand);
  527. Consume(actasmtoken);
  528. end;
  529. end; { end case }
  530. end;
  531. {*****************************************************************************
  532. tarmattreader
  533. *****************************************************************************}
  534. procedure tarmattreader.BuildOpCode(instr : tarminstruction);
  535. var
  536. operandnum : longint;
  537. Begin
  538. { opcode }
  539. if (actasmtoken<>AS_OPCODE) then
  540. Begin
  541. Message(asmr_e_invalid_or_missing_opcode);
  542. RecoverConsume(true);
  543. exit;
  544. end;
  545. { Fill the instr object with the current state }
  546. with instr do
  547. begin
  548. Opcode:=ActOpcode;
  549. condition:=ActCondition;
  550. oppostfix:=actoppostfix;
  551. end;
  552. { We are reading operands, so opcode will be an AS_ID }
  553. operandnum:=1;
  554. Consume(AS_OPCODE);
  555. { Zero operand opcode ? }
  556. if actasmtoken in [AS_SEPARATOR,AS_END] then
  557. begin
  558. operandnum:=0;
  559. exit;
  560. end;
  561. { Read the operands }
  562. repeat
  563. case actasmtoken of
  564. AS_COMMA: { Operand delimiter }
  565. Begin
  566. if ((instr.opcode=A_MOV) and (operandnum=2)) or
  567. ((operandnum=3) and not(instr.opcode in [A_UMLAL,A_UMULL,A_SMLAL,A_SMULL])) then
  568. begin
  569. Consume(AS_COMMA);
  570. if not(TryBuildShifterOp(instr.Operands[4] as tarmoperand)) then
  571. Message(asmr_e_illegal_shifterop_syntax);
  572. Inc(operandnum);
  573. end
  574. else
  575. begin
  576. if operandnum>Max_Operands then
  577. Message(asmr_e_too_many_operands)
  578. else
  579. Inc(operandnum);
  580. Consume(AS_COMMA);
  581. end;
  582. end;
  583. AS_SEPARATOR,
  584. AS_END : { End of asm operands for this opcode }
  585. begin
  586. break;
  587. end;
  588. else
  589. BuildOperand(instr.Operands[operandnum] as tarmoperand);
  590. end; { end case }
  591. until false;
  592. instr.Ops:=operandnum;
  593. end;
  594. function tarmattreader.is_asmopcode(const s: string):boolean;
  595. const
  596. { sorted by length so longer postfixes will match first }
  597. postfix2strsorted : array[1..19] of string[2] = (
  598. 'EP','SB','BT','SH',
  599. 'IA','IB','DA','DB','FD','FA','ED','EA',
  600. 'B','D','E','P','T','H','S');
  601. postfixsorted : array[1..19] of TOpPostfix = (
  602. PF_EP,PF_SB,PF_BT,PF_SH,
  603. PF_IA,PF_IB,PF_DA,PF_DB,PF_FD,PF_FA,PF_ED,PF_EA,
  604. PF_B,PF_D,PF_E,PF_P,PF_T,PF_H,PF_S);
  605. var
  606. str2opentry: tstr2opentry;
  607. len,
  608. j,
  609. sufidx : longint;
  610. hs : string;
  611. maxlen : longint;
  612. icond : tasmcond;
  613. Begin
  614. { making s a value parameter would break other assembler readers }
  615. hs:=s;
  616. is_asmopcode:=false;
  617. { clear op code }
  618. actopcode:=A_None;
  619. actcondition:=C_None;
  620. { first, handle B else BLS is read wrong }
  621. if ((hs[1]='B') and (length(hs)=3)) then
  622. begin
  623. for icond:=low(tasmcond) to high(tasmcond) do
  624. begin
  625. if copy(hs,2,3)=uppercond2str[icond] then
  626. begin
  627. actopcode:=A_B;
  628. actasmtoken:=AS_OPCODE;
  629. actcondition:=icond;
  630. is_asmopcode:=true;
  631. exit;
  632. end;
  633. end;
  634. end;
  635. maxlen:=max(length(hs),5);
  636. for j:=maxlen downto 1 do
  637. begin
  638. str2opentry:=tstr2opentry(iasmops.search(copy(hs,1,j)));
  639. if assigned(str2opentry) then
  640. begin
  641. actopcode:=str2opentry.op;
  642. actasmtoken:=AS_OPCODE;
  643. { strip op code }
  644. delete(hs,1,j);
  645. break;
  646. end;
  647. end;
  648. if not(assigned(str2opentry)) then
  649. exit;
  650. { search for condition, conditions are always 2 chars }
  651. if length(hs)>1 then
  652. begin
  653. for icond:=low(tasmcond) to high(tasmcond) do
  654. begin
  655. if copy(hs,1,2)=uppercond2str[icond] then
  656. begin
  657. actcondition:=icond;
  658. { strip condition }
  659. delete(hs,1,2);
  660. break;
  661. end;
  662. end;
  663. end;
  664. { check for postfix }
  665. if length(hs)>0 then
  666. begin
  667. for j:=low(postfixsorted) to high(postfixsorted) do
  668. begin
  669. if copy(hs,1,length(postfix2strsorted[j]))=postfix2strsorted[j] then
  670. begin
  671. actoppostfix:=postfixsorted[j];
  672. { strip postfix }
  673. delete(hs,1,length(postfix2strsorted[j]));
  674. break;
  675. end;
  676. end;
  677. end;
  678. { if we stripped all postfixes, it's a valid opcode }
  679. is_asmopcode:=length(hs)=0;
  680. end;
  681. procedure tarmattreader.ConvertCalljmp(instr : tarminstruction);
  682. var
  683. newopr : toprrec;
  684. begin
  685. if instr.Operands[1].opr.typ=OPR_REFERENCE then
  686. begin
  687. newopr.typ:=OPR_SYMBOL;
  688. newopr.symbol:=instr.Operands[1].opr.ref.symbol;
  689. newopr.symofs:=instr.Operands[1].opr.ref.offset;
  690. if (instr.Operands[1].opr.ref.base<>NR_NO) or
  691. (instr.Operands[1].opr.ref.index<>NR_NO) then
  692. Message(asmr_e_syn_operand);
  693. instr.Operands[1].opr:=newopr;
  694. end;
  695. end;
  696. procedure tarmattreader.handleopcode;
  697. var
  698. instr : tarminstruction;
  699. begin
  700. instr:=TarmInstruction.Create(TarmOperand);
  701. BuildOpcode(instr);
  702. if is_calljmp(instr.opcode) then
  703. ConvertCalljmp(instr);
  704. {
  705. instr.AddReferenceSizes;
  706. instr.SetInstructionOpsize;
  707. instr.CheckOperandSizes;
  708. }
  709. instr.ConcatInstruction(curlist);
  710. instr.Free;
  711. actoppostfix:=PF_None;
  712. end;
  713. {*****************************************************************************
  714. Initialize
  715. *****************************************************************************}
  716. const
  717. asmmode_arm_att_info : tasmmodeinfo =
  718. (
  719. id : asmmode_arm_gas;
  720. idtxt : 'GAS';
  721. casmreader : tarmattreader;
  722. );
  723. asmmode_arm_standard_info : tasmmodeinfo =
  724. (
  725. id : asmmode_standard;
  726. idtxt : 'STANDARD';
  727. casmreader : tarmattreader;
  728. );
  729. initialization
  730. RegisterAsmMode(asmmode_arm_att_info);
  731. RegisterAsmMode(asmmode_arm_standard_info);
  732. end.