rax86int.pas 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  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_VMTOFFSET,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; var mangledname: string; needvmtofs: boolean);
  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[9];
  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','VMTOFFSET','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','vmtoffset','','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; var mangledname: string; needvmtofs: boolean);
  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,mangledname,needvmtofs) 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,mangledname : string;
  673. parenlevel : longint;
  674. l,k : aint;
  675. hasparen,
  676. errorflag,
  677. needvmtofs : boolean;
  678. prevtok : tasmtoken;
  679. hl : tasmlabel;
  680. hssymtyp : Tasmsymtype;
  681. def : tdef;
  682. sym : tsym;
  683. srsymtable : TSymtable;
  684. Begin
  685. { reset }
  686. value:=0;
  687. asmsym:='';
  688. asmsymtyp:=AT_DATA;
  689. errorflag:=FALSE;
  690. tempstr:='';
  691. expr:='';
  692. inexpression:=TRUE;
  693. parenlevel:=0;
  694. sym:=nil;
  695. needvmtofs:=FALSE;
  696. Repeat
  697. { Support ugly delphi constructs like: [ECX].1+2[EDX] }
  698. if isref and (actasmtoken=AS_LBRACKET) then
  699. break;
  700. Case actasmtoken of
  701. AS_LPAREN:
  702. Begin
  703. Consume(AS_LPAREN);
  704. expr:=expr + '(';
  705. inc(parenlevel);
  706. end;
  707. AS_RPAREN:
  708. Begin
  709. { Keep the AS_PAREN in actasmtoken, it is maybe a typecast }
  710. if parenlevel=0 then
  711. break;
  712. Consume(AS_RPAREN);
  713. expr:=expr + ')';
  714. dec(parenlevel);
  715. end;
  716. AS_SHL:
  717. Begin
  718. Consume(AS_SHL);
  719. expr:=expr + '<';
  720. end;
  721. AS_SHR:
  722. Begin
  723. Consume(AS_SHR);
  724. expr:=expr + '>';
  725. end;
  726. AS_SLASH:
  727. Begin
  728. Consume(AS_SLASH);
  729. expr:=expr + '/';
  730. end;
  731. AS_MOD:
  732. Begin
  733. Consume(AS_MOD);
  734. expr:=expr + '%';
  735. end;
  736. AS_STAR:
  737. Begin
  738. Consume(AS_STAR);
  739. if isref and (actasmtoken=AS_REGISTER) then
  740. break;
  741. expr:=expr + '*';
  742. end;
  743. AS_PLUS:
  744. Begin
  745. Consume(AS_PLUS);
  746. if isref and (actasmtoken=AS_REGISTER) then
  747. break;
  748. expr:=expr + '+';
  749. end;
  750. AS_MINUS:
  751. Begin
  752. Consume(AS_MINUS);
  753. expr:=expr + '-';
  754. end;
  755. AS_AND:
  756. Begin
  757. Consume(AS_AND);
  758. expr:=expr + '&';
  759. end;
  760. AS_NOT:
  761. Begin
  762. Consume(AS_NOT);
  763. expr:=expr + '~';
  764. end;
  765. AS_XOR:
  766. Begin
  767. Consume(AS_XOR);
  768. expr:=expr + '^';
  769. end;
  770. AS_OR:
  771. Begin
  772. Consume(AS_OR);
  773. expr:=expr + '|';
  774. end;
  775. AS_INTNUM:
  776. Begin
  777. expr:=expr + actasmpattern;
  778. Consume(AS_INTNUM);
  779. end;
  780. AS_VMTOFFSET,
  781. AS_OFFSET:
  782. begin
  783. if (actasmtoken = AS_OFFSET) then
  784. needofs:=true
  785. else
  786. needvmtofs:=true;
  787. Consume(actasmtoken);
  788. if actasmtoken<>AS_ID then
  789. Message(asmr_e_offset_without_identifier);
  790. end;
  791. AS_SIZEOF,
  792. AS_TYPE:
  793. begin
  794. l:=0;
  795. hasparen:=false;
  796. Consume(actasmtoken);
  797. if actasmtoken=AS_LPAREN then
  798. begin
  799. hasparen:=true;
  800. Consume(AS_LPAREN);
  801. end;
  802. if actasmtoken<>AS_ID then
  803. Message(asmr_e_type_without_identifier)
  804. else
  805. begin
  806. tempstr:=actasmpattern;
  807. Consume(AS_ID);
  808. if actasmtoken=AS_DOT then
  809. begin
  810. BuildRecordOffsetSize(tempstr,k,l,mangledname,false);
  811. if mangledname<>'' then
  812. { procsym }
  813. Message(asmr_e_wrong_sym_type);
  814. end
  815. else
  816. begin
  817. searchsym(tempstr,sym,srsymtable);
  818. if assigned(sym) then
  819. begin
  820. case sym.typ of
  821. staticvarsym,
  822. localvarsym,
  823. paravarsym :
  824. l:=tabstractvarsym(sym).getsize;
  825. typesym :
  826. l:=ttypesym(sym).typedef.size;
  827. else
  828. Message(asmr_e_wrong_sym_type);
  829. end;
  830. end
  831. else
  832. Message1(sym_e_unknown_id,tempstr);
  833. end;
  834. end;
  835. str(l, tempstr);
  836. expr:=expr + tempstr;
  837. if hasparen then
  838. Consume(AS_RPAREN);
  839. end;
  840. AS_PTR :
  841. begin
  842. { Support ugly delphi constructs like <constant> PTR [ref] }
  843. break;
  844. end;
  845. AS_STRING:
  846. begin
  847. l:=0;
  848. case Length(actasmpattern) of
  849. 1 :
  850. l:=ord(actasmpattern[1]);
  851. 2 :
  852. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  853. 3 :
  854. l:=ord(actasmpattern[3]) +
  855. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  856. 4 :
  857. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  858. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  859. else
  860. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  861. end;
  862. str(l, tempstr);
  863. expr:=expr + tempstr;
  864. Consume(AS_STRING);
  865. end;
  866. AS_ID:
  867. begin
  868. hs:='';
  869. hssymtyp:=AT_DATA;
  870. def:=nil;
  871. tempstr:=actasmpattern;
  872. prevtok:=prevasmtoken;
  873. { stop parsing a constant expression if we find an opcode after a
  874. non-operator like "db $66 mov eax,ebx" }
  875. if (prevtok in [AS_ID,AS_INTNUM,AS_RPAREN]) and
  876. is_asmopcode(actasmpattern) then
  877. break;
  878. consume(AS_ID);
  879. if SearchIConstant(tempstr,l) then
  880. begin
  881. str(l, tempstr);
  882. expr:=expr + tempstr;
  883. end
  884. else
  885. begin
  886. if is_locallabel(tempstr) then
  887. begin
  888. CreateLocalLabel(tempstr,hl,false);
  889. hs:=hl.name;
  890. hssymtyp:=AT_FUNCTION;
  891. end
  892. else
  893. if SearchLabel(tempstr,hl,false) then
  894. begin
  895. hs:=hl.name;
  896. hssymtyp:=AT_FUNCTION;
  897. end
  898. else
  899. begin
  900. searchsym(tempstr,sym,srsymtable);
  901. if assigned(sym) then
  902. begin
  903. case sym.typ of
  904. staticvarsym :
  905. begin
  906. hs:=tstaticvarsym(sym).mangledname;
  907. def:=tstaticvarsym(sym).vardef;
  908. end;
  909. localvarsym,
  910. paravarsym :
  911. begin
  912. Message(asmr_e_no_local_or_para_allowed);
  913. end;
  914. procsym :
  915. begin
  916. if Tprocsym(sym).ProcdefList.Count>1 then
  917. Message(asmr_w_calling_overload_func);
  918. hs:=tprocdef(tprocsym(sym).ProcdefList[0]).mangledname;
  919. hssymtyp:=AT_FUNCTION;
  920. end;
  921. typesym :
  922. begin
  923. if not(ttypesym(sym).typedef.typ in [recorddef,objectdef]) then
  924. Message(asmr_e_wrong_sym_type);
  925. end;
  926. fieldvarsym :
  927. begin
  928. tempstr:=upper(tdef(sym.owner.defowner).GetTypeName)+'.'+tempstr;
  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) or
  963. (assigned(sym) and
  964. (sym.typ = fieldvarsym)) then
  965. begin
  966. BuildRecordOffsetSize(tempstr,l,k,hs,needvmtofs);
  967. if hs <> '' then
  968. hssymtyp:=AT_FUNCTION
  969. else
  970. begin
  971. str(l, tempstr);
  972. expr:=expr + tempstr;
  973. end
  974. end
  975. else
  976. begin
  977. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  978. delete(expr,length(expr),1);
  979. end;
  980. if (actasmtoken=AS_LBRACKET) and
  981. assigned(def) and
  982. (def.typ=arraydef) then
  983. begin
  984. consume(AS_LBRACKET);
  985. l:=BuildConstExpression;
  986. if l<tarraydef(def).lowrange then
  987. begin
  988. Message(asmr_e_constant_out_of_bounds);
  989. l:=0;
  990. end
  991. else
  992. l:=(l-tarraydef(def).lowrange)*tarraydef(def).elesize;
  993. str(l, tempstr);
  994. expr:=expr + '+' + tempstr;
  995. consume(AS_RBRACKET);
  996. end;
  997. end;
  998. { check if there are wrong operator used like / or mod etc. }
  999. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_END,AS_RBRACKET]) then
  1000. Message(asmr_e_only_add_relocatable_symbol);
  1001. end;
  1002. AS_ALIGN,
  1003. AS_DB,
  1004. AS_DW,
  1005. AS_DD,
  1006. AS_END,
  1007. AS_RBRACKET,
  1008. AS_SEPARATOR,
  1009. AS_COMMA,
  1010. AS_COLON:
  1011. break;
  1012. else
  1013. begin
  1014. { write error only once. }
  1015. if not errorflag then
  1016. Message(asmr_e_invalid_constant_expression);
  1017. { consume tokens until we find COMMA or SEPARATOR }
  1018. Consume(actasmtoken);
  1019. errorflag:=TRUE;
  1020. end;
  1021. end;
  1022. Until false;
  1023. { calculate expression }
  1024. if not ErrorFlag then
  1025. value:=CalculateExpression(expr)
  1026. else
  1027. value:=0;
  1028. { no longer in an expression }
  1029. inexpression:=FALSE;
  1030. end;
  1031. Function tx86intreader.BuildConstExpression:aint;
  1032. var
  1033. l : aint;
  1034. hs : string;
  1035. hssymtyp : TAsmsymtype;
  1036. begin
  1037. BuildConstSymbolExpression(false,false,l,hs,hssymtyp);
  1038. if hs<>'' then
  1039. Message(asmr_e_relocatable_symbol_not_allowed);
  1040. BuildConstExpression:=l;
  1041. end;
  1042. Function tx86intreader.BuildRefConstExpression:aint;
  1043. var
  1044. l : aint;
  1045. hs : string;
  1046. hssymtyp : TAsmsymtype;
  1047. begin
  1048. BuildConstSymbolExpression(false,true,l,hs,hssymtyp);
  1049. if hs<>'' then
  1050. Message(asmr_e_relocatable_symbol_not_allowed);
  1051. BuildRefConstExpression:=l;
  1052. end;
  1053. procedure tx86intreader.BuildReference(oper : tx86operand);
  1054. var
  1055. scale : byte;
  1056. k,l : aint;
  1057. tempstr,hs : string;
  1058. tempsymtyp : tasmsymtype;
  1059. code : integer;
  1060. hreg : tregister;
  1061. GotStar,GotOffset,HadVar,
  1062. GotPlus,Negative : boolean;
  1063. hl : tasmlabel;
  1064. Begin
  1065. Consume(AS_LBRACKET);
  1066. if not(oper.opr.typ in [OPR_LOCAL,OPR_REFERENCE]) then
  1067. oper.InitRef;
  1068. GotStar:=false;
  1069. GotPlus:=true;
  1070. GotOffset:=false;
  1071. Negative:=false;
  1072. Scale:=0;
  1073. repeat
  1074. if GotOffset and (actasmtoken<>AS_ID) then
  1075. Message(asmr_e_invalid_reference_syntax);
  1076. Case actasmtoken of
  1077. AS_ID, { Constant reference expression OR variable reference expression }
  1078. AS_VMTOFFSET:
  1079. Begin
  1080. if not GotPlus then
  1081. Message(asmr_e_invalid_reference_syntax);
  1082. GotStar:=false;
  1083. GotPlus:=false;
  1084. if (actasmtoken = AS_VMTOFFSET) or
  1085. (SearchIConstant(actasmpattern,l) or
  1086. SearchRecordType(actasmpattern)) then
  1087. begin
  1088. l:=BuildRefConstExpression;
  1089. GotPlus:=(prevasmtoken=AS_PLUS);
  1090. GotStar:=(prevasmtoken=AS_STAR);
  1091. case oper.opr.typ of
  1092. OPR_LOCAL :
  1093. begin
  1094. if GotStar then
  1095. Message(asmr_e_invalid_reference_syntax);
  1096. if negative then
  1097. Dec(oper.opr.localsymofs,l)
  1098. else
  1099. Inc(oper.opr.localsymofs,l);
  1100. end;
  1101. OPR_REFERENCE :
  1102. begin
  1103. if GotStar then
  1104. oper.opr.ref.scalefactor:=l
  1105. else
  1106. begin
  1107. if negative then
  1108. Dec(oper.opr.ref.offset,l)
  1109. else
  1110. Inc(oper.opr.ref.offset,l);
  1111. end;
  1112. end;
  1113. end;
  1114. end
  1115. else
  1116. Begin
  1117. if oper.hasvar and not GotOffset then
  1118. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1119. HadVar:=oper.hasvar and GotOffset;
  1120. if negative then
  1121. Message(asmr_e_only_add_relocatable_symbol);
  1122. tempstr:=actasmpattern;
  1123. Consume(AS_ID);
  1124. { typecasting? }
  1125. if (actasmtoken=AS_LPAREN) and
  1126. SearchType(tempstr,l) then
  1127. begin
  1128. oper.hastype:=true;
  1129. oper.typesize:=l;
  1130. Consume(AS_LPAREN);
  1131. BuildOperand(oper,true);
  1132. Consume(AS_RPAREN);
  1133. end
  1134. else
  1135. if is_locallabel(tempstr) then
  1136. begin
  1137. CreateLocalLabel(tempstr,hl,false);
  1138. oper.InitRef;
  1139. oper.opr.ref.symbol:=hl;
  1140. oper.hasvar:=true;
  1141. end
  1142. else
  1143. if oper.SetupVar(tempstr,GotOffset) then
  1144. begin
  1145. { force OPR_LOCAL to be a reference }
  1146. if oper.opr.typ=OPR_LOCAL then
  1147. oper.opr.localforceref:=true;
  1148. end
  1149. else
  1150. Message1(sym_e_unknown_id,tempstr);
  1151. { record.field ? }
  1152. if actasmtoken=AS_DOT then
  1153. begin
  1154. BuildRecordOffsetSize(tempstr,l,k,hs,false);
  1155. if (hs<>'') then
  1156. Message(asmr_e_invalid_symbol_ref);
  1157. case oper.opr.typ of
  1158. OPR_LOCAL :
  1159. inc(oper.opr.localsymofs,l);
  1160. OPR_REFERENCE :
  1161. inc(oper.opr.ref.offset,l);
  1162. end;
  1163. end;
  1164. if GotOffset then
  1165. begin
  1166. if oper.hasvar and (oper.opr.ref.base=current_procinfo.framepointer) then
  1167. begin
  1168. if (oper.opr.typ=OPR_REFERENCE) then
  1169. oper.opr.ref.base:=NR_NO;
  1170. oper.hasvar:=hadvar;
  1171. end
  1172. else
  1173. begin
  1174. if oper.hasvar and hadvar then
  1175. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1176. { should we allow ?? }
  1177. end;
  1178. end;
  1179. end;
  1180. GotOffset:=false;
  1181. end;
  1182. AS_PLUS :
  1183. Begin
  1184. Consume(AS_PLUS);
  1185. Negative:=false;
  1186. GotPlus:=true;
  1187. GotStar:=false;
  1188. Scale:=0;
  1189. end;
  1190. AS_DOT :
  1191. Begin
  1192. { Handle like a + }
  1193. Consume(AS_DOT);
  1194. Negative:=false;
  1195. GotPlus:=true;
  1196. GotStar:=false;
  1197. Scale:=0;
  1198. end;
  1199. AS_MINUS :
  1200. begin
  1201. Consume(AS_MINUS);
  1202. Negative:=true;
  1203. GotPlus:=true;
  1204. GotStar:=false;
  1205. Scale:=0;
  1206. end;
  1207. AS_STAR : { Scaling, with eax*4 order }
  1208. begin
  1209. Consume(AS_STAR);
  1210. hs:='';
  1211. l:=0;
  1212. case actasmtoken of
  1213. AS_LPAREN :
  1214. l:=BuildConstExpression;
  1215. AS_INTNUM:
  1216. Begin
  1217. hs:=actasmpattern;
  1218. Consume(AS_INTNUM);
  1219. end;
  1220. AS_REGISTER :
  1221. begin
  1222. case oper.opr.typ of
  1223. OPR_REFERENCE :
  1224. begin
  1225. if oper.opr.ref.scalefactor=0 then
  1226. begin
  1227. if scale<>0 then
  1228. begin
  1229. oper.opr.ref.scalefactor:=scale;
  1230. scale:=0;
  1231. end
  1232. else
  1233. Message(asmr_e_wrong_scale_factor);
  1234. end
  1235. else
  1236. Message(asmr_e_invalid_reference_syntax);
  1237. end;
  1238. OPR_LOCAL :
  1239. begin
  1240. if oper.opr.localscale=0 then
  1241. begin
  1242. if scale<>0 then
  1243. begin
  1244. oper.opr.localscale:=scale;
  1245. scale:=0;
  1246. end
  1247. else
  1248. Message(asmr_e_wrong_scale_factor);
  1249. end
  1250. else
  1251. Message(asmr_e_invalid_reference_syntax);
  1252. end;
  1253. end;
  1254. end;
  1255. else
  1256. Message(asmr_e_invalid_reference_syntax);
  1257. end;
  1258. if actasmtoken<>AS_REGISTER then
  1259. begin
  1260. if hs<>'' then
  1261. val(hs,l,code);
  1262. case oper.opr.typ of
  1263. OPR_REFERENCE :
  1264. oper.opr.ref.scalefactor:=l;
  1265. OPR_LOCAL :
  1266. oper.opr.localscale:=l;
  1267. end;
  1268. if l>9 then
  1269. Message(asmr_e_wrong_scale_factor);
  1270. end;
  1271. GotPlus:=false;
  1272. GotStar:=false;
  1273. end;
  1274. AS_REGISTER :
  1275. begin
  1276. if not((GotPlus and (not Negative)) or
  1277. GotStar) then
  1278. Message(asmr_e_invalid_reference_syntax);
  1279. hreg:=actasmregister;
  1280. Consume(AS_REGISTER);
  1281. { this register will be the index:
  1282. 1. just read a *
  1283. 2. next token is a *
  1284. 3. base register is already used }
  1285. case oper.opr.typ of
  1286. OPR_LOCAL :
  1287. begin
  1288. if (oper.opr.localindexreg<>NR_NO) then
  1289. Message(asmr_e_multiple_index);
  1290. oper.opr.localindexreg:=hreg;
  1291. if scale<>0 then
  1292. begin
  1293. oper.opr.localscale:=scale;
  1294. scale:=0;
  1295. end;
  1296. end;
  1297. OPR_REFERENCE :
  1298. begin
  1299. if (GotStar) or
  1300. (actasmtoken=AS_STAR) or
  1301. (oper.opr.ref.base<>NR_NO) then
  1302. begin
  1303. if (oper.opr.ref.index<>NR_NO) then
  1304. Message(asmr_e_multiple_index);
  1305. oper.opr.ref.index:=hreg;
  1306. if scale<>0 then
  1307. begin
  1308. oper.opr.ref.scalefactor:=scale;
  1309. scale:=0;
  1310. end;
  1311. end
  1312. else
  1313. oper.opr.ref.base:=hreg;
  1314. end;
  1315. end;
  1316. GotPlus:=false;
  1317. GotStar:=false;
  1318. end;
  1319. AS_OFFSET :
  1320. begin
  1321. Consume(AS_OFFSET);
  1322. GotOffset:=true;
  1323. end;
  1324. AS_TYPE,
  1325. AS_NOT,
  1326. AS_STRING,
  1327. AS_INTNUM,
  1328. AS_LPAREN : { Constant reference expression }
  1329. begin
  1330. if not GotPlus and not GotStar then
  1331. Message(asmr_e_invalid_reference_syntax);
  1332. BuildConstSymbolExpression(true,true,l,tempstr,tempsymtyp);
  1333. if tempstr<>'' then
  1334. begin
  1335. if GotStar then
  1336. Message(asmr_e_only_add_relocatable_symbol);
  1337. if not assigned(oper.opr.ref.symbol) then
  1338. oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr)
  1339. else
  1340. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1341. end;
  1342. case oper.opr.typ of
  1343. OPR_REFERENCE :
  1344. begin
  1345. if GotStar then
  1346. oper.opr.ref.scalefactor:=l
  1347. else if (prevasmtoken = AS_STAR) then
  1348. begin
  1349. if scale<>0 then
  1350. scale:=l*scale
  1351. else
  1352. scale:=l;
  1353. end
  1354. else
  1355. begin
  1356. if negative then
  1357. Dec(oper.opr.ref.offset,l)
  1358. else
  1359. Inc(oper.opr.ref.offset,l);
  1360. end;
  1361. end;
  1362. OPR_LOCAL :
  1363. begin
  1364. if GotStar then
  1365. oper.opr.localscale:=l
  1366. else if (prevasmtoken = AS_STAR) then
  1367. begin
  1368. if scale<>0 then
  1369. scale:=l*scale
  1370. else
  1371. scale:=l;
  1372. end
  1373. else
  1374. begin
  1375. if negative then
  1376. Dec(oper.opr.localsymofs,l)
  1377. else
  1378. Inc(oper.opr.localsymofs,l);
  1379. end;
  1380. end;
  1381. end;
  1382. GotPlus:=(prevasmtoken=AS_PLUS) or
  1383. (prevasmtoken=AS_MINUS);
  1384. if GotPlus then
  1385. negative := prevasmtoken = AS_MINUS;
  1386. GotStar:=(prevasmtoken=AS_STAR);
  1387. end;
  1388. AS_RBRACKET :
  1389. begin
  1390. if GotPlus or GotStar then
  1391. Message(asmr_e_invalid_reference_syntax);
  1392. Consume(AS_RBRACKET);
  1393. break;
  1394. end;
  1395. else
  1396. Begin
  1397. Message(asmr_e_invalid_reference_syntax);
  1398. RecoverConsume(true);
  1399. break;
  1400. end;
  1401. end;
  1402. until false;
  1403. end;
  1404. Procedure tx86intreader.BuildConstantOperand(oper: tx86operand);
  1405. var
  1406. l : aint;
  1407. tempstr : string;
  1408. tempsymtyp : tasmsymtype;
  1409. begin
  1410. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1411. Message(asmr_e_invalid_operand_type);
  1412. BuildConstSymbolExpression(true,false,l,tempstr,tempsymtyp);
  1413. if tempstr<>'' then
  1414. begin
  1415. oper.opr.typ:=OPR_SYMBOL;
  1416. oper.opr.symofs:=l;
  1417. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr);
  1418. end
  1419. else
  1420. if oper.opr.typ=OPR_NONE then
  1421. begin
  1422. oper.opr.typ:=OPR_CONSTANT;
  1423. oper.opr.val:=l;
  1424. end
  1425. else
  1426. inc(oper.opr.val,l);
  1427. end;
  1428. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1429. procedure AddLabelOperand(hl:tasmlabel);
  1430. begin
  1431. if (oper.opr.typ=OPR_NONE) and
  1432. is_calljmp(actopcode) then
  1433. begin
  1434. oper.opr.typ:=OPR_SYMBOL;
  1435. oper.opr.symbol:=hl;
  1436. end
  1437. else
  1438. begin
  1439. oper.InitRef;
  1440. oper.opr.ref.symbol:=hl;
  1441. end;
  1442. end;
  1443. var
  1444. expr,
  1445. hs : string;
  1446. tempreg : tregister;
  1447. l : aint;
  1448. hl : tasmlabel;
  1449. toffset,
  1450. tsize : aint;
  1451. begin
  1452. expr:='';
  1453. repeat
  1454. if actasmtoken=AS_DOT then
  1455. begin
  1456. if expr<>'' then
  1457. begin
  1458. BuildRecordOffsetSize(expr,toffset,tsize,hs,false);
  1459. if (oper.opr.typ<>OPR_NONE) and
  1460. (hs<>'') then
  1461. Message(asmr_e_wrong_sym_type);
  1462. oper.SetSize(tsize,true);
  1463. { we have used the size of a field. Reset the typesize of the record }
  1464. oper.typesize:=0;
  1465. case oper.opr.typ of
  1466. OPR_LOCAL :
  1467. begin
  1468. { don't allow direct access to fields of parameters, becuase that
  1469. will generate buggy code. Allow it only for explicit typecasting
  1470. and when the parameter is in a register (delphi compatible) }
  1471. if (not oper.hastype) and
  1472. (oper.opr.localsym.owner.symtabletype=parasymtable) and
  1473. (current_procinfo.procdef.proccalloption<>pocall_register) then
  1474. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1475. inc(oper.opr.localsymofs,toffset)
  1476. end;
  1477. OPR_CONSTANT :
  1478. inc(oper.opr.val,toffset);
  1479. OPR_REFERENCE :
  1480. inc(oper.opr.ref.offset,toffset);
  1481. OPR_NONE :
  1482. begin
  1483. if (hs <> '') then
  1484. begin
  1485. oper.opr.typ:=OPR_SYMBOL;
  1486. oper.opr.symbol:=current_asmdata.RefAsmSymbol(hs);
  1487. end
  1488. else
  1489. begin
  1490. oper.opr.typ:=OPR_CONSTANT;
  1491. oper.opr.val:=toffset;
  1492. end;
  1493. end;
  1494. OPR_SYMBOL:
  1495. Message(asmr_e_invalid_symbol_ref);
  1496. else
  1497. internalerror(200309222);
  1498. end;
  1499. expr:='';
  1500. end
  1501. else
  1502. begin
  1503. { See it as a separator }
  1504. Consume(AS_DOT);
  1505. end;
  1506. end;
  1507. case actasmtoken of
  1508. AS_OFFSET,
  1509. AS_SIZEOF,
  1510. AS_VMTOFFSET,
  1511. AS_TYPE,
  1512. AS_NOT,
  1513. AS_STRING,
  1514. AS_PLUS,
  1515. AS_MINUS,
  1516. AS_LPAREN,
  1517. AS_INTNUM :
  1518. begin
  1519. case oper.opr.typ of
  1520. OPR_REFERENCE :
  1521. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1522. OPR_LOCAL :
  1523. inc(oper.opr.localsymofs,BuildConstExpression);
  1524. OPR_NONE,
  1525. OPR_CONSTANT :
  1526. BuildConstantOperand(oper);
  1527. else
  1528. Message(asmr_e_invalid_operand_type);
  1529. end;
  1530. end;
  1531. AS_PTR :
  1532. begin
  1533. if not oper.hastype then
  1534. begin
  1535. if (oper.opr.typ=OPR_CONSTANT) then
  1536. begin
  1537. oper.typesize:=oper.opr.val;
  1538. { reset constant value of operand }
  1539. oper.opr.typ:=OPR_NONE;
  1540. oper.opr.val:=0;
  1541. end
  1542. else
  1543. Message(asmr_e_syn_operand);
  1544. end;
  1545. Consume(AS_PTR);
  1546. oper.InitRef;
  1547. BuildOperand(oper,false);
  1548. end;
  1549. AS_ID : { A constant expression, or a Variable ref. }
  1550. Begin
  1551. { Label or Special symbol reference? }
  1552. if actasmpattern[1] = '@' then
  1553. Begin
  1554. if actasmpattern = '@RESULT' then
  1555. Begin
  1556. oper.SetupResult;
  1557. Consume(AS_ID);
  1558. end
  1559. else
  1560. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1561. begin
  1562. Message(asmr_w_CODE_and_DATA_not_supported);
  1563. Consume(AS_ID);
  1564. end
  1565. else
  1566. { Local Label }
  1567. begin
  1568. CreateLocalLabel(actasmpattern,hl,false);
  1569. Consume(AS_ID);
  1570. AddLabelOperand(hl);
  1571. end;
  1572. end
  1573. else
  1574. { support result for delphi modes }
  1575. if (m_objpas in current_settings.modeswitches) and (actasmpattern='RESULT') then
  1576. begin
  1577. oper.SetUpResult;
  1578. Consume(AS_ID);
  1579. end
  1580. { probably a variable or normal expression }
  1581. { or a procedure (such as in CALL ID) }
  1582. else
  1583. Begin
  1584. { is it a constant ? }
  1585. if SearchIConstant(actasmpattern,l) then
  1586. Begin
  1587. case oper.opr.typ of
  1588. OPR_REFERENCE :
  1589. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1590. OPR_LOCAL :
  1591. inc(oper.opr.localsymofs,BuildRefConstExpression);
  1592. OPR_NONE,
  1593. OPR_CONSTANT :
  1594. BuildConstantOperand(oper);
  1595. else
  1596. Message(asmr_e_invalid_operand_type);
  1597. end;
  1598. end
  1599. else
  1600. { Check for pascal label }
  1601. if SearchLabel(actasmpattern,hl,false) then
  1602. begin
  1603. Consume(AS_ID);
  1604. AddLabelOperand(hl);
  1605. end
  1606. else
  1607. { is it a normal variable ? }
  1608. Begin
  1609. expr:=actasmpattern;
  1610. Consume(AS_ID);
  1611. { typecasting? }
  1612. if SearchType(expr,l) then
  1613. begin
  1614. oper.hastype:=true;
  1615. oper.typesize:=l;
  1616. case actasmtoken of
  1617. AS_LPAREN :
  1618. begin
  1619. { Support Type([Reference]) }
  1620. Consume(AS_LPAREN);
  1621. BuildOperand(oper,true);
  1622. Consume(AS_RPAREN);
  1623. end;
  1624. AS_LBRACKET :
  1625. begin
  1626. { Support Var.Type[Index] }
  1627. { Convert @label.Byte[1] to reference }
  1628. if oper.opr.typ=OPR_SYMBOL then
  1629. oper.initref;
  1630. end;
  1631. end;
  1632. end
  1633. else
  1634. begin
  1635. if not oper.SetupVar(expr,false) then
  1636. Begin
  1637. { not a variable, check special variables.. }
  1638. if expr = 'SELF' then
  1639. oper.SetupSelf
  1640. else
  1641. Message1(sym_e_unknown_id,expr);
  1642. expr:='';
  1643. end;
  1644. end;
  1645. end;
  1646. end;
  1647. end;
  1648. AS_REGISTER : { Register, a variable reference or a constant reference }
  1649. begin
  1650. { save the type of register used. }
  1651. tempreg:=actasmregister;
  1652. Consume(AS_REGISTER);
  1653. if actasmtoken = AS_COLON then
  1654. Begin
  1655. Consume(AS_COLON);
  1656. oper.InitRef;
  1657. oper.opr.ref.segment:=tempreg;
  1658. BuildReference(oper);
  1659. end
  1660. else
  1661. { Simple register }
  1662. begin
  1663. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1664. Message(asmr_e_invalid_operand_type);
  1665. oper.opr.typ:=OPR_REGISTER;
  1666. oper.opr.reg:=tempreg;
  1667. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1668. end;
  1669. end;
  1670. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1671. Begin
  1672. BuildReference(oper);
  1673. end;
  1674. AS_SEG :
  1675. Begin
  1676. Message(asmr_e_seg_not_supported);
  1677. Consume(actasmtoken);
  1678. end;
  1679. AS_DWORD,
  1680. AS_BYTE,
  1681. AS_WORD,
  1682. AS_TBYTE,
  1683. AS_DQWORD,
  1684. AS_QWORD :
  1685. begin
  1686. { Type specifier }
  1687. oper.hastype:=true;
  1688. oper.typesize:=0;
  1689. case actasmtoken of
  1690. AS_DWORD : oper.typesize:=4;
  1691. AS_WORD : oper.typesize:=2;
  1692. AS_BYTE : oper.typesize:=1;
  1693. AS_QWORD : oper.typesize:=8;
  1694. AS_DQWORD : oper.typesize:=16;
  1695. AS_TBYTE : oper.typesize:=10;
  1696. end;
  1697. Consume(actasmtoken);
  1698. if (actasmtoken=AS_LPAREN) then
  1699. begin
  1700. { Support Type([Reference]) }
  1701. Consume(AS_LPAREN);
  1702. BuildOperand(oper,true);
  1703. Consume(AS_RPAREN);
  1704. end;
  1705. end;
  1706. AS_SEPARATOR,
  1707. AS_END,
  1708. AS_COMMA,
  1709. AS_COLON:
  1710. begin
  1711. break;
  1712. end;
  1713. AS_RPAREN:
  1714. begin
  1715. if not istypecast then
  1716. begin
  1717. Message(asmr_e_syn_operand);
  1718. Consume(AS_RPAREN);
  1719. end
  1720. else
  1721. break;
  1722. end;
  1723. else
  1724. begin
  1725. Message(asmr_e_syn_operand);
  1726. RecoverConsume(true);
  1727. break;
  1728. end;
  1729. end;
  1730. until false;
  1731. { End of operand, update size if a typecast is forced }
  1732. if (oper.typesize<>0) and
  1733. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1734. oper.SetSize(oper.typesize,true);
  1735. end;
  1736. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  1737. var
  1738. PrefixOp,OverrideOp: tasmop;
  1739. operandnum : longint;
  1740. is_far_const:boolean;
  1741. i:byte;
  1742. begin
  1743. PrefixOp:=A_None;
  1744. OverrideOp:=A_None;
  1745. is_far_const:=false;
  1746. { prefix seg opcode / prefix opcode }
  1747. repeat
  1748. if is_prefix(actopcode) then
  1749. with instr do
  1750. begin
  1751. OpOrder:=op_intel;
  1752. PrefixOp:=ActOpcode;
  1753. opcode:=ActOpcode;
  1754. condition:=ActCondition;
  1755. opsize:=ActOpsize;
  1756. ConcatInstruction(curlist);
  1757. consume(AS_OPCODE);
  1758. end
  1759. else
  1760. if is_override(actopcode) then
  1761. with instr do
  1762. begin
  1763. OpOrder:=op_intel;
  1764. OverrideOp:=ActOpcode;
  1765. opcode:=ActOpcode;
  1766. condition:=ActCondition;
  1767. opsize:=ActOpsize;
  1768. ConcatInstruction(curlist);
  1769. consume(AS_OPCODE);
  1770. end
  1771. else
  1772. break;
  1773. { allow for newline after prefix or override }
  1774. while actasmtoken=AS_SEPARATOR do
  1775. consume(AS_SEPARATOR);
  1776. until (actasmtoken<>AS_OPCODE);
  1777. { opcode }
  1778. if (actasmtoken <> AS_OPCODE) then
  1779. begin
  1780. Message(asmr_e_invalid_or_missing_opcode);
  1781. RecoverConsume(false);
  1782. exit;
  1783. end;
  1784. { Fill the instr object with the current state }
  1785. with instr do
  1786. begin
  1787. OpOrder:=op_intel;
  1788. Opcode:=ActOpcode;
  1789. condition:=ActCondition;
  1790. opsize:=ActOpsize;
  1791. { Valid combination of prefix/override and instruction ? }
  1792. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1793. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1794. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1795. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1796. end;
  1797. { We are reading operands, so opcode will be an AS_ID }
  1798. operandnum:=1;
  1799. is_far_const:=false;
  1800. Consume(AS_OPCODE);
  1801. { Zero operand opcode ? }
  1802. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1803. begin
  1804. operandnum:=0;
  1805. exit;
  1806. end;
  1807. { Read Operands }
  1808. repeat
  1809. case actasmtoken of
  1810. { End of asm operands for this opcode }
  1811. AS_END,
  1812. AS_SEPARATOR :
  1813. break;
  1814. { Operand delimiter }
  1815. AS_COMMA :
  1816. begin
  1817. if operandnum > Max_Operands then
  1818. Message(asmr_e_too_many_operands)
  1819. else
  1820. Inc(operandnum);
  1821. Consume(AS_COMMA);
  1822. end;
  1823. {Far constant, i.e. jmp $0000:$11111111.}
  1824. AS_COLON:
  1825. begin
  1826. is_far_const:=true;
  1827. if operandnum>1 then
  1828. message(asmr_e_too_many_operands)
  1829. else
  1830. inc(operandnum);
  1831. consume(AS_COLON);
  1832. end;
  1833. { Type specifier }
  1834. AS_NEAR,
  1835. AS_FAR :
  1836. begin
  1837. if actasmtoken = AS_NEAR then
  1838. begin
  1839. Message(asmr_w_near_ignored);
  1840. instr.opsize:=S_NEAR;
  1841. end
  1842. else
  1843. begin
  1844. Message(asmr_w_far_ignored);
  1845. instr.opsize:=S_FAR;
  1846. end;
  1847. Consume(actasmtoken);
  1848. if actasmtoken=AS_PTR then
  1849. begin
  1850. Consume(AS_PTR);
  1851. instr.Operands[operandnum].InitRef;
  1852. end;
  1853. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1854. end;
  1855. else
  1856. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1857. end; { end case }
  1858. until false;
  1859. instr.ops:=operandnum;
  1860. { Check operands }
  1861. for i:=1 to operandnum do
  1862. begin
  1863. if is_far_const and
  1864. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  1865. message(asmr_e_expr_illegal)
  1866. else
  1867. if instr.operands[i].opr.typ=OPR_NONE then
  1868. Message(asmr_e_syntax_error);
  1869. end;
  1870. { e.g. for "push dword 1", "push word 6" }
  1871. if (instr.ops=1) and
  1872. (instr.operands[1].typesize<>0) then
  1873. instr.operands[1].setsize(instr.operands[1].typesize,false);
  1874. end;
  1875. Procedure tx86intreader.BuildConstant(constsize: byte);
  1876. var
  1877. asmsymtyp : tasmsymtype;
  1878. asmsym,
  1879. expr: string;
  1880. value : aint;
  1881. Begin
  1882. Repeat
  1883. Case actasmtoken of
  1884. AS_STRING:
  1885. Begin
  1886. { DD and DW cases }
  1887. if constsize <> 1 then
  1888. Begin
  1889. if Not PadZero(actasmpattern,constsize) then
  1890. Message(scan_f_string_exceeds_line);
  1891. end;
  1892. expr:=actasmpattern;
  1893. Consume(AS_STRING);
  1894. Case actasmtoken of
  1895. AS_COMMA:
  1896. Consume(AS_COMMA);
  1897. AS_END,
  1898. AS_SEPARATOR: ;
  1899. else
  1900. Message(asmr_e_invalid_string_expression);
  1901. end;
  1902. ConcatString(curlist,expr);
  1903. end;
  1904. AS_PLUS,
  1905. AS_MINUS,
  1906. AS_LPAREN,
  1907. AS_NOT,
  1908. AS_INTNUM,
  1909. AS_ID :
  1910. Begin
  1911. BuildConstSymbolExpression(false,false,value,asmsym,asmsymtyp);
  1912. if asmsym<>'' then
  1913. begin
  1914. if constsize<>sizeof(aint) then
  1915. Message1(asmr_w_const32bit_for_address,asmsym);
  1916. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  1917. end
  1918. else
  1919. ConcatConstant(curlist,value,constsize);
  1920. end;
  1921. AS_COMMA:
  1922. begin
  1923. Consume(AS_COMMA);
  1924. end;
  1925. AS_ALIGN,
  1926. AS_DB,
  1927. AS_DW,
  1928. AS_DD,
  1929. AS_OPCODE,
  1930. AS_END,
  1931. AS_SEPARATOR:
  1932. break;
  1933. else
  1934. begin
  1935. Message(asmr_e_syn_constant);
  1936. RecoverConsume(false);
  1937. end
  1938. end;
  1939. Until false;
  1940. end;
  1941. function tx86intreader.Assemble: tlinkedlist;
  1942. Var
  1943. hl : tasmlabel;
  1944. instr : Tx86Instruction;
  1945. Begin
  1946. Message1(asmr_d_start_reading,'intel');
  1947. inexpression:=FALSE;
  1948. firsttoken:=TRUE;
  1949. { sets up all opcode and register tables in uppercase
  1950. done in the construtor now
  1951. if not _asmsorted then
  1952. Begin
  1953. SetupTables;
  1954. _asmsorted:=TRUE;
  1955. end;
  1956. }
  1957. curlist:=TAsmList.Create;
  1958. { setup label linked list }
  1959. LocalLabelList:=TLocalLabelList.Create;
  1960. { start tokenizer }
  1961. c:=current_scanner.asmgetcharstart;
  1962. gettoken;
  1963. { main loop }
  1964. repeat
  1965. case actasmtoken of
  1966. AS_LLABEL:
  1967. Begin
  1968. if CreateLocalLabel(actasmpattern,hl,true) then
  1969. ConcatLabel(curlist,hl);
  1970. Consume(AS_LLABEL);
  1971. end;
  1972. AS_LABEL:
  1973. Begin
  1974. if SearchLabel(upper(actasmpattern),hl,true) then
  1975. ConcatLabel(curlist,hl)
  1976. else
  1977. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1978. Consume(AS_LABEL);
  1979. end;
  1980. AS_DW :
  1981. Begin
  1982. inexpression:=true;
  1983. Consume(AS_DW);
  1984. BuildConstant(2);
  1985. inexpression:=false;
  1986. end;
  1987. AS_DB :
  1988. Begin
  1989. inexpression:=true;
  1990. Consume(AS_DB);
  1991. BuildConstant(1);
  1992. inexpression:=false;
  1993. end;
  1994. AS_DD :
  1995. Begin
  1996. inexpression:=true;
  1997. Consume(AS_DD);
  1998. BuildConstant(4);
  1999. inexpression:=false;
  2000. end;
  2001. AS_ALIGN:
  2002. Begin
  2003. Consume(AS_ALIGN);
  2004. ConcatAlign(curlist,BuildConstExpression);
  2005. if actasmtoken<>AS_SEPARATOR then
  2006. Consume(AS_SEPARATOR);
  2007. end;
  2008. AS_OPCODE :
  2009. Begin
  2010. instr:=Tx86Instruction.Create(Tx86Operand);
  2011. BuildOpcode(instr);
  2012. with instr do
  2013. begin
  2014. { We need AT&T style operands }
  2015. Swapoperands;
  2016. { Must be done with args in ATT order }
  2017. CheckNonCommutativeOpcodes;
  2018. AddReferenceSizes;
  2019. SetInstructionOpsize;
  2020. CheckOperandSizes;
  2021. ConcatInstruction(curlist);
  2022. end;
  2023. instr.Free;
  2024. end;
  2025. AS_SEPARATOR :
  2026. Begin
  2027. Consume(AS_SEPARATOR);
  2028. end;
  2029. AS_END :
  2030. break; { end assembly block }
  2031. else
  2032. Begin
  2033. Message(asmr_e_syntax_error);
  2034. RecoverConsume(false);
  2035. end;
  2036. end; { end case }
  2037. until false;
  2038. { Check LocalLabelList }
  2039. LocalLabelList.CheckEmitted;
  2040. LocalLabelList.Free;
  2041. { Return the list in an asmnode }
  2042. assemble:=curlist;
  2043. Message1(asmr_d_finish_reading,'intel');
  2044. end;
  2045. end.