rax86int.pas 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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. { we have used the size of a field. Reset the typesize of the record }
  1449. oper.typesize:=0;
  1450. case oper.opr.typ of
  1451. OPR_LOCAL :
  1452. begin
  1453. { don't allow direct access to fields of parameters, becuase that
  1454. will generate buggy code. Allow it only for explicit typecasting
  1455. and when the parameter is in a register (delphi compatible) }
  1456. if (not oper.hastype) and
  1457. (oper.opr.localsym.owner.symtabletype=parasymtable) and
  1458. (current_procinfo.procdef.proccalloption<>pocall_register) then
  1459. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1460. inc(oper.opr.localsymofs,toffset)
  1461. end;
  1462. OPR_CONSTANT :
  1463. inc(oper.opr.val,toffset);
  1464. OPR_REFERENCE :
  1465. inc(oper.opr.ref.offset,toffset);
  1466. OPR_NONE :
  1467. begin
  1468. oper.opr.typ:=OPR_CONSTANT;
  1469. oper.opr.val:=toffset;
  1470. end;
  1471. else
  1472. internalerror(200309222);
  1473. end;
  1474. expr:='';
  1475. end
  1476. else
  1477. begin
  1478. { See it as a separator }
  1479. Consume(AS_DOT);
  1480. end;
  1481. end;
  1482. case actasmtoken of
  1483. AS_OFFSET,
  1484. AS_SIZEOF,
  1485. AS_TYPE,
  1486. AS_NOT,
  1487. AS_STRING,
  1488. AS_PLUS,
  1489. AS_MINUS,
  1490. AS_LPAREN,
  1491. AS_INTNUM :
  1492. begin
  1493. case oper.opr.typ of
  1494. OPR_REFERENCE :
  1495. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1496. OPR_LOCAL :
  1497. inc(oper.opr.localsymofs,BuildConstExpression);
  1498. OPR_NONE,
  1499. OPR_CONSTANT :
  1500. BuildConstantOperand(oper);
  1501. else
  1502. Message(asmr_e_invalid_operand_type);
  1503. end;
  1504. end;
  1505. AS_PTR :
  1506. begin
  1507. if not oper.hastype then
  1508. begin
  1509. if (oper.opr.typ=OPR_CONSTANT) then
  1510. begin
  1511. oper.typesize:=oper.opr.val;
  1512. { reset constant value of operand }
  1513. oper.opr.typ:=OPR_NONE;
  1514. oper.opr.val:=0;
  1515. end
  1516. else
  1517. Message(asmr_e_syn_operand);
  1518. end;
  1519. Consume(AS_PTR);
  1520. oper.InitRef;
  1521. BuildOperand(oper,false);
  1522. end;
  1523. AS_ID : { A constant expression, or a Variable ref. }
  1524. Begin
  1525. { Label or Special symbol reference? }
  1526. if actasmpattern[1] = '@' then
  1527. Begin
  1528. if actasmpattern = '@RESULT' then
  1529. Begin
  1530. oper.SetupResult;
  1531. Consume(AS_ID);
  1532. end
  1533. else
  1534. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1535. begin
  1536. Message(asmr_w_CODE_and_DATA_not_supported);
  1537. Consume(AS_ID);
  1538. end
  1539. else
  1540. { Local Label }
  1541. begin
  1542. CreateLocalLabel(actasmpattern,hl,false);
  1543. Consume(AS_ID);
  1544. AddLabelOperand(hl);
  1545. end;
  1546. end
  1547. else
  1548. { support result for delphi modes }
  1549. if (m_objpas in aktmodeswitches) and (actasmpattern='RESULT') then
  1550. begin
  1551. oper.SetUpResult;
  1552. Consume(AS_ID);
  1553. end
  1554. { probably a variable or normal expression }
  1555. { or a procedure (such as in CALL ID) }
  1556. else
  1557. Begin
  1558. { is it a constant ? }
  1559. if SearchIConstant(actasmpattern,l) then
  1560. Begin
  1561. case oper.opr.typ of
  1562. OPR_REFERENCE :
  1563. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1564. OPR_LOCAL :
  1565. inc(oper.opr.localsymofs,BuildRefConstExpression);
  1566. OPR_NONE,
  1567. OPR_CONSTANT :
  1568. BuildConstantOperand(oper);
  1569. else
  1570. Message(asmr_e_invalid_operand_type);
  1571. end;
  1572. end
  1573. else
  1574. { Check for pascal label }
  1575. if SearchLabel(actasmpattern,hl,false) then
  1576. begin
  1577. Consume(AS_ID);
  1578. AddLabelOperand(hl);
  1579. end
  1580. else
  1581. { is it a normal variable ? }
  1582. Begin
  1583. expr:=actasmpattern;
  1584. Consume(AS_ID);
  1585. { typecasting? }
  1586. if SearchType(expr,l) then
  1587. begin
  1588. oper.hastype:=true;
  1589. oper.typesize:=l;
  1590. case actasmtoken of
  1591. AS_LPAREN :
  1592. begin
  1593. { Support Type([Reference]) }
  1594. Consume(AS_LPAREN);
  1595. BuildOperand(oper,true);
  1596. Consume(AS_RPAREN);
  1597. end;
  1598. AS_LBRACKET :
  1599. begin
  1600. { Support Var.Type[Index] }
  1601. { Convert @label.Byte[1] to reference }
  1602. if oper.opr.typ=OPR_SYMBOL then
  1603. oper.initref;
  1604. end;
  1605. end;
  1606. end
  1607. else
  1608. begin
  1609. if not oper.SetupVar(expr,false) then
  1610. Begin
  1611. { not a variable, check special variables.. }
  1612. if expr = 'SELF' then
  1613. oper.SetupSelf
  1614. else
  1615. Message1(sym_e_unknown_id,expr);
  1616. expr:='';
  1617. end;
  1618. end;
  1619. end;
  1620. end;
  1621. end;
  1622. AS_REGISTER : { Register, a variable reference or a constant reference }
  1623. begin
  1624. { save the type of register used. }
  1625. tempreg:=actasmregister;
  1626. Consume(AS_REGISTER);
  1627. if actasmtoken = AS_COLON then
  1628. Begin
  1629. Consume(AS_COLON);
  1630. oper.InitRef;
  1631. oper.opr.ref.segment:=tempreg;
  1632. BuildReference(oper);
  1633. end
  1634. else
  1635. { Simple register }
  1636. begin
  1637. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1638. Message(asmr_e_invalid_operand_type);
  1639. oper.opr.typ:=OPR_REGISTER;
  1640. oper.opr.reg:=tempreg;
  1641. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1642. end;
  1643. end;
  1644. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1645. Begin
  1646. BuildReference(oper);
  1647. end;
  1648. AS_SEG :
  1649. Begin
  1650. Message(asmr_e_seg_not_supported);
  1651. Consume(actasmtoken);
  1652. end;
  1653. AS_DWORD,
  1654. AS_BYTE,
  1655. AS_WORD,
  1656. AS_TBYTE,
  1657. AS_DQWORD,
  1658. AS_QWORD :
  1659. begin
  1660. { Type specifier }
  1661. oper.hastype:=true;
  1662. oper.typesize:=0;
  1663. case actasmtoken of
  1664. AS_DWORD : oper.typesize:=4;
  1665. AS_WORD : oper.typesize:=2;
  1666. AS_BYTE : oper.typesize:=1;
  1667. AS_QWORD : oper.typesize:=8;
  1668. AS_DQWORD : oper.typesize:=16;
  1669. AS_TBYTE : oper.typesize:=10;
  1670. end;
  1671. Consume(actasmtoken);
  1672. if (actasmtoken=AS_LPAREN) then
  1673. begin
  1674. { Support Type([Reference]) }
  1675. Consume(AS_LPAREN);
  1676. BuildOperand(oper,true);
  1677. Consume(AS_RPAREN);
  1678. end;
  1679. end;
  1680. AS_SEPARATOR,
  1681. AS_END,
  1682. AS_COMMA,
  1683. AS_COLON:
  1684. begin
  1685. break;
  1686. end;
  1687. AS_RPAREN:
  1688. begin
  1689. if not istypecast then
  1690. begin
  1691. Message(asmr_e_syn_operand);
  1692. Consume(AS_RPAREN);
  1693. end
  1694. else
  1695. break;
  1696. end;
  1697. else
  1698. begin
  1699. Message(asmr_e_syn_operand);
  1700. RecoverConsume(true);
  1701. break;
  1702. end;
  1703. end;
  1704. until false;
  1705. { End of operand, update size if a typecast is forced }
  1706. if (oper.typesize<>0) and
  1707. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1708. oper.SetSize(oper.typesize,true);
  1709. end;
  1710. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  1711. var
  1712. PrefixOp,OverrideOp: tasmop;
  1713. operandnum : longint;
  1714. is_far_const:boolean;
  1715. i:byte;
  1716. begin
  1717. PrefixOp:=A_None;
  1718. OverrideOp:=A_None;
  1719. is_far_const:=false;
  1720. { prefix seg opcode / prefix opcode }
  1721. repeat
  1722. if is_prefix(actopcode) then
  1723. with instr do
  1724. begin
  1725. OpOrder:=op_intel;
  1726. PrefixOp:=ActOpcode;
  1727. opcode:=ActOpcode;
  1728. condition:=ActCondition;
  1729. opsize:=ActOpsize;
  1730. ConcatInstruction(curlist);
  1731. consume(AS_OPCODE);
  1732. end
  1733. else
  1734. if is_override(actopcode) then
  1735. with instr do
  1736. begin
  1737. OpOrder:=op_intel;
  1738. OverrideOp:=ActOpcode;
  1739. opcode:=ActOpcode;
  1740. condition:=ActCondition;
  1741. opsize:=ActOpsize;
  1742. ConcatInstruction(curlist);
  1743. consume(AS_OPCODE);
  1744. end
  1745. else
  1746. break;
  1747. { allow for newline after prefix or override }
  1748. while actasmtoken=AS_SEPARATOR do
  1749. consume(AS_SEPARATOR);
  1750. until (actasmtoken<>AS_OPCODE);
  1751. { opcode }
  1752. if (actasmtoken <> AS_OPCODE) then
  1753. begin
  1754. Message(asmr_e_invalid_or_missing_opcode);
  1755. RecoverConsume(false);
  1756. exit;
  1757. end;
  1758. { Fill the instr object with the current state }
  1759. with instr do
  1760. begin
  1761. OpOrder:=op_intel;
  1762. Opcode:=ActOpcode;
  1763. condition:=ActCondition;
  1764. opsize:=ActOpsize;
  1765. { Valid combination of prefix/override and instruction ? }
  1766. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1767. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1768. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1769. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1770. end;
  1771. { We are reading operands, so opcode will be an AS_ID }
  1772. operandnum:=1;
  1773. is_far_const:=false;
  1774. Consume(AS_OPCODE);
  1775. { Zero operand opcode ? }
  1776. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1777. begin
  1778. operandnum:=0;
  1779. exit;
  1780. end;
  1781. { Read Operands }
  1782. repeat
  1783. case actasmtoken of
  1784. { End of asm operands for this opcode }
  1785. AS_END,
  1786. AS_SEPARATOR :
  1787. break;
  1788. { Operand delimiter }
  1789. AS_COMMA :
  1790. begin
  1791. if operandnum > Max_Operands then
  1792. Message(asmr_e_too_many_operands)
  1793. else
  1794. Inc(operandnum);
  1795. Consume(AS_COMMA);
  1796. end;
  1797. {Far constant, i.e. jmp $0000:$11111111.}
  1798. AS_COLON:
  1799. begin
  1800. is_far_const:=true;
  1801. if operandnum>1 then
  1802. message(asmr_e_too_many_operands)
  1803. else
  1804. inc(operandnum);
  1805. consume(AS_COLON);
  1806. end;
  1807. { Type specifier }
  1808. AS_NEAR,
  1809. AS_FAR :
  1810. begin
  1811. if actasmtoken = AS_NEAR then
  1812. begin
  1813. Message(asmr_w_near_ignored);
  1814. instr.opsize:=S_NEAR;
  1815. end
  1816. else
  1817. begin
  1818. Message(asmr_w_far_ignored);
  1819. instr.opsize:=S_FAR;
  1820. end;
  1821. Consume(actasmtoken);
  1822. if actasmtoken=AS_PTR then
  1823. begin
  1824. Consume(AS_PTR);
  1825. instr.Operands[operandnum].InitRef;
  1826. end;
  1827. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1828. end;
  1829. else
  1830. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1831. end; { end case }
  1832. until false;
  1833. instr.ops:=operandnum;
  1834. { Check operands }
  1835. for i:=1 to operandnum do
  1836. begin
  1837. if is_far_const and
  1838. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  1839. message(asmr_e_expr_illegal)
  1840. else
  1841. if instr.operands[i].opr.typ=OPR_NONE then
  1842. Message(asmr_e_syntax_error);
  1843. end;
  1844. end;
  1845. Procedure tx86intreader.BuildConstant(constsize: byte);
  1846. var
  1847. asmsymtyp : tasmsymtype;
  1848. asmsym,
  1849. expr: string;
  1850. value : aint;
  1851. Begin
  1852. Repeat
  1853. Case actasmtoken of
  1854. AS_STRING:
  1855. Begin
  1856. { DD and DW cases }
  1857. if constsize <> 1 then
  1858. Begin
  1859. if Not PadZero(actasmpattern,constsize) then
  1860. Message(scan_f_string_exceeds_line);
  1861. end;
  1862. expr:=actasmpattern;
  1863. Consume(AS_STRING);
  1864. Case actasmtoken of
  1865. AS_COMMA:
  1866. Consume(AS_COMMA);
  1867. AS_END,
  1868. AS_SEPARATOR: ;
  1869. else
  1870. Message(asmr_e_invalid_string_expression);
  1871. end;
  1872. ConcatString(curlist,expr);
  1873. end;
  1874. AS_PLUS,
  1875. AS_MINUS,
  1876. AS_LPAREN,
  1877. AS_NOT,
  1878. AS_INTNUM,
  1879. AS_ID :
  1880. Begin
  1881. BuildConstSymbolExpression(false,false,value,asmsym,asmsymtyp);
  1882. if asmsym<>'' then
  1883. begin
  1884. if constsize<>sizeof(aint) then
  1885. Message1(asmr_w_const32bit_for_address,asmsym);
  1886. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  1887. end
  1888. else
  1889. ConcatConstant(curlist,value,constsize);
  1890. end;
  1891. AS_COMMA:
  1892. begin
  1893. Consume(AS_COMMA);
  1894. end;
  1895. AS_ALIGN,
  1896. AS_DB,
  1897. AS_DW,
  1898. AS_DD,
  1899. AS_OPCODE,
  1900. AS_END,
  1901. AS_SEPARATOR:
  1902. break;
  1903. else
  1904. begin
  1905. Message(asmr_e_syn_constant);
  1906. RecoverConsume(false);
  1907. end
  1908. end;
  1909. Until false;
  1910. end;
  1911. function tx86intreader.Assemble: tlinkedlist;
  1912. Var
  1913. hl : tasmlabel;
  1914. instr : Tx86Instruction;
  1915. Begin
  1916. Message1(asmr_d_start_reading,'intel');
  1917. inexpression:=FALSE;
  1918. firsttoken:=TRUE;
  1919. { sets up all opcode and register tables in uppercase
  1920. done in the construtor now
  1921. if not _asmsorted then
  1922. Begin
  1923. SetupTables;
  1924. _asmsorted:=TRUE;
  1925. end;
  1926. }
  1927. curlist:=TAsmList.Create;
  1928. { setup label linked list }
  1929. LocalLabelList:=TLocalLabelList.Create;
  1930. { start tokenizer }
  1931. c:=current_scanner.asmgetcharstart;
  1932. gettoken;
  1933. { main loop }
  1934. repeat
  1935. case actasmtoken of
  1936. AS_LLABEL:
  1937. Begin
  1938. if CreateLocalLabel(actasmpattern,hl,true) then
  1939. ConcatLabel(curlist,hl);
  1940. Consume(AS_LLABEL);
  1941. end;
  1942. AS_LABEL:
  1943. Begin
  1944. if SearchLabel(upper(actasmpattern),hl,true) then
  1945. ConcatLabel(curlist,hl)
  1946. else
  1947. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1948. Consume(AS_LABEL);
  1949. end;
  1950. AS_DW :
  1951. Begin
  1952. inexpression:=true;
  1953. Consume(AS_DW);
  1954. BuildConstant(2);
  1955. inexpression:=false;
  1956. end;
  1957. AS_DB :
  1958. Begin
  1959. inexpression:=true;
  1960. Consume(AS_DB);
  1961. BuildConstant(1);
  1962. inexpression:=false;
  1963. end;
  1964. AS_DD :
  1965. Begin
  1966. inexpression:=true;
  1967. Consume(AS_DD);
  1968. BuildConstant(4);
  1969. inexpression:=false;
  1970. end;
  1971. AS_ALIGN:
  1972. Begin
  1973. Consume(AS_ALIGN);
  1974. ConcatAlign(curlist,BuildConstExpression);
  1975. if actasmtoken<>AS_SEPARATOR then
  1976. Consume(AS_SEPARATOR);
  1977. end;
  1978. AS_OPCODE :
  1979. Begin
  1980. instr:=Tx86Instruction.Create(Tx86Operand);
  1981. BuildOpcode(instr);
  1982. with instr do
  1983. begin
  1984. { We need AT&T style operands }
  1985. Swapoperands;
  1986. { Must be done with args in ATT order }
  1987. CheckNonCommutativeOpcodes;
  1988. AddReferenceSizes;
  1989. SetInstructionOpsize;
  1990. CheckOperandSizes;
  1991. ConcatInstruction(curlist);
  1992. end;
  1993. instr.Free;
  1994. end;
  1995. AS_SEPARATOR :
  1996. Begin
  1997. Consume(AS_SEPARATOR);
  1998. end;
  1999. AS_END :
  2000. break; { end assembly block }
  2001. else
  2002. Begin
  2003. Message(asmr_e_syntax_error);
  2004. RecoverConsume(false);
  2005. end;
  2006. end; { end case }
  2007. until false;
  2008. { Check LocalLabelList }
  2009. LocalLabelList.CheckEmitted;
  2010. LocalLabelList.Free;
  2011. { Return the list in an asmnode }
  2012. assemble:=curlist;
  2013. Message1(asmr_d_finish_reading,'intel');
  2014. end;
  2015. end.