rax86int.pas 71 KB

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