rax86att.pas 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  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,globals,verbose,
  40. systems,
  41. { aasm }
  42. cpuinfo,aasmbase,aasmtai,aasmcpu,
  43. { symtable }
  44. symconst,symbase,symtype,symsym,symtable,
  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. (tvarsym(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. { check for direct symbolic names }
  479. { only if compiling the system unit }
  480. if (cs_compilesystem in aktmoduleswitches) then
  481. begin
  482. if not oper.SetupDirectVar(expr) then
  483. Begin
  484. { not found, finally ... add it anyways ... }
  485. Message1(asmr_w_id_supposed_external,expr);
  486. oper.InitRef;
  487. oper.opr.ref.symbol:=objectlibrary.newasmsymbol(expr,AB_EXTERNAL,AT_FUNCTION);
  488. end;
  489. end
  490. else
  491. Message1(sym_e_unknown_id,expr);
  492. end;
  493. end;
  494. end;
  495. if actasmtoken=AS_DOT then
  496. MaybeRecordOffset;
  497. { add a constant expression? }
  498. if (actasmtoken=AS_PLUS) then
  499. begin
  500. l:=BuildConstExpression(true,false);
  501. case oper.opr.typ of
  502. OPR_CONSTANT :
  503. inc(oper.opr.val,l);
  504. OPR_LOCAL :
  505. inc(oper.opr.localsymofs,l);
  506. OPR_REFERENCE :
  507. inc(oper.opr.ref.offset,l);
  508. else
  509. internalerror(200309202);
  510. end;
  511. end
  512. end;
  513. { Do we have a indexing reference, then parse it also }
  514. if actasmtoken=AS_LPAREN then
  515. BuildReference(oper);
  516. end;
  517. AS_REGISTER: { Register, a variable reference or a constant reference }
  518. Begin
  519. { save the type of register used. }
  520. tempreg:=actasmregister;
  521. Consume(AS_REGISTER);
  522. if actasmtoken = AS_COLON then
  523. Begin
  524. Consume(AS_COLON);
  525. oper.InitRef;
  526. oper.opr.ref.segment:=tempreg;
  527. { This must absolutely be followed by a reference }
  528. if not MaybeBuildReference then
  529. Begin
  530. Message(asmr_e_invalid_seg_override);
  531. Consume(actasmtoken);
  532. end;
  533. end
  534. { Simple register }
  535. else if (actasmtoken in [AS_END,AS_SEPARATOR,AS_COMMA]) then
  536. Begin
  537. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  538. Message(asmr_e_invalid_operand_type);
  539. oper.opr.typ:=OPR_REGISTER;
  540. oper.opr.reg:=tempreg;
  541. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  542. end
  543. else
  544. Message(asmr_e_syn_operand);
  545. end;
  546. AS_END,
  547. AS_SEPARATOR,
  548. AS_COMMA: ;
  549. else
  550. Begin
  551. Message(asmr_e_syn_operand);
  552. Consume(actasmtoken);
  553. end;
  554. end; { end case }
  555. end;
  556. procedure tx86attreader.BuildOpCode(instr : tx86instruction);
  557. var
  558. operandnum : longint;
  559. PrefixOp,OverrideOp: tasmop;
  560. Begin
  561. PrefixOp:=A_None;
  562. OverrideOp:=A_None;
  563. { prefix seg opcode / prefix opcode }
  564. repeat
  565. if is_prefix(actopcode) then
  566. begin
  567. PrefixOp:=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. if is_override(actopcode) then
  579. begin
  580. OverrideOp:=ActOpcode;
  581. with instr do
  582. begin
  583. opcode:=ActOpcode;
  584. condition:=ActCondition;
  585. opsize:=ActOpsize;
  586. ConcatInstruction(curlist);
  587. end;
  588. Consume(AS_OPCODE);
  589. end
  590. else
  591. break;
  592. { allow for newline as in gas styled syntax }
  593. while actasmtoken=AS_SEPARATOR do
  594. Consume(AS_SEPARATOR);
  595. until (actasmtoken<>AS_OPCODE);
  596. { opcode }
  597. if (actasmtoken<>AS_OPCODE) then
  598. Begin
  599. Message(asmr_e_invalid_or_missing_opcode);
  600. RecoverConsume(true);
  601. exit;
  602. end;
  603. { Fill the instr object with the current state }
  604. with instr do
  605. begin
  606. Opcode:=ActOpcode;
  607. condition:=ActCondition;
  608. opsize:=ActOpsize;
  609. end;
  610. { Valid combination of prefix/override and instruction ? }
  611. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  612. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  613. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  614. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  615. { We are reading operands, so opcode will be an AS_ID }
  616. operandnum:=1;
  617. Consume(AS_OPCODE);
  618. { Zero operand opcode ? }
  619. if actasmtoken in [AS_SEPARATOR,AS_END] then
  620. begin
  621. operandnum:=0;
  622. exit;
  623. end;
  624. { Read the operands }
  625. repeat
  626. case actasmtoken of
  627. AS_COMMA: { Operand delimiter }
  628. Begin
  629. if operandnum > Max_Operands then
  630. Message(asmr_e_too_many_operands)
  631. else
  632. Inc(operandnum);
  633. Consume(AS_COMMA);
  634. end;
  635. AS_SEPARATOR,
  636. AS_END : { End of asm operands for this opcode }
  637. begin
  638. break;
  639. end;
  640. else
  641. BuildOperand(instr.Operands[operandnum] as tx86operand);
  642. end; { end case }
  643. until false;
  644. instr.Ops:=operandnum;
  645. end;
  646. function tx86attreader.is_asmopcode(const s: string):boolean;
  647. const
  648. { We need first to check the long prefixes, else we get probs
  649. with things like movsbl }
  650. att_sizesuffixstr : array[0..9] of string[2] = (
  651. '','BW','BL','WL','B','W','L','S','Q','T'
  652. );
  653. att_sizesuffix : array[0..9] of topsize = (
  654. S_NO,S_BW,S_BL,S_WL,S_B,S_W,S_L,S_FS,S_IQ,S_FX
  655. );
  656. att_sizefpusuffix : array[0..9] of topsize = (
  657. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_FL,S_FS,S_IQ,S_FX
  658. );
  659. att_sizefpuintsuffix : array[0..9] of topsize = (
  660. S_NO,S_NO,S_NO,S_NO,S_NO,S_NO,S_IL,S_IS,S_IQ,S_NO
  661. );
  662. var
  663. str2opentry: tstr2opentry;
  664. cond : string[4];
  665. cnd : tasmcond;
  666. len,
  667. j,
  668. sufidx : longint;
  669. Begin
  670. is_asmopcode:=FALSE;
  671. actopcode:=A_None;
  672. actcondition:=C_None;
  673. actopsize:=S_NO;
  674. { search for all possible suffixes }
  675. for sufidx:=low(att_sizesuffixstr) to high(att_sizesuffixstr) do
  676. begin
  677. len:=length(s)-length(att_sizesuffixstr[sufidx]);
  678. if copy(s,len+1,length(att_sizesuffixstr[sufidx]))=att_sizesuffixstr[sufidx] then
  679. begin
  680. { here we search the entire table... }
  681. str2opentry:=nil;
  682. if {(length(s)>0) and} (len>0) then
  683. str2opentry:=tstr2opentry(iasmops.search(copy(s,1,len)));
  684. if assigned(str2opentry) then
  685. begin
  686. actopcode:=str2opentry.op;
  687. if gas_needsuffix[actopcode]=attsufFPU then
  688. actopsize:=att_sizefpusuffix[sufidx]
  689. else if gas_needsuffix[actopcode]=attsufFPUint then
  690. actopsize:=att_sizefpuintsuffix[sufidx]
  691. else
  692. actopsize:=att_sizesuffix[sufidx];
  693. actasmtoken:=AS_OPCODE;
  694. is_asmopcode:=TRUE;
  695. exit;
  696. end;
  697. { not found, check condition opcodes }
  698. j:=0;
  699. while (j<CondAsmOps) do
  700. begin
  701. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  702. begin
  703. cond:=Copy(s,Length(CondAsmOpStr[j])+1,len-Length(CondAsmOpStr[j]));
  704. if cond<>'' then
  705. begin
  706. for cnd:=low(TasmCond) to high(TasmCond) do
  707. if Cond=Upper(cond2str[cnd]) then
  708. begin
  709. actopcode:=CondASmOp[j];
  710. if gas_needsuffix[actopcode]=attsufFPU then
  711. actopsize:=att_sizefpusuffix[sufidx]
  712. else if gas_needsuffix[actopcode]=attsufFPUint then
  713. actopsize:=att_sizefpuintsuffix[sufidx]
  714. else
  715. actopsize:=att_sizesuffix[sufidx];
  716. actcondition:=cnd;
  717. actasmtoken:=AS_OPCODE;
  718. is_asmopcode:=TRUE;
  719. exit;
  720. end;
  721. end;
  722. end;
  723. inc(j);
  724. end;
  725. end;
  726. end;
  727. end;
  728. procedure tx86attreader.handleopcode;
  729. var
  730. instr : Tx86Instruction;
  731. begin
  732. instr:=Tx86Instruction.Create(Tx86Operand);
  733. instr.OpOrder:=op_att;
  734. BuildOpcode(instr);
  735. instr.AddReferenceSizes;
  736. instr.SetInstructionOpsize;
  737. instr.CheckOperandSizes;
  738. instr.ConcatInstruction(curlist);
  739. instr.Free;
  740. end;
  741. end.
  742. {
  743. $Log$
  744. Revision 1.5 2004-06-20 08:55:32 florian
  745. * logs truncated
  746. Revision 1.4 2004/06/16 20:07:11 florian
  747. * dwarf branch merged
  748. Revision 1.3.2.3 2004/05/01 23:36:47 peter
  749. * assembler reader 64bit fixes
  750. Revision 1.3.2.2 2004/05/01 16:02:10 peter
  751. * POINTER_SIZE replaced with sizeof(aint)
  752. * aint,aword,tconst*int moved to globtype
  753. Revision 1.3.2.1 2004/05/01 11:12:24 florian
  754. * spilling of registers with size<>4 fixed
  755. Revision 1.3 2004/03/02 00:36:33 olle
  756. * big transformation of Tai_[const_]Symbol.Create[data]name*
  757. }