rax86int.pas 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Does the parsing process for the intel 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 Rax86int;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. cpubase,
  23. globtype,
  24. aasmbase,
  25. rasm,
  26. rax86;
  27. type
  28. tasmtoken = (
  29. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_INTNUM,
  30. AS_COMMA,AS_LBRACKET,AS_RBRACKET,AS_LPAREN,
  31. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
  32. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,
  33. {------------------ Assembler directives --------------------}
  34. AS_ALIGN,AS_DB,AS_DW,AS_DD,AS_END,
  35. {------------------ Assembler Operators --------------------}
  36. AS_BYTE,AS_WORD,AS_DWORD,AS_QWORD,AS_TBYTE,AS_DQWORD,AS_NEAR,AS_FAR,
  37. AS_HIGH,AS_LOW,AS_OFFSET,AS_SIZEOF,AS_SEG,AS_TYPE,AS_PTR,AS_MOD,AS_SHL,AS_SHR,AS_NOT,
  38. AS_AND,AS_OR,AS_XOR);
  39. type
  40. tx86intreader = class(tasmreader)
  41. actasmtoken : tasmtoken;
  42. prevasmtoken : tasmtoken;
  43. ActOpsize : topsize;
  44. constructor create;override;
  45. function is_asmopcode(const s: string):boolean;
  46. function is_asmoperator(const s: string):boolean;
  47. function is_asmdirective(const s: string):boolean;
  48. function is_register(const s:string):boolean;
  49. function is_locallabel(const s:string):boolean;
  50. function Assemble: tlinkedlist;override;
  51. procedure GetToken;
  52. function consume(t : tasmtoken):boolean;
  53. procedure RecoverConsume(allowcomma:boolean);
  54. procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint);
  55. procedure BuildConstSymbolExpression(needofs,isref:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  56. function BuildConstExpression:aint;
  57. function BuildRefConstExpression:aint;
  58. procedure BuildReference(oper : tx86operand);
  59. procedure BuildOperand(oper: tx86operand;istypecast:boolean);
  60. procedure BuildConstantOperand(oper: tx86operand);
  61. procedure BuildOpCode(instr : tx86instruction);
  62. procedure BuildConstant(constsize: byte);
  63. end;
  64. implementation
  65. uses
  66. { common }
  67. cutils,
  68. { global }
  69. globals,verbose,
  70. systems,
  71. { aasm }
  72. aasmtai,aasmdata,aasmcpu,
  73. { symtable }
  74. symconst,symbase,symtype,symsym,symdef,symtable,
  75. { parser }
  76. scanner,
  77. { register allocator }
  78. rabase,rautils,itx86int,
  79. { codegen }
  80. cgbase,cgobj,procinfo
  81. ;
  82. type
  83. tasmkeyword = string[6];
  84. const
  85. { These tokens should be modified accordingly to the modifications }
  86. { in the different enumerations. }
  87. firstdirective = AS_ALIGN;
  88. lastdirective = AS_END;
  89. firstoperator = AS_BYTE;
  90. lastoperator = AS_XOR;
  91. _count_asmdirectives = longint(lastdirective)-longint(firstdirective);
  92. _count_asmoperators = longint(lastoperator)-longint(firstoperator);
  93. _asmdirectives : array[0.._count_asmdirectives] of tasmkeyword =
  94. ('ALIGN','DB','DW','DD','END');
  95. { problems with shl,shr,not,and,or and xor, they are }
  96. { context sensitive. }
  97. _asmoperators : array[0.._count_asmoperators] of tasmkeyword = (
  98. 'BYTE','WORD','DWORD','QWORD','TBYTE','DQWORD','NEAR','FAR','HIGH',
  99. 'LOW','OFFSET','SIZEOF','SEG','TYPE','PTR','MOD','SHL','SHR','NOT','AND',
  100. 'OR','XOR');
  101. token2str : array[tasmtoken] of string[10] = (
  102. '','Label','LLabel','String','Integer',
  103. ',','[',']','(',
  104. ')',':','.','+','-','*',
  105. ';','identifier','register','opcode','/',
  106. '','','','','END',
  107. '','','','','','','','','',
  108. '','','sizeof','','type','ptr','mod','shl','shr','not',
  109. 'and','or','xor'
  110. );
  111. var
  112. inexpression : boolean;
  113. constructor tx86intreader.create;
  114. var
  115. i : tasmop;
  116. str2opentry: tstr2opentry;
  117. Begin
  118. inherited create;
  119. { opcodes }
  120. { creates uppercased symbol tables for speed access }
  121. iasmops:=tdictionary.create;
  122. iasmops.delete_doubles:=true;
  123. for i:=firstop to lastop do
  124. begin
  125. str2opentry:=tstr2opentry.createname(upper(std_op2str[i]));
  126. str2opentry.op:=i;
  127. iasmops.insert(str2opentry);
  128. end;
  129. end;
  130. {---------------------------------------------------------------------}
  131. { Routines for the tokenizing }
  132. {---------------------------------------------------------------------}
  133. function tx86intreader.is_asmopcode(const s: string):boolean;
  134. var
  135. str2opentry: tstr2opentry;
  136. cond : string[4];
  137. cnd : tasmcond;
  138. j: longint;
  139. Begin
  140. is_asmopcode:=FALSE;
  141. actopcode:=A_None;
  142. actcondition:=C_None;
  143. actopsize:=S_NO;
  144. str2opentry:=tstr2opentry(iasmops.search(s));
  145. if assigned(str2opentry) then
  146. begin
  147. actopcode:=str2opentry.op;
  148. actasmtoken:=AS_OPCODE;
  149. is_asmopcode:=TRUE;
  150. exit;
  151. end;
  152. { not found yet, check condition opcodes }
  153. j:=0;
  154. while (j<CondAsmOps) do
  155. begin
  156. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  157. begin
  158. cond:=Copy(s,Length(CondAsmOpStr[j])+1,255);
  159. if cond<>'' then
  160. begin
  161. for cnd:=low(TasmCond) to high(TasmCond) do
  162. if Cond=Upper(cond2str[cnd]) then
  163. begin
  164. actopcode:=CondASmOp[j];
  165. actcondition:=cnd;
  166. is_asmopcode:=TRUE;
  167. actasmtoken:=AS_OPCODE;
  168. exit
  169. end;
  170. end;
  171. end;
  172. inc(j);
  173. end;
  174. end;
  175. function tx86intreader.is_asmoperator(const s: string):boolean;
  176. var
  177. i : longint;
  178. Begin
  179. for i:=0 to _count_asmoperators do
  180. if s=_asmoperators[i] then
  181. begin
  182. actasmtoken:=tasmtoken(longint(firstoperator)+i);
  183. is_asmoperator:=true;
  184. exit;
  185. end;
  186. is_asmoperator:=false;
  187. end;
  188. Function tx86intreader.is_asmdirective(const s: string):boolean;
  189. var
  190. i : longint;
  191. Begin
  192. for i:=0 to _count_asmdirectives do
  193. if s=_asmdirectives[i] then
  194. begin
  195. actasmtoken:=tasmtoken(longint(firstdirective)+i);
  196. is_asmdirective:=true;
  197. exit;
  198. end;
  199. is_asmdirective:=false;
  200. end;
  201. function tx86intreader.is_register(const s:string):boolean;
  202. begin
  203. is_register:=false;
  204. actasmregister:=masm_regnum_search(lower(s));
  205. if actasmregister<>NR_NO then
  206. begin
  207. is_register:=true;
  208. actasmtoken:=AS_REGISTER;
  209. end;
  210. end;
  211. function tx86intreader.is_locallabel(const s:string):boolean;
  212. begin
  213. is_locallabel:=(length(s)>1) and (s[1]='@');
  214. end;
  215. Procedure tx86intreader.GetToken;
  216. var
  217. len : longint;
  218. forcelabel : boolean;
  219. srsym : tsym;
  220. srsymtable : tsymtable;
  221. begin
  222. { save old token and reset new token }
  223. prevasmtoken:=actasmtoken;
  224. actasmtoken:=AS_NONE;
  225. { reset }
  226. forcelabel:=FALSE;
  227. actasmpattern:='';
  228. { while space and tab , continue scan... }
  229. while (c in [' ',#9]) do
  230. c:=current_scanner.asmgetchar;
  231. { get token pos }
  232. if not (c in [#10,#13,'{',';']) then
  233. current_scanner.gettokenpos;
  234. { Local Label, Label, Directive, Prefix or Opcode }
  235. if firsttoken and not (c in [#10,#13,'{',';']) then
  236. begin
  237. firsttoken:=FALSE;
  238. len:=0;
  239. while c in ['A'..'Z','a'..'z','0'..'9','_','@'] do
  240. begin
  241. { if there is an at_sign, then this must absolutely be a label }
  242. if c = '@' then
  243. forcelabel:=TRUE;
  244. inc(len);
  245. actasmpattern[len]:=c;
  246. c:=current_scanner.asmgetchar;
  247. end;
  248. actasmpattern[0]:=chr(len);
  249. uppervar(actasmpattern);
  250. { allow spaces }
  251. while (c in [' ',#9]) do
  252. c:=current_scanner.asmgetchar;
  253. { label ? }
  254. if c = ':' then
  255. begin
  256. if actasmpattern[1]='@' then
  257. actasmtoken:=AS_LLABEL
  258. else
  259. actasmtoken:=AS_LABEL;
  260. { let us point to the next character }
  261. c:=current_scanner.asmgetchar;
  262. firsttoken:=true;
  263. exit;
  264. end;
  265. { Are we trying to create an identifier with }
  266. { an at-sign...? }
  267. if forcelabel then
  268. Message(asmr_e_none_label_contain_at);
  269. { opcode ? }
  270. If is_asmopcode(actasmpattern) then
  271. Begin
  272. { check if we are in an expression }
  273. { then continue with asm directives }
  274. if not inexpression then
  275. exit;
  276. end;
  277. if is_asmdirective(actasmpattern) then
  278. exit;
  279. message1(asmr_e_unknown_opcode,actasmpattern);
  280. actasmtoken:=AS_NONE;
  281. exit;
  282. end
  283. else { else firsttoken }
  284. begin
  285. case c of
  286. '@' : { possiblities : - local label reference , such as in jmp @local1 }
  287. { - @Result, @Code or @Data special variables. }
  288. begin
  289. actasmpattern:=c;
  290. c:=current_scanner.asmgetchar;
  291. while c in ['A'..'Z','a'..'z','0'..'9','_','@'] do
  292. begin
  293. actasmpattern:=actasmpattern + c;
  294. c:=current_scanner.asmgetchar;
  295. end;
  296. uppervar(actasmpattern);
  297. actasmtoken:=AS_ID;
  298. exit;
  299. end;
  300. 'A'..'Z','a'..'z','_': { identifier, register, opcode, prefix or directive }
  301. begin
  302. actasmpattern:=c;
  303. c:=current_scanner.asmgetchar;
  304. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  305. begin
  306. actasmpattern:=actasmpattern + c;
  307. c:=current_scanner.asmgetchar;
  308. end;
  309. uppervar(actasmpattern);
  310. { after prefix we allow also a new opcode }
  311. If is_prefix(actopcode) and is_asmopcode(actasmpattern) then
  312. Begin
  313. { if we are not in a constant }
  314. { expression than this is an }
  315. { opcode. }
  316. if not inexpression then
  317. exit;
  318. end;
  319. { support st(X) for fpu registers }
  320. if (actasmpattern = 'ST') and (c='(') then
  321. Begin
  322. actasmpattern:=actasmpattern+c;
  323. c:=current_scanner.asmgetchar;
  324. { allow spaces }
  325. while (c in [' ',#9]) do
  326. c:=current_scanner.asmgetchar;
  327. if c in ['0'..'7'] then
  328. actasmpattern:=actasmpattern + c
  329. else
  330. Message(asmr_e_invalid_fpu_register);
  331. c:=current_scanner.asmgetchar;
  332. { allow spaces }
  333. while (c in [' ',#9]) do
  334. c:=current_scanner.asmgetchar;
  335. if c <> ')' then
  336. Message(asmr_e_invalid_fpu_register)
  337. else
  338. Begin
  339. actasmpattern:=actasmpattern + c;
  340. c:=current_scanner.asmgetchar;
  341. end;
  342. end;
  343. if is_register(actasmpattern) then
  344. exit;
  345. if is_asmdirective(actasmpattern) then
  346. exit;
  347. if is_asmoperator(actasmpattern) then
  348. exit;
  349. { allow spaces }
  350. while (c in [' ',#9]) do
  351. c:=current_scanner.asmgetchar;
  352. { if next is a '.' and this is a unitsym then we also need to
  353. parse the identifier }
  354. if (c='.') then
  355. begin
  356. searchsym(actasmpattern,srsym,srsymtable);
  357. if assigned(srsym) and
  358. (srsym.typ=unitsym) and
  359. (srsym.owner.symtabletype in [staticsymtable,globalsymtable]) and
  360. srsym.owner.iscurrentunit then
  361. begin
  362. { Add . to create System.Identifier }
  363. actasmpattern:=actasmpattern+c;
  364. c:=current_scanner.asmgetchar;
  365. { Delphi allows System.@Halt, just ignore the @ }
  366. if c='@' then
  367. c:=current_scanner.asmgetchar;
  368. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  369. begin
  370. actasmpattern:=actasmpattern + upcase(c);
  371. c:=current_scanner.asmgetchar;
  372. end;
  373. end;
  374. end;
  375. actasmtoken:=AS_ID;
  376. exit;
  377. end;
  378. '''' : { string or character }
  379. begin
  380. actasmpattern:='';
  381. current_scanner.in_asm_string:=true;
  382. repeat
  383. if c = '''' then
  384. begin
  385. c:=current_scanner.asmgetchar;
  386. if c in [#10,#13] then
  387. begin
  388. Message(scan_f_string_exceeds_line);
  389. break;
  390. end;
  391. repeat
  392. if c='''' then
  393. begin
  394. c:=current_scanner.asmgetchar;
  395. if c='''' then
  396. begin
  397. actasmpattern:=actasmpattern+'''';
  398. c:=current_scanner.asmgetchar;
  399. if c in [#10,#13] then
  400. begin
  401. Message(scan_f_string_exceeds_line);
  402. break;
  403. end;
  404. end
  405. else
  406. break;
  407. end
  408. else
  409. begin
  410. actasmpattern:=actasmpattern+c;
  411. c:=current_scanner.asmgetchar;
  412. if c in [#10,#13] then
  413. begin
  414. Message(scan_f_string_exceeds_line);
  415. break
  416. end;
  417. end;
  418. until false; { end repeat }
  419. end
  420. else
  421. break; { end if }
  422. until false;
  423. current_scanner.in_asm_string:=false;
  424. actasmtoken:=AS_STRING;
  425. exit;
  426. end;
  427. '"' : { string or character }
  428. begin
  429. current_scanner.in_asm_string:=true;
  430. actasmpattern:='';
  431. repeat
  432. if c = '"' then
  433. begin
  434. c:=current_scanner.asmgetchar;
  435. if c in [#10,#13] then
  436. begin
  437. Message(scan_f_string_exceeds_line);
  438. break;
  439. end;
  440. repeat
  441. if c='"' then
  442. begin
  443. c:=current_scanner.asmgetchar;
  444. if c='"' then
  445. begin
  446. actasmpattern:=actasmpattern+'"';
  447. c:=current_scanner.asmgetchar;
  448. if c in [#10,#13] then
  449. begin
  450. Message(scan_f_string_exceeds_line);
  451. break;
  452. end;
  453. end
  454. else
  455. break;
  456. end
  457. else
  458. begin
  459. actasmpattern:=actasmpattern+c;
  460. c:=current_scanner.asmgetchar;
  461. if c in [#10,#13] then
  462. begin
  463. Message(scan_f_string_exceeds_line);
  464. break
  465. end;
  466. end;
  467. until false; { end repeat }
  468. end
  469. else
  470. break; { end if }
  471. until false;
  472. current_scanner.in_asm_string:=false;
  473. actasmtoken:=AS_STRING;
  474. exit;
  475. end;
  476. '$' :
  477. begin
  478. c:=current_scanner.asmgetchar;
  479. while c in ['0'..'9','A'..'F','a'..'f'] do
  480. begin
  481. actasmpattern:=actasmpattern + c;
  482. c:=current_scanner.asmgetchar;
  483. end;
  484. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  485. actasmtoken:=AS_INTNUM;
  486. exit;
  487. end;
  488. '&' : { identifier }
  489. begin
  490. actasmpattern:='';
  491. c:=current_scanner.asmgetchar;
  492. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  493. begin
  494. actasmpattern:=actasmpattern + c;
  495. c:=current_scanner.asmgetchar;
  496. end;
  497. uppervar(actasmpattern);
  498. actasmtoken:=AS_ID;
  499. exit;
  500. end;
  501. ',' :
  502. begin
  503. actasmtoken:=AS_COMMA;
  504. c:=current_scanner.asmgetchar;
  505. exit;
  506. end;
  507. '[' :
  508. begin
  509. actasmtoken:=AS_LBRACKET;
  510. c:=current_scanner.asmgetchar;
  511. exit;
  512. end;
  513. ']' :
  514. begin
  515. actasmtoken:=AS_RBRACKET;
  516. c:=current_scanner.asmgetchar;
  517. exit;
  518. end;
  519. '(' :
  520. begin
  521. actasmtoken:=AS_LPAREN;
  522. c:=current_scanner.asmgetchar;
  523. exit;
  524. end;
  525. ')' :
  526. begin
  527. actasmtoken:=AS_RPAREN;
  528. c:=current_scanner.asmgetchar;
  529. exit;
  530. end;
  531. ':' :
  532. begin
  533. actasmtoken:=AS_COLON;
  534. c:=current_scanner.asmgetchar;
  535. exit;
  536. end;
  537. '.' :
  538. begin
  539. actasmtoken:=AS_DOT;
  540. c:=current_scanner.asmgetchar;
  541. exit;
  542. end;
  543. '+' :
  544. begin
  545. actasmtoken:=AS_PLUS;
  546. c:=current_scanner.asmgetchar;
  547. exit;
  548. end;
  549. '-' :
  550. begin
  551. actasmtoken:=AS_MINUS;
  552. c:=current_scanner.asmgetchar;
  553. exit;
  554. end;
  555. '*' :
  556. begin
  557. actasmtoken:=AS_STAR;
  558. c:=current_scanner.asmgetchar;
  559. exit;
  560. end;
  561. '/' :
  562. begin
  563. actasmtoken:=AS_SLASH;
  564. c:=current_scanner.asmgetchar;
  565. exit;
  566. end;
  567. '0'..'9':
  568. begin
  569. actasmpattern:=c;
  570. c:=current_scanner.asmgetchar;
  571. { Get the possible characters }
  572. while c in ['0'..'9','A'..'F','a'..'f'] do
  573. begin
  574. actasmpattern:=actasmpattern + c;
  575. c:=current_scanner.asmgetchar;
  576. end;
  577. { Get ending character }
  578. uppervar(actasmpattern);
  579. c:=upcase(c);
  580. { possibly a binary number. }
  581. if (actasmpattern[length(actasmpattern)] = 'B') and (c <> 'H') then
  582. Begin
  583. { Delete the last binary specifier }
  584. delete(actasmpattern,length(actasmpattern),1);
  585. actasmpattern:=tostr(ParseVal(actasmpattern,2));
  586. actasmtoken:=AS_INTNUM;
  587. exit;
  588. end
  589. else
  590. Begin
  591. case c of
  592. 'O' :
  593. Begin
  594. actasmpattern:=tostr(ParseVal(actasmpattern,8));
  595. actasmtoken:=AS_INTNUM;
  596. c:=current_scanner.asmgetchar;
  597. exit;
  598. end;
  599. 'H' :
  600. Begin
  601. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  602. actasmtoken:=AS_INTNUM;
  603. c:=current_scanner.asmgetchar;
  604. exit;
  605. end;
  606. else { must be an integer number }
  607. begin
  608. actasmpattern:=tostr(ParseVal(actasmpattern,10));
  609. actasmtoken:=AS_INTNUM;
  610. exit;
  611. end;
  612. end;
  613. end;
  614. end;
  615. ';','{',#13,#10 :
  616. begin
  617. c:=current_scanner.asmgetchar;
  618. firsttoken:=TRUE;
  619. actasmtoken:=AS_SEPARATOR;
  620. exit;
  621. end;
  622. else
  623. current_scanner.illegal_char(c);
  624. end;
  625. end;
  626. end;
  627. function tx86intreader.consume(t : tasmtoken):boolean;
  628. begin
  629. Consume:=true;
  630. if t<>actasmtoken then
  631. begin
  632. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  633. Consume:=false;
  634. end;
  635. repeat
  636. gettoken;
  637. until actasmtoken<>AS_NONE;
  638. end;
  639. procedure tx86intreader.RecoverConsume(allowcomma:boolean);
  640. begin
  641. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  642. begin
  643. if allowcomma and (actasmtoken=AS_COMMA) then
  644. break;
  645. Consume(actasmtoken);
  646. end;
  647. end;
  648. {*****************************************************************************
  649. Parsing Helpers
  650. *****************************************************************************}
  651. { This routine builds up a record offset after a AS_DOT
  652. token is encountered.
  653. On entry actasmtoken should be equal to AS_DOT }
  654. Procedure tx86intreader.BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint);
  655. var
  656. s : string;
  657. Begin
  658. offset:=0;
  659. size:=0;
  660. s:=expr;
  661. while (actasmtoken=AS_DOT) do
  662. begin
  663. Consume(AS_DOT);
  664. if actasmtoken in [AS_BYTE,AS_ID,AS_WORD,AS_DWORD,AS_QWORD] then
  665. begin
  666. s:=s+'.'+actasmpattern;
  667. consume(actasmtoken);
  668. end
  669. else
  670. begin
  671. Consume(AS_ID);
  672. RecoverConsume(true);
  673. break;
  674. end;
  675. end;
  676. if not GetRecordOffsetSize(s,offset,size) then
  677. Message(asmr_e_building_record_offset);
  678. end;
  679. Procedure tx86intreader.BuildConstSymbolExpression(needofs,isref:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  680. var
  681. tempstr,expr,hs : string;
  682. parenlevel : longint;
  683. l,k : aint;
  684. hasparen,
  685. errorflag : boolean;
  686. prevtok : tasmtoken;
  687. hl : tasmlabel;
  688. hssymtyp : Tasmsymtype;
  689. def : tdef;
  690. sym : tsym;
  691. srsymtable : tsymtable;
  692. Begin
  693. { reset }
  694. value:=0;
  695. asmsym:='';
  696. asmsymtyp:=AT_DATA;
  697. errorflag:=FALSE;
  698. tempstr:='';
  699. expr:='';
  700. inexpression:=TRUE;
  701. parenlevel:=0;
  702. Repeat
  703. { Support ugly delphi constructs like: [ECX].1+2[EDX] }
  704. if isref and (actasmtoken=AS_LBRACKET) then
  705. break;
  706. Case actasmtoken of
  707. AS_LPAREN:
  708. Begin
  709. Consume(AS_LPAREN);
  710. expr:=expr + '(';
  711. inc(parenlevel);
  712. end;
  713. AS_RPAREN:
  714. Begin
  715. { Keep the AS_PAREN in actasmtoken, it is maybe a typecast }
  716. if parenlevel=0 then
  717. break;
  718. Consume(AS_RPAREN);
  719. expr:=expr + ')';
  720. dec(parenlevel);
  721. end;
  722. AS_SHL:
  723. Begin
  724. Consume(AS_SHL);
  725. expr:=expr + '<';
  726. end;
  727. AS_SHR:
  728. Begin
  729. Consume(AS_SHR);
  730. expr:=expr + '>';
  731. end;
  732. AS_SLASH:
  733. Begin
  734. Consume(AS_SLASH);
  735. expr:=expr + '/';
  736. end;
  737. AS_MOD:
  738. Begin
  739. Consume(AS_MOD);
  740. expr:=expr + '%';
  741. end;
  742. AS_STAR:
  743. Begin
  744. Consume(AS_STAR);
  745. if isref and (actasmtoken=AS_REGISTER) then
  746. break;
  747. expr:=expr + '*';
  748. end;
  749. AS_PLUS:
  750. Begin
  751. Consume(AS_PLUS);
  752. if isref and (actasmtoken=AS_REGISTER) then
  753. break;
  754. expr:=expr + '+';
  755. end;
  756. AS_MINUS:
  757. Begin
  758. Consume(AS_MINUS);
  759. expr:=expr + '-';
  760. end;
  761. AS_AND:
  762. Begin
  763. Consume(AS_AND);
  764. expr:=expr + '&';
  765. end;
  766. AS_NOT:
  767. Begin
  768. Consume(AS_NOT);
  769. expr:=expr + '~';
  770. end;
  771. AS_XOR:
  772. Begin
  773. Consume(AS_XOR);
  774. expr:=expr + '^';
  775. end;
  776. AS_OR:
  777. Begin
  778. Consume(AS_OR);
  779. expr:=expr + '|';
  780. end;
  781. AS_INTNUM:
  782. Begin
  783. expr:=expr + actasmpattern;
  784. Consume(AS_INTNUM);
  785. end;
  786. AS_OFFSET:
  787. begin
  788. Consume(AS_OFFSET);
  789. needofs:=true;
  790. if actasmtoken<>AS_ID then
  791. Message(asmr_e_offset_without_identifier);
  792. end;
  793. AS_SIZEOF,
  794. AS_TYPE:
  795. begin
  796. l:=0;
  797. hasparen:=false;
  798. Consume(actasmtoken);
  799. if actasmtoken=AS_LPAREN then
  800. begin
  801. hasparen:=true;
  802. Consume(AS_LPAREN);
  803. end;
  804. if actasmtoken<>AS_ID then
  805. Message(asmr_e_type_without_identifier)
  806. else
  807. begin
  808. tempstr:=actasmpattern;
  809. Consume(AS_ID);
  810. if actasmtoken=AS_DOT then
  811. BuildRecordOffsetSize(tempstr,k,l)
  812. else
  813. begin
  814. searchsym(tempstr,sym,srsymtable);
  815. if assigned(sym) then
  816. begin
  817. case sym.typ of
  818. globalvarsym,
  819. localvarsym,
  820. paravarsym :
  821. l:=tabstractvarsym(sym).getsize;
  822. typedconstsym :
  823. l:=ttypedconstsym(sym).getsize;
  824. typesym :
  825. l:=ttypesym(sym).restype.def.size;
  826. else
  827. Message(asmr_e_wrong_sym_type);
  828. end;
  829. end
  830. else
  831. Message1(sym_e_unknown_id,tempstr);
  832. end;
  833. end;
  834. str(l, tempstr);
  835. expr:=expr + tempstr;
  836. if hasparen then
  837. Consume(AS_RPAREN);
  838. end;
  839. AS_PTR :
  840. begin
  841. { Support ugly delphi constructs like <constant> PTR [ref] }
  842. break;
  843. end;
  844. AS_STRING:
  845. begin
  846. l:=0;
  847. case Length(actasmpattern) of
  848. 1 :
  849. l:=ord(actasmpattern[1]);
  850. 2 :
  851. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  852. 3 :
  853. l:=ord(actasmpattern[3]) +
  854. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  855. 4 :
  856. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  857. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  858. else
  859. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  860. end;
  861. str(l, tempstr);
  862. expr:=expr + tempstr;
  863. Consume(AS_STRING);
  864. end;
  865. AS_ID:
  866. begin
  867. hs:='';
  868. hssymtyp:=AT_DATA;
  869. def:=nil;
  870. tempstr:=actasmpattern;
  871. prevtok:=prevasmtoken;
  872. { stop parsing a constant expression if we find an opcode after a
  873. non-operator like "db $66 mov eax,ebx" }
  874. if (prevtok in [AS_ID,AS_INTNUM,AS_RPAREN]) and
  875. is_asmopcode(actasmpattern) then
  876. break;
  877. consume(AS_ID);
  878. if SearchIConstant(tempstr,l) then
  879. begin
  880. str(l, tempstr);
  881. expr:=expr + tempstr;
  882. end
  883. else
  884. begin
  885. if is_locallabel(tempstr) then
  886. begin
  887. CreateLocalLabel(tempstr,hl,false);
  888. hs:=hl.name;
  889. hssymtyp:=AT_FUNCTION;
  890. end
  891. else
  892. if SearchLabel(tempstr,hl,false) then
  893. begin
  894. hs:=hl.name;
  895. hssymtyp:=AT_FUNCTION;
  896. end
  897. else
  898. begin
  899. searchsym(tempstr,sym,srsymtable);
  900. if assigned(sym) then
  901. begin
  902. case sym.typ of
  903. globalvarsym :
  904. begin
  905. hs:=tglobalvarsym(sym).mangledname;
  906. def:=tglobalvarsym(sym).vartype.def;
  907. end;
  908. localvarsym,
  909. paravarsym :
  910. begin
  911. Message(asmr_e_no_local_or_para_allowed);
  912. end;
  913. typedconstsym :
  914. begin
  915. hs:=ttypedconstsym(sym).mangledname;
  916. def:=ttypedconstsym(sym).typedconsttype.def;
  917. end;
  918. procsym :
  919. begin
  920. if Tprocsym(sym).procdef_count>1 then
  921. Message(asmr_w_calling_overload_func);
  922. hs:=tprocsym(sym).first_procdef.mangledname;
  923. hssymtyp:=AT_FUNCTION;
  924. end;
  925. typesym :
  926. begin
  927. if not(ttypesym(sym).restype.def.deftype in [recorddef,objectdef]) then
  928. Message(asmr_e_wrong_sym_type);
  929. end;
  930. else
  931. Message(asmr_e_wrong_sym_type);
  932. end;
  933. end
  934. else
  935. Message1(sym_e_unknown_id,tempstr);
  936. end;
  937. { symbol found? }
  938. if hs<>'' then
  939. begin
  940. if asmsym='' then
  941. begin
  942. asmsym:=hs;
  943. asmsymtyp:=hssymtyp;
  944. end
  945. else
  946. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  947. if (expr='') or (expr[length(expr)]='+') then
  948. begin
  949. { don't remove the + if there could be a record field }
  950. if actasmtoken<>AS_DOT then
  951. delete(expr,length(expr),1);
  952. end
  953. else
  954. if needofs then
  955. begin
  956. if (prevtok<>AS_OFFSET) then
  957. Message(asmr_e_need_offset);
  958. end
  959. else
  960. Message(asmr_e_only_add_relocatable_symbol);
  961. end;
  962. if actasmtoken=AS_DOT then
  963. begin
  964. BuildRecordOffsetSize(tempstr,l,k);
  965. str(l, tempstr);
  966. expr:=expr + tempstr;
  967. end
  968. else
  969. begin
  970. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  971. delete(expr,length(expr),1);
  972. end;
  973. if (actasmtoken=AS_LBRACKET) and
  974. assigned(def) and
  975. (def.deftype=arraydef) then
  976. begin
  977. consume(AS_LBRACKET);
  978. l:=BuildConstExpression;
  979. if l<tarraydef(def).lowrange then
  980. begin
  981. Message(asmr_e_constant_out_of_bounds);
  982. l:=0;
  983. end
  984. else
  985. l:=(l-tarraydef(def).lowrange)*tarraydef(def).elesize;
  986. str(l, tempstr);
  987. expr:=expr + '+' + tempstr;
  988. consume(AS_RBRACKET);
  989. end;
  990. end;
  991. { check if there are wrong operator used like / or mod etc. }
  992. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_END,AS_RBRACKET]) then
  993. Message(asmr_e_only_add_relocatable_symbol);
  994. end;
  995. AS_ALIGN,
  996. AS_DB,
  997. AS_DW,
  998. AS_DD,
  999. AS_END,
  1000. AS_RBRACKET,
  1001. AS_SEPARATOR,
  1002. AS_COMMA,
  1003. AS_COLON:
  1004. break;
  1005. else
  1006. begin
  1007. { write error only once. }
  1008. if not errorflag then
  1009. Message(asmr_e_invalid_constant_expression);
  1010. { consume tokens until we find COMMA or SEPARATOR }
  1011. Consume(actasmtoken);
  1012. errorflag:=TRUE;
  1013. end;
  1014. end;
  1015. Until false;
  1016. { calculate expression }
  1017. if not ErrorFlag then
  1018. value:=CalculateExpression(expr)
  1019. else
  1020. value:=0;
  1021. { no longer in an expression }
  1022. inexpression:=FALSE;
  1023. end;
  1024. Function tx86intreader.BuildConstExpression:aint;
  1025. var
  1026. l : aint;
  1027. hs : string;
  1028. hssymtyp : TAsmsymtype;
  1029. begin
  1030. BuildConstSymbolExpression(false,false,l,hs,hssymtyp);
  1031. if hs<>'' then
  1032. Message(asmr_e_relocatable_symbol_not_allowed);
  1033. BuildConstExpression:=l;
  1034. end;
  1035. Function tx86intreader.BuildRefConstExpression:aint;
  1036. var
  1037. l : aint;
  1038. hs : string;
  1039. hssymtyp : TAsmsymtype;
  1040. begin
  1041. BuildConstSymbolExpression(false,true,l,hs,hssymtyp);
  1042. if hs<>'' then
  1043. Message(asmr_e_relocatable_symbol_not_allowed);
  1044. BuildRefConstExpression:=l;
  1045. end;
  1046. procedure tx86intreader.BuildReference(oper : tx86operand);
  1047. var
  1048. scale : byte;
  1049. k,l : aint;
  1050. tempstr,hs : string;
  1051. tempsymtyp : tasmsymtype;
  1052. code : integer;
  1053. hreg : tregister;
  1054. GotStar,GotOffset,HadVar,
  1055. GotPlus,Negative : boolean;
  1056. hl : tasmlabel;
  1057. Begin
  1058. Consume(AS_LBRACKET);
  1059. if not(oper.opr.typ in [OPR_LOCAL,OPR_REFERENCE]) then
  1060. oper.InitRef;
  1061. GotStar:=false;
  1062. GotPlus:=true;
  1063. GotOffset:=false;
  1064. Negative:=false;
  1065. Scale:=0;
  1066. repeat
  1067. if GotOffset and (actasmtoken<>AS_ID) then
  1068. Message(asmr_e_invalid_reference_syntax);
  1069. Case actasmtoken of
  1070. AS_ID: { Constant reference expression OR variable reference expression }
  1071. Begin
  1072. if not GotPlus then
  1073. Message(asmr_e_invalid_reference_syntax);
  1074. GotStar:=false;
  1075. GotPlus:=false;
  1076. if SearchIConstant(actasmpattern,l) or
  1077. SearchRecordType(actasmpattern) then
  1078. begin
  1079. l:=BuildRefConstExpression;
  1080. GotPlus:=(prevasmtoken=AS_PLUS);
  1081. GotStar:=(prevasmtoken=AS_STAR);
  1082. case oper.opr.typ of
  1083. OPR_LOCAL :
  1084. begin
  1085. if GotStar then
  1086. Message(asmr_e_invalid_reference_syntax);
  1087. if negative then
  1088. Dec(oper.opr.localsymofs,l)
  1089. else
  1090. Inc(oper.opr.localsymofs,l);
  1091. end;
  1092. OPR_REFERENCE :
  1093. begin
  1094. if GotStar then
  1095. oper.opr.ref.scalefactor:=l
  1096. else
  1097. begin
  1098. if negative then
  1099. Dec(oper.opr.ref.offset,l)
  1100. else
  1101. Inc(oper.opr.ref.offset,l);
  1102. end;
  1103. end;
  1104. end;
  1105. end
  1106. else
  1107. Begin
  1108. if oper.hasvar and not GotOffset then
  1109. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1110. HadVar:=oper.hasvar and GotOffset;
  1111. if negative then
  1112. Message(asmr_e_only_add_relocatable_symbol);
  1113. tempstr:=actasmpattern;
  1114. Consume(AS_ID);
  1115. { typecasting? }
  1116. if (actasmtoken=AS_LPAREN) and
  1117. SearchType(tempstr,l) then
  1118. begin
  1119. oper.hastype:=true;
  1120. oper.typesize:=l;
  1121. Consume(AS_LPAREN);
  1122. BuildOperand(oper,true);
  1123. Consume(AS_RPAREN);
  1124. end
  1125. else
  1126. if is_locallabel(tempstr) then
  1127. begin
  1128. CreateLocalLabel(tempstr,hl,false);
  1129. oper.InitRef;
  1130. oper.opr.ref.symbol:=hl;
  1131. oper.hasvar:=true;
  1132. end
  1133. else
  1134. if oper.SetupVar(tempstr,GotOffset) then
  1135. begin
  1136. { force OPR_LOCAL to be a reference }
  1137. if oper.opr.typ=OPR_LOCAL then
  1138. oper.opr.localforceref:=true;
  1139. end
  1140. else
  1141. Message1(sym_e_unknown_id,tempstr);
  1142. { record.field ? }
  1143. if actasmtoken=AS_DOT then
  1144. begin
  1145. BuildRecordOffsetSize(tempstr,l,k);
  1146. case oper.opr.typ of
  1147. OPR_LOCAL :
  1148. inc(oper.opr.localsymofs,l);
  1149. OPR_REFERENCE :
  1150. inc(oper.opr.ref.offset,l);
  1151. end;
  1152. end;
  1153. if GotOffset then
  1154. begin
  1155. if oper.hasvar and (oper.opr.ref.base=current_procinfo.framepointer) then
  1156. begin
  1157. if (oper.opr.typ=OPR_REFERENCE) then
  1158. oper.opr.ref.base:=NR_NO;
  1159. oper.hasvar:=hadvar;
  1160. end
  1161. else
  1162. begin
  1163. if oper.hasvar and hadvar then
  1164. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1165. { should we allow ?? }
  1166. end;
  1167. end;
  1168. end;
  1169. GotOffset:=false;
  1170. end;
  1171. AS_PLUS :
  1172. Begin
  1173. Consume(AS_PLUS);
  1174. Negative:=false;
  1175. GotPlus:=true;
  1176. GotStar:=false;
  1177. Scale:=0;
  1178. end;
  1179. AS_DOT :
  1180. Begin
  1181. { Handle like a + }
  1182. Consume(AS_DOT);
  1183. Negative:=false;
  1184. GotPlus:=true;
  1185. GotStar:=false;
  1186. Scale:=0;
  1187. end;
  1188. AS_MINUS :
  1189. begin
  1190. Consume(AS_MINUS);
  1191. Negative:=true;
  1192. GotPlus:=true;
  1193. GotStar:=false;
  1194. Scale:=0;
  1195. end;
  1196. AS_STAR : { Scaling, with eax*4 order }
  1197. begin
  1198. Consume(AS_STAR);
  1199. hs:='';
  1200. l:=0;
  1201. case actasmtoken of
  1202. AS_LPAREN :
  1203. l:=BuildConstExpression;
  1204. AS_INTNUM:
  1205. Begin
  1206. hs:=actasmpattern;
  1207. Consume(AS_INTNUM);
  1208. end;
  1209. AS_REGISTER :
  1210. begin
  1211. case oper.opr.typ of
  1212. OPR_REFERENCE :
  1213. begin
  1214. if oper.opr.ref.scalefactor=0 then
  1215. begin
  1216. if scale<>0 then
  1217. begin
  1218. oper.opr.ref.scalefactor:=scale;
  1219. scale:=0;
  1220. end
  1221. else
  1222. Message(asmr_e_wrong_scale_factor);
  1223. end
  1224. else
  1225. Message(asmr_e_invalid_reference_syntax);
  1226. end;
  1227. OPR_LOCAL :
  1228. begin
  1229. if oper.opr.localscale=0 then
  1230. begin
  1231. if scale<>0 then
  1232. begin
  1233. oper.opr.localscale:=scale;
  1234. scale:=0;
  1235. end
  1236. else
  1237. Message(asmr_e_wrong_scale_factor);
  1238. end
  1239. else
  1240. Message(asmr_e_invalid_reference_syntax);
  1241. end;
  1242. end;
  1243. end;
  1244. else
  1245. Message(asmr_e_invalid_reference_syntax);
  1246. end;
  1247. if actasmtoken<>AS_REGISTER then
  1248. begin
  1249. if hs<>'' then
  1250. val(hs,l,code);
  1251. case oper.opr.typ of
  1252. OPR_REFERENCE :
  1253. oper.opr.ref.scalefactor:=l;
  1254. OPR_LOCAL :
  1255. oper.opr.localscale:=l;
  1256. end;
  1257. if l>9 then
  1258. Message(asmr_e_wrong_scale_factor);
  1259. end;
  1260. GotPlus:=false;
  1261. GotStar:=false;
  1262. end;
  1263. AS_REGISTER :
  1264. begin
  1265. if not((GotPlus and (not Negative)) or
  1266. GotStar) then
  1267. Message(asmr_e_invalid_reference_syntax);
  1268. hreg:=actasmregister;
  1269. Consume(AS_REGISTER);
  1270. { this register will be the index:
  1271. 1. just read a *
  1272. 2. next token is a *
  1273. 3. base register is already used }
  1274. case oper.opr.typ of
  1275. OPR_LOCAL :
  1276. begin
  1277. if (oper.opr.localindexreg<>NR_NO) then
  1278. Message(asmr_e_multiple_index);
  1279. oper.opr.localindexreg:=hreg;
  1280. if scale<>0 then
  1281. begin
  1282. oper.opr.localscale:=scale;
  1283. scale:=0;
  1284. end;
  1285. end;
  1286. OPR_REFERENCE :
  1287. begin
  1288. if (GotStar) or
  1289. (actasmtoken=AS_STAR) or
  1290. (oper.opr.ref.base<>NR_NO) then
  1291. begin
  1292. if (oper.opr.ref.index<>NR_NO) then
  1293. Message(asmr_e_multiple_index);
  1294. oper.opr.ref.index:=hreg;
  1295. if scale<>0 then
  1296. begin
  1297. oper.opr.ref.scalefactor:=scale;
  1298. scale:=0;
  1299. end;
  1300. end
  1301. else
  1302. oper.opr.ref.base:=hreg;
  1303. end;
  1304. end;
  1305. GotPlus:=false;
  1306. GotStar:=false;
  1307. end;
  1308. AS_OFFSET :
  1309. begin
  1310. Consume(AS_OFFSET);
  1311. GotOffset:=true;
  1312. end;
  1313. AS_TYPE,
  1314. AS_NOT,
  1315. AS_STRING,
  1316. AS_INTNUM,
  1317. AS_LPAREN : { Constant reference expression }
  1318. begin
  1319. if not GotPlus and not GotStar then
  1320. Message(asmr_e_invalid_reference_syntax);
  1321. BuildConstSymbolExpression(true,true,l,tempstr,tempsymtyp);
  1322. if tempstr<>'' then
  1323. begin
  1324. if GotStar then
  1325. Message(asmr_e_only_add_relocatable_symbol);
  1326. if not assigned(oper.opr.ref.symbol) then
  1327. oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr)
  1328. else
  1329. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1330. end;
  1331. case oper.opr.typ of
  1332. OPR_REFERENCE :
  1333. begin
  1334. if GotStar then
  1335. oper.opr.ref.scalefactor:=l
  1336. else if (prevasmtoken = AS_STAR) then
  1337. begin
  1338. if scale<>0 then
  1339. scale:=l*scale
  1340. else
  1341. scale:=l;
  1342. end
  1343. else
  1344. begin
  1345. if negative then
  1346. Dec(oper.opr.ref.offset,l)
  1347. else
  1348. Inc(oper.opr.ref.offset,l);
  1349. end;
  1350. end;
  1351. OPR_LOCAL :
  1352. begin
  1353. if GotStar then
  1354. oper.opr.localscale:=l
  1355. else if (prevasmtoken = AS_STAR) then
  1356. begin
  1357. if scale<>0 then
  1358. scale:=l*scale
  1359. else
  1360. scale:=l;
  1361. end
  1362. else
  1363. begin
  1364. if negative then
  1365. Dec(oper.opr.localsymofs,l)
  1366. else
  1367. Inc(oper.opr.localsymofs,l);
  1368. end;
  1369. end;
  1370. end;
  1371. GotPlus:=(prevasmtoken=AS_PLUS) or
  1372. (prevasmtoken=AS_MINUS);
  1373. if GotPlus then
  1374. negative := prevasmtoken = AS_MINUS;
  1375. GotStar:=(prevasmtoken=AS_STAR);
  1376. end;
  1377. AS_RBRACKET :
  1378. begin
  1379. if GotPlus or GotStar then
  1380. Message(asmr_e_invalid_reference_syntax);
  1381. Consume(AS_RBRACKET);
  1382. break;
  1383. end;
  1384. else
  1385. Begin
  1386. Message(asmr_e_invalid_reference_syntax);
  1387. RecoverConsume(true);
  1388. break;
  1389. end;
  1390. end;
  1391. until false;
  1392. end;
  1393. Procedure tx86intreader.BuildConstantOperand(oper: tx86operand);
  1394. var
  1395. l : aint;
  1396. tempstr : string;
  1397. tempsymtyp : tasmsymtype;
  1398. begin
  1399. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1400. Message(asmr_e_invalid_operand_type);
  1401. BuildConstSymbolExpression(true,false,l,tempstr,tempsymtyp);
  1402. if tempstr<>'' then
  1403. begin
  1404. oper.opr.typ:=OPR_SYMBOL;
  1405. oper.opr.symofs:=l;
  1406. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr);
  1407. end
  1408. else
  1409. if oper.opr.typ=OPR_NONE then
  1410. begin
  1411. oper.opr.typ:=OPR_CONSTANT;
  1412. oper.opr.val:=l;
  1413. end
  1414. else
  1415. inc(oper.opr.val,l);
  1416. end;
  1417. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1418. procedure AddLabelOperand(hl:tasmlabel);
  1419. begin
  1420. if (oper.opr.typ=OPR_NONE) and
  1421. is_calljmp(actopcode) then
  1422. begin
  1423. oper.opr.typ:=OPR_SYMBOL;
  1424. oper.opr.symbol:=hl;
  1425. end
  1426. else
  1427. begin
  1428. oper.InitRef;
  1429. oper.opr.ref.symbol:=hl;
  1430. end;
  1431. end;
  1432. var
  1433. expr : string;
  1434. tempreg : tregister;
  1435. l : aint;
  1436. hl : tasmlabel;
  1437. toffset,
  1438. tsize : aint;
  1439. begin
  1440. expr:='';
  1441. repeat
  1442. if actasmtoken=AS_DOT then
  1443. begin
  1444. if expr<>'' then
  1445. begin
  1446. BuildRecordOffsetSize(expr,toffset,tsize);
  1447. oper.SetSize(tsize,true);
  1448. case oper.opr.typ of
  1449. OPR_LOCAL :
  1450. begin
  1451. { don't allow direct access to fields of parameters, becuase that
  1452. will generate buggy code. Allow it only for explicit typecasting
  1453. and when the parameter is in a register (delphi compatible) }
  1454. if (not oper.hastype) and
  1455. (oper.opr.localsym.owner.symtabletype=parasymtable) and
  1456. (current_procinfo.procdef.proccalloption<>pocall_register) then
  1457. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1458. inc(oper.opr.localsymofs,toffset)
  1459. end;
  1460. OPR_CONSTANT :
  1461. inc(oper.opr.val,toffset);
  1462. OPR_REFERENCE :
  1463. inc(oper.opr.ref.offset,toffset);
  1464. OPR_NONE :
  1465. begin
  1466. oper.opr.typ:=OPR_CONSTANT;
  1467. oper.opr.val:=toffset;
  1468. end;
  1469. else
  1470. internalerror(200309222);
  1471. end;
  1472. expr:='';
  1473. end
  1474. else
  1475. begin
  1476. { See it as a separator }
  1477. Consume(AS_DOT);
  1478. end;
  1479. end;
  1480. case actasmtoken of
  1481. AS_OFFSET,
  1482. AS_SIZEOF,
  1483. AS_TYPE,
  1484. AS_NOT,
  1485. AS_STRING,
  1486. AS_PLUS,
  1487. AS_MINUS,
  1488. AS_LPAREN,
  1489. AS_INTNUM :
  1490. begin
  1491. case oper.opr.typ of
  1492. OPR_REFERENCE :
  1493. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1494. OPR_LOCAL :
  1495. inc(oper.opr.localsymofs,BuildConstExpression);
  1496. OPR_NONE,
  1497. OPR_CONSTANT :
  1498. BuildConstantOperand(oper);
  1499. else
  1500. Message(asmr_e_invalid_operand_type);
  1501. end;
  1502. end;
  1503. AS_PTR :
  1504. begin
  1505. if not oper.hastype then
  1506. begin
  1507. if (oper.opr.typ=OPR_CONSTANT) then
  1508. begin
  1509. oper.typesize:=oper.opr.val;
  1510. { reset constant value of operand }
  1511. oper.opr.typ:=OPR_NONE;
  1512. oper.opr.val:=0;
  1513. end
  1514. else
  1515. Message(asmr_e_syn_operand);
  1516. end;
  1517. Consume(AS_PTR);
  1518. oper.InitRef;
  1519. BuildOperand(oper,false);
  1520. end;
  1521. AS_ID : { A constant expression, or a Variable ref. }
  1522. Begin
  1523. { Label or Special symbol reference? }
  1524. if actasmpattern[1] = '@' then
  1525. Begin
  1526. if actasmpattern = '@RESULT' then
  1527. Begin
  1528. oper.SetupResult;
  1529. Consume(AS_ID);
  1530. end
  1531. else
  1532. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1533. begin
  1534. Message(asmr_w_CODE_and_DATA_not_supported);
  1535. Consume(AS_ID);
  1536. end
  1537. else
  1538. { Local Label }
  1539. begin
  1540. CreateLocalLabel(actasmpattern,hl,false);
  1541. Consume(AS_ID);
  1542. AddLabelOperand(hl);
  1543. end;
  1544. end
  1545. else
  1546. { support result for delphi modes }
  1547. if (m_objpas in aktmodeswitches) and (actasmpattern='RESULT') then
  1548. begin
  1549. oper.SetUpResult;
  1550. Consume(AS_ID);
  1551. end
  1552. { probably a variable or normal expression }
  1553. { or a procedure (such as in CALL ID) }
  1554. else
  1555. Begin
  1556. { is it a constant ? }
  1557. if SearchIConstant(actasmpattern,l) then
  1558. Begin
  1559. case oper.opr.typ of
  1560. OPR_REFERENCE :
  1561. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1562. OPR_LOCAL :
  1563. inc(oper.opr.localsymofs,BuildRefConstExpression);
  1564. OPR_NONE,
  1565. OPR_CONSTANT :
  1566. BuildConstantOperand(oper);
  1567. else
  1568. Message(asmr_e_invalid_operand_type);
  1569. end;
  1570. end
  1571. else
  1572. { Check for pascal label }
  1573. if SearchLabel(actasmpattern,hl,false) then
  1574. begin
  1575. Consume(AS_ID);
  1576. AddLabelOperand(hl);
  1577. end
  1578. else
  1579. { is it a normal variable ? }
  1580. Begin
  1581. expr:=actasmpattern;
  1582. Consume(AS_ID);
  1583. { typecasting? }
  1584. if SearchType(expr,l) then
  1585. begin
  1586. oper.hastype:=true;
  1587. oper.typesize:=l;
  1588. case actasmtoken of
  1589. AS_LPAREN :
  1590. begin
  1591. { Support Type([Reference]) }
  1592. Consume(AS_LPAREN);
  1593. BuildOperand(oper,true);
  1594. Consume(AS_RPAREN);
  1595. end;
  1596. AS_LBRACKET :
  1597. begin
  1598. { Support Var.Type[Index] }
  1599. { Convert @label.Byte[1] to reference }
  1600. if oper.opr.typ=OPR_SYMBOL then
  1601. oper.initref;
  1602. end;
  1603. end;
  1604. end
  1605. else
  1606. begin
  1607. if not oper.SetupVar(expr,false) then
  1608. Begin
  1609. { not a variable, check special variables.. }
  1610. if expr = 'SELF' then
  1611. oper.SetupSelf
  1612. else
  1613. Message1(sym_e_unknown_id,expr);
  1614. expr:='';
  1615. end;
  1616. end;
  1617. end;
  1618. end;
  1619. end;
  1620. AS_REGISTER : { Register, a variable reference or a constant reference }
  1621. begin
  1622. { save the type of register used. }
  1623. tempreg:=actasmregister;
  1624. Consume(AS_REGISTER);
  1625. if actasmtoken = AS_COLON then
  1626. Begin
  1627. Consume(AS_COLON);
  1628. oper.InitRef;
  1629. oper.opr.ref.segment:=tempreg;
  1630. BuildReference(oper);
  1631. end
  1632. else
  1633. { Simple register }
  1634. begin
  1635. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1636. Message(asmr_e_invalid_operand_type);
  1637. oper.opr.typ:=OPR_REGISTER;
  1638. oper.opr.reg:=tempreg;
  1639. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1640. end;
  1641. end;
  1642. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1643. Begin
  1644. BuildReference(oper);
  1645. end;
  1646. AS_SEG :
  1647. Begin
  1648. Message(asmr_e_seg_not_supported);
  1649. Consume(actasmtoken);
  1650. end;
  1651. AS_DWORD,
  1652. AS_BYTE,
  1653. AS_WORD,
  1654. AS_TBYTE,
  1655. AS_DQWORD,
  1656. AS_QWORD :
  1657. begin
  1658. { Type specifier }
  1659. oper.hastype:=true;
  1660. oper.typesize:=0;
  1661. case actasmtoken of
  1662. AS_DWORD : oper.typesize:=4;
  1663. AS_WORD : oper.typesize:=2;
  1664. AS_BYTE : oper.typesize:=1;
  1665. AS_QWORD : oper.typesize:=8;
  1666. AS_DQWORD : oper.typesize:=16;
  1667. AS_TBYTE : oper.typesize:=10;
  1668. end;
  1669. Consume(actasmtoken);
  1670. if (actasmtoken=AS_LPAREN) then
  1671. begin
  1672. { Support Type([Reference]) }
  1673. Consume(AS_LPAREN);
  1674. BuildOperand(oper,true);
  1675. Consume(AS_RPAREN);
  1676. end;
  1677. end;
  1678. AS_SEPARATOR,
  1679. AS_END,
  1680. AS_COMMA,
  1681. AS_COLON:
  1682. begin
  1683. break;
  1684. end;
  1685. AS_RPAREN:
  1686. begin
  1687. if not istypecast then
  1688. begin
  1689. Message(asmr_e_syn_operand);
  1690. Consume(AS_RPAREN);
  1691. end
  1692. else
  1693. break;
  1694. end;
  1695. else
  1696. begin
  1697. Message(asmr_e_syn_operand);
  1698. RecoverConsume(true);
  1699. break;
  1700. end;
  1701. end;
  1702. until false;
  1703. { End of operand, update size if a typecast is forced }
  1704. if (oper.typesize<>0) and
  1705. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1706. oper.SetSize(oper.typesize,true);
  1707. end;
  1708. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  1709. var
  1710. PrefixOp,OverrideOp: tasmop;
  1711. operandnum : longint;
  1712. is_far_const:boolean;
  1713. i:byte;
  1714. begin
  1715. PrefixOp:=A_None;
  1716. OverrideOp:=A_None;
  1717. is_far_const:=false;
  1718. { prefix seg opcode / prefix opcode }
  1719. repeat
  1720. if is_prefix(actopcode) then
  1721. with instr do
  1722. begin
  1723. OpOrder:=op_intel;
  1724. PrefixOp:=ActOpcode;
  1725. opcode:=ActOpcode;
  1726. condition:=ActCondition;
  1727. opsize:=ActOpsize;
  1728. ConcatInstruction(curlist);
  1729. consume(AS_OPCODE);
  1730. end
  1731. else
  1732. if is_override(actopcode) then
  1733. with instr do
  1734. begin
  1735. OpOrder:=op_intel;
  1736. OverrideOp:=ActOpcode;
  1737. opcode:=ActOpcode;
  1738. condition:=ActCondition;
  1739. opsize:=ActOpsize;
  1740. ConcatInstruction(curlist);
  1741. consume(AS_OPCODE);
  1742. end
  1743. else
  1744. break;
  1745. { allow for newline after prefix or override }
  1746. while actasmtoken=AS_SEPARATOR do
  1747. consume(AS_SEPARATOR);
  1748. until (actasmtoken<>AS_OPCODE);
  1749. { opcode }
  1750. if (actasmtoken <> AS_OPCODE) then
  1751. begin
  1752. Message(asmr_e_invalid_or_missing_opcode);
  1753. RecoverConsume(false);
  1754. exit;
  1755. end;
  1756. { Fill the instr object with the current state }
  1757. with instr do
  1758. begin
  1759. OpOrder:=op_intel;
  1760. Opcode:=ActOpcode;
  1761. condition:=ActCondition;
  1762. opsize:=ActOpsize;
  1763. { Valid combination of prefix/override and instruction ? }
  1764. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1765. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1766. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1767. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1768. end;
  1769. { We are reading operands, so opcode will be an AS_ID }
  1770. operandnum:=1;
  1771. is_far_const:=false;
  1772. Consume(AS_OPCODE);
  1773. { Zero operand opcode ? }
  1774. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1775. begin
  1776. operandnum:=0;
  1777. exit;
  1778. end;
  1779. { Read Operands }
  1780. repeat
  1781. case actasmtoken of
  1782. { End of asm operands for this opcode }
  1783. AS_END,
  1784. AS_SEPARATOR :
  1785. break;
  1786. { Operand delimiter }
  1787. AS_COMMA :
  1788. begin
  1789. if operandnum > Max_Operands then
  1790. Message(asmr_e_too_many_operands)
  1791. else
  1792. Inc(operandnum);
  1793. Consume(AS_COMMA);
  1794. end;
  1795. {Far constant, i.e. jmp $0000:$11111111.}
  1796. AS_COLON:
  1797. begin
  1798. is_far_const:=true;
  1799. if operandnum>1 then
  1800. message(asmr_e_too_many_operands)
  1801. else
  1802. inc(operandnum);
  1803. consume(AS_COLON);
  1804. end;
  1805. { Type specifier }
  1806. AS_NEAR,
  1807. AS_FAR :
  1808. begin
  1809. if actasmtoken = AS_NEAR then
  1810. begin
  1811. Message(asmr_w_near_ignored);
  1812. instr.opsize:=S_NEAR;
  1813. end
  1814. else
  1815. begin
  1816. Message(asmr_w_far_ignored);
  1817. instr.opsize:=S_FAR;
  1818. end;
  1819. Consume(actasmtoken);
  1820. if actasmtoken=AS_PTR then
  1821. begin
  1822. Consume(AS_PTR);
  1823. instr.Operands[operandnum].InitRef;
  1824. end;
  1825. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1826. end;
  1827. else
  1828. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1829. end; { end case }
  1830. until false;
  1831. instr.ops:=operandnum;
  1832. { Check operands }
  1833. for i:=1 to operandnum do
  1834. begin
  1835. if is_far_const and
  1836. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  1837. message(asmr_e_expr_illegal)
  1838. else
  1839. if instr.operands[i].opr.typ=OPR_NONE then
  1840. Message(asmr_e_syntax_error);
  1841. end;
  1842. end;
  1843. Procedure tx86intreader.BuildConstant(constsize: byte);
  1844. var
  1845. asmsymtyp : tasmsymtype;
  1846. asmsym,
  1847. expr: string;
  1848. value : aint;
  1849. Begin
  1850. Repeat
  1851. Case actasmtoken of
  1852. AS_STRING:
  1853. Begin
  1854. { DD and DW cases }
  1855. if constsize <> 1 then
  1856. Begin
  1857. if Not PadZero(actasmpattern,constsize) then
  1858. Message(scan_f_string_exceeds_line);
  1859. end;
  1860. expr:=actasmpattern;
  1861. Consume(AS_STRING);
  1862. Case actasmtoken of
  1863. AS_COMMA:
  1864. Consume(AS_COMMA);
  1865. AS_END,
  1866. AS_SEPARATOR: ;
  1867. else
  1868. Message(asmr_e_invalid_string_expression);
  1869. end;
  1870. ConcatString(curlist,expr);
  1871. end;
  1872. AS_PLUS,
  1873. AS_MINUS,
  1874. AS_LPAREN,
  1875. AS_NOT,
  1876. AS_INTNUM,
  1877. AS_ID :
  1878. Begin
  1879. BuildConstSymbolExpression(false,false,value,asmsym,asmsymtyp);
  1880. if asmsym<>'' then
  1881. begin
  1882. if constsize<>sizeof(aint) then
  1883. Message1(asmr_w_const32bit_for_address,asmsym);
  1884. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  1885. end
  1886. else
  1887. ConcatConstant(curlist,value,constsize);
  1888. end;
  1889. AS_COMMA:
  1890. begin
  1891. Consume(AS_COMMA);
  1892. end;
  1893. AS_ALIGN,
  1894. AS_DB,
  1895. AS_DW,
  1896. AS_DD,
  1897. AS_OPCODE,
  1898. AS_END,
  1899. AS_SEPARATOR:
  1900. break;
  1901. else
  1902. begin
  1903. Message(asmr_e_syn_constant);
  1904. RecoverConsume(false);
  1905. end
  1906. end;
  1907. Until false;
  1908. end;
  1909. function tx86intreader.Assemble: tlinkedlist;
  1910. Var
  1911. hl : tasmlabel;
  1912. instr : Tx86Instruction;
  1913. Begin
  1914. Message1(asmr_d_start_reading,'intel');
  1915. inexpression:=FALSE;
  1916. firsttoken:=TRUE;
  1917. { sets up all opcode and register tables in uppercase
  1918. done in the construtor now
  1919. if not _asmsorted then
  1920. Begin
  1921. SetupTables;
  1922. _asmsorted:=TRUE;
  1923. end;
  1924. }
  1925. curlist:=TAsmList.Create;
  1926. { setup label linked list }
  1927. LocalLabelList:=TLocalLabelList.Create;
  1928. { start tokenizer }
  1929. c:=current_scanner.asmgetcharstart;
  1930. gettoken;
  1931. { main loop }
  1932. repeat
  1933. case actasmtoken of
  1934. AS_LLABEL:
  1935. Begin
  1936. if CreateLocalLabel(actasmpattern,hl,true) then
  1937. ConcatLabel(curlist,hl);
  1938. Consume(AS_LLABEL);
  1939. end;
  1940. AS_LABEL:
  1941. Begin
  1942. if SearchLabel(upper(actasmpattern),hl,true) then
  1943. ConcatLabel(curlist,hl)
  1944. else
  1945. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1946. Consume(AS_LABEL);
  1947. end;
  1948. AS_DW :
  1949. Begin
  1950. inexpression:=true;
  1951. Consume(AS_DW);
  1952. BuildConstant(2);
  1953. inexpression:=false;
  1954. end;
  1955. AS_DB :
  1956. Begin
  1957. inexpression:=true;
  1958. Consume(AS_DB);
  1959. BuildConstant(1);
  1960. inexpression:=false;
  1961. end;
  1962. AS_DD :
  1963. Begin
  1964. inexpression:=true;
  1965. Consume(AS_DD);
  1966. BuildConstant(4);
  1967. inexpression:=false;
  1968. end;
  1969. AS_ALIGN:
  1970. Begin
  1971. Consume(AS_ALIGN);
  1972. ConcatAlign(curlist,BuildConstExpression);
  1973. if actasmtoken<>AS_SEPARATOR then
  1974. Consume(AS_SEPARATOR);
  1975. end;
  1976. AS_OPCODE :
  1977. Begin
  1978. instr:=Tx86Instruction.Create(Tx86Operand);
  1979. BuildOpcode(instr);
  1980. with instr do
  1981. begin
  1982. { We need AT&T style operands }
  1983. Swapoperands;
  1984. { Must be done with args in ATT order }
  1985. CheckNonCommutativeOpcodes;
  1986. AddReferenceSizes;
  1987. SetInstructionOpsize;
  1988. CheckOperandSizes;
  1989. ConcatInstruction(curlist);
  1990. end;
  1991. instr.Free;
  1992. end;
  1993. AS_SEPARATOR :
  1994. Begin
  1995. Consume(AS_SEPARATOR);
  1996. end;
  1997. AS_END :
  1998. break; { end assembly block }
  1999. else
  2000. Begin
  2001. Message(asmr_e_syntax_error);
  2002. RecoverConsume(false);
  2003. end;
  2004. end; { end case }
  2005. until false;
  2006. { Check LocalLabelList }
  2007. LocalLabelList.CheckEmitted;
  2008. LocalLabelList.Free;
  2009. { Return the list in an asmnode }
  2010. assemble:=curlist;
  2011. Message1(asmr_d_finish_reading,'intel');
  2012. end;
  2013. end.