rax86int.pas 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123
  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_MINUS :
  1180. begin
  1181. Consume(AS_MINUS);
  1182. Negative:=true;
  1183. GotPlus:=true;
  1184. GotStar:=false;
  1185. Scale:=0;
  1186. end;
  1187. AS_STAR : { Scaling, with eax*4 order }
  1188. begin
  1189. Consume(AS_STAR);
  1190. hs:='';
  1191. l:=0;
  1192. case actasmtoken of
  1193. AS_LPAREN :
  1194. l:=BuildConstExpression;
  1195. AS_INTNUM:
  1196. Begin
  1197. hs:=actasmpattern;
  1198. Consume(AS_INTNUM);
  1199. end;
  1200. AS_REGISTER :
  1201. begin
  1202. case oper.opr.typ of
  1203. OPR_REFERENCE :
  1204. begin
  1205. if oper.opr.ref.scalefactor=0 then
  1206. begin
  1207. if scale<>0 then
  1208. begin
  1209. oper.opr.ref.scalefactor:=scale;
  1210. scale:=0;
  1211. end
  1212. else
  1213. Message(asmr_e_wrong_scale_factor);
  1214. end
  1215. else
  1216. Message(asmr_e_invalid_reference_syntax);
  1217. end;
  1218. OPR_LOCAL :
  1219. begin
  1220. if oper.opr.localscale=0 then
  1221. begin
  1222. if scale<>0 then
  1223. begin
  1224. oper.opr.localscale:=scale;
  1225. scale:=0;
  1226. end
  1227. else
  1228. Message(asmr_e_wrong_scale_factor);
  1229. end
  1230. else
  1231. Message(asmr_e_invalid_reference_syntax);
  1232. end;
  1233. end;
  1234. end;
  1235. else
  1236. Message(asmr_e_invalid_reference_syntax);
  1237. end;
  1238. if actasmtoken<>AS_REGISTER then
  1239. begin
  1240. if hs<>'' then
  1241. val(hs,l,code);
  1242. case oper.opr.typ of
  1243. OPR_REFERENCE :
  1244. oper.opr.ref.scalefactor:=l;
  1245. OPR_LOCAL :
  1246. oper.opr.localscale:=l;
  1247. end;
  1248. if l>9 then
  1249. Message(asmr_e_wrong_scale_factor);
  1250. end;
  1251. GotPlus:=false;
  1252. GotStar:=false;
  1253. end;
  1254. AS_REGISTER :
  1255. begin
  1256. if not((GotPlus and (not Negative)) or
  1257. GotStar) then
  1258. Message(asmr_e_invalid_reference_syntax);
  1259. hreg:=actasmregister;
  1260. Consume(AS_REGISTER);
  1261. { this register will be the index:
  1262. 1. just read a *
  1263. 2. next token is a *
  1264. 3. base register is already used }
  1265. case oper.opr.typ of
  1266. OPR_LOCAL :
  1267. begin
  1268. if (oper.opr.localindexreg<>NR_NO) then
  1269. Message(asmr_e_multiple_index);
  1270. oper.opr.localindexreg:=hreg;
  1271. if scale<>0 then
  1272. begin
  1273. oper.opr.localscale:=scale;
  1274. scale:=0;
  1275. end;
  1276. end;
  1277. OPR_REFERENCE :
  1278. begin
  1279. if (GotStar) or
  1280. (actasmtoken=AS_STAR) or
  1281. (oper.opr.ref.base<>NR_NO) then
  1282. begin
  1283. if (oper.opr.ref.index<>NR_NO) then
  1284. Message(asmr_e_multiple_index);
  1285. oper.opr.ref.index:=hreg;
  1286. if scale<>0 then
  1287. begin
  1288. oper.opr.ref.scalefactor:=scale;
  1289. scale:=0;
  1290. end;
  1291. end
  1292. else
  1293. oper.opr.ref.base:=hreg;
  1294. end;
  1295. end;
  1296. GotPlus:=false;
  1297. GotStar:=false;
  1298. end;
  1299. AS_OFFSET :
  1300. begin
  1301. Consume(AS_OFFSET);
  1302. GotOffset:=true;
  1303. end;
  1304. AS_TYPE,
  1305. AS_NOT,
  1306. AS_STRING,
  1307. AS_INTNUM,
  1308. AS_LPAREN : { Constant reference expression }
  1309. begin
  1310. if not GotPlus and not GotStar then
  1311. Message(asmr_e_invalid_reference_syntax);
  1312. BuildConstSymbolExpression(true,true,l,tempstr,tempsymtyp);
  1313. if tempstr<>'' then
  1314. begin
  1315. if GotStar then
  1316. Message(asmr_e_only_add_relocatable_symbol);
  1317. if not assigned(oper.opr.ref.symbol) then
  1318. oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr)
  1319. else
  1320. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1321. end;
  1322. case oper.opr.typ of
  1323. OPR_REFERENCE :
  1324. begin
  1325. if GotStar then
  1326. oper.opr.ref.scalefactor:=l
  1327. else if (prevasmtoken = AS_STAR) then
  1328. begin
  1329. if scale<>0 then
  1330. scale:=l*scale
  1331. else
  1332. scale:=l;
  1333. end
  1334. else
  1335. begin
  1336. if negative then
  1337. Dec(oper.opr.ref.offset,l)
  1338. else
  1339. Inc(oper.opr.ref.offset,l);
  1340. end;
  1341. end;
  1342. OPR_LOCAL :
  1343. begin
  1344. if GotStar then
  1345. oper.opr.localscale:=l
  1346. else if (prevasmtoken = AS_STAR) then
  1347. begin
  1348. if scale<>0 then
  1349. scale:=l*scale
  1350. else
  1351. scale:=l;
  1352. end
  1353. else
  1354. begin
  1355. if negative then
  1356. Dec(oper.opr.localsymofs,l)
  1357. else
  1358. Inc(oper.opr.localsymofs,l);
  1359. end;
  1360. end;
  1361. end;
  1362. GotPlus:=(prevasmtoken=AS_PLUS) or
  1363. (prevasmtoken=AS_MINUS);
  1364. if GotPlus then
  1365. negative := prevasmtoken = AS_MINUS;
  1366. GotStar:=(prevasmtoken=AS_STAR);
  1367. end;
  1368. AS_RBRACKET :
  1369. begin
  1370. if GotPlus or GotStar then
  1371. Message(asmr_e_invalid_reference_syntax);
  1372. Consume(AS_RBRACKET);
  1373. break;
  1374. end;
  1375. else
  1376. Begin
  1377. Message(asmr_e_invalid_reference_syntax);
  1378. RecoverConsume(true);
  1379. break;
  1380. end;
  1381. end;
  1382. until false;
  1383. end;
  1384. Procedure tx86intreader.BuildConstantOperand(oper: tx86operand);
  1385. var
  1386. l : aint;
  1387. tempstr : string;
  1388. tempsymtyp : tasmsymtype;
  1389. begin
  1390. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1391. Message(asmr_e_invalid_operand_type);
  1392. BuildConstSymbolExpression(true,false,l,tempstr,tempsymtyp);
  1393. if tempstr<>'' then
  1394. begin
  1395. oper.opr.typ:=OPR_SYMBOL;
  1396. oper.opr.symofs:=l;
  1397. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr);
  1398. end
  1399. else
  1400. if oper.opr.typ=OPR_NONE then
  1401. begin
  1402. oper.opr.typ:=OPR_CONSTANT;
  1403. oper.opr.val:=l;
  1404. end
  1405. else
  1406. inc(oper.opr.val,l);
  1407. end;
  1408. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1409. procedure AddLabelOperand(hl:tasmlabel);
  1410. begin
  1411. if (oper.opr.typ=OPR_NONE) and
  1412. is_calljmp(actopcode) then
  1413. begin
  1414. oper.opr.typ:=OPR_SYMBOL;
  1415. oper.opr.symbol:=hl;
  1416. end
  1417. else
  1418. begin
  1419. oper.InitRef;
  1420. oper.opr.ref.symbol:=hl;
  1421. end;
  1422. end;
  1423. var
  1424. expr : string;
  1425. tempreg : tregister;
  1426. l : aint;
  1427. hl : tasmlabel;
  1428. toffset,
  1429. tsize : aint;
  1430. begin
  1431. expr:='';
  1432. repeat
  1433. if actasmtoken=AS_DOT then
  1434. begin
  1435. if expr<>'' then
  1436. begin
  1437. BuildRecordOffsetSize(expr,toffset,tsize);
  1438. oper.SetSize(tsize,true);
  1439. case oper.opr.typ of
  1440. OPR_LOCAL :
  1441. begin
  1442. { don't allow direct access to fields of parameters, becuase that
  1443. will generate buggy code. Allow it only for explicit typecasting
  1444. and when the parameter is in a register (delphi compatible) }
  1445. if (not oper.hastype) and
  1446. (oper.opr.localsym.owner.symtabletype=parasymtable) and
  1447. (current_procinfo.procdef.proccalloption<>pocall_register) then
  1448. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1449. inc(oper.opr.localsymofs,toffset)
  1450. end;
  1451. OPR_CONSTANT :
  1452. inc(oper.opr.val,toffset);
  1453. OPR_REFERENCE :
  1454. inc(oper.opr.ref.offset,toffset);
  1455. OPR_NONE :
  1456. begin
  1457. oper.opr.typ:=OPR_CONSTANT;
  1458. oper.opr.val:=toffset;
  1459. end;
  1460. else
  1461. internalerror(200309222);
  1462. end;
  1463. expr:='';
  1464. end
  1465. else
  1466. begin
  1467. { See it as a separator }
  1468. Consume(AS_DOT);
  1469. end;
  1470. end;
  1471. case actasmtoken of
  1472. AS_OFFSET,
  1473. AS_SIZEOF,
  1474. AS_TYPE,
  1475. AS_NOT,
  1476. AS_STRING,
  1477. AS_PLUS,
  1478. AS_MINUS,
  1479. AS_LPAREN,
  1480. AS_INTNUM :
  1481. begin
  1482. case oper.opr.typ of
  1483. OPR_REFERENCE :
  1484. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1485. OPR_LOCAL :
  1486. inc(oper.opr.localsymofs,BuildConstExpression);
  1487. OPR_NONE,
  1488. OPR_CONSTANT :
  1489. BuildConstantOperand(oper);
  1490. else
  1491. Message(asmr_e_invalid_operand_type);
  1492. end;
  1493. end;
  1494. AS_PTR :
  1495. begin
  1496. if not oper.hastype then
  1497. begin
  1498. if (oper.opr.typ=OPR_CONSTANT) then
  1499. begin
  1500. oper.typesize:=oper.opr.val;
  1501. { reset constant value of operand }
  1502. oper.opr.typ:=OPR_NONE;
  1503. oper.opr.val:=0;
  1504. end
  1505. else
  1506. Message(asmr_e_syn_operand);
  1507. end;
  1508. Consume(AS_PTR);
  1509. oper.InitRef;
  1510. BuildOperand(oper,false);
  1511. end;
  1512. AS_ID : { A constant expression, or a Variable ref. }
  1513. Begin
  1514. { Label or Special symbol reference? }
  1515. if actasmpattern[1] = '@' then
  1516. Begin
  1517. if actasmpattern = '@RESULT' then
  1518. Begin
  1519. oper.SetupResult;
  1520. Consume(AS_ID);
  1521. end
  1522. else
  1523. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1524. begin
  1525. Message(asmr_w_CODE_and_DATA_not_supported);
  1526. Consume(AS_ID);
  1527. end
  1528. else
  1529. { Local Label }
  1530. begin
  1531. CreateLocalLabel(actasmpattern,hl,false);
  1532. Consume(AS_ID);
  1533. AddLabelOperand(hl);
  1534. end;
  1535. end
  1536. else
  1537. { support result for delphi modes }
  1538. if (m_objpas in aktmodeswitches) and (actasmpattern='RESULT') then
  1539. begin
  1540. oper.SetUpResult;
  1541. Consume(AS_ID);
  1542. end
  1543. { probably a variable or normal expression }
  1544. { or a procedure (such as in CALL ID) }
  1545. else
  1546. Begin
  1547. { is it a constant ? }
  1548. if SearchIConstant(actasmpattern,l) then
  1549. Begin
  1550. case oper.opr.typ of
  1551. OPR_REFERENCE :
  1552. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1553. OPR_LOCAL :
  1554. inc(oper.opr.localsymofs,BuildRefConstExpression);
  1555. OPR_NONE,
  1556. OPR_CONSTANT :
  1557. BuildConstantOperand(oper);
  1558. else
  1559. Message(asmr_e_invalid_operand_type);
  1560. end;
  1561. end
  1562. else
  1563. { Check for pascal label }
  1564. if SearchLabel(actasmpattern,hl,false) then
  1565. begin
  1566. Consume(AS_ID);
  1567. AddLabelOperand(hl);
  1568. end
  1569. else
  1570. { is it a normal variable ? }
  1571. Begin
  1572. expr:=actasmpattern;
  1573. Consume(AS_ID);
  1574. { typecasting? }
  1575. if SearchType(expr,l) then
  1576. begin
  1577. oper.hastype:=true;
  1578. oper.typesize:=l;
  1579. case actasmtoken of
  1580. AS_LPAREN :
  1581. begin
  1582. { Support Type([Reference]) }
  1583. Consume(AS_LPAREN);
  1584. BuildOperand(oper,true);
  1585. Consume(AS_RPAREN);
  1586. end;
  1587. AS_LBRACKET :
  1588. begin
  1589. { Support Var.Type[Index] }
  1590. { Convert @label.Byte[1] to reference }
  1591. if oper.opr.typ=OPR_SYMBOL then
  1592. oper.initref;
  1593. end;
  1594. end;
  1595. end
  1596. else
  1597. begin
  1598. if not oper.SetupVar(expr,false) then
  1599. Begin
  1600. { not a variable, check special variables.. }
  1601. if expr = 'SELF' then
  1602. oper.SetupSelf
  1603. else
  1604. Message1(sym_e_unknown_id,expr);
  1605. expr:='';
  1606. end;
  1607. end;
  1608. end;
  1609. end;
  1610. end;
  1611. AS_REGISTER : { Register, a variable reference or a constant reference }
  1612. begin
  1613. { save the type of register used. }
  1614. tempreg:=actasmregister;
  1615. Consume(AS_REGISTER);
  1616. if actasmtoken = AS_COLON then
  1617. Begin
  1618. Consume(AS_COLON);
  1619. oper.InitRef;
  1620. oper.opr.ref.segment:=tempreg;
  1621. BuildReference(oper);
  1622. end
  1623. else
  1624. { Simple register }
  1625. begin
  1626. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1627. Message(asmr_e_invalid_operand_type);
  1628. oper.opr.typ:=OPR_REGISTER;
  1629. oper.opr.reg:=tempreg;
  1630. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1631. end;
  1632. end;
  1633. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1634. Begin
  1635. BuildReference(oper);
  1636. end;
  1637. AS_SEG :
  1638. Begin
  1639. Message(asmr_e_seg_not_supported);
  1640. Consume(actasmtoken);
  1641. end;
  1642. AS_DWORD,
  1643. AS_BYTE,
  1644. AS_WORD,
  1645. AS_TBYTE,
  1646. AS_DQWORD,
  1647. AS_QWORD :
  1648. begin
  1649. { Type specifier }
  1650. oper.hastype:=true;
  1651. oper.typesize:=0;
  1652. case actasmtoken of
  1653. AS_DWORD : oper.typesize:=4;
  1654. AS_WORD : oper.typesize:=2;
  1655. AS_BYTE : oper.typesize:=1;
  1656. AS_QWORD : oper.typesize:=8;
  1657. AS_DQWORD : oper.typesize:=16;
  1658. AS_TBYTE : oper.typesize:=10;
  1659. end;
  1660. Consume(actasmtoken);
  1661. if (actasmtoken=AS_LPAREN) then
  1662. begin
  1663. { Support Type([Reference]) }
  1664. Consume(AS_LPAREN);
  1665. BuildOperand(oper,true);
  1666. Consume(AS_RPAREN);
  1667. end;
  1668. end;
  1669. AS_SEPARATOR,
  1670. AS_END,
  1671. AS_COMMA,
  1672. AS_COLON:
  1673. begin
  1674. break;
  1675. end;
  1676. AS_RPAREN:
  1677. begin
  1678. if not istypecast then
  1679. begin
  1680. Message(asmr_e_syn_operand);
  1681. Consume(AS_RPAREN);
  1682. end
  1683. else
  1684. break;
  1685. end;
  1686. else
  1687. begin
  1688. Message(asmr_e_syn_operand);
  1689. RecoverConsume(true);
  1690. break;
  1691. end;
  1692. end;
  1693. until false;
  1694. { End of operand, update size if a typecast is forced }
  1695. if (oper.typesize<>0) and
  1696. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1697. oper.SetSize(oper.typesize,true);
  1698. end;
  1699. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  1700. var
  1701. PrefixOp,OverrideOp: tasmop;
  1702. operandnum : longint;
  1703. is_far_const:boolean;
  1704. i:byte;
  1705. begin
  1706. PrefixOp:=A_None;
  1707. OverrideOp:=A_None;
  1708. is_far_const:=false;
  1709. { prefix seg opcode / prefix opcode }
  1710. repeat
  1711. if is_prefix(actopcode) then
  1712. with instr do
  1713. begin
  1714. OpOrder:=op_intel;
  1715. PrefixOp:=ActOpcode;
  1716. opcode:=ActOpcode;
  1717. condition:=ActCondition;
  1718. opsize:=ActOpsize;
  1719. ConcatInstruction(curlist);
  1720. consume(AS_OPCODE);
  1721. end
  1722. else
  1723. if is_override(actopcode) then
  1724. with instr do
  1725. begin
  1726. OpOrder:=op_intel;
  1727. OverrideOp:=ActOpcode;
  1728. opcode:=ActOpcode;
  1729. condition:=ActCondition;
  1730. opsize:=ActOpsize;
  1731. ConcatInstruction(curlist);
  1732. consume(AS_OPCODE);
  1733. end
  1734. else
  1735. break;
  1736. { allow for newline after prefix or override }
  1737. while actasmtoken=AS_SEPARATOR do
  1738. consume(AS_SEPARATOR);
  1739. until (actasmtoken<>AS_OPCODE);
  1740. { opcode }
  1741. if (actasmtoken <> AS_OPCODE) then
  1742. begin
  1743. Message(asmr_e_invalid_or_missing_opcode);
  1744. RecoverConsume(false);
  1745. exit;
  1746. end;
  1747. { Fill the instr object with the current state }
  1748. with instr do
  1749. begin
  1750. OpOrder:=op_intel;
  1751. Opcode:=ActOpcode;
  1752. condition:=ActCondition;
  1753. opsize:=ActOpsize;
  1754. { Valid combination of prefix/override and instruction ? }
  1755. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1756. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1757. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1758. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1759. end;
  1760. { We are reading operands, so opcode will be an AS_ID }
  1761. operandnum:=1;
  1762. is_far_const:=false;
  1763. Consume(AS_OPCODE);
  1764. { Zero operand opcode ? }
  1765. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1766. begin
  1767. operandnum:=0;
  1768. exit;
  1769. end;
  1770. { Read Operands }
  1771. repeat
  1772. case actasmtoken of
  1773. { End of asm operands for this opcode }
  1774. AS_END,
  1775. AS_SEPARATOR :
  1776. break;
  1777. { Operand delimiter }
  1778. AS_COMMA :
  1779. begin
  1780. if operandnum > Max_Operands then
  1781. Message(asmr_e_too_many_operands)
  1782. else
  1783. Inc(operandnum);
  1784. Consume(AS_COMMA);
  1785. end;
  1786. {Far constant, i.e. jmp $0000:$11111111.}
  1787. AS_COLON:
  1788. begin
  1789. is_far_const:=true;
  1790. if operandnum>1 then
  1791. message(asmr_e_too_many_operands)
  1792. else
  1793. inc(operandnum);
  1794. consume(AS_COLON);
  1795. end;
  1796. { Type specifier }
  1797. AS_NEAR,
  1798. AS_FAR :
  1799. begin
  1800. if actasmtoken = AS_NEAR then
  1801. begin
  1802. Message(asmr_w_near_ignored);
  1803. instr.opsize:=S_NEAR;
  1804. end
  1805. else
  1806. begin
  1807. Message(asmr_w_far_ignored);
  1808. instr.opsize:=S_FAR;
  1809. end;
  1810. Consume(actasmtoken);
  1811. if actasmtoken=AS_PTR then
  1812. begin
  1813. Consume(AS_PTR);
  1814. instr.Operands[operandnum].InitRef;
  1815. end;
  1816. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1817. end;
  1818. else
  1819. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1820. end; { end case }
  1821. until false;
  1822. instr.ops:=operandnum;
  1823. { Check operands }
  1824. for i:=1 to operandnum do
  1825. begin
  1826. if is_far_const and
  1827. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  1828. message(asmr_e_expr_illegal)
  1829. else
  1830. if instr.operands[i].opr.typ=OPR_NONE then
  1831. Message(asmr_e_syntax_error);
  1832. end;
  1833. end;
  1834. Procedure tx86intreader.BuildConstant(constsize: byte);
  1835. var
  1836. asmsymtyp : tasmsymtype;
  1837. asmsym,
  1838. expr: string;
  1839. value : aint;
  1840. Begin
  1841. Repeat
  1842. Case actasmtoken of
  1843. AS_STRING:
  1844. Begin
  1845. { DD and DW cases }
  1846. if constsize <> 1 then
  1847. Begin
  1848. if Not PadZero(actasmpattern,constsize) then
  1849. Message(scan_f_string_exceeds_line);
  1850. end;
  1851. expr:=actasmpattern;
  1852. Consume(AS_STRING);
  1853. Case actasmtoken of
  1854. AS_COMMA:
  1855. Consume(AS_COMMA);
  1856. AS_END,
  1857. AS_SEPARATOR: ;
  1858. else
  1859. Message(asmr_e_invalid_string_expression);
  1860. end;
  1861. ConcatString(curlist,expr);
  1862. end;
  1863. AS_PLUS,
  1864. AS_MINUS,
  1865. AS_LPAREN,
  1866. AS_NOT,
  1867. AS_INTNUM,
  1868. AS_ID :
  1869. Begin
  1870. BuildConstSymbolExpression(false,false,value,asmsym,asmsymtyp);
  1871. if asmsym<>'' then
  1872. begin
  1873. if constsize<>sizeof(aint) then
  1874. Message1(asmr_w_const32bit_for_address,asmsym);
  1875. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  1876. end
  1877. else
  1878. ConcatConstant(curlist,value,constsize);
  1879. end;
  1880. AS_COMMA:
  1881. begin
  1882. Consume(AS_COMMA);
  1883. end;
  1884. AS_ALIGN,
  1885. AS_DB,
  1886. AS_DW,
  1887. AS_DD,
  1888. AS_OPCODE,
  1889. AS_END,
  1890. AS_SEPARATOR:
  1891. break;
  1892. else
  1893. begin
  1894. Message(asmr_e_syn_constant);
  1895. RecoverConsume(false);
  1896. end
  1897. end;
  1898. Until false;
  1899. end;
  1900. function tx86intreader.Assemble: tlinkedlist;
  1901. Var
  1902. hl : tasmlabel;
  1903. instr : Tx86Instruction;
  1904. Begin
  1905. Message1(asmr_d_start_reading,'intel');
  1906. inexpression:=FALSE;
  1907. firsttoken:=TRUE;
  1908. { sets up all opcode and register tables in uppercase
  1909. done in the construtor now
  1910. if not _asmsorted then
  1911. Begin
  1912. SetupTables;
  1913. _asmsorted:=TRUE;
  1914. end;
  1915. }
  1916. curlist:=TAsmList.Create;
  1917. { setup label linked list }
  1918. LocalLabelList:=TLocalLabelList.Create;
  1919. { start tokenizer }
  1920. c:=current_scanner.asmgetcharstart;
  1921. gettoken;
  1922. { main loop }
  1923. repeat
  1924. case actasmtoken of
  1925. AS_LLABEL:
  1926. Begin
  1927. if CreateLocalLabel(actasmpattern,hl,true) then
  1928. ConcatLabel(curlist,hl);
  1929. Consume(AS_LLABEL);
  1930. end;
  1931. AS_LABEL:
  1932. Begin
  1933. if SearchLabel(upper(actasmpattern),hl,true) then
  1934. ConcatLabel(curlist,hl)
  1935. else
  1936. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1937. Consume(AS_LABEL);
  1938. end;
  1939. AS_DW :
  1940. Begin
  1941. inexpression:=true;
  1942. Consume(AS_DW);
  1943. BuildConstant(2);
  1944. inexpression:=false;
  1945. end;
  1946. AS_DB :
  1947. Begin
  1948. inexpression:=true;
  1949. Consume(AS_DB);
  1950. BuildConstant(1);
  1951. inexpression:=false;
  1952. end;
  1953. AS_DD :
  1954. Begin
  1955. inexpression:=true;
  1956. Consume(AS_DD);
  1957. BuildConstant(4);
  1958. inexpression:=false;
  1959. end;
  1960. AS_ALIGN:
  1961. Begin
  1962. Consume(AS_ALIGN);
  1963. ConcatAlign(curlist,BuildConstExpression);
  1964. if actasmtoken<>AS_SEPARATOR then
  1965. Consume(AS_SEPARATOR);
  1966. end;
  1967. AS_OPCODE :
  1968. Begin
  1969. instr:=Tx86Instruction.Create(Tx86Operand);
  1970. BuildOpcode(instr);
  1971. with instr do
  1972. begin
  1973. { We need AT&T style operands }
  1974. Swapoperands;
  1975. { Must be done with args in ATT order }
  1976. CheckNonCommutativeOpcodes;
  1977. AddReferenceSizes;
  1978. SetInstructionOpsize;
  1979. CheckOperandSizes;
  1980. ConcatInstruction(curlist);
  1981. end;
  1982. instr.Free;
  1983. end;
  1984. AS_SEPARATOR :
  1985. Begin
  1986. Consume(AS_SEPARATOR);
  1987. end;
  1988. AS_END :
  1989. break; { end assembly block }
  1990. else
  1991. Begin
  1992. Message(asmr_e_syntax_error);
  1993. RecoverConsume(false);
  1994. end;
  1995. end; { end case }
  1996. until false;
  1997. { Check LocalLabelList }
  1998. LocalLabelList.CheckEmitted;
  1999. LocalLabelList.Free;
  2000. { Return the list in an asmnode }
  2001. assemble:=curlist;
  2002. Message1(asmr_d_finish_reading,'intel');
  2003. end;
  2004. end.