rax86att.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Does the parsing for the x86 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 rax86att;
  18. {$i fpcdefs.inc}
  19. Interface
  20. uses
  21. cpubase,
  22. raatt,rax86;
  23. type
  24. tx86attreader = class(tattreader)
  25. ActOpsize : topsize;
  26. function is_asmopcode(const s: string):boolean;override;
  27. procedure handleopcode;override;
  28. procedure BuildReference(oper : tx86operand);
  29. procedure BuildOperand(oper : tx86operand);
  30. procedure BuildOpCode(instr : tx86instruction);
  31. procedure handlepercent;override;
  32. end;
  33. Implementation
  34. uses
  35. { helpers }
  36. cutils,
  37. { global }
  38. globtype,verbose,
  39. systems,
  40. { aasm }
  41. aasmbase,aasmtai,aasmcpu,
  42. { symtable }
  43. symconst,
  44. { parser }
  45. scanner,
  46. procinfo,
  47. itcpugas,
  48. rabase,rautils,
  49. cgbase
  50. ;
  51. procedure tx86attreader.handlepercent;
  52. var
  53. len : longint;
  54. begin
  55. len:=1;
  56. actasmpattern[len]:='%';
  57. c:=current_scanner.asmgetchar;
  58. { to be a register there must be a letter and not a number }
  59. if c in ['0'..'9'] then
  60. begin
  61. actasmtoken:=AS_MOD;
  62. end
  63. else
  64. begin
  65. while c in ['a'..'z','A'..'Z','0'..'9'] do
  66. Begin
  67. inc(len);
  68. actasmpattern[len]:=c;
  69. c:=current_scanner.asmgetchar;
  70. end;
  71. actasmpattern[0]:=chr(len);
  72. uppervar(actasmpattern);
  73. if (actasmpattern = '%ST') and (c='(') then
  74. Begin
  75. actasmpattern:=actasmpattern+c;
  76. c:=current_scanner.asmgetchar;
  77. if c in ['0'..'9'] then
  78. actasmpattern:=actasmpattern + c
  79. else
  80. Message(asmr_e_invalid_fpu_register);
  81. c:=current_scanner.asmgetchar;
  82. if c <> ')' then
  83. Message(asmr_e_invalid_fpu_register)
  84. else
  85. Begin
  86. actasmpattern:=actasmpattern + c;
  87. c:=current_scanner.asmgetchar; { let us point to next character. }
  88. end;
  89. end;
  90. if is_register(actasmpattern) then
  91. exit;
  92. Message(asmr_e_invalid_register);
  93. actasmtoken:=raatt.AS_NONE;
  94. end;
  95. end;
  96. Procedure tx86attreader.BuildReference(oper : tx86operand);
  97. procedure Consume_RParen;
  98. begin
  99. if actasmtoken <> AS_RPAREN then
  100. Begin
  101. Message(asmr_e_invalid_reference_syntax);
  102. RecoverConsume(true);
  103. end
  104. else
  105. begin
  106. Consume(AS_RPAREN);
  107. if not (actasmtoken in [AS_COMMA,AS_SEPARATOR,AS_END]) then
  108. Begin
  109. Message(asmr_e_invalid_reference_syntax);
  110. RecoverConsume(true);
  111. end;
  112. end;
  113. end;
  114. procedure Consume_Scale;
  115. var
  116. l : aint;
  117. begin
  118. { we have to process the scaling }
  119. l:=BuildConstExpression(false,true);
  120. if ((l = 2) or (l = 4) or (l = 8) or (l = 1)) then
  121. oper.opr.ref.scalefactor:=l
  122. else
  123. Begin
  124. Message(asmr_e_wrong_scale_factor);
  125. oper.opr.ref.scalefactor:=0;
  126. end;
  127. end;
  128. begin
  129. oper.InitRef;
  130. Consume(AS_LPAREN);
  131. Case actasmtoken of
  132. AS_INTNUM,
  133. AS_MINUS,
  134. AS_PLUS: { absolute offset, such as fs:(0x046c) }
  135. Begin
  136. { offset(offset) is invalid }
  137. If oper.opr.Ref.Offset <> 0 Then
  138. Begin
  139. Message(asmr_e_invalid_reference_syntax);
  140. RecoverConsume(true);
  141. End
  142. Else
  143. Begin
  144. oper.opr.Ref.Offset:=BuildConstExpression(false,true);
  145. Consume_RParen;
  146. end;
  147. exit;
  148. End;
  149. AS_REGISTER: { (reg ... }
  150. Begin
  151. { Check if there is already a base (mostly ebp,esp) than this is
  152. not allowed, because it will give crashing code }
  153. if ((oper.opr.typ=OPR_REFERENCE) and (oper.opr.ref.base<>NR_NO)) or
  154. ((oper.opr.typ=OPR_LOCAL) and (oper.opr.localsym.localloc.loc<>LOC_REGISTER)) then
  155. message(asmr_e_cannot_index_relative_var);
  156. oper.opr.ref.base:=actasmregister;
  157. Consume(AS_REGISTER);
  158. { can either be a register or a right parenthesis }
  159. { (reg) }
  160. if actasmtoken=AS_RPAREN then
  161. Begin
  162. Consume_RParen;
  163. exit;
  164. end;
  165. { (reg,reg .. }
  166. Consume(AS_COMMA);
  167. if actasmtoken=AS_REGISTER then
  168. Begin
  169. oper.opr.ref.index:=actasmregister;
  170. Consume(AS_REGISTER);
  171. { check for scaling ... }
  172. case actasmtoken of
  173. AS_RPAREN:
  174. Begin
  175. Consume_RParen;
  176. exit;
  177. end;
  178. AS_COMMA:
  179. Begin
  180. Consume(AS_COMMA);
  181. Consume_Scale;
  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. end
  191. else
  192. Begin
  193. Message(asmr_e_invalid_reference_syntax);
  194. RecoverConsume(false);
  195. end;
  196. end; {end case }
  197. AS_COMMA: { (, ... can either be scaling, or index }
  198. Begin
  199. Consume(AS_COMMA);
  200. { Index }
  201. if (actasmtoken=AS_REGISTER) then
  202. Begin
  203. oper.opr.ref.index:=actasmregister;
  204. Consume(AS_REGISTER);
  205. { check for scaling ... }
  206. case actasmtoken of
  207. AS_RPAREN:
  208. Begin
  209. Consume_RParen;
  210. exit;
  211. end;
  212. AS_COMMA:
  213. Begin
  214. Consume(AS_COMMA);
  215. Consume_Scale;
  216. Consume_RParen;
  217. end;
  218. else
  219. Begin
  220. Message(asmr_e_invalid_reference_syntax);
  221. RecoverConsume(false);
  222. end;
  223. end; {end case }
  224. end
  225. { Scaling }
  226. else
  227. Begin
  228. Consume_Scale;
  229. Consume_RParen;
  230. exit;
  231. end;
  232. end;
  233. else
  234. Begin
  235. Message(asmr_e_invalid_reference_syntax);
  236. RecoverConsume(false);
  237. end;
  238. end;
  239. end;
  240. Procedure tx86attreader.BuildOperand(oper : tx86operand);
  241. var
  242. tempstr,
  243. expr : string;
  244. typesize,l,k : aint;
  245. procedure AddLabelOperand(hl:tasmlabel);
  246. begin
  247. if not(actasmtoken in [AS_PLUS,AS_MINUS,AS_LPAREN]) and
  248. is_calljmp(actopcode) then
  249. begin
  250. oper.opr.typ:=OPR_SYMBOL;
  251. oper.opr.symbol:=hl;
  252. end
  253. else
  254. begin
  255. oper.InitRef;
  256. oper.opr.ref.symbol:=hl;
  257. end;
  258. end;
  259. procedure MaybeRecordOffset;
  260. var
  261. hasdot : boolean;
  262. l,
  263. toffset,
  264. tsize : aint;
  265. begin
  266. if not(actasmtoken in [AS_DOT,AS_PLUS,AS_MINUS]) then
  267. exit;
  268. l:=0;
  269. hasdot:=(actasmtoken=AS_DOT);
  270. if hasdot then
  271. begin
  272. if expr<>'' then
  273. begin
  274. BuildRecordOffsetSize(expr,toffset,tsize);
  275. inc(l,toffset);
  276. oper.SetSize(tsize,true);
  277. end;
  278. end;
  279. if actasmtoken in [AS_PLUS,AS_MINUS] then
  280. inc(l,BuildConstExpression(true,false));
  281. case oper.opr.typ of
  282. OPR_LOCAL :
  283. begin
  284. { don't allow direct access to fields of parameters, because that
  285. will generate buggy code. Allow it only for explicit typecasting }
  286. if hasdot and
  287. (not oper.hastype) and
  288. (oper.opr.localsym.owner.symtabletype=parasymtable) and
  289. (current_procinfo.procdef.proccalloption<>pocall_register) then
  290. Message(asmr_e_cannot_access_field_directly_for_parameters);
  291. inc(oper.opr.localsymofs,l)
  292. end;
  293. OPR_CONSTANT :
  294. inc(oper.opr.val,l);
  295. OPR_REFERENCE :
  296. inc(oper.opr.ref.offset,l);
  297. else
  298. internalerror(200309221);
  299. end;
  300. end;
  301. procedure handleat;
  302. begin
  303. end;
  304. function MaybeBuildReference:boolean;
  305. { Try to create a reference, if not a reference is found then false
  306. is returned }
  307. begin
  308. MaybeBuildReference:=true;
  309. case actasmtoken of
  310. AS_INTNUM,
  311. AS_MINUS,
  312. AS_PLUS:
  313. Begin
  314. oper.opr.ref.offset:=BuildConstExpression(True,False);
  315. if actasmtoken<>AS_LPAREN then
  316. Message(asmr_e_invalid_reference_syntax)
  317. else
  318. BuildReference(oper);
  319. end;
  320. AS_LPAREN:
  321. BuildReference(oper);
  322. AS_ID: { only a variable is allowed ... }
  323. Begin
  324. tempstr:=actasmpattern;
  325. Consume(AS_ID);
  326. { typecasting? }
  327. if (actasmtoken=AS_LPAREN) and
  328. SearchType(tempstr,typesize) then
  329. begin
  330. oper.hastype:=true;
  331. Consume(AS_LPAREN);
  332. BuildOperand(oper);
  333. Consume(AS_RPAREN);
  334. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  335. oper.SetSize(typesize,true);
  336. end
  337. else
  338. if not oper.SetupVar(tempstr,false) then
  339. Message1(sym_e_unknown_id,tempstr);
  340. { record.field ? }
  341. if actasmtoken=AS_DOT then
  342. begin
  343. BuildRecordOffsetSize(tempstr,l,k);
  344. inc(oper.opr.ref.offset,l);
  345. end;
  346. if actasmtoken=AS_AT then
  347. begin
  348. consume(AS_AT);
  349. if actasmtoken=AS_ID then
  350. begin
  351. if actasmpattern='GOTPCREL' then
  352. oper.opr.ref.refaddr:=addr_pic
  353. else
  354. Message(asmr_e_invalid_reference_syntax);
  355. end
  356. else
  357. Message(asmr_e_invalid_reference_syntax);
  358. end;
  359. case actasmtoken of
  360. AS_END,
  361. AS_SEPARATOR,
  362. AS_COMMA: ;
  363. AS_LPAREN:
  364. BuildReference(oper);
  365. else
  366. Begin
  367. Message(asmr_e_invalid_reference_syntax);
  368. Consume(actasmtoken);
  369. end;
  370. end; {end case }
  371. end;
  372. else
  373. MaybeBuildReference:=false;
  374. end; { end case }
  375. end;
  376. var
  377. tempreg : tregister;
  378. hl : tasmlabel;
  379. Begin
  380. expr:='';
  381. case actasmtoken of
  382. AS_LPAREN: { Memory reference or constant expression }
  383. Begin
  384. oper.InitRef;
  385. BuildReference(oper);
  386. end;
  387. AS_DOLLAR: { Constant expression }
  388. Begin
  389. Consume(AS_DOLLAR);
  390. BuildConstantOperand(oper);
  391. end;
  392. AS_INTNUM,
  393. AS_MINUS,
  394. AS_PLUS:
  395. Begin
  396. { Constant memory offset }
  397. { This must absolutely be followed by ( }
  398. oper.InitRef;
  399. oper.opr.ref.offset:=BuildConstExpression(True,False);
  400. if actasmtoken<>AS_LPAREN then
  401. Message(asmr_e_invalid_reference_syntax)
  402. else
  403. BuildReference(oper);
  404. end;
  405. AS_STAR: { Call from memory address }
  406. Begin
  407. Consume(AS_STAR);
  408. if actasmtoken=AS_REGISTER then
  409. begin
  410. oper.opr.typ:=OPR_REGISTER;
  411. oper.opr.reg:=actasmregister;
  412. oper.SetSize(tcgsize2size[reg_cgsize(actasmregister)],true);
  413. Consume(AS_REGISTER);
  414. end
  415. else
  416. begin
  417. oper.InitRef;
  418. if not MaybeBuildReference then
  419. Message(asmr_e_syn_operand);
  420. end;
  421. { this is only allowed for call's and jmp's }
  422. if not is_calljmp(actopcode) then
  423. Message(asmr_e_syn_operand);
  424. end;
  425. AS_ID: { A constant expression, or a Variable ref. }
  426. Begin
  427. { Local Label ? }
  428. if is_locallabel(actasmpattern) then
  429. begin
  430. CreateLocalLabel(actasmpattern,hl,false);
  431. Consume(AS_ID);
  432. AddLabelOperand(hl);
  433. end
  434. else
  435. { Check for label }
  436. if SearchLabel(actasmpattern,hl,false) then
  437. begin
  438. Consume(AS_ID);
  439. AddLabelOperand(hl);
  440. end
  441. else
  442. { probably a variable or normal expression }
  443. { or a procedure (such as in CALL ID) }
  444. Begin
  445. { is it a constant ? }
  446. if SearchIConstant(actasmpattern,l) then
  447. Begin
  448. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  449. Message(asmr_e_invalid_operand_type);
  450. BuildConstantOperand(oper);
  451. end
  452. else
  453. begin
  454. expr:=actasmpattern;
  455. Consume(AS_ID);
  456. { typecasting? }
  457. if (actasmtoken=AS_LPAREN) and
  458. SearchType(expr,typesize) then
  459. begin
  460. oper.hastype:=true;
  461. Consume(AS_LPAREN);
  462. BuildOperand(oper);
  463. Consume(AS_RPAREN);
  464. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  465. oper.SetSize(typesize,true);
  466. end
  467. else
  468. begin
  469. if oper.SetupVar(expr,false) then
  470. begin
  471. if actasmtoken=AS_AT then
  472. begin
  473. consume(AS_AT);
  474. if actasmtoken=AS_ID then
  475. begin
  476. if actasmpattern='GOTPCREL' then
  477. begin
  478. oper.opr.ref.refaddr:=addr_pic;
  479. consume(AS_ID);
  480. end
  481. else
  482. Message(asmr_e_invalid_reference_syntax);
  483. end
  484. else
  485. Message(asmr_e_invalid_reference_syntax);
  486. end;
  487. end
  488. else
  489. Begin
  490. { look for special symbols ... }
  491. if expr= '__HIGH' then
  492. begin
  493. consume(AS_LPAREN);
  494. if not oper.setupvar('high'+actasmpattern,false) then
  495. Message1(sym_e_unknown_id,'high'+actasmpattern);
  496. consume(AS_ID);
  497. consume(AS_RPAREN);
  498. end
  499. else
  500. if expr = '__RESULT' then
  501. oper.SetUpResult
  502. else
  503. if expr = '__SELF' then
  504. oper.SetupSelf
  505. else
  506. if expr = '__OLDEBP' then
  507. oper.SetupOldEBP
  508. else
  509. Message1(sym_e_unknown_id,expr);
  510. end;
  511. end;
  512. end;
  513. if actasmtoken=AS_DOT then
  514. MaybeRecordOffset;
  515. { add a constant expression? }
  516. if (actasmtoken=AS_PLUS) then
  517. begin
  518. l:=BuildConstExpression(true,false);
  519. case oper.opr.typ of
  520. OPR_CONSTANT :
  521. inc(oper.opr.val,l);
  522. OPR_LOCAL :
  523. inc(oper.opr.localsymofs,l);
  524. OPR_REFERENCE :
  525. inc(oper.opr.ref.offset,l);
  526. else
  527. internalerror(200309202);
  528. end;
  529. end
  530. end;
  531. { Do we have a indexing reference, then parse it also }
  532. if actasmtoken=AS_LPAREN then
  533. BuildReference(oper);
  534. end;
  535. AS_REGISTER: { Register, a variable reference or a constant reference }
  536. Begin
  537. { save the type of register used. }
  538. tempreg:=actasmregister;
  539. Consume(AS_REGISTER);
  540. if actasmtoken = AS_COLON then
  541. Begin
  542. Consume(AS_COLON);
  543. oper.InitRef;
  544. oper.opr.ref.segment:=tempreg;
  545. { This must absolutely be followed by a reference }
  546. if not MaybeBuildReference then
  547. Begin
  548. Message(asmr_e_invalid_seg_override);
  549. Consume(actasmtoken);
  550. end;
  551. end
  552. { Simple register }
  553. else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  554. Begin
  555. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  556. Message(asmr_e_invalid_operand_type);
  557. oper.opr.typ:=OPR_REGISTER;
  558. oper.opr.reg:=tempreg;
  559. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  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. procedure tx86attreader.BuildOpCode(instr : tx86instruction);
  575. var
  576. operandnum : longint;
  577. PrefixOp,OverrideOp: tasmop;
  578. Begin
  579. PrefixOp:=A_None;
  580. OverrideOp:=A_None;
  581. { prefix seg opcode / prefix opcode }
  582. repeat
  583. if is_prefix(actopcode) then
  584. begin
  585. PrefixOp:=ActOpcode;
  586. with instr do
  587. begin
  588. opcode:=ActOpcode;
  589. condition:=ActCondition;
  590. opsize:=ActOpsize;
  591. ConcatInstruction(curlist);
  592. end;
  593. Consume(AS_OPCODE);
  594. end
  595. else
  596. if is_override(actopcode) then
  597. begin
  598. OverrideOp:=ActOpcode;
  599. with instr do
  600. begin
  601. opcode:=ActOpcode;
  602. condition:=ActCondition;
  603. opsize:=ActOpsize;
  604. ConcatInstruction(curlist);
  605. end;
  606. Consume(AS_OPCODE);
  607. end
  608. else
  609. break;
  610. { allow for newline as in gas styled syntax }
  611. while actasmtoken=AS_SEPARATOR do
  612. Consume(AS_SEPARATOR);
  613. until (actasmtoken<>AS_OPCODE);
  614. { opcode }
  615. if (actasmtoken<>AS_OPCODE) then
  616. Begin
  617. Message(asmr_e_invalid_or_missing_opcode);
  618. RecoverConsume(true);
  619. exit;
  620. end;
  621. { Fill the instr object with the current state }
  622. with instr do
  623. begin
  624. Opcode:=ActOpcode;
  625. condition:=ActCondition;
  626. opsize:=ActOpsize;
  627. end;
  628. { Valid combination of prefix/override and instruction ? }
  629. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  630. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  631. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  632. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  633. { We are reading operands, so opcode will be an AS_ID }
  634. operandnum:=1;
  635. Consume(AS_OPCODE);
  636. { Zero operand opcode ? }
  637. if actasmtoken in [AS_SEPARATOR,AS_END] then
  638. begin
  639. operandnum:=0;
  640. exit;
  641. end;
  642. { Read the operands }
  643. repeat
  644. case actasmtoken of
  645. AS_COMMA: { Operand delimiter }
  646. Begin
  647. if operandnum > Max_Operands then
  648. Message(asmr_e_too_many_operands)
  649. else
  650. Inc(operandnum);
  651. Consume(AS_COMMA);
  652. end;
  653. AS_SEPARATOR,
  654. AS_END : { End of asm operands for this opcode }
  655. begin
  656. break;
  657. end;
  658. else
  659. BuildOperand(instr.Operands[operandnum] as tx86operand);
  660. end; { end case }
  661. until false;
  662. instr.Ops:=operandnum;
  663. end;
  664. function tx86attreader.is_asmopcode(const s: string):boolean;
  665. const
  666. { We need first to check the long prefixes, else we get probs
  667. with things like movsbl }
  668. att_sizesuffixstr : array[0..9] of string[2] = (
  669. '','BW','BL','WL','B','W','L','S','Q','T'
  670. );
  671. att_sizesuffix : array[0..9] of topsize = (
  672. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_FS,S_IQ,S_FX
  673. );
  674. att_sizefpusuffix : array[0..9] of topsize = (
  675. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_IQ,S_FX
  676. );
  677. att_sizefpuintsuffix : array[0..9] of topsize = (
  678. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
  679. );
  680. var
  681. str2opentry: tstr2opentry;
  682. cond : string[4];
  683. cnd : tasmcond;
  684. len,
  685. j,
  686. sufidx : longint;
  687. Begin
  688. is_asmopcode:=FALSE;
  689. actopcode:=A_None;
  690. actcondition:=C_None;
  691. actopsize:=S_NO;
  692. { search for all possible suffixes }
  693. for sufidx:=low(att_sizesuffixstr) to high(att_sizesuffixstr) do
  694. begin
  695. len:=length(s)-length(att_sizesuffixstr[sufidx]);
  696. if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
  697. begin
  698. { here we search the entire table... }
  699. str2opentry:=nil;
  700. if {(length(s)>0) and} (len>0) then
  701. str2opentry:=tstr2opentry(iasmops.search(copy(s,1,len)));
  702. if assigned(str2opentry) then
  703. begin
  704. actopcode:=str2opentry.op;
  705. if gas_needsuffix[actopcode]=attsufFPU then
  706. actopsize:=att_sizefpusuffix[sufidx]
  707. else if gas_needsuffix[actopcode]=attsufFPUint then
  708. actopsize:=att_sizefpuintsuffix[sufidx]
  709. else
  710. actopsize:=att_sizesuffix[sufidx];
  711. actasmtoken:=AS_OPCODE;
  712. is_asmopcode:=TRUE;
  713. exit;
  714. end;
  715. { not found, check condition opcodes }
  716. j:=0;
  717. while (j<CondAsmOps) do
  718. begin
  719. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  720. begin
  721. cond:=Copy(s,Length(CondAsmOpStr[j])+1,len-Length(CondAsmOpStr[j]));
  722. if cond<>'' then
  723. begin
  724. for cnd:=low(TasmCond) to high(TasmCond) do
  725. if Cond=Upper(cond2str[cnd]) then
  726. begin
  727. actopcode:=CondASmOp[j];
  728. if gas_needsuffix[actopcode]=attsufFPU then
  729. actopsize:=att_sizefpusuffix[sufidx]
  730. else if gas_needsuffix[actopcode]=attsufFPUint then
  731. actopsize:=att_sizefpuintsuffix[sufidx]
  732. else
  733. actopsize:=att_sizesuffix[sufidx];
  734. actcondition:=cnd;
  735. actasmtoken:=AS_OPCODE;
  736. is_asmopcode:=TRUE;
  737. exit;
  738. end;
  739. end;
  740. end;
  741. inc(j);
  742. end;
  743. end;
  744. end;
  745. end;
  746. procedure tx86attreader.handleopcode;
  747. var
  748. instr : Tx86Instruction;
  749. begin
  750. instr:=Tx86Instruction.Create(Tx86Operand);
  751. instr.OpOrder:=op_att;
  752. BuildOpcode(instr);
  753. instr.AddReferenceSizes;
  754. instr.SetInstructionOpsize;
  755. instr.CheckOperandSizes;
  756. instr.ConcatInstruction(curlist);
  757. instr.Free;
  758. end;
  759. end.