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