rax86int.pas 70 KB

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