raarmgas.pas 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509
  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. actwideformat : boolean;
  27. function is_asmopcode(const s: string):boolean;override;
  28. function is_register(const s:string):boolean;override;
  29. function is_targetdirective(const s: string): boolean; override;
  30. procedure handleopcode;override;
  31. procedure BuildReference(oper : tarmoperand);
  32. procedure BuildOperand(oper : tarmoperand);
  33. procedure BuildSpecialreg(oper : tarmoperand);
  34. function TryBuildShifterOp(oper : tarmoperand) : boolean;
  35. procedure BuildOpCode(instr : tarminstruction);
  36. procedure ReadSym(oper : tarmoperand);
  37. procedure ConvertCalljmp(instr : tarminstruction);
  38. procedure HandleTargetDirective; override;
  39. protected
  40. function is_unified: boolean; virtual;
  41. end;
  42. tarmunifiedattreader = class(tarmattreader)
  43. protected
  44. function is_unified: boolean; override;
  45. end;
  46. Implementation
  47. uses
  48. { helpers }
  49. cutils,
  50. { global }
  51. globtype,verbose,
  52. systems,aasmbase,aasmtai,aasmdata,aasmcpu,
  53. { symtable }
  54. symconst,symsym,
  55. procinfo,
  56. rabase,rautils,
  57. cgbase,cgutils;
  58. function tarmunifiedattreader.is_unified: boolean;
  59. begin
  60. result:=true;
  61. end;
  62. function tarmattreader.is_register(const s:string):boolean;
  63. type
  64. treg2str = record
  65. name : string[3];
  66. reg : tregister;
  67. end;
  68. const
  69. extraregs : array[0..19+16] of treg2str = (
  70. (name: 'A1'; reg : NR_R0),
  71. (name: 'A2'; reg : NR_R1),
  72. (name: 'A3'; reg : NR_R2),
  73. (name: 'A4'; reg : NR_R3),
  74. (name: 'V1'; reg : NR_R4),
  75. (name: 'V2'; reg : NR_R5),
  76. (name: 'V3'; reg : NR_R6),
  77. (name: 'V4'; reg : NR_R7),
  78. (name: 'V5'; reg : NR_R8),
  79. (name: 'V6'; reg : NR_R9),
  80. (name: 'V7'; reg : NR_R10),
  81. (name: 'V8'; reg : NR_R11),
  82. (name: 'WR'; reg : NR_R7),
  83. (name: 'SB'; reg : NR_R9),
  84. (name: 'SL'; reg : NR_R10),
  85. (name: 'FP'; reg : NR_R11),
  86. (name: 'IP'; reg : NR_R12),
  87. (name: 'SP'; reg : NR_R13),
  88. (name: 'LR'; reg : NR_R14),
  89. (name: 'PC'; reg : NR_R15),
  90. (name: 'C0'; reg : NR_CR0),
  91. (name: 'C1'; reg : NR_CR1),
  92. (name: 'C2'; reg : NR_CR2),
  93. (name: 'C3'; reg : NR_CR3),
  94. (name: 'C4'; reg : NR_CR4),
  95. (name: 'C5'; reg : NR_CR5),
  96. (name: 'C6'; reg : NR_CR6),
  97. (name: 'C7'; reg : NR_CR7),
  98. (name: 'C8'; reg : NR_CR8),
  99. (name: 'C9'; reg : NR_CR9),
  100. (name: 'C10'; reg : NR_CR10),
  101. (name: 'C11'; reg : NR_CR11),
  102. (name: 'C12'; reg : NR_CR12),
  103. (name: 'C13'; reg : NR_CR13),
  104. (name: 'C14'; reg : NR_CR14),
  105. (name: 'C15'; reg : NR_CR15)
  106. );
  107. var
  108. i : longint;
  109. begin
  110. result:=inherited is_register(s);
  111. { reg found?
  112. possible aliases are always 2 char
  113. }
  114. if result or (not (length(s) in [2,3])) then
  115. exit;
  116. for i:=low(extraregs) to high(extraregs) do
  117. begin
  118. if s=extraregs[i].name then
  119. begin
  120. actasmregister:=extraregs[i].reg;
  121. result:=true;
  122. actasmtoken:=AS_REGISTER;
  123. exit;
  124. end;
  125. end;
  126. end;
  127. function tarmattreader.is_targetdirective(const s: string): boolean;
  128. begin
  129. if s = '.thumb_func' then
  130. result:=true
  131. else if s='.thumb_set' then
  132. result:=true
  133. else
  134. Result:=inherited is_targetdirective(s);
  135. end;
  136. procedure tarmattreader.ReadSym(oper : tarmoperand);
  137. var
  138. tempstr, mangledname : string;
  139. typesize,l,k : longint;
  140. begin
  141. tempstr:=actasmpattern;
  142. Consume(AS_ID);
  143. { typecasting? }
  144. if (actasmtoken=AS_LPAREN) and
  145. SearchType(tempstr,typesize) then
  146. begin
  147. oper.hastype:=true;
  148. Consume(AS_LPAREN);
  149. BuildOperand(oper);
  150. Consume(AS_RPAREN);
  151. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  152. oper.SetSize(typesize,true);
  153. end
  154. else
  155. if not oper.SetupVar(tempstr,false) then
  156. Message1(sym_e_unknown_id,tempstr);
  157. { record.field ? }
  158. if actasmtoken=AS_DOT then
  159. begin
  160. BuildRecordOffsetSize(tempstr,l,k,mangledname,false);
  161. if (mangledname<>'') then
  162. Message(asmr_e_invalid_reference_syntax);
  163. inc(oper.opr.ref.offset,l);
  164. end;
  165. end;
  166. Procedure tarmattreader.BuildReference(oper : tarmoperand);
  167. procedure do_error;
  168. begin
  169. Message(asmr_e_invalid_reference_syntax);
  170. RecoverConsume(false);
  171. end;
  172. procedure test_end(require_rbracket : boolean);
  173. begin
  174. if require_rbracket then begin
  175. if not(actasmtoken=AS_RBRACKET) then
  176. begin
  177. do_error;
  178. exit;
  179. end
  180. else
  181. Consume(AS_RBRACKET);
  182. if (actasmtoken=AS_NOT) then
  183. begin
  184. oper.opr.ref.addressmode:=AM_PREINDEXED;
  185. Consume(AS_NOT);
  186. end;
  187. end;
  188. if not(actasmtoken in [AS_SEPARATOR,AS_end]) then
  189. do_error
  190. else
  191. begin
  192. {$IFDEF debugasmreader}
  193. writeln('TEST_end_FINAL_OK. Created the following ref:');
  194. writeln('oper.opr.ref.shiftimm=',oper.opr.ref.shiftimm);
  195. writeln('oper.opr.ref.shiftmode=',ord(oper.opr.ref.shiftmode));
  196. writeln('oper.opr.ref.index=',ord(oper.opr.ref.index));
  197. writeln('oper.opr.ref.base=',ord(oper.opr.ref.base));
  198. writeln('oper.opr.ref.signindex=',ord(oper.opr.ref.signindex));
  199. writeln('oper.opr.ref.addressmode=',ord(oper.opr.ref.addressmode));
  200. writeln;
  201. {$endIF debugasmreader}
  202. end;
  203. end;
  204. function is_shifter_ref_operation(var a : tshiftmode) : boolean;
  205. begin
  206. a := SM_NONE;
  207. if (actasmpattern='LSL') then
  208. a := SM_LSL
  209. else if (actasmpattern='LSR') then
  210. a := SM_LSR
  211. else if (actasmpattern='ASR') then
  212. a := SM_ASR
  213. else if (actasmpattern='ROR') then
  214. a := SM_ROR
  215. else if (actasmpattern='RRX') then
  216. a := SM_RRX;
  217. is_shifter_ref_operation := not(a=SM_NONE);
  218. end;
  219. procedure read_index_shift(require_rbracket : boolean);
  220. var
  221. shift : aint;
  222. begin
  223. case actasmtoken of
  224. AS_COMMA :
  225. begin
  226. Consume(AS_COMMA);
  227. if not(actasmtoken=AS_ID) then
  228. do_error;
  229. if is_shifter_ref_operation(oper.opr.ref.shiftmode) then
  230. begin
  231. Consume(AS_ID);
  232. if not(oper.opr.ref.shiftmode=SM_RRX) then
  233. begin
  234. if not(actasmtoken=AS_HASH) then
  235. do_error;
  236. Consume(AS_HASH);
  237. shift := BuildConstExpression(false,true);
  238. if (shift<0) or (shift>32) then
  239. do_error;
  240. oper.opr.ref.shiftimm := shift;
  241. test_end(require_rbracket);
  242. end
  243. else
  244. test_end(require_rbracket);
  245. end
  246. else
  247. begin
  248. do_error;
  249. exit;
  250. end;
  251. end;
  252. AS_RBRACKET :
  253. if require_rbracket then
  254. test_end(require_rbracket)
  255. else
  256. begin
  257. do_error;
  258. exit;
  259. end;
  260. AS_SEPARATOR,AS_END :
  261. if not require_rbracket then
  262. test_end(false)
  263. else
  264. do_error;
  265. else
  266. begin
  267. do_error;
  268. exit;
  269. end;
  270. end;
  271. end;
  272. procedure read_index(require_rbracket : boolean);
  273. var
  274. recname : string;
  275. o_int,s_int : aint;
  276. begin
  277. case actasmtoken of
  278. AS_REGISTER :
  279. begin
  280. oper.opr.ref.index:=actasmregister;
  281. Consume(AS_REGISTER);
  282. read_index_shift(require_rbracket);
  283. exit;
  284. end;
  285. AS_PLUS,AS_MINUS :
  286. begin
  287. if actasmtoken=AS_PLUS then
  288. begin
  289. Consume(AS_PLUS);
  290. end
  291. else
  292. begin
  293. oper.opr.ref.signindex := -1;
  294. Consume(AS_MINUS);
  295. end;
  296. if actasmtoken=AS_REGISTER then
  297. begin
  298. oper.opr.ref.index:=actasmregister;
  299. Consume(AS_REGISTER);
  300. read_index_shift(require_rbracket);
  301. exit;
  302. end
  303. else
  304. begin
  305. do_error;
  306. exit;
  307. end;
  308. test_end(require_rbracket);
  309. exit;
  310. end;
  311. AS_HASH : // constant
  312. begin
  313. Consume(AS_HASH);
  314. o_int := BuildConstExpression(false,true);
  315. if (o_int>4095) or (o_int<-4095) then
  316. begin
  317. Message(asmr_e_constant_out_of_bounds);
  318. RecoverConsume(false);
  319. exit;
  320. end
  321. else
  322. begin
  323. inc(oper.opr.ref.offset,o_int);
  324. test_end(require_rbracket);
  325. exit;
  326. end;
  327. end;
  328. AS_ID :
  329. begin
  330. recname := actasmpattern;
  331. Consume(AS_ID);
  332. BuildRecordOffsetSize(recname,o_int,s_int,recname,false);
  333. if (o_int>4095)or(o_int<-4095) then
  334. begin
  335. Message(asmr_e_constant_out_of_bounds);
  336. RecoverConsume(false);
  337. exit;
  338. end
  339. else
  340. begin
  341. inc(oper.opr.ref.offset,o_int);
  342. test_end(require_rbracket);
  343. exit;
  344. end;
  345. end;
  346. AS_AT:
  347. begin
  348. do_error;
  349. exit;
  350. end;
  351. AS_DOT : // local label
  352. begin
  353. oper.opr.ref.signindex := BuildConstExpression(true,false);
  354. test_end(require_rbracket);
  355. exit;
  356. end;
  357. AS_RBRACKET :
  358. begin
  359. if require_rbracket then
  360. begin
  361. test_end(require_rbracket);
  362. exit;
  363. end
  364. else
  365. begin
  366. do_error; // unexpected rbracket
  367. exit;
  368. end;
  369. end;
  370. AS_SEPARATOR,AS_end :
  371. begin
  372. if not require_rbracket then
  373. begin
  374. test_end(false);
  375. exit;
  376. end
  377. else
  378. begin
  379. do_error;
  380. exit;
  381. end;
  382. end;
  383. else
  384. begin
  385. // unexpected token
  386. do_error;
  387. exit;
  388. end;
  389. end; // case
  390. end;
  391. procedure try_prepostindexed;
  392. begin
  393. Consume(AS_RBRACKET);
  394. case actasmtoken of
  395. AS_COMMA :
  396. begin // post-indexed
  397. Consume(AS_COMMA);
  398. oper.opr.ref.addressmode:=AM_POSTINDEXED;
  399. read_index(false);
  400. exit;
  401. end;
  402. AS_NOT :
  403. begin // pre-indexed
  404. Consume(AS_NOT);
  405. oper.opr.ref.addressmode:=AM_PREINDEXED;
  406. test_end(false);
  407. exit;
  408. end;
  409. else
  410. begin
  411. test_end(false);
  412. exit;
  413. end;
  414. end; // case
  415. end;
  416. var
  417. lab : TASMLABEL;
  418. begin
  419. Consume(AS_LBRACKET);
  420. oper.opr.ref.addressmode:=AM_OFFSET; // assume "neither PRE nor POST inc"
  421. if actasmtoken=AS_REGISTER then
  422. begin
  423. oper.opr.ref.base:=actasmregister;
  424. Consume(AS_REGISTER);
  425. case actasmtoken of
  426. AS_RBRACKET :
  427. begin
  428. try_prepostindexed;
  429. exit;
  430. end;
  431. AS_COMMA :
  432. begin
  433. Consume(AS_COMMA);
  434. read_index(true);
  435. exit;
  436. end;
  437. else
  438. begin
  439. Message(asmr_e_invalid_reference_syntax);
  440. RecoverConsume(false);
  441. end;
  442. end;
  443. end
  444. else
  445. {
  446. if base isn't a register, r15=PC is implied base, so it must be a local label.
  447. pascal constants don't make sense, because implied r15
  448. record offsets probably don't make sense, too (a record offset of code?)
  449. TODO: However, we could make the Stackpointer implied.
  450. }
  451. Begin
  452. case actasmtoken of
  453. AS_ID :
  454. begin
  455. if is_locallabel(actasmpattern) then
  456. begin
  457. CreateLocalLabel(actasmpattern,lab,false);
  458. oper.opr.ref.symbol := lab;
  459. oper.opr.ref.base := NR_PC;
  460. Consume(AS_ID);
  461. test_end(true);
  462. exit;
  463. end
  464. else
  465. begin
  466. // TODO: Stackpointer implied,
  467. Message(asmr_e_invalid_reference_syntax);
  468. RecoverConsume(false);
  469. exit;
  470. end;
  471. end;
  472. else
  473. begin // elsecase
  474. Message(asmr_e_invalid_reference_syntax);
  475. RecoverConsume(false);
  476. exit;
  477. end;
  478. end;
  479. end;
  480. end;
  481. function tarmattreader.TryBuildShifterOp(oper : tarmoperand) : boolean;
  482. procedure handlepara(sm : tshiftmode);
  483. begin
  484. consume(AS_ID);
  485. fillchar(oper.opr,sizeof(oper.opr),0);
  486. oper.opr.typ:=OPR_SHIFTEROP;
  487. oper.opr.shifterop.shiftmode:=sm;
  488. if sm<>SM_RRX then
  489. begin
  490. case actasmtoken of
  491. AS_REGISTER:
  492. begin
  493. oper.opr.shifterop.rs:=actasmregister;
  494. consume(AS_REGISTER);
  495. end;
  496. AS_HASH:
  497. begin
  498. consume(AS_HASH);
  499. oper.opr.shifterop.shiftimm:=BuildConstExpression(false,false);
  500. end;
  501. else
  502. Message(asmr_e_illegal_shifterop_syntax);
  503. end;
  504. end;
  505. end;
  506. begin
  507. result:=true;
  508. if (actasmtoken=AS_ID) then
  509. begin
  510. if (actasmpattern='LSL') then
  511. handlepara(SM_LSL)
  512. else if (actasmpattern='LSR') then
  513. handlepara(SM_LSR)
  514. else if (actasmpattern='ASR') then
  515. handlepara(SM_ASR)
  516. else if (actasmpattern='ROR') then
  517. handlepara(SM_ROR)
  518. else if (actasmpattern='RRX') then
  519. handlepara(SM_RRX)
  520. else
  521. result:=false;
  522. end
  523. else
  524. result:=false;
  525. end;
  526. Procedure tarmattreader.BuildOperand(oper : tarmoperand);
  527. var
  528. expr : string;
  529. typesize,l : longint;
  530. procedure AddLabelOperand(hl:tasmlabel);
  531. begin
  532. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  533. is_calljmp(actopcode) then
  534. begin
  535. oper.opr.typ:=OPR_SYMBOL;
  536. oper.opr.symbol:=hl;
  537. end
  538. else
  539. begin
  540. oper.InitRef;
  541. oper.opr.ref.symbol:=hl;
  542. oper.opr.ref.base:=NR_PC;
  543. if (actasmtoken in [AS_PLUS, AS_MINUS]) then
  544. begin
  545. l:=BuildConstExpression(true,false);
  546. oper.opr.ref.offset:=l;
  547. end;
  548. end;
  549. end;
  550. procedure MaybeRecordOffset;
  551. var
  552. mangledname: string;
  553. hasdot : boolean;
  554. l,
  555. toffset,
  556. tsize : longint;
  557. begin
  558. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  559. exit;
  560. l:=0;
  561. hasdot:=(actasmtoken=AS_DOT);
  562. if hasdot then
  563. begin
  564. if expr<>'' then
  565. begin
  566. BuildRecordOffsetSize(expr,toffset,tsize,mangledname,false);
  567. if (oper.opr.typ<>OPR_CONSTANT) and
  568. (mangledname<>'') then
  569. Message(asmr_e_wrong_sym_type);
  570. inc(l,toffset);
  571. oper.SetSize(tsize,true);
  572. end;
  573. end;
  574. if actasmtoken in [AS_PLUS,AS_MINUS] then
  575. inc(l,BuildConstExpression(true,false));
  576. case oper.opr.typ of
  577. OPR_LOCAL :
  578. begin
  579. { don't allow direct access to fields of parameters, because that
  580. will generate buggy code. Allow it only for explicit typecasting }
  581. if hasdot and
  582. (not oper.hastype) and
  583. (tabstractnormalvarsym(oper.opr.localsym).owner.symtabletype=parasymtable) and
  584. (current_procinfo.procdef.proccalloption<>pocall_register) then
  585. Message(asmr_e_cannot_access_field_directly_for_parameters);
  586. inc(oper.opr.localsymofs,l)
  587. end;
  588. OPR_CONSTANT :
  589. inc(oper.opr.val,l);
  590. OPR_REFERENCE :
  591. if (mangledname<>'') then
  592. begin
  593. if (oper.opr.val<>0) then
  594. Message(asmr_e_wrong_sym_type);
  595. oper.opr.typ:=OPR_SYMBOL;
  596. oper.opr.symbol:=current_asmdata.RefAsmSymbol(mangledname);
  597. end
  598. else
  599. inc(oper.opr.val,l);
  600. OPR_SYMBOL:
  601. Message(asmr_e_invalid_symbol_ref);
  602. else
  603. internalerror(200309221);
  604. end;
  605. end;
  606. function MaybeBuildReference:boolean;
  607. { Try to create a reference, if not a reference is found then false
  608. is returned }
  609. begin
  610. MaybeBuildReference:=true;
  611. case actasmtoken of
  612. AS_INTNUM,
  613. AS_MINUS,
  614. AS_PLUS:
  615. Begin
  616. oper.opr.ref.offset:=BuildConstExpression(True,False);
  617. if actasmtoken<>AS_LPAREN then
  618. Message(asmr_e_invalid_reference_syntax)
  619. else
  620. BuildReference(oper);
  621. end;
  622. AS_LPAREN:
  623. BuildReference(oper);
  624. AS_ID: { only a variable is allowed ... }
  625. Begin
  626. ReadSym(oper);
  627. case actasmtoken of
  628. AS_end,
  629. AS_SEPARATOR,
  630. AS_COMMA: ;
  631. AS_LPAREN:
  632. BuildReference(oper);
  633. else
  634. Begin
  635. Message(asmr_e_invalid_reference_syntax);
  636. Consume(actasmtoken);
  637. end;
  638. end; {end case }
  639. end;
  640. else
  641. MaybeBuildReference:=false;
  642. end; { end case }
  643. end;
  644. function is_ConditionCode(hs: string): boolean;
  645. var icond: tasmcond;
  646. begin
  647. is_ConditionCode := false;
  648. case actopcode of
  649. A_IT,A_ITE,A_ITT,
  650. A_ITEE,A_ITTE,A_ITET,A_ITTT,
  651. A_ITEEE,A_ITTEE,A_ITETE,A_ITTTE,A_ITEET,A_ITTET,A_ITETT,A_ITTTT:
  652. begin
  653. { search for condition, conditions are always 2 chars }
  654. if length(hs)>1 then
  655. begin
  656. for icond:=low(tasmcond) to high(tasmcond) do
  657. begin
  658. if copy(hs,1,2)=uppercond2str[icond] then
  659. begin
  660. //actcondition:=icond;
  661. oper.opr.typ := OPR_COND;
  662. oper.opr.cc := icond;
  663. exit(true);
  664. end;
  665. end;
  666. end;
  667. end;
  668. end;
  669. end;
  670. function is_modeflag(hs : string): boolean;
  671. var
  672. i: longint;
  673. flags: tcpumodeflags;
  674. begin
  675. is_modeflag := false;
  676. flags:=[];
  677. hs:=lower(hs);
  678. if (actopcode in [A_CPSID,A_CPSIE]) and (length(hs) >= 1) then
  679. begin
  680. for i:=1 to length(hs) do
  681. begin
  682. case hs[i] of
  683. 'a':
  684. Include(flags,mfA);
  685. 'f':
  686. Include(flags,mfF);
  687. 'i':
  688. Include(flags,mfI);
  689. else
  690. exit;
  691. end;
  692. end;
  693. oper.opr.typ := OPR_MODEFLAGS;
  694. oper.opr.flags := flags;
  695. exit(true);
  696. end;
  697. end;
  698. procedure BuildDirectRef;
  699. function GetConstLabel(const symname: string; ofs: aint): TAsmLabel;
  700. var
  701. hp: tai;
  702. newconst: tai_const;
  703. lab: TAsmLabel;
  704. begin
  705. if symname<>'' then
  706. newconst:=tai_const.Createname(symname,ofs)
  707. else
  708. newconst:=tai_const.Create_32bit(ofs);
  709. hp:=tai(current_procinfo.aktlocaldata.First);
  710. while assigned(hp) do
  711. begin
  712. if hp.typ=ait_const then
  713. begin
  714. if (tai_const(hp).sym=newconst.sym) and
  715. (tai_const(hp).value=newconst.value) and
  716. assigned(hp.Previous) and
  717. (tai(hp.previous).typ=ait_label) then
  718. begin
  719. newconst.Free;
  720. result:=tai_label(hp.Previous).labsym;
  721. exit;
  722. end;
  723. end;
  724. hp:=tai(hp.Next);
  725. end;
  726. current_asmdata.getjumplabel(lab);
  727. current_procinfo.aktlocaldata.concat(tai_align.create(4));
  728. current_procinfo.aktlocaldata.concat(tai_label.create(lab));
  729. current_procinfo.aktlocaldata.concat(newconst);
  730. result:=lab;
  731. end;
  732. var
  733. symtype: TAsmsymtype;
  734. sym: string;
  735. val: aint;
  736. begin
  737. case actasmtoken of
  738. AS_INTNUM,
  739. AS_ID:
  740. begin
  741. BuildConstSymbolExpression(true,false,false,val,sym,symtype);
  742. if symtype=AT_NONE then
  743. sym:='';
  744. reference_reset(oper.opr.ref,4);
  745. oper.opr.ref.base:=NR_PC;
  746. oper.opr.ref.symbol:=GetConstLabel(sym,val);
  747. end;
  748. end;
  749. end;
  750. function getregsetindex(reg: tregister): integer;
  751. begin
  752. if getsubreg(reg)=R_SUBFS then
  753. begin
  754. result:=getsupreg(reg)*2;
  755. if result>32 then
  756. result:=result-63;
  757. end
  758. else
  759. result:=getsupreg(reg);
  760. end;
  761. var
  762. tempreg : tregister;
  763. ireg : tsuperregister;
  764. regtype: tregistertype;
  765. subreg: tsubregister;
  766. hl : tasmlabel;
  767. {ofs : longint;}
  768. registerset : tcpuregisterset;
  769. Begin
  770. expr:='';
  771. case actasmtoken of
  772. AS_LBRACKET: { Memory reference or constant expression }
  773. Begin
  774. oper.InitRef;
  775. BuildReference(oper);
  776. end;
  777. AS_HASH: { Constant expression }
  778. Begin
  779. Consume(AS_HASH);
  780. BuildConstantOperand(oper);
  781. end;
  782. AS_EQUAL:
  783. begin
  784. case actopcode of
  785. A_LDRBT,A_LDRB,A_LDR,A_LDRH,A_LDRSB,A_LDRSH,A_LDRT,
  786. A_LDREX,A_LDREXB,A_LDREXD,A_LDREXH:
  787. begin
  788. consume(AS_EQUAL);
  789. oper.InitRef;
  790. BuildDirectRef;
  791. end;
  792. else
  793. Message(asmr_e_invalid_opcode_and_operand);
  794. end;
  795. end;
  796. (*
  797. AS_INTNUM,
  798. AS_MINUS,
  799. AS_PLUS:
  800. Begin
  801. { Constant memory offset }
  802. { This must absolutely be followed by ( }
  803. oper.InitRef;
  804. oper.opr.ref.offset:=BuildConstExpression(True,False);
  805. if actasmtoken<>AS_LPAREN then
  806. begin
  807. ofs:=oper.opr.ref.offset;
  808. BuildConstantOperand(oper);
  809. inc(oper.opr.val,ofs);
  810. end
  811. else
  812. BuildReference(oper);
  813. end;
  814. *)
  815. AS_ID: { A constant expression, or a Variable ref. }
  816. Begin
  817. if is_modeflag(actasmpattern) then
  818. begin
  819. consume(AS_ID);
  820. end
  821. else
  822. { Condition code? }
  823. if is_conditioncode(actasmpattern) then
  824. begin
  825. consume(AS_ID);
  826. end
  827. else
  828. { Local Label ? }
  829. if is_locallabel(actasmpattern) then
  830. begin
  831. CreateLocalLabel(actasmpattern,hl,false);
  832. Consume(AS_ID);
  833. AddLabelOperand(hl);
  834. end
  835. else
  836. { Check for label }
  837. if SearchLabel(actasmpattern,hl,false) then
  838. begin
  839. Consume(AS_ID);
  840. AddLabelOperand(hl);
  841. end
  842. else
  843. { probably a variable or normal expression }
  844. { or a procedure (such as in CALL ID) }
  845. Begin
  846. { is it a constant ? }
  847. if SearchIConstant(actasmpattern,l) then
  848. Begin
  849. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  850. Message(asmr_e_invalid_operand_type);
  851. BuildConstantOperand(oper);
  852. end
  853. else
  854. begin
  855. expr:=actasmpattern;
  856. Consume(AS_ID);
  857. { typecasting? }
  858. if (actasmtoken=AS_LPAREN) and
  859. SearchType(expr,typesize) then
  860. begin
  861. oper.hastype:=true;
  862. Consume(AS_LPAREN);
  863. BuildOperand(oper);
  864. Consume(AS_RPAREN);
  865. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  866. oper.SetSize(typesize,true);
  867. end
  868. else
  869. begin
  870. if not(oper.SetupVar(expr,false)) then
  871. Begin
  872. { look for special symbols ... }
  873. if expr= '__HIGH' then
  874. begin
  875. consume(AS_LPAREN);
  876. if not oper.setupvar('high'+actasmpattern,false) then
  877. Message1(sym_e_unknown_id,'high'+actasmpattern);
  878. consume(AS_ID);
  879. consume(AS_RPAREN);
  880. end
  881. else
  882. if expr = '__RESULT' then
  883. oper.SetUpResult
  884. else
  885. if expr = '__SELF' then
  886. oper.SetupSelf
  887. else
  888. if expr = '__OLDEBP' then
  889. oper.SetupOldEBP
  890. else
  891. Message1(sym_e_unknown_id,expr);
  892. end;
  893. end;
  894. end;
  895. if actasmtoken=AS_DOT then
  896. MaybeRecordOffset;
  897. { add a constant expression? }
  898. if (actasmtoken=AS_PLUS) then
  899. begin
  900. l:=BuildConstExpression(true,false);
  901. case oper.opr.typ of
  902. OPR_CONSTANT :
  903. inc(oper.opr.val,l);
  904. OPR_LOCAL :
  905. inc(oper.opr.localsymofs,l);
  906. OPR_REFERENCE :
  907. inc(oper.opr.ref.offset,l);
  908. else
  909. internalerror(200309202);
  910. end;
  911. end
  912. end;
  913. { Do we have a indexing reference, then parse it also }
  914. if actasmtoken=AS_LPAREN then
  915. BuildReference(oper);
  916. end;
  917. { Register, a variable reference or a constant reference }
  918. AS_REGISTER:
  919. Begin
  920. { save the type of register used. }
  921. tempreg:=actasmregister;
  922. Consume(AS_REGISTER);
  923. if (actasmtoken in [AS_end,AS_SEPARATOR,AS_COMMA]) then
  924. Begin
  925. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  926. Message(asmr_e_invalid_operand_type);
  927. oper.opr.typ:=OPR_REGISTER;
  928. oper.opr.reg:=tempreg;
  929. end
  930. else if (actasmtoken=AS_NOT) and (actopcode in [A_LDM,A_STM,A_FLDM,A_FSTM,A_VLDM,A_VSTM]) then
  931. begin
  932. consume(AS_NOT);
  933. oper.opr.typ:=OPR_REFERENCE;
  934. oper.opr.ref.addressmode:=AM_PREINDEXED;
  935. oper.opr.ref.index:=tempreg;
  936. end
  937. else
  938. Message(asmr_e_syn_operand);
  939. end;
  940. { Registerset }
  941. AS_LSBRACKET:
  942. begin
  943. consume(AS_LSBRACKET);
  944. registerset:=[];
  945. regtype:=R_INVALIDREGISTER;
  946. subreg:=R_SUBNONE;
  947. while actasmtoken<>AS_RSBRACKET do
  948. begin
  949. if actasmtoken=AS_REGISTER then
  950. begin
  951. include(registerset,getregsetindex(actasmregister));
  952. if regtype<>R_INVALIDREGISTER then
  953. begin
  954. if (getregtype(actasmregister)<>regtype) or
  955. (getsubreg(actasmregister)<>subreg) then
  956. Message(asmr_e_mixing_regtypes);
  957. end
  958. else
  959. begin
  960. regtype:=getregtype(actasmregister);
  961. subreg:=getsubreg(actasmregister);
  962. end;
  963. tempreg:=actasmregister;
  964. consume(AS_REGISTER);
  965. if actasmtoken=AS_MINUS then
  966. begin
  967. consume(AS_MINUS);
  968. for ireg:=getregsetindex(tempreg) to getregsetindex(actasmregister) do
  969. include(registerset,ireg);
  970. consume(AS_REGISTER);
  971. end;
  972. end
  973. else
  974. consume(AS_REGISTER);
  975. if actasmtoken=AS_COMMA then
  976. consume(AS_COMMA)
  977. else
  978. break;
  979. end;
  980. consume(AS_RSBRACKET);
  981. oper.opr.typ:=OPR_REGSET;
  982. oper.opr.regtype:=regtype;
  983. oper.opr.subreg:=subreg;
  984. oper.opr.regset:=registerset;
  985. if actasmtoken=AS_XOR then
  986. begin
  987. consume(AS_XOR);
  988. oper.opr.usermode:=true;
  989. end
  990. else
  991. oper.opr.usermode:=false;
  992. if (registerset=[]) then
  993. Message(asmr_e_empty_regset);
  994. end;
  995. AS_end,
  996. AS_SEPARATOR,
  997. AS_COMMA: ;
  998. else
  999. Begin
  1000. Message(asmr_e_syn_operand);
  1001. Consume(actasmtoken);
  1002. end;
  1003. end; { end case }
  1004. end;
  1005. procedure tarmattreader.BuildSpecialreg(oper: tarmoperand);
  1006. var
  1007. hs, reg : String;
  1008. ch : char;
  1009. i, t : longint;
  1010. hreg : tregister;
  1011. flags : tspecialregflags;
  1012. begin
  1013. hreg:=NR_NO;
  1014. case actasmtoken of
  1015. AS_REGISTER:
  1016. begin
  1017. oper.opr.typ:=OPR_REGISTER;
  1018. oper.opr.reg:=actasmregister;
  1019. Consume(AS_REGISTER);
  1020. end;
  1021. AS_ID:
  1022. begin
  1023. t := pos('_', actasmpattern);
  1024. if t > 0 then
  1025. begin
  1026. hs:=lower(actasmpattern);
  1027. reg:=copy(hs, 1, t-1);
  1028. delete(hs, 1, t);
  1029. if length(hs) < 1 then
  1030. Message(asmr_e_invalid_operand_type);
  1031. if reg = 'cpsr' then
  1032. hreg:=NR_CPSR
  1033. else if reg='spsr' then
  1034. hreg:=NR_SPSR
  1035. else
  1036. Message(asmr_e_invalid_register);
  1037. flags:=[];
  1038. for i := 1 to length(hs) do
  1039. begin
  1040. ch:=hs[i];
  1041. if ch='c' then
  1042. include(flags, srC)
  1043. else if ch='x' then
  1044. include(flags, srX)
  1045. else if ch='f' then
  1046. include(flags, srF)
  1047. else if ch='s' then
  1048. include(flags, srS)
  1049. else
  1050. message(asmr_e_invalid_operand_type);
  1051. end;
  1052. oper.opr.typ:=OPR_SPECIALREG;
  1053. oper.opr.specialreg:=hreg;
  1054. oper.opr.specialregflags:=flags;
  1055. consume(AS_ID);
  1056. end
  1057. else
  1058. Message(asmr_e_invalid_operand_type); // Otherwise it would have been seen as a AS_REGISTER
  1059. end;
  1060. end;
  1061. end;
  1062. {*****************************************************************************
  1063. tarmattreader
  1064. *****************************************************************************}
  1065. procedure tarmattreader.BuildOpCode(instr : tarminstruction);
  1066. var
  1067. operandnum : longint;
  1068. Begin
  1069. { opcode }
  1070. if (actasmtoken<>AS_OPCODE) then
  1071. Begin
  1072. Message(asmr_e_invalid_or_missing_opcode);
  1073. RecoverConsume(true);
  1074. exit;
  1075. end;
  1076. { Fill the instr object with the current state }
  1077. with instr do
  1078. begin
  1079. Opcode:=ActOpcode;
  1080. condition:=ActCondition;
  1081. oppostfix:=actoppostfix;
  1082. wideformat:=actwideformat;
  1083. end;
  1084. { We are reading operands, so opcode will be an AS_ID }
  1085. operandnum:=1;
  1086. Consume(AS_OPCODE);
  1087. { Zero operand opcode ? }
  1088. if actasmtoken in [AS_SEPARATOR,AS_end] then
  1089. begin
  1090. operandnum:=0;
  1091. exit;
  1092. end;
  1093. { Read the operands }
  1094. repeat
  1095. case actasmtoken of
  1096. AS_COMMA: { Operand delimiter }
  1097. Begin
  1098. if ((instr.opcode in [A_MOV,A_MVN,A_CMP,A_CMN,A_TST,A_TEQ,
  1099. A_UXTB,A_UXTH,A_UXTB16,
  1100. A_SXTB,A_SXTH,A_SXTB16]) and
  1101. (operandnum=2)) or
  1102. ((operandnum=3) and not(instr.opcode in [A_UMLAL,A_UMULL,A_SMLAL,A_SMULL,A_MLA,A_UMAAL,A_MLS,
  1103. A_SMLABB,A_SMLABT,A_SMLATB,A_SMLATT,A_SMMLA,A_SMMLS,A_SMLAD,A_SMLALD,A_SMLSD,
  1104. A_SMLALBB,A_SMLALBT,A_SMLALTB,A_SMLALTT,A_SMLSLD,
  1105. A_SMLAWB,A_SMLAWT,
  1106. A_MRC,A_MCR,A_MCRR,A_MRRC,A_MRC2,A_MCR2,A_MCRR2,A_MRRC2,
  1107. A_STREXD,A_STRD,
  1108. A_USADA8,
  1109. A_VMOV,
  1110. A_SBFX,A_UBFX,A_BFI])) then
  1111. begin
  1112. Consume(AS_COMMA);
  1113. if not(TryBuildShifterOp(instr.Operands[operandnum+1] as tarmoperand)) then
  1114. Message(asmr_e_illegal_shifterop_syntax);
  1115. Inc(operandnum);
  1116. end
  1117. else
  1118. begin
  1119. if operandnum>Max_Operands then
  1120. Message(asmr_e_too_many_operands)
  1121. else
  1122. Inc(operandnum);
  1123. Consume(AS_COMMA);
  1124. end;
  1125. end;
  1126. AS_SEPARATOR,
  1127. AS_end : { End of asm operands for this opcode }
  1128. begin
  1129. break;
  1130. end;
  1131. else
  1132. if (instr.opcode = A_MSR) and (operandnum = 1) then
  1133. BuildSpecialreg(instr.Operands[operandnum] as tarmoperand)
  1134. else
  1135. BuildOperand(instr.Operands[operandnum] as tarmoperand);
  1136. end; { end case }
  1137. until false;
  1138. instr.Ops:=operandnum;
  1139. end;
  1140. function tarmattreader.is_asmopcode(const s: string):boolean;
  1141. const
  1142. { sorted by length so longer postfixes will match first }
  1143. postfix2strsorted : array[1..70] of string[9] = (
  1144. '.F32.S32','.F32.U32','.S32.F32','.U32.F32','.F64.S32','.F64.U32','.S32.F64','.U32.F64',
  1145. '.F32.S16','.F32.U16','.S16.F32','.U16.F32','.F64.S16','.F64.U16','.S16.F64','.U16.F64',
  1146. '.F32.F64','.F64.F32',
  1147. '.I16','.I32','.I64','.S16','.S32','.S64','.U16','.U32','.U64','.F32','.F64',
  1148. 'IAD','DBD','FDD','EAD','IAS','DBS','FDS','EAS','IAX','DBX','FDX','EAX',
  1149. '.16','.32','.64','.I8','.S8','.U8','.P8',
  1150. 'EP','SB','BT','SH','IA','IB','DA','DB','FD','FA','ED','EA',
  1151. '.8','S','D','E','P','X','R','B','H','T');
  1152. postfixsorted : array[1..70] of TOpPostfix = (
  1153. PF_F32S32,PF_F32U32,PF_S32F32,PF_U32F32,PF_F64S32,PF_F64U32,PF_S32F64,PF_U32F64,
  1154. PF_F32S16,PF_F32U16,PF_S16F32,PF_U16F32,PF_F64S16,PF_F64U16,PF_S16F64,PF_U16F64,
  1155. PF_F32F64,PF_F64F32,
  1156. PF_I16,PF_I32,
  1157. PF_I64,PF_S16,PF_S32,PF_S64,PF_U16,PF_U32,PF_U64,PF_F32,
  1158. PF_F64,PF_IAD,PF_DBD,PF_FDD,PF_EAD,
  1159. PF_IAS,PF_DBS,PF_FDS,PF_EAS,PF_IAX,
  1160. PF_DBX,PF_FDX,PF_EAX,PF_16,PF_32,
  1161. PF_64,PF_I8,PF_S8,PF_U8,PF_P8,
  1162. PF_EP,PF_SB,PF_BT,PF_SH,PF_IA,
  1163. PF_IB,PF_DA,PF_DB,PF_FD,PF_FA,
  1164. PF_ED,PF_EA,PF_8,PF_S,PF_D,PF_E,
  1165. PF_P,PF_X,PF_R,PF_B,PF_H,PF_T);
  1166. var
  1167. j, j2 : longint;
  1168. hs,hs2 : string;
  1169. maxlen : longint;
  1170. icond : tasmcond;
  1171. Begin
  1172. { making s a value parameter would break other assembler readers }
  1173. hs:=s;
  1174. is_asmopcode:=false;
  1175. { clear op code }
  1176. actopcode:=A_None;
  1177. actcondition:=C_None;
  1178. { first, handle B else BLS is read wrong }
  1179. if ((hs[1]='B') and (length(hs)=3)) then
  1180. begin
  1181. for icond:=low(tasmcond) to high(tasmcond) do
  1182. begin
  1183. if copy(hs,2,3)=uppercond2str[icond] then
  1184. begin
  1185. actopcode:=A_B;
  1186. actasmtoken:=AS_OPCODE;
  1187. actcondition:=icond;
  1188. is_asmopcode:=true;
  1189. exit;
  1190. end;
  1191. end;
  1192. end;
  1193. maxlen:=min(length(hs),5);
  1194. actopcode:=A_NONE;
  1195. j2:=maxlen;
  1196. hs2:=hs;
  1197. while j2>1 do
  1198. begin
  1199. hs:=hs2;
  1200. while j2>=1 do
  1201. begin
  1202. actopcode:=tasmop(PtrUInt(iasmops.Find(copy(hs,1,j2))));
  1203. if actopcode<>A_NONE then
  1204. begin
  1205. actasmtoken:=AS_OPCODE;
  1206. { strip op code }
  1207. delete(hs,1,j2);
  1208. dec(j2);
  1209. break;
  1210. end;
  1211. dec(j2);
  1212. end;
  1213. if actopcode=A_NONE then
  1214. exit;
  1215. if is_unified then
  1216. begin
  1217. { check for postfix }
  1218. if (length(hs)>0) and (actoppostfix=PF_None) then
  1219. begin
  1220. for j:=low(postfixsorted) to high(postfixsorted) do
  1221. begin
  1222. if copy(hs,1,length(postfix2strsorted[j]))=postfix2strsorted[j] then
  1223. begin
  1224. if not ((length(hs)-length(postfix2strsorted[j])) in [0,2,4]) then
  1225. continue;
  1226. actoppostfix:=postfixsorted[j];
  1227. { strip postfix }
  1228. delete(hs,1,length(postfix2strsorted[j]));
  1229. break;
  1230. end;
  1231. end;
  1232. end;
  1233. { search for condition, conditions are always 2 chars }
  1234. if length(hs)>1 then
  1235. begin
  1236. for icond:=low(tasmcond) to high(tasmcond) do
  1237. begin
  1238. if copy(hs,1,2)=uppercond2str[icond] then
  1239. begin
  1240. actcondition:=icond;
  1241. { strip condition }
  1242. delete(hs,1,2);
  1243. break;
  1244. end;
  1245. end;
  1246. end;
  1247. { check for postfix }
  1248. if (length(hs)>0) and (actoppostfix=PF_None) then
  1249. begin
  1250. for j:=low(postfixsorted) to high(postfixsorted) do
  1251. begin
  1252. if copy(hs,1,length(postfix2strsorted[j]))=postfix2strsorted[j] then
  1253. begin
  1254. if not ((length(hs)-length(postfix2strsorted[j])) = 0) then
  1255. continue;
  1256. actoppostfix:=postfixsorted[j];
  1257. { strip postfix }
  1258. delete(hs,1,length(postfix2strsorted[j]));
  1259. break;
  1260. end;
  1261. end;
  1262. end;
  1263. end
  1264. else
  1265. begin
  1266. { search for condition, conditions are always 2 chars }
  1267. if length(hs)>1 then
  1268. begin
  1269. for icond:=low(tasmcond) to high(tasmcond) do
  1270. begin
  1271. if copy(hs,1,2)=uppercond2str[icond] then
  1272. begin
  1273. actcondition:=icond;
  1274. { strip condition }
  1275. delete(hs,1,2);
  1276. break;
  1277. end;
  1278. end;
  1279. end;
  1280. { check for postfix }
  1281. if (length(hs)>0) and (actoppostfix=PF_None) then
  1282. begin
  1283. for j:=low(postfixsorted) to high(postfixsorted) do
  1284. begin
  1285. if copy(hs,1,length(postfix2strsorted[j]))=postfix2strsorted[j] then
  1286. begin
  1287. actoppostfix:=postfixsorted[j];
  1288. { strip postfix }
  1289. delete(hs,1,length(postfix2strsorted[j]));
  1290. break;
  1291. end;
  1292. end;
  1293. end;
  1294. end;
  1295. { check for format postfix }
  1296. if length(hs)>0 then
  1297. begin
  1298. if copy(hs,1,2) = '.W' then
  1299. begin
  1300. actwideformat:=true;
  1301. delete(hs,1,2);
  1302. end;
  1303. end;
  1304. { if we stripped all postfixes, it's a valid opcode }
  1305. is_asmopcode:=length(hs)=0;
  1306. if is_asmopcode = true then
  1307. break;
  1308. end;
  1309. end;
  1310. procedure tarmattreader.ConvertCalljmp(instr : tarminstruction);
  1311. var
  1312. newopr : toprrec;
  1313. begin
  1314. if instr.Operands[1].opr.typ=OPR_REFERENCE then
  1315. begin
  1316. newopr.typ:=OPR_SYMBOL;
  1317. newopr.symbol:=instr.Operands[1].opr.ref.symbol;
  1318. newopr.symofs:=instr.Operands[1].opr.ref.offset;
  1319. if (instr.Operands[1].opr.ref.base<>NR_NO) or
  1320. (instr.Operands[1].opr.ref.index<>NR_NO) then
  1321. Message(asmr_e_syn_operand);
  1322. instr.Operands[1].opr:=newopr;
  1323. end;
  1324. end;
  1325. procedure tarmattreader.HandleTargetDirective;
  1326. var
  1327. symname,
  1328. symval : String;
  1329. val : aint;
  1330. symtyp : TAsmsymtype;
  1331. begin
  1332. if actasmpattern='.thumb_set' then
  1333. begin
  1334. consume(AS_TARGET_DIRECTIVE);
  1335. BuildConstSymbolExpression(true,false,false, val,symname,symtyp);
  1336. Consume(AS_COMMA);
  1337. BuildConstSymbolExpression(true,false,false, val,symval,symtyp);
  1338. curList.concat(tai_thumb_set.create(symname,symval));
  1339. end
  1340. else if actasmpattern='.thumb_func' then
  1341. begin
  1342. consume(AS_TARGET_DIRECTIVE);
  1343. curList.concat(tai_directive.create(asd_thumb_func,''));
  1344. end
  1345. else
  1346. inherited HandleTargetDirective;
  1347. end;
  1348. function tarmattreader.is_unified: boolean;
  1349. begin
  1350. result:=false;
  1351. end;
  1352. procedure tarmattreader.handleopcode;
  1353. var
  1354. instr : tarminstruction;
  1355. begin
  1356. instr:=TarmInstruction.Create(TarmOperand);
  1357. BuildOpcode(instr);
  1358. if is_calljmp(instr.opcode) then
  1359. ConvertCalljmp(instr);
  1360. {
  1361. instr.AddReferenceSizes;
  1362. instr.SetInstructionOpsize;
  1363. instr.CheckOperandSizes;
  1364. }
  1365. instr.ConcatInstruction(curlist);
  1366. instr.Free;
  1367. actoppostfix:=PF_None;
  1368. actwideformat:=false;
  1369. end;
  1370. {*****************************************************************************
  1371. Initialize
  1372. *****************************************************************************}
  1373. const
  1374. asmmode_arm_att_info : tasmmodeinfo =
  1375. (
  1376. id : asmmode_arm_gas;
  1377. idtxt : 'DIVIDED';
  1378. casmreader : tarmattreader;
  1379. );
  1380. asmmode_arm_att_unified_info : tasmmodeinfo =
  1381. (
  1382. id : asmmode_arm_gas_unified;
  1383. idtxt : 'UNIFIED';
  1384. casmreader : tarmunifiedattreader;
  1385. );
  1386. asmmode_arm_standard_info : tasmmodeinfo =
  1387. (
  1388. id : asmmode_standard;
  1389. idtxt : 'STANDARD';
  1390. casmreader : tarmattreader;
  1391. );
  1392. initialization
  1393. RegisterAsmMode(asmmode_arm_att_info);
  1394. RegisterAsmMode(asmmode_arm_att_unified_info);
  1395. RegisterAsmMode(asmmode_arm_standard_info);
  1396. end.