rax86att.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  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. {$ifdef x86_64}
  352. if actasmpattern='GOTPCREL' then
  353. {$endif x86_64}
  354. {$ifdef i386}
  355. if actasmpattern='GOT' then
  356. {$endif i386}
  357. oper.opr.ref.refaddr:=addr_pic
  358. else
  359. Message(asmr_e_invalid_reference_syntax);
  360. end
  361. else
  362. Message(asmr_e_invalid_reference_syntax);
  363. end;
  364. case actasmtoken of
  365. AS_END,
  366. AS_SEPARATOR,
  367. AS_COMMA: ;
  368. AS_LPAREN:
  369. BuildReference(oper);
  370. else
  371. Begin
  372. Message(asmr_e_invalid_reference_syntax);
  373. Consume(actasmtoken);
  374. end;
  375. end; {end case }
  376. end;
  377. else
  378. MaybeBuildReference:=false;
  379. end; { end case }
  380. end;
  381. var
  382. tempreg : tregister;
  383. hl : tasmlabel;
  384. Begin
  385. expr:='';
  386. case actasmtoken of
  387. AS_LPAREN: { Memory reference or constant expression }
  388. Begin
  389. oper.InitRef;
  390. BuildReference(oper);
  391. end;
  392. AS_DOLLAR: { Constant expression }
  393. Begin
  394. Consume(AS_DOLLAR);
  395. BuildConstantOperand(oper);
  396. end;
  397. AS_INTNUM,
  398. AS_MINUS,
  399. AS_PLUS:
  400. Begin
  401. { Constant memory offset }
  402. { This must absolutely be followed by ( }
  403. oper.InitRef;
  404. oper.opr.ref.offset:=BuildConstExpression(True,False);
  405. if actasmtoken<>AS_LPAREN then
  406. Message(asmr_e_invalid_reference_syntax)
  407. else
  408. BuildReference(oper);
  409. end;
  410. AS_STAR: { Call from memory address }
  411. Begin
  412. Consume(AS_STAR);
  413. if actasmtoken=AS_REGISTER then
  414. begin
  415. oper.opr.typ:=OPR_REGISTER;
  416. oper.opr.reg:=actasmregister;
  417. oper.SetSize(tcgsize2size[reg_cgsize(actasmregister)],true);
  418. Consume(AS_REGISTER);
  419. end
  420. else
  421. begin
  422. oper.InitRef;
  423. if not MaybeBuildReference then
  424. Message(asmr_e_syn_operand);
  425. end;
  426. { this is only allowed for call's and jmp's }
  427. if not is_calljmp(actopcode) then
  428. Message(asmr_e_syn_operand);
  429. end;
  430. AS_ID: { A constant expression, or a Variable ref. }
  431. Begin
  432. { Local Label ? }
  433. if is_locallabel(actasmpattern) then
  434. begin
  435. CreateLocalLabel(actasmpattern,hl,false);
  436. Consume(AS_ID);
  437. AddLabelOperand(hl);
  438. end
  439. else
  440. { Check for label }
  441. if SearchLabel(actasmpattern,hl,false) then
  442. begin
  443. Consume(AS_ID);
  444. AddLabelOperand(hl);
  445. end
  446. else
  447. { probably a variable or normal expression }
  448. { or a procedure (such as in CALL ID) }
  449. Begin
  450. { is it a constant ? }
  451. if SearchIConstant(actasmpattern,l) then
  452. Begin
  453. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  454. Message(asmr_e_invalid_operand_type);
  455. BuildConstantOperand(oper);
  456. end
  457. else
  458. begin
  459. expr:=actasmpattern;
  460. Consume(AS_ID);
  461. { typecasting? }
  462. if (actasmtoken=AS_LPAREN) and
  463. SearchType(expr,typesize) then
  464. begin
  465. oper.hastype:=true;
  466. Consume(AS_LPAREN);
  467. BuildOperand(oper);
  468. Consume(AS_RPAREN);
  469. if oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL] then
  470. oper.SetSize(typesize,true);
  471. end
  472. else
  473. begin
  474. if oper.SetupVar(expr,false) then
  475. begin
  476. if actasmtoken=AS_AT then
  477. begin
  478. consume(AS_AT);
  479. if actasmtoken=AS_ID then
  480. begin
  481. {$ifdef x86_64}
  482. if actasmpattern='GOTPCREL' then
  483. {$endif x86_64}
  484. {$ifdef i386}
  485. if actasmpattern='GOT' then
  486. {$endif i386}
  487. begin
  488. oper.opr.ref.refaddr:=addr_pic;
  489. consume(AS_ID);
  490. end
  491. else
  492. Message(asmr_e_invalid_reference_syntax);
  493. end
  494. else
  495. Message(asmr_e_invalid_reference_syntax);
  496. end;
  497. end
  498. else
  499. Begin
  500. { look for special symbols ... }
  501. if expr= '__HIGH' then
  502. begin
  503. consume(AS_LPAREN);
  504. if not oper.setupvar('high'+actasmpattern,false) then
  505. Message1(sym_e_unknown_id,'high'+actasmpattern);
  506. consume(AS_ID);
  507. consume(AS_RPAREN);
  508. end
  509. else
  510. if expr = '__RESULT' then
  511. oper.SetUpResult
  512. else
  513. if expr = '__SELF' then
  514. oper.SetupSelf
  515. else
  516. if expr = '__OLDEBP' then
  517. oper.SetupOldEBP
  518. else
  519. Message1(sym_e_unknown_id,expr);
  520. end;
  521. end;
  522. end;
  523. if actasmtoken=AS_DOT then
  524. MaybeRecordOffset;
  525. { add a constant expression? }
  526. if (actasmtoken=AS_PLUS) then
  527. begin
  528. l:=BuildConstExpression(true,false);
  529. case oper.opr.typ of
  530. OPR_CONSTANT :
  531. inc(oper.opr.val,l);
  532. OPR_LOCAL :
  533. inc(oper.opr.localsymofs,l);
  534. OPR_REFERENCE :
  535. inc(oper.opr.ref.offset,l);
  536. else
  537. internalerror(200309202);
  538. end;
  539. end
  540. end;
  541. { Do we have a indexing reference, then parse it also }
  542. if actasmtoken=AS_LPAREN then
  543. BuildReference(oper);
  544. end;
  545. AS_REGISTER: { Register, a variable reference or a constant reference }
  546. Begin
  547. { save the type of register used. }
  548. tempreg:=actasmregister;
  549. Consume(AS_REGISTER);
  550. if actasmtoken = AS_COLON then
  551. Begin
  552. Consume(AS_COLON);
  553. oper.InitRef;
  554. oper.opr.ref.segment:=tempreg;
  555. { This must absolutely be followed by a reference }
  556. if not MaybeBuildReference then
  557. Begin
  558. Message(asmr_e_invalid_seg_override);
  559. Consume(actasmtoken);
  560. end;
  561. end
  562. { Simple register }
  563. else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  564. Begin
  565. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  566. Message(asmr_e_invalid_operand_type);
  567. oper.opr.typ:=OPR_REGISTER;
  568. oper.opr.reg:=tempreg;
  569. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  570. end
  571. else
  572. Message(asmr_e_syn_operand);
  573. end;
  574. AS_END,
  575. AS_SEPARATOR,
  576. AS_COMMA: ;
  577. else
  578. Begin
  579. Message(asmr_e_syn_operand);
  580. Consume(actasmtoken);
  581. end;
  582. end; { end case }
  583. end;
  584. procedure tx86attreader.BuildOpCode(instr : tx86instruction);
  585. var
  586. operandnum : longint;
  587. PrefixOp,OverrideOp: tasmop;
  588. Begin
  589. PrefixOp:=A_None;
  590. OverrideOp:=A_None;
  591. { prefix seg opcode / prefix opcode }
  592. repeat
  593. if is_prefix(actopcode) then
  594. begin
  595. PrefixOp:=ActOpcode;
  596. with instr do
  597. begin
  598. opcode:=ActOpcode;
  599. condition:=ActCondition;
  600. opsize:=ActOpsize;
  601. ConcatInstruction(curlist);
  602. end;
  603. Consume(AS_OPCODE);
  604. end
  605. else
  606. if is_override(actopcode) then
  607. begin
  608. OverrideOp:=ActOpcode;
  609. with instr do
  610. begin
  611. opcode:=ActOpcode;
  612. condition:=ActCondition;
  613. opsize:=ActOpsize;
  614. ConcatInstruction(curlist);
  615. end;
  616. Consume(AS_OPCODE);
  617. end
  618. else
  619. break;
  620. { allow for newline as in gas styled syntax }
  621. while actasmtoken=AS_SEPARATOR do
  622. Consume(AS_SEPARATOR);
  623. until (actasmtoken<>AS_OPCODE);
  624. { opcode }
  625. if (actasmtoken<>AS_OPCODE) then
  626. Begin
  627. Message(asmr_e_invalid_or_missing_opcode);
  628. RecoverConsume(true);
  629. exit;
  630. end;
  631. { Fill the instr object with the current state }
  632. with instr do
  633. begin
  634. Opcode:=ActOpcode;
  635. condition:=ActCondition;
  636. opsize:=ActOpsize;
  637. end;
  638. { Valid combination of prefix/override and instruction ? }
  639. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  640. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  641. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  642. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  643. { We are reading operands, so opcode will be an AS_ID }
  644. operandnum:=1;
  645. Consume(AS_OPCODE);
  646. { Zero operand opcode ? }
  647. if actasmtoken in [AS_SEPARATOR,AS_END] then
  648. begin
  649. operandnum:=0;
  650. exit;
  651. end;
  652. { Read the operands }
  653. repeat
  654. case actasmtoken of
  655. AS_COMMA: { Operand delimiter }
  656. Begin
  657. if operandnum > Max_Operands then
  658. Message(asmr_e_too_many_operands)
  659. else
  660. Inc(operandnum);
  661. Consume(AS_COMMA);
  662. end;
  663. AS_SEPARATOR,
  664. AS_END : { End of asm operands for this opcode }
  665. begin
  666. break;
  667. end;
  668. else
  669. BuildOperand(instr.Operands[operandnum] as tx86operand);
  670. end; { end case }
  671. until false;
  672. instr.Ops:=operandnum;
  673. end;
  674. function tx86attreader.is_asmopcode(const s: string):boolean;
  675. const
  676. { We need first to check the long prefixes, else we get probs
  677. with things like movsbl }
  678. att_sizesuffixstr : array[0..9] of string[2] = (
  679. '','BW','BL','WL','B','W','L','S','Q','T'
  680. );
  681. att_sizesuffix : array[0..9] of topsize = (
  682. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_FS,S_IQ,S_FX
  683. );
  684. att_sizefpusuffix : array[0..9] of topsize = (
  685. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_IQ,S_FX
  686. );
  687. att_sizefpuintsuffix : array[0..9] of topsize = (
  688. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
  689. );
  690. var
  691. str2opentry: tstr2opentry;
  692. cond : string[4];
  693. cnd : tasmcond;
  694. len,
  695. j,
  696. sufidx : longint;
  697. Begin
  698. is_asmopcode:=FALSE;
  699. actopcode:=A_None;
  700. actcondition:=C_None;
  701. actopsize:=S_NO;
  702. { search for all possible suffixes }
  703. for sufidx:=low(att_sizesuffixstr) to high(att_sizesuffixstr) do
  704. begin
  705. len:=length(s)-length(att_sizesuffixstr[sufidx]);
  706. if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
  707. begin
  708. { here we search the entire table... }
  709. str2opentry:=nil;
  710. if {(length(s)>0) and} (len>0) then
  711. str2opentry:=tstr2opentry(iasmops.search(copy(s,1,len)));
  712. if assigned(str2opentry) then
  713. begin
  714. actopcode:=str2opentry.op;
  715. if gas_needsuffix[actopcode]=attsufFPU then
  716. actopsize:=att_sizefpusuffix[sufidx]
  717. else if gas_needsuffix[actopcode]=attsufFPUint then
  718. actopsize:=att_sizefpuintsuffix[sufidx]
  719. else
  720. actopsize:=att_sizesuffix[sufidx];
  721. actasmtoken:=AS_OPCODE;
  722. is_asmopcode:=TRUE;
  723. exit;
  724. end;
  725. { not found, check condition opcodes }
  726. j:=0;
  727. while (j<CondAsmOps) do
  728. begin
  729. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  730. begin
  731. cond:=Copy(s,Length(CondAsmOpStr[j])+1,len-Length(CondAsmOpStr[j]));
  732. if cond<>'' then
  733. begin
  734. for cnd:=low(TasmCond) to high(TasmCond) do
  735. if Cond=Upper(cond2str[cnd]) then
  736. begin
  737. actopcode:=CondASmOp[j];
  738. if gas_needsuffix[actopcode]=attsufFPU then
  739. actopsize:=att_sizefpusuffix[sufidx]
  740. else if gas_needsuffix[actopcode]=attsufFPUint then
  741. actopsize:=att_sizefpuintsuffix[sufidx]
  742. else
  743. actopsize:=att_sizesuffix[sufidx];
  744. actcondition:=cnd;
  745. actasmtoken:=AS_OPCODE;
  746. is_asmopcode:=TRUE;
  747. exit;
  748. end;
  749. end;
  750. end;
  751. inc(j);
  752. end;
  753. end;
  754. end;
  755. end;
  756. procedure tx86attreader.handleopcode;
  757. var
  758. instr : Tx86Instruction;
  759. begin
  760. instr:=Tx86Instruction.Create(Tx86Operand);
  761. instr.OpOrder:=op_att;
  762. BuildOpcode(instr);
  763. instr.AddReferenceSizes;
  764. instr.SetInstructionOpsize;
  765. instr.CheckOperandSizes;
  766. instr.ConcatInstruction(curlist);
  767. instr.Free;
  768. end;
  769. end.