rax86att.pas 26 KB

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