raarmgas.pas 26 KB

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