rax86int.pas 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615
  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_DQ,AS_END,
  35. {------------------ Assembler Operators --------------------}
  36. AS_BYTE,AS_WORD,AS_DWORD,AS_QWORD,AS_TBYTE,AS_DQWORD,AS_OWORD,AS_XMMWORD,AS_YWORD,AS_YMMWORD,AS_NEAR,AS_FAR,
  37. AS_HIGH,AS_LOW,AS_OFFSET,AS_SIZEOF,AS_VMTOFFSET,AS_SEG,AS_TYPE,AS_PTR,AS_MOD,AS_SHL,AS_SHR,AS_NOT,
  38. AS_AND,AS_OR,AS_XOR,AS_WRT,AS___GOTPCREL);
  39. type
  40. tx86intreader = class(tasmreader)
  41. actasmtoken : tasmtoken;
  42. prevasmtoken : tasmtoken;
  43. ActOpsize : topsize;
  44. inexpression : boolean;
  45. constructor create;override;
  46. function is_asmopcode(const s: string):boolean;
  47. function is_asmoperator(const s: string):boolean;
  48. function is_asmdirective(const s: string):boolean;
  49. function is_register(const s:string):boolean;
  50. function is_locallabel(const s:string):boolean;
  51. function Assemble: tlinkedlist;override;
  52. procedure GetToken;
  53. function consume(t : tasmtoken):boolean;
  54. procedure RecoverConsume(allowcomma:boolean);
  55. procedure BuildRecordOffsetSize(const expr: string;var offset:tcgint;var size:tcgint; var mangledname: string; needvmtofs: boolean; out hastypecast: boolean);
  56. procedure BuildConstSymbolExpression(needofs,isref,startingminus:boolean;var value:tcgint;var asmsym:string;var asmsymtyp:TAsmsymtype;out isseg,is_farproc_entry:boolean);
  57. function BuildConstExpression:aint;
  58. function BuildRefConstExpression(startingminus:boolean=false):aint;
  59. procedure BuildReference(oper : tx86operand);
  60. procedure BuildOperand(oper: tx86operand;istypecast:boolean);
  61. procedure BuildConstantOperand(oper: tx86operand);
  62. procedure BuildOpCode(instr : tx86instruction);
  63. procedure BuildConstant(constsize: byte);
  64. end;
  65. implementation
  66. uses
  67. { common }
  68. cutils,
  69. { global }
  70. globals,verbose,
  71. systems,
  72. { aasm }
  73. aasmdata,aasmcpu,
  74. {$ifdef i8086}
  75. aasmtai,
  76. {$endif i8086}
  77. { symtable }
  78. symconst,symbase,symtype,symsym,symdef,
  79. {$ifdef i8086}
  80. symcpu,
  81. {$endif i8086}
  82. { parser }
  83. scanner,pbase,
  84. { register allocator }
  85. rautils,itx86int,
  86. { codegen }
  87. cgbase,procinfo,paramgr
  88. ;
  89. type
  90. tasmkeyword = string[9];
  91. const
  92. { These tokens should be modified accordingly to the modifications }
  93. { in the different enumerations. }
  94. firstdirective = AS_ALIGN;
  95. lastdirective = AS_END;
  96. firstoperator = AS_BYTE;
  97. lastoperator = AS___GOTPCREL;
  98. _count_asmdirectives = longint(lastdirective)-longint(firstdirective);
  99. _count_asmoperators = longint(lastoperator)-longint(firstoperator);
  100. _asmdirectives : array[0.._count_asmdirectives] of tasmkeyword =
  101. ('ALIGN','DB','DW','DD','DQ','END');
  102. { problems with shl,shr,not,and,or and xor, they are }
  103. { context sensitive. }
  104. _asmoperators : array[0.._count_asmoperators] of tasmkeyword = (
  105. 'BYTE','WORD','DWORD','QWORD','TBYTE','DQWORD','OWORD','XMMWORD','YWORD','YMMWORD','NEAR','FAR','HIGH',
  106. 'LOW','OFFSET','SIZEOF','VMTOFFSET','SEG','TYPE','PTR','MOD','SHL','SHR','NOT','AND',
  107. 'OR','XOR','WRT','GOTPCREL');
  108. token2str : array[tasmtoken] of string[10] = (
  109. '','Label','LLabel','String','Integer',
  110. ',',',',',',',',',','[',']','(',
  111. ')',':','.','+','-','*',
  112. ';','identifier','register','opcode','/',
  113. '','','','','','END',
  114. '','','','','','','','','',
  115. '','','sizeof','vmtoffset','','type','ptr','mod','shl','shr','not',
  116. 'and','or','xor','wrt','..gotpcrel'
  117. );
  118. constructor tx86intreader.create;
  119. var
  120. i : tasmop;
  121. Begin
  122. inherited create;
  123. iasmops:=TFPHashList.create;
  124. for i:=firstop to lastop do
  125. iasmops.Add(upper(std_op2str[i]),Pointer(PtrInt(i)));
  126. end;
  127. {---------------------------------------------------------------------}
  128. { Routines for the tokenizing }
  129. {---------------------------------------------------------------------}
  130. function tx86intreader.is_asmopcode(const s: string):boolean;
  131. var
  132. cond : string[4];
  133. cnd : tasmcond;
  134. j: longint;
  135. Begin
  136. is_asmopcode:=FALSE;
  137. actopcode:=A_None;
  138. actcondition:=C_None;
  139. actopsize:=S_NO;
  140. { Search opcodes }
  141. actopcode:=tasmop(PtrUInt(iasmops.Find(s)));
  142. if actopcode<>A_NONE then
  143. begin
  144. actasmtoken:=AS_OPCODE;
  145. result:=TRUE;
  146. exit;
  147. end;
  148. { not found yet, check condition opcodes }
  149. j:=0;
  150. while (j<CondAsmOps) do
  151. begin
  152. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  153. begin
  154. cond:=Copy(s,Length(CondAsmOpStr[j])+1,255);
  155. if cond<>'' then
  156. begin
  157. for cnd:=low(TasmCond) to high(TasmCond) do
  158. if Cond=Upper(cond2str[cnd]) then
  159. begin
  160. actopcode:=CondASmOp[j];
  161. actcondition:=cnd;
  162. is_asmopcode:=TRUE;
  163. actasmtoken:=AS_OPCODE;
  164. exit
  165. end;
  166. end;
  167. end;
  168. inc(j);
  169. end;
  170. end;
  171. function tx86intreader.is_asmoperator(const s: string):boolean;
  172. var
  173. i : longint;
  174. Begin
  175. for i:=0 to _count_asmoperators do
  176. if s=_asmoperators[i] then
  177. begin
  178. actasmtoken:=tasmtoken(longint(firstoperator)+i);
  179. is_asmoperator:=true;
  180. exit;
  181. end;
  182. is_asmoperator:=false;
  183. end;
  184. Function tx86intreader.is_asmdirective(const s: string):boolean;
  185. var
  186. i : longint;
  187. Begin
  188. for i:=0 to _count_asmdirectives do
  189. if s=_asmdirectives[i] then
  190. begin
  191. actasmtoken:=tasmtoken(longint(firstdirective)+i);
  192. is_asmdirective:=true;
  193. exit;
  194. end;
  195. is_asmdirective:=false;
  196. end;
  197. function tx86intreader.is_register(const s:string):boolean;
  198. begin
  199. is_register:=false;
  200. actasmregister:=masm_regnum_search(lower(s));
  201. { don't acceps "flags" as register name in an instruction }
  202. if (getsupreg(actasmregister)=RS_DEFAULTFLAGS) and (getregtype(actasmregister)=getregtype(NR_DEFAULTFLAGS)) then
  203. actasmregister:=NR_NO;
  204. if actasmregister<>NR_NO then
  205. begin
  206. is_register:=true;
  207. actasmtoken:=AS_REGISTER;
  208. end;
  209. end;
  210. function tx86intreader.is_locallabel(const s:string):boolean;
  211. begin
  212. is_locallabel:=(length(s)>1) and (s[1]='@');
  213. end;
  214. Procedure tx86intreader.GetToken;
  215. var
  216. len : longint;
  217. forcelabel : boolean;
  218. srsym : tsym;
  219. srsymtable : TSymtable;
  220. begin
  221. c:=scanner.c;
  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 (or segment override) we allow also a new opcode }
  311. If (is_prefix(actopcode) or is_override(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_asmdirective(actasmpattern) then
  344. exit;
  345. if is_asmoperator(actasmpattern) then
  346. exit;
  347. if is_register(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. asmsearchsym(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. repeat
  382. if c = '''' then
  383. begin
  384. c:=current_scanner.asmgetchar;
  385. if c in [#10,#13] then
  386. begin
  387. Message(scan_f_string_exceeds_line);
  388. break;
  389. end;
  390. repeat
  391. if c='''' then
  392. begin
  393. c:=current_scanner.asmgetchar;
  394. if c='''' then
  395. begin
  396. actasmpattern:=actasmpattern+'''';
  397. c:=current_scanner.asmgetchar;
  398. if c in [#10,#13] then
  399. begin
  400. Message(scan_f_string_exceeds_line);
  401. break;
  402. end;
  403. end
  404. else
  405. break;
  406. end
  407. else
  408. begin
  409. actasmpattern:=actasmpattern+c;
  410. c:=current_scanner.asmgetchar;
  411. if c in [#10,#13] then
  412. begin
  413. Message(scan_f_string_exceeds_line);
  414. break
  415. end;
  416. end;
  417. until false; { end repeat }
  418. end
  419. else
  420. break; { end if }
  421. until false;
  422. actasmtoken:=AS_STRING;
  423. exit;
  424. end;
  425. '"' : { string or character }
  426. begin
  427. actasmpattern:='';
  428. repeat
  429. if c = '"' then
  430. begin
  431. c:=current_scanner.asmgetchar;
  432. if c in [#10,#13] then
  433. begin
  434. Message(scan_f_string_exceeds_line);
  435. break;
  436. end;
  437. repeat
  438. if c='"' then
  439. begin
  440. c:=current_scanner.asmgetchar;
  441. if c='"' then
  442. begin
  443. actasmpattern:=actasmpattern+'"';
  444. c:=current_scanner.asmgetchar;
  445. if c in [#10,#13] then
  446. begin
  447. Message(scan_f_string_exceeds_line);
  448. break;
  449. end;
  450. end
  451. else
  452. break;
  453. end
  454. else
  455. begin
  456. actasmpattern:=actasmpattern+c;
  457. c:=current_scanner.asmgetchar;
  458. if c in [#10,#13] then
  459. begin
  460. Message(scan_f_string_exceeds_line);
  461. break
  462. end;
  463. end;
  464. until false; { end repeat }
  465. end
  466. else
  467. break; { end if }
  468. until false;
  469. actasmtoken:=AS_STRING;
  470. exit;
  471. end;
  472. '$' :
  473. begin
  474. c:=current_scanner.asmgetchar;
  475. while c in ['0'..'9','A'..'F','a'..'f'] do
  476. begin
  477. actasmpattern:=actasmpattern + c;
  478. c:=current_scanner.asmgetchar;
  479. end;
  480. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  481. actasmtoken:=AS_INTNUM;
  482. exit;
  483. end;
  484. '&' : { identifier }
  485. begin
  486. actasmpattern:='';
  487. c:=current_scanner.asmgetchar;
  488. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  489. begin
  490. actasmpattern:=actasmpattern + c;
  491. c:=current_scanner.asmgetchar;
  492. end;
  493. uppervar(actasmpattern);
  494. actasmtoken:=AS_ID;
  495. exit;
  496. end;
  497. ',' :
  498. begin
  499. actasmtoken:=AS_COMMA;
  500. c:=current_scanner.asmgetchar;
  501. exit;
  502. end;
  503. '[' :
  504. begin
  505. actasmtoken:=AS_LBRACKET;
  506. c:=current_scanner.asmgetchar;
  507. exit;
  508. end;
  509. ']' :
  510. begin
  511. actasmtoken:=AS_RBRACKET;
  512. c:=current_scanner.asmgetchar;
  513. exit;
  514. end;
  515. '(' :
  516. begin
  517. c:=current_scanner.asmgetchar;
  518. if c='*' then
  519. begin
  520. current_scanner.skipoldtpcomment(true);
  521. GetToken;
  522. end
  523. else
  524. actasmtoken:=AS_LPAREN;
  525. exit;
  526. end;
  527. ')' :
  528. begin
  529. actasmtoken:=AS_RPAREN;
  530. c:=current_scanner.asmgetchar;
  531. exit;
  532. end;
  533. ':' :
  534. begin
  535. actasmtoken:=AS_COLON;
  536. c:=current_scanner.asmgetchar;
  537. exit;
  538. end;
  539. '.' :
  540. begin
  541. c:=current_scanner.asmgetchar;
  542. {$ifdef x86_64}
  543. if c='.' then
  544. begin
  545. actasmpattern:='..';
  546. c:=current_scanner.asmgetchar;
  547. repeat
  548. actasmpattern:=actasmpattern+c;
  549. c:=current_scanner.asmgetchar;
  550. until not(c in ['A'..'Z','a'..'z','0'..'9','_']);
  551. if upper(actasmpattern)<>'..GOTPCREL' then
  552. begin
  553. actasmtoken:=AS_ID;
  554. consume(AS___GOTPCREL);
  555. end;
  556. actasmtoken:=AS___GOTPCREL
  557. end
  558. else
  559. {$endif x86_64}
  560. actasmtoken:=AS_DOT;
  561. exit;
  562. end;
  563. '+' :
  564. begin
  565. actasmtoken:=AS_PLUS;
  566. c:=current_scanner.asmgetchar;
  567. exit;
  568. end;
  569. '-' :
  570. begin
  571. actasmtoken:=AS_MINUS;
  572. c:=current_scanner.asmgetchar;
  573. exit;
  574. end;
  575. '*' :
  576. begin
  577. actasmtoken:=AS_STAR;
  578. c:=current_scanner.asmgetchar;
  579. exit;
  580. end;
  581. '/' :
  582. begin
  583. c:=current_scanner.asmgetchar;
  584. if c='/' then
  585. begin
  586. current_scanner.skipdelphicomment;
  587. GetToken;
  588. end
  589. else
  590. actasmtoken:=AS_SLASH;
  591. exit;
  592. end;
  593. '0'..'9':
  594. begin
  595. actasmpattern:=c;
  596. c:=current_scanner.asmgetchar;
  597. { Get the possible characters }
  598. while c in ['0'..'9','A'..'F','a'..'f'] do
  599. begin
  600. actasmpattern:=actasmpattern + c;
  601. c:=current_scanner.asmgetchar;
  602. end;
  603. { Get ending character }
  604. uppervar(actasmpattern);
  605. c:=upcase(c);
  606. { possibly a binary number. }
  607. if (actasmpattern[length(actasmpattern)] = 'B') and (c <> 'H') then
  608. Begin
  609. { Delete the last binary specifier }
  610. delete(actasmpattern,length(actasmpattern),1);
  611. actasmpattern:=tostr(ParseVal(actasmpattern,2));
  612. actasmtoken:=AS_INTNUM;
  613. exit;
  614. end
  615. else
  616. Begin
  617. case c of
  618. 'O' :
  619. Begin
  620. actasmpattern:=tostr(ParseVal(actasmpattern,8));
  621. actasmtoken:=AS_INTNUM;
  622. c:=current_scanner.asmgetchar;
  623. exit;
  624. end;
  625. 'H' :
  626. Begin
  627. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  628. actasmtoken:=AS_INTNUM;
  629. c:=current_scanner.asmgetchar;
  630. exit;
  631. end;
  632. else { must be an integer number }
  633. begin
  634. actasmpattern:=tostr(ParseVal(actasmpattern,10));
  635. actasmtoken:=AS_INTNUM;
  636. exit;
  637. end;
  638. end;
  639. end;
  640. end;
  641. #13,#10:
  642. begin
  643. current_scanner.linebreak;
  644. c:=current_scanner.asmgetchar;
  645. firsttoken:=TRUE;
  646. actasmtoken:=AS_SEPARATOR;
  647. exit;
  648. end;
  649. ';':
  650. begin
  651. c:=current_scanner.asmgetchar;
  652. firsttoken:=TRUE;
  653. actasmtoken:=AS_SEPARATOR;
  654. exit;
  655. end;
  656. '{':
  657. begin
  658. current_scanner.skipcomment(true);
  659. GetToken;
  660. end;
  661. else
  662. current_scanner.illegal_char(c);
  663. end;
  664. end;
  665. end;
  666. function tx86intreader.consume(t : tasmtoken):boolean;
  667. begin
  668. Consume:=true;
  669. if t<>actasmtoken then
  670. begin
  671. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  672. Consume:=false;
  673. end;
  674. repeat
  675. gettoken;
  676. until actasmtoken<>AS_NONE;
  677. end;
  678. procedure tx86intreader.RecoverConsume(allowcomma:boolean);
  679. begin
  680. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  681. begin
  682. if allowcomma and (actasmtoken=AS_COMMA) then
  683. break;
  684. Consume(actasmtoken);
  685. end;
  686. end;
  687. {*****************************************************************************
  688. Parsing Helpers
  689. *****************************************************************************}
  690. { This routine builds up a record offset after a AS_DOT
  691. token is encountered.
  692. On entry actasmtoken should be equal to AS_DOT }
  693. Procedure tx86intreader.BuildRecordOffsetSize(const expr: string;var offset:tcgint;var size:tcgint; var mangledname: string; needvmtofs: boolean; out hastypecast: boolean);
  694. var
  695. s: string;
  696. Begin
  697. offset:=0;
  698. size:=0;
  699. hastypecast:=false;
  700. s:=expr;
  701. while (actasmtoken=AS_DOT) do
  702. begin
  703. Consume(AS_DOT);
  704. if actasmtoken in [AS_BYTE,AS_ID,AS_WORD,AS_DWORD,AS_QWORD,AS_OWORD,AS_XMMWORD,AS_YWORD,AS_YMMWORD,AS_REGISTER] then
  705. begin
  706. s:=s+'.'+actasmpattern;
  707. consume(actasmtoken);
  708. end
  709. else
  710. begin
  711. Consume(AS_ID);
  712. RecoverConsume(true);
  713. break;
  714. end;
  715. end;
  716. if not GetRecordOffsetSize(s,offset,size,mangledname,needvmtofs,hastypecast) then
  717. Message(asmr_e_building_record_offset);
  718. end;
  719. Procedure tx86intreader.BuildConstSymbolExpression(needofs,isref,startingminus:boolean;var value:tcgint;var asmsym:string;var asmsymtyp:TAsmsymtype;out isseg,is_farproc_entry:boolean);
  720. var
  721. tempstr,expr,hs,mangledname : string;
  722. parenlevel : longint;
  723. l,k : tcgint;
  724. hasparen,
  725. errorflag,
  726. needvmtofs : boolean;
  727. prevtok : tasmtoken;
  728. hl : tasmlabel;
  729. hssymtyp : Tasmsymtype;
  730. def : tdef;
  731. sym : tsym;
  732. srsymtable : TSymtable;
  733. hastypecast : boolean;
  734. Begin
  735. { reset }
  736. value:=0;
  737. asmsym:='';
  738. asmsymtyp:=AT_DATA;
  739. isseg:=false;
  740. is_farproc_entry:=FALSE;
  741. errorflag:=FALSE;
  742. tempstr:='';
  743. expr:='';
  744. if startingminus then
  745. expr:='-';
  746. inexpression:=TRUE;
  747. parenlevel:=0;
  748. sym:=nil;
  749. needvmtofs:=FALSE;
  750. Repeat
  751. { Support ugly delphi constructs like: [ECX].1+2[EDX] }
  752. if isref and (actasmtoken=AS_LBRACKET) then
  753. break;
  754. Case actasmtoken of
  755. AS_LPAREN:
  756. Begin
  757. Consume(AS_LPAREN);
  758. expr:=expr + '(';
  759. inc(parenlevel);
  760. end;
  761. AS_RPAREN:
  762. Begin
  763. { Keep the AS_PAREN in actasmtoken, it is maybe a typecast }
  764. if parenlevel=0 then
  765. break;
  766. Consume(AS_RPAREN);
  767. expr:=expr + ')';
  768. dec(parenlevel);
  769. end;
  770. AS_SHL:
  771. Begin
  772. Consume(AS_SHL);
  773. expr:=expr + '<';
  774. end;
  775. AS_SHR:
  776. Begin
  777. Consume(AS_SHR);
  778. expr:=expr + '>';
  779. end;
  780. AS_SLASH:
  781. Begin
  782. Consume(AS_SLASH);
  783. expr:=expr + '/';
  784. end;
  785. AS_MOD:
  786. Begin
  787. Consume(AS_MOD);
  788. expr:=expr + '%';
  789. end;
  790. AS_STAR:
  791. Begin
  792. Consume(AS_STAR);
  793. if isref and (actasmtoken=AS_REGISTER) then
  794. break;
  795. expr:=expr + '*';
  796. end;
  797. AS_PLUS:
  798. Begin
  799. Consume(AS_PLUS);
  800. if isref and (actasmtoken=AS_REGISTER) then
  801. break;
  802. expr:=expr + '+';
  803. end;
  804. AS_MINUS:
  805. Begin
  806. Consume(AS_MINUS);
  807. expr:=expr + '-';
  808. end;
  809. AS_AND:
  810. Begin
  811. Consume(AS_AND);
  812. expr:=expr + '&';
  813. end;
  814. AS_NOT:
  815. Begin
  816. Consume(AS_NOT);
  817. expr:=expr + '~';
  818. end;
  819. AS_XOR:
  820. Begin
  821. Consume(AS_XOR);
  822. expr:=expr + '^';
  823. end;
  824. AS_OR:
  825. Begin
  826. Consume(AS_OR);
  827. expr:=expr + '|';
  828. end;
  829. AS_INTNUM:
  830. Begin
  831. expr:=expr + actasmpattern;
  832. Consume(AS_INTNUM);
  833. end;
  834. {$ifdef i8086}
  835. AS_SEG:
  836. begin
  837. isseg:=true;
  838. Consume(actasmtoken);
  839. if actasmtoken<>AS_ID then
  840. Message(asmr_e_seg_without_identifier);
  841. end;
  842. {$endif i8086}
  843. AS_VMTOFFSET,
  844. AS_OFFSET:
  845. begin
  846. if (actasmtoken = AS_OFFSET) then
  847. needofs:=true
  848. else
  849. needvmtofs:=true;
  850. Consume(actasmtoken);
  851. if actasmtoken<>AS_ID then
  852. Message(asmr_e_offset_without_identifier);
  853. end;
  854. AS_SIZEOF,
  855. AS_TYPE:
  856. begin
  857. l:=0;
  858. hasparen:=false;
  859. Consume(actasmtoken);
  860. if actasmtoken=AS_LPAREN then
  861. begin
  862. hasparen:=true;
  863. Consume(AS_LPAREN);
  864. end;
  865. if actasmtoken<>AS_ID then
  866. Message(asmr_e_type_without_identifier)
  867. else
  868. begin
  869. tempstr:=actasmpattern;
  870. Consume(AS_ID);
  871. if actasmtoken=AS_DOT then
  872. begin
  873. BuildRecordOffsetSize(tempstr,k,l,mangledname,false,hastypecast);
  874. if mangledname<>'' then
  875. { procsym }
  876. Message(asmr_e_wrong_sym_type);
  877. if hastypecast then
  878. end
  879. else
  880. begin
  881. asmsearchsym(tempstr,sym,srsymtable);
  882. if assigned(sym) then
  883. begin
  884. case sym.typ of
  885. staticvarsym,
  886. localvarsym,
  887. paravarsym :
  888. l:=tabstractvarsym(sym).getsize;
  889. typesym :
  890. l:=ttypesym(sym).typedef.size;
  891. else
  892. Message(asmr_e_wrong_sym_type);
  893. end;
  894. end
  895. else
  896. Message1(sym_e_unknown_id,tempstr);
  897. end;
  898. end;
  899. str(l, tempstr);
  900. expr:=expr + tempstr;
  901. if hasparen then
  902. Consume(AS_RPAREN);
  903. end;
  904. AS_PTR :
  905. begin
  906. { Support ugly delphi constructs like <constant> PTR [ref] }
  907. break;
  908. end;
  909. AS_STRING:
  910. begin
  911. l:=0;
  912. case Length(actasmpattern) of
  913. 1 :
  914. l:=ord(actasmpattern[1]);
  915. 2 :
  916. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  917. 3 :
  918. l:=ord(actasmpattern[3]) +
  919. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  920. 4 :
  921. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  922. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  923. else
  924. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  925. end;
  926. str(l, tempstr);
  927. expr:=expr + tempstr;
  928. Consume(AS_STRING);
  929. end;
  930. AS_ID:
  931. begin
  932. hs:='';
  933. hssymtyp:=AT_DATA;
  934. def:=nil;
  935. tempstr:=actasmpattern;
  936. prevtok:=prevasmtoken;
  937. { stop parsing a constant expression if we find an opcode after a
  938. non-operator like "db $66 mov eax,ebx" }
  939. if (prevtok in [AS_ID,AS_INTNUM,AS_RPAREN]) and
  940. is_asmopcode(actasmpattern) then
  941. break;
  942. consume(AS_ID);
  943. if (tempstr='@CODE') or (tempstr='@DATA') then
  944. begin
  945. if asmsym='' then
  946. begin
  947. asmsym:=tempstr;
  948. asmsymtyp:=AT_SECTION;
  949. end
  950. else
  951. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  952. end
  953. else if SearchIConstant(tempstr,l) then
  954. begin
  955. str(l, tempstr);
  956. expr:=expr + tempstr;
  957. end
  958. else
  959. begin
  960. if is_locallabel(tempstr) then
  961. begin
  962. CreateLocalLabel(tempstr,hl,false);
  963. hs:=hl.name;
  964. hssymtyp:=AT_FUNCTION;
  965. end
  966. else
  967. if SearchLabel(tempstr,hl,false) then
  968. begin
  969. hs:=hl.name;
  970. hssymtyp:=AT_FUNCTION;
  971. end
  972. else
  973. begin
  974. asmsearchsym(tempstr,sym,srsymtable);
  975. if assigned(sym) then
  976. begin
  977. case sym.typ of
  978. staticvarsym :
  979. begin
  980. hs:=tstaticvarsym(sym).mangledname;
  981. def:=tstaticvarsym(sym).vardef;
  982. end;
  983. localvarsym,
  984. paravarsym :
  985. begin
  986. Message(asmr_e_no_local_or_para_allowed);
  987. end;
  988. procsym :
  989. begin
  990. if Tprocsym(sym).ProcdefList.Count>1 then
  991. Message(asmr_w_calling_overload_func);
  992. hs:=tprocdef(tprocsym(sym).ProcdefList[0]).mangledname;
  993. {$ifdef i8086}
  994. is_farproc_entry:=is_proc_far(tprocdef(tprocsym(sym).ProcdefList[0]))
  995. and not (po_interrupt in tprocdef(tprocsym(sym).ProcdefList[0]).procoptions);
  996. {$endif i8086}
  997. hssymtyp:=AT_FUNCTION;
  998. end;
  999. typesym :
  1000. begin
  1001. if not(ttypesym(sym).typedef.typ in [recorddef,objectdef]) then
  1002. Message(asmr_e_wrong_sym_type);
  1003. end;
  1004. fieldvarsym :
  1005. begin
  1006. tempstr:=upper(tdef(sym.owner.defowner).GetTypeName)+'.'+tempstr;
  1007. end;
  1008. else
  1009. Message(asmr_e_wrong_sym_type);
  1010. end;
  1011. end
  1012. else
  1013. Message1(sym_e_unknown_id,tempstr);
  1014. end;
  1015. { symbol found? }
  1016. if hs<>'' then
  1017. begin
  1018. if asmsym='' then
  1019. begin
  1020. asmsym:=hs;
  1021. asmsymtyp:=hssymtyp;
  1022. end
  1023. else
  1024. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1025. if (expr='') or (expr[length(expr)]='+') then
  1026. begin
  1027. { don't remove the + if there could be a record field }
  1028. if actasmtoken<>AS_DOT then
  1029. delete(expr,length(expr),1);
  1030. end
  1031. else
  1032. if needofs then
  1033. begin
  1034. if (prevtok<>AS_OFFSET) then
  1035. Message(asmr_e_need_offset);
  1036. end
  1037. else
  1038. Message(asmr_e_only_add_relocatable_symbol);
  1039. end;
  1040. if (actasmtoken=AS_DOT) or
  1041. (assigned(sym) and
  1042. (sym.typ = fieldvarsym) and
  1043. not(sp_static in sym.symoptions)) then
  1044. begin
  1045. BuildRecordOffsetSize(tempstr,l,k,hs,needvmtofs,hastypecast);
  1046. if hs <> '' then
  1047. hssymtyp:=AT_FUNCTION
  1048. else
  1049. begin
  1050. str(l, tempstr);
  1051. expr:=expr + tempstr;
  1052. end
  1053. end
  1054. else
  1055. begin
  1056. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1057. delete(expr,length(expr),1);
  1058. end;
  1059. if (actasmtoken=AS_LBRACKET) and
  1060. assigned(def) and
  1061. (def.typ=arraydef) then
  1062. begin
  1063. consume(AS_LBRACKET);
  1064. l:=BuildConstExpression;
  1065. if l<tarraydef(def).lowrange then
  1066. begin
  1067. Message(asmr_e_constant_out_of_bounds);
  1068. l:=0;
  1069. end
  1070. else
  1071. l:=(l-tarraydef(def).lowrange)*tarraydef(def).elesize;
  1072. str(l, tempstr);
  1073. expr:=expr + '+' + tempstr;
  1074. consume(AS_RBRACKET);
  1075. end;
  1076. end;
  1077. { check if there are wrong operator used like / or mod etc. }
  1078. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_END,AS_RBRACKET]) then
  1079. Message(asmr_e_only_add_relocatable_symbol);
  1080. end;
  1081. AS_ALIGN,
  1082. AS_DB,
  1083. AS_DW,
  1084. AS_DD,
  1085. AS_DQ,
  1086. AS_END,
  1087. AS_RBRACKET,
  1088. AS_SEPARATOR,
  1089. AS_COMMA,
  1090. AS_COLON:
  1091. break;
  1092. else
  1093. begin
  1094. { write error only once. }
  1095. if not errorflag then
  1096. Message(asmr_e_invalid_constant_expression);
  1097. { consume tokens until we find COMMA or SEPARATOR }
  1098. Consume(actasmtoken);
  1099. errorflag:=TRUE;
  1100. end;
  1101. end;
  1102. Until false;
  1103. { calculate expression }
  1104. if not ErrorFlag then
  1105. value:=CalculateExpression(expr)
  1106. else
  1107. value:=0;
  1108. { no longer in an expression }
  1109. inexpression:=FALSE;
  1110. end;
  1111. Function tx86intreader.BuildConstExpression:aint;
  1112. var
  1113. l : tcgint;
  1114. hs : string;
  1115. hssymtyp : TAsmsymtype;
  1116. isseg : boolean;
  1117. is_farproc_entry : boolean;
  1118. begin
  1119. BuildConstSymbolExpression(false,false,false,l,hs,hssymtyp,isseg,is_farproc_entry);
  1120. if hs<>'' then
  1121. Message(asmr_e_relocatable_symbol_not_allowed);
  1122. BuildConstExpression:=l;
  1123. end;
  1124. Function tx86intreader.BuildRefConstExpression(startingminus:boolean):aint;
  1125. var
  1126. l : tcgint;
  1127. hs : string;
  1128. hssymtyp : TAsmsymtype;
  1129. isseg : boolean;
  1130. is_farproc_entry : boolean;
  1131. begin
  1132. BuildConstSymbolExpression(false,true,startingminus,l,hs,hssymtyp,isseg,is_farproc_entry);
  1133. if hs<>'' then
  1134. Message(asmr_e_relocatable_symbol_not_allowed);
  1135. BuildRefConstExpression:=l;
  1136. end;
  1137. procedure tx86intreader.BuildReference(oper : tx86operand);
  1138. var
  1139. scale : byte;
  1140. k,l : tcgint;
  1141. tempstr,hs : string;
  1142. tempsymtyp : tasmsymtype;
  1143. code : integer;
  1144. hreg : tregister;
  1145. GotStar,GotOffset,HadVar,
  1146. GotPlus,Negative : boolean;
  1147. hl : tasmlabel;
  1148. isseg: boolean;
  1149. is_farproc_entry,
  1150. hastypecast: boolean;
  1151. Begin
  1152. Consume(AS_LBRACKET);
  1153. if not(oper.opr.typ in [OPR_LOCAL,OPR_REFERENCE]) then
  1154. oper.InitRef;
  1155. GotStar:=false;
  1156. GotPlus:=true;
  1157. GotOffset:=false;
  1158. Negative:=false;
  1159. Scale:=0;
  1160. repeat
  1161. if GotOffset and (actasmtoken<>AS_ID) then
  1162. Message(asmr_e_invalid_reference_syntax);
  1163. Case actasmtoken of
  1164. AS_ID, { Constant reference expression OR variable reference expression }
  1165. AS_VMTOFFSET:
  1166. Begin
  1167. if not GotPlus then
  1168. Message(asmr_e_invalid_reference_syntax);
  1169. GotStar:=false;
  1170. GotPlus:=false;
  1171. if (actasmtoken = AS_VMTOFFSET) or
  1172. (SearchIConstant(actasmpattern,l) or
  1173. SearchRecordType(actasmpattern)) then
  1174. begin
  1175. l:=BuildRefConstExpression(negative);
  1176. negative:=false; { "l" was negated if necessary }
  1177. GotPlus:=(prevasmtoken=AS_PLUS);
  1178. GotStar:=(prevasmtoken=AS_STAR);
  1179. case oper.opr.typ of
  1180. OPR_LOCAL :
  1181. begin
  1182. if GotStar then
  1183. Message(asmr_e_invalid_reference_syntax);
  1184. Inc(oper.opr.localsymofs,l);
  1185. end;
  1186. OPR_REFERENCE :
  1187. begin
  1188. if GotStar then
  1189. oper.opr.ref.scalefactor:=l
  1190. else
  1191. Inc(oper.opr.ref.offset,l);
  1192. end;
  1193. end;
  1194. end
  1195. else
  1196. Begin
  1197. if negative and not oper.hasvar then
  1198. Message(asmr_e_only_add_relocatable_symbol)
  1199. else if oper.hasvar and not GotOffset and
  1200. (not negative or assigned(oper.opr.ref.relsymbol)) then
  1201. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1202. HadVar:=oper.hasvar and GotOffset;
  1203. tempstr:=actasmpattern;
  1204. Consume(AS_ID);
  1205. { typecasting? }
  1206. if (actasmtoken=AS_LPAREN) and
  1207. SearchType(tempstr,l) then
  1208. begin
  1209. oper.hastype:=true;
  1210. oper.typesize:=l;
  1211. Consume(AS_LPAREN);
  1212. BuildOperand(oper,true);
  1213. Consume(AS_RPAREN);
  1214. end
  1215. else
  1216. if is_locallabel(tempstr) then
  1217. begin
  1218. CreateLocalLabel(tempstr,hl,false);
  1219. oper.InitRef;
  1220. if not negative then
  1221. begin
  1222. oper.opr.ref.symbol:=hl;
  1223. oper.hasvar:=true;
  1224. end
  1225. else
  1226. oper.opr.ref.relsymbol:=hl;
  1227. {$ifdef i8086}
  1228. if oper.opr.ref.segment=NR_NO then
  1229. oper.opr.ref.segment:=NR_CS;
  1230. {$endif i8086}
  1231. end
  1232. else
  1233. if oper.SetupVar(tempstr,GotOffset) then
  1234. begin
  1235. { convert OPR_LOCAL register para into a reference base }
  1236. if (oper.opr.typ=OPR_LOCAL) and
  1237. AsmRegisterPara(oper.opr.localsym) then
  1238. oper.InitRefConvertLocal
  1239. else
  1240. begin
  1241. {$ifdef x86_64}
  1242. if actasmtoken=AS_WRT then
  1243. begin
  1244. if (oper.opr.typ=OPR_REFERENCE) then
  1245. begin
  1246. Consume(AS_WRT);
  1247. Consume(AS___GOTPCREL);
  1248. if (oper.opr.ref.base<>NR_NO) or
  1249. (oper.opr.ref.index<>NR_NO) or
  1250. (oper.opr.ref.offset<>0) then
  1251. Message(asmr_e_wrong_gotpcrel_intel_syntax);
  1252. if tf_no_pic_supported in target_info.flags then
  1253. Message(asmr_e_no_gotpcrel_support);
  1254. oper.opr.ref.refaddr:=addr_pic;
  1255. oper.opr.ref.base:=NR_RIP;
  1256. end
  1257. else
  1258. message(asmr_e_invalid_reference_syntax);
  1259. end;
  1260. {$endif x86_64}
  1261. end;
  1262. end
  1263. else
  1264. Message1(sym_e_unknown_id,tempstr);
  1265. { record.field ? }
  1266. if actasmtoken=AS_DOT then
  1267. begin
  1268. BuildRecordOffsetSize(tempstr,l,k,hs,false,hastypecast);
  1269. if (hs<>'') then
  1270. Message(asmr_e_invalid_symbol_ref);
  1271. case oper.opr.typ of
  1272. OPR_LOCAL :
  1273. inc(oper.opr.localsymofs,l);
  1274. OPR_REFERENCE :
  1275. inc(oper.opr.ref.offset,l);
  1276. end;
  1277. if hastypecast then
  1278. oper.hastype:=true;
  1279. oper.SetSize(k,false);
  1280. end;
  1281. if GotOffset then
  1282. begin
  1283. if oper.hasvar and (oper.opr.ref.base=current_procinfo.framepointer) then
  1284. begin
  1285. if (oper.opr.typ=OPR_REFERENCE) then
  1286. oper.opr.ref.base:=NR_NO;
  1287. oper.hasvar:=hadvar;
  1288. end
  1289. else
  1290. begin
  1291. if oper.hasvar and hadvar then
  1292. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1293. { should we allow ?? }
  1294. end;
  1295. end;
  1296. end;
  1297. GotOffset:=false;
  1298. end;
  1299. AS_PLUS :
  1300. Begin
  1301. Consume(AS_PLUS);
  1302. Negative:=false;
  1303. GotPlus:=true;
  1304. GotStar:=false;
  1305. Scale:=0;
  1306. end;
  1307. AS_DOT :
  1308. Begin
  1309. { Handle like a + }
  1310. Consume(AS_DOT);
  1311. Negative:=false;
  1312. GotPlus:=true;
  1313. GotStar:=false;
  1314. Scale:=0;
  1315. end;
  1316. AS_MINUS :
  1317. begin
  1318. Consume(AS_MINUS);
  1319. Negative:=true;
  1320. GotPlus:=true;
  1321. GotStar:=false;
  1322. Scale:=0;
  1323. end;
  1324. AS_STAR : { Scaling, with eax*4 order }
  1325. begin
  1326. Consume(AS_STAR);
  1327. hs:='';
  1328. l:=0;
  1329. case actasmtoken of
  1330. AS_ID,
  1331. AS_LPAREN :
  1332. l:=BuildConstExpression;
  1333. AS_INTNUM:
  1334. Begin
  1335. hs:=actasmpattern;
  1336. Consume(AS_INTNUM);
  1337. end;
  1338. AS_REGISTER :
  1339. begin
  1340. case oper.opr.typ of
  1341. OPR_REFERENCE :
  1342. begin
  1343. if oper.opr.ref.scalefactor=0 then
  1344. begin
  1345. if scale<>0 then
  1346. begin
  1347. oper.opr.ref.scalefactor:=scale;
  1348. scale:=0;
  1349. end
  1350. else
  1351. Message(asmr_e_wrong_scale_factor);
  1352. end
  1353. else
  1354. Message(asmr_e_invalid_reference_syntax);
  1355. end;
  1356. OPR_LOCAL :
  1357. begin
  1358. if oper.opr.localscale=0 then
  1359. begin
  1360. if scale<>0 then
  1361. begin
  1362. oper.opr.localscale:=scale;
  1363. scale:=0;
  1364. end
  1365. else
  1366. Message(asmr_e_wrong_scale_factor);
  1367. end
  1368. else
  1369. Message(asmr_e_invalid_reference_syntax);
  1370. end;
  1371. end;
  1372. end;
  1373. else
  1374. Message(asmr_e_invalid_reference_syntax);
  1375. end;
  1376. if actasmtoken<>AS_REGISTER then
  1377. begin
  1378. if hs<>'' then
  1379. val(hs,l,code);
  1380. case oper.opr.typ of
  1381. OPR_REFERENCE :
  1382. oper.opr.ref.scalefactor:=l;
  1383. OPR_LOCAL :
  1384. oper.opr.localscale:=l;
  1385. end;
  1386. if l>9 then
  1387. Message(asmr_e_wrong_scale_factor);
  1388. end;
  1389. GotPlus:=false;
  1390. GotStar:=false;
  1391. end;
  1392. AS_REGISTER :
  1393. begin
  1394. if not((GotPlus and (not Negative)) or
  1395. GotStar) then
  1396. Message(asmr_e_invalid_reference_syntax);
  1397. hreg:=actasmregister;
  1398. Consume(AS_REGISTER);
  1399. { this register will be the index:
  1400. 1. just read a *
  1401. 2. next token is a *
  1402. 3. base register is already used }
  1403. case oper.opr.typ of
  1404. OPR_LOCAL :
  1405. begin
  1406. if (oper.opr.localindexreg<>NR_NO) then
  1407. Message(asmr_e_multiple_index);
  1408. {$ifdef x86_64}
  1409. { Locals/parameters cannot be accessed RIP-relative. Need a dedicated error message here? }
  1410. if (hreg=NR_RIP) then
  1411. Message(asmr_e_no_local_or_para_allowed);
  1412. {$endif x86_64}
  1413. oper.opr.localindexreg:=hreg;
  1414. if scale<>0 then
  1415. begin
  1416. oper.opr.localscale:=scale;
  1417. scale:=0;
  1418. end;
  1419. end;
  1420. OPR_REFERENCE :
  1421. begin
  1422. if (GotStar) or
  1423. (actasmtoken=AS_STAR) or
  1424. (oper.opr.ref.base<>NR_NO) then
  1425. begin
  1426. if (oper.opr.ref.index<>NR_NO) then
  1427. Message(asmr_e_multiple_index);
  1428. oper.opr.ref.index:=hreg;
  1429. if scale<>0 then
  1430. begin
  1431. oper.opr.ref.scalefactor:=scale;
  1432. scale:=0;
  1433. end;
  1434. end
  1435. else
  1436. begin
  1437. oper.opr.ref.base:=hreg;
  1438. {$ifdef x86_64}
  1439. { non-GOT based RIP-relative accesses are also position-independent }
  1440. if (oper.opr.ref.base=NR_RIP) and
  1441. (oper.opr.ref.refaddr<>addr_pic) then
  1442. oper.opr.ref.refaddr:=addr_pic_no_got;
  1443. {$endif x86_64}
  1444. end;
  1445. end;
  1446. end;
  1447. GotPlus:=false;
  1448. GotStar:=false;
  1449. end;
  1450. AS_OFFSET :
  1451. begin
  1452. Consume(AS_OFFSET);
  1453. GotOffset:=true;
  1454. end;
  1455. AS_TYPE,
  1456. AS_NOT,
  1457. AS_STRING,
  1458. AS_INTNUM,
  1459. AS_LPAREN : { Constant reference expression }
  1460. begin
  1461. if not GotPlus and not GotStar then
  1462. Message(asmr_e_invalid_reference_syntax);
  1463. BuildConstSymbolExpression(true,true,GotPlus and negative,l,tempstr,tempsymtyp,isseg,is_farproc_entry);
  1464. { already handled by BuildConstSymbolExpression(); must be
  1465. handled there to avoid [reg-1+1] being interpreted as
  1466. [reg-(1+1)] }
  1467. negative:=false;
  1468. if tempstr<>'' then
  1469. begin
  1470. if GotStar then
  1471. Message(asmr_e_only_add_relocatable_symbol);
  1472. if not assigned(oper.opr.ref.symbol) then
  1473. begin
  1474. oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr,tempsymtyp);
  1475. {$ifdef i8086}
  1476. if isseg then
  1477. begin
  1478. if not (oper.opr.ref.refaddr in [addr_fardataseg,addr_dgroup]) then
  1479. oper.opr.ref.refaddr:=addr_seg;
  1480. end
  1481. else if (tempsymtyp=AT_FUNCTION) and (oper.opr.ref.segment=NR_NO) then
  1482. oper.opr.ref.segment:=NR_CS;
  1483. {$endif i8086}
  1484. end
  1485. else
  1486. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1487. end;
  1488. case oper.opr.typ of
  1489. OPR_REFERENCE :
  1490. begin
  1491. if GotStar then
  1492. oper.opr.ref.scalefactor:=l
  1493. else if (prevasmtoken = AS_STAR) then
  1494. begin
  1495. if scale<>0 then
  1496. scale:=l*scale
  1497. else
  1498. scale:=l;
  1499. end
  1500. else
  1501. begin
  1502. Inc(oper.opr.ref.offset,l);
  1503. Inc(oper.opr.constoffset,l);
  1504. end;
  1505. end;
  1506. OPR_LOCAL :
  1507. begin
  1508. if GotStar then
  1509. oper.opr.localscale:=l
  1510. else if (prevasmtoken = AS_STAR) then
  1511. begin
  1512. if scale<>0 then
  1513. scale:=l*scale
  1514. else
  1515. scale:=l;
  1516. end
  1517. else
  1518. Inc(oper.opr.localsymofs,l);
  1519. end;
  1520. end;
  1521. GotPlus:=(prevasmtoken=AS_PLUS) or
  1522. (prevasmtoken=AS_MINUS);
  1523. if GotPlus then
  1524. negative := prevasmtoken = AS_MINUS;
  1525. GotStar:=(prevasmtoken=AS_STAR);
  1526. end;
  1527. AS_RBRACKET :
  1528. begin
  1529. if GotPlus or GotStar then
  1530. Message(asmr_e_invalid_reference_syntax);
  1531. Consume(AS_RBRACKET);
  1532. break;
  1533. end;
  1534. else
  1535. Begin
  1536. Message(asmr_e_invalid_reference_syntax);
  1537. RecoverConsume(true);
  1538. break;
  1539. end;
  1540. end;
  1541. until false;
  1542. end;
  1543. Procedure tx86intreader.BuildConstantOperand(oper: tx86operand);
  1544. var
  1545. l : tcgint;
  1546. tempstr : string;
  1547. tempsymtyp : tasmsymtype;
  1548. isseg: boolean;
  1549. is_farproc_entry : boolean;
  1550. begin
  1551. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1552. Message(asmr_e_invalid_operand_type);
  1553. BuildConstSymbolExpression(true,false,false,l,tempstr,tempsymtyp,isseg,is_farproc_entry);
  1554. {$ifdef i8086}
  1555. if tempstr='@DATA' then
  1556. begin
  1557. if not isseg then
  1558. Message(asmr_e_CODE_or_DATA_without_SEG);
  1559. oper.SetupData;
  1560. end
  1561. else if tempstr='@CODE' then
  1562. begin
  1563. if not isseg then
  1564. Message(asmr_e_CODE_or_DATA_without_SEG);
  1565. oper.SetupCode;
  1566. end
  1567. else
  1568. {$endif i8086}
  1569. if tempstr<>'' then
  1570. begin
  1571. oper.opr.typ:=OPR_SYMBOL;
  1572. oper.opr.symofs:=l;
  1573. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr,tempsymtyp);
  1574. oper.opr.symseg:=isseg;
  1575. oper.opr.sym_farproc_entry:=is_farproc_entry;
  1576. end
  1577. else
  1578. if oper.opr.typ=OPR_NONE then
  1579. begin
  1580. oper.opr.typ:=OPR_CONSTANT;
  1581. oper.opr.val:=l;
  1582. end
  1583. else
  1584. inc(oper.opr.val,l);
  1585. end;
  1586. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1587. procedure AddLabelOperand(hl:tasmlabel);
  1588. begin
  1589. if (oper.opr.typ=OPR_NONE) and
  1590. is_calljmp(actopcode) then
  1591. begin
  1592. oper.opr.typ:=OPR_SYMBOL;
  1593. oper.opr.symbol:=hl;
  1594. end
  1595. else
  1596. begin
  1597. oper.InitRef;
  1598. oper.opr.ref.symbol:=hl;
  1599. {$ifdef i8086}
  1600. if oper.opr.ref.segment=NR_NO then
  1601. oper.opr.ref.segment:=NR_CS;
  1602. {$endif i8086}
  1603. end;
  1604. end;
  1605. var
  1606. expr,
  1607. hs : string;
  1608. tempreg : tregister;
  1609. l : tcgint;
  1610. hl : tasmlabel;
  1611. toffset,
  1612. tsize : tcgint;
  1613. hastypecast: boolean;
  1614. begin
  1615. expr:='';
  1616. repeat
  1617. if actasmtoken=AS_DOT then
  1618. begin
  1619. if expr<>'' then
  1620. begin
  1621. BuildRecordOffsetSize(expr,toffset,tsize,hs,false,hastypecast);
  1622. if (oper.opr.typ<>OPR_NONE) and
  1623. (hs<>'') then
  1624. Message(asmr_e_wrong_sym_type);
  1625. oper.SetSize(tsize,true);
  1626. if hastypecast then
  1627. oper.hastype:=true;
  1628. { we have used the size of a field. Reset the typesize of the record }
  1629. oper.typesize:=0;
  1630. case oper.opr.typ of
  1631. OPR_LOCAL :
  1632. begin
  1633. { don't allow direct access to fields of parameters, because that
  1634. will generate buggy code. Allow it only for explicit typecasting
  1635. and when the parameter is in a register (delphi compatible) }
  1636. if (not oper.hastype) and
  1637. (oper.opr.localsym.typ=paravarsym) and
  1638. (not(po_assembler in current_procinfo.procdef.procoptions) or
  1639. (tparavarsym(oper.opr.localsym).paraloc[calleeside].location^.loc<>LOC_REGISTER) or
  1640. (not is_implicit_pointer_object_type(oper.opr.localsym.vardef) and
  1641. not paramanager.push_addr_param(oper.opr.localsym.varspez,oper.opr.localsym.vardef,current_procinfo.procdef.proccalloption))) then
  1642. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1643. oper.opr.localforceref:=true;
  1644. inc(oper.opr.localsymofs,toffset);
  1645. oper.opr.localvarsize := tsize;
  1646. end;
  1647. OPR_CONSTANT :
  1648. inc(oper.opr.val,toffset);
  1649. OPR_REFERENCE :
  1650. begin
  1651. inc(oper.opr.ref.offset,toffset);
  1652. oper.opr.varsize := tsize;
  1653. end;
  1654. OPR_NONE :
  1655. begin
  1656. if (hs <> '') then
  1657. begin
  1658. oper.opr.typ:=OPR_SYMBOL;
  1659. oper.opr.symbol:=current_asmdata.RefAsmSymbol(hs,AT_FUNCTION);
  1660. end
  1661. else
  1662. begin
  1663. oper.opr.typ:=OPR_CONSTANT;
  1664. oper.opr.val:=toffset;
  1665. end;
  1666. end;
  1667. OPR_REGISTER :
  1668. Message(asmr_e_invalid_reference_syntax);
  1669. OPR_SYMBOL:
  1670. Message(asmr_e_invalid_symbol_ref);
  1671. else
  1672. internalerror(200309222);
  1673. end;
  1674. expr:='';
  1675. end
  1676. else
  1677. begin
  1678. { See it as a separator }
  1679. Consume(AS_DOT);
  1680. end;
  1681. end;
  1682. case actasmtoken of
  1683. {$ifndef i8086}
  1684. AS_SEG :
  1685. Begin
  1686. Message(asmr_e_seg_not_supported);
  1687. Consume(actasmtoken);
  1688. end;
  1689. {$else not i8086}
  1690. AS_SEG,
  1691. {$endif not i8086}
  1692. AS_OFFSET,
  1693. AS_SIZEOF,
  1694. AS_VMTOFFSET,
  1695. AS_TYPE,
  1696. AS_NOT,
  1697. AS_STRING,
  1698. AS_PLUS,
  1699. AS_MINUS,
  1700. AS_LPAREN,
  1701. AS_INTNUM :
  1702. begin
  1703. case oper.opr.typ of
  1704. OPR_REFERENCE :
  1705. {$ifndef x86_64}
  1706. { this is for the i386 scenario where you have
  1707. <load got into ebx>
  1708. mov eax, [ebx].offset globalvar
  1709. x86-64 uses RIP-based addresses (both for GOT and non-GOT
  1710. relative accesses)
  1711. }
  1712. if (actasmtoken=AS_OFFSET) and
  1713. (cs_create_pic in current_settings.moduleswitches) then
  1714. begin
  1715. Consume(AS_OFFSET);
  1716. oper.opr.ref.refaddr:=addr_pic;
  1717. BuildOperand(oper,false);
  1718. end
  1719. else
  1720. {$endif x86_64}
  1721. begin
  1722. l := BuildRefConstExpression;
  1723. inc(oper.opr.ref.offset,l);
  1724. inc(oper.opr.constoffset,l);
  1725. end;
  1726. OPR_LOCAL :
  1727. begin
  1728. l := BuildConstExpression;
  1729. inc(oper.opr.localsymofs,l);
  1730. inc(oper.opr.localconstoffset,l);
  1731. end;
  1732. OPR_NONE,
  1733. OPR_CONSTANT :
  1734. BuildConstantOperand(oper);
  1735. else
  1736. Message(asmr_e_invalid_operand_type);
  1737. end;
  1738. end;
  1739. AS_PTR :
  1740. begin
  1741. if not oper.hastype then
  1742. begin
  1743. if (oper.opr.typ=OPR_CONSTANT) then
  1744. begin
  1745. oper.typesize:=oper.opr.val;
  1746. { reset constant value of operand }
  1747. oper.opr.typ:=OPR_NONE;
  1748. oper.opr.val:=0;
  1749. end
  1750. else
  1751. Message(asmr_e_syn_operand);
  1752. end;
  1753. Consume(AS_PTR);
  1754. { in delphi mode, allow e.g. call dword ptr eax,
  1755. see also webtbs/tw18225.pp }
  1756. if not(m_delphi in current_settings.modeswitches) then
  1757. oper.InitRef;
  1758. { if the operand subscripts a record, the typesize will be
  1759. rest -> save it here and restore it afterwards }
  1760. l:=oper.typesize;
  1761. BuildOperand(oper,false);
  1762. oper.setsize(l,true);
  1763. end;
  1764. AS_ID : { A constant expression, or a Variable ref. }
  1765. Begin
  1766. { Label or Special symbol reference? }
  1767. if actasmpattern[1] = '@' then
  1768. Begin
  1769. if actasmpattern = '@RESULT' then
  1770. Begin
  1771. oper.SetupResult;
  1772. Consume(AS_ID);
  1773. expr:='result';
  1774. end
  1775. else
  1776. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1777. begin
  1778. {$ifdef i8086}
  1779. Message(asmr_e_CODE_or_DATA_without_SEG);
  1780. {$else i8086}
  1781. Message(asmr_w_CODE_and_DATA_not_supported);
  1782. {$endif i8086}
  1783. Consume(AS_ID);
  1784. end
  1785. else
  1786. { Local Label }
  1787. begin
  1788. CreateLocalLabel(actasmpattern,hl,false);
  1789. Consume(AS_ID);
  1790. AddLabelOperand(hl);
  1791. end;
  1792. end
  1793. else
  1794. { support result for delphi modes }
  1795. if (m_objpas in current_settings.modeswitches) and (actasmpattern='RESULT') then
  1796. begin
  1797. oper.SetUpResult;
  1798. Consume(AS_ID);
  1799. expr:='result';
  1800. end
  1801. { probably a variable or normal expression }
  1802. { or a procedure (such as in CALL ID) }
  1803. else
  1804. Begin
  1805. { is it a constant ? }
  1806. if SearchIConstant(actasmpattern,l) then
  1807. Begin
  1808. case oper.opr.typ of
  1809. OPR_REFERENCE :
  1810. begin
  1811. l := BuildRefConstExpression;
  1812. inc(oper.opr.ref.offset,l);
  1813. inc(oper.opr.constoffset,l);
  1814. end;
  1815. OPR_LOCAL :
  1816. begin
  1817. l := BuildRefConstExpression;
  1818. inc(oper.opr.localsymofs,l);
  1819. inc(oper.opr.localconstoffset,l);
  1820. end;
  1821. OPR_NONE,
  1822. OPR_CONSTANT :
  1823. BuildConstantOperand(oper);
  1824. else
  1825. Message(asmr_e_invalid_operand_type);
  1826. end;
  1827. end
  1828. else
  1829. { Check for pascal label }
  1830. if SearchLabel(actasmpattern,hl,false) then
  1831. begin
  1832. Consume(AS_ID);
  1833. AddLabelOperand(hl);
  1834. end
  1835. else
  1836. { is it a normal variable ? }
  1837. Begin
  1838. expr:=actasmpattern;
  1839. Consume(AS_ID);
  1840. { typecasting? }
  1841. if SearchType(expr,l) then
  1842. begin
  1843. oper.hastype:=true;
  1844. oper.typesize:=l;
  1845. case actasmtoken of
  1846. AS_LPAREN :
  1847. begin
  1848. { Support Type([Reference]) }
  1849. Consume(AS_LPAREN);
  1850. BuildOperand(oper,true);
  1851. { Delphi also supports Type(Register) and
  1852. interprets it the same as Type([Register]). }
  1853. if (oper.opr.typ = OPR_REGISTER) then
  1854. { This also sets base to the register. }
  1855. oper.InitRef;
  1856. Consume(AS_RPAREN);
  1857. end;
  1858. AS_LBRACKET :
  1859. begin
  1860. { Support Var.Type[Index] }
  1861. { Convert @label.Byte[1] to reference }
  1862. if oper.opr.typ=OPR_SYMBOL then
  1863. oper.initref;
  1864. end;
  1865. end;
  1866. end
  1867. else
  1868. begin
  1869. if not oper.SetupVar(expr,false) then
  1870. Begin
  1871. { not a variable, check special variables.. }
  1872. if expr = 'SELF' then
  1873. begin
  1874. oper.SetupSelf;
  1875. expr:='self';
  1876. end
  1877. else
  1878. begin
  1879. Message1(sym_e_unknown_id,expr);
  1880. expr:='';
  1881. end;
  1882. end;
  1883. { indexed access to variable? }
  1884. if actasmtoken=AS_LBRACKET then
  1885. begin
  1886. { ... then the operand size is not known anymore }
  1887. oper.size:=OS_NO;
  1888. BuildReference(oper);
  1889. end;
  1890. end;
  1891. end;
  1892. end;
  1893. end;
  1894. AS_REGISTER : { Register, a variable reference or a constant reference }
  1895. begin
  1896. { save the type of register used. }
  1897. tempreg:=actasmregister;
  1898. Consume(AS_REGISTER);
  1899. if actasmtoken = AS_COLON then
  1900. Begin
  1901. Consume(AS_COLON);
  1902. oper.InitRef;
  1903. oper.opr.ref.segment:=tempreg;
  1904. BuildReference(oper);
  1905. end
  1906. else
  1907. { Simple register }
  1908. begin
  1909. if (oper.opr.typ <> OPR_NONE) then
  1910. Message(asmr_e_syn_operand);
  1911. oper.opr.typ:=OPR_REGISTER;
  1912. oper.opr.reg:=tempreg;
  1913. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1914. end;
  1915. end;
  1916. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1917. Begin
  1918. BuildReference(oper);
  1919. end;
  1920. AS_DWORD,
  1921. AS_BYTE,
  1922. AS_WORD,
  1923. AS_TBYTE,
  1924. AS_DQWORD,
  1925. AS_QWORD,
  1926. AS_OWORD,
  1927. AS_XMMWORD,
  1928. AS_YWORD,
  1929. AS_YMMWORD:
  1930. begin
  1931. { Type specifier }
  1932. oper.hastype:=true;
  1933. oper.typesize:=0;
  1934. case actasmtoken of
  1935. AS_DWORD : oper.typesize:=4;
  1936. AS_WORD : oper.typesize:=2;
  1937. AS_BYTE : oper.typesize:=1;
  1938. AS_QWORD : oper.typesize:=8;
  1939. AS_DQWORD : oper.typesize:=16;
  1940. AS_TBYTE : oper.typesize:=10;
  1941. AS_OWORD,
  1942. AS_XMMWORD: oper.typesize:=16;
  1943. AS_YWORD,
  1944. AS_YMMWORD: oper.typesize:=32;
  1945. else
  1946. internalerror(2010061101);
  1947. end;
  1948. Consume(actasmtoken);
  1949. if (actasmtoken=AS_LPAREN) then
  1950. begin
  1951. { Support "xxx ptr [Reference]" }
  1952. { in case the expression subscripts a record, the typesize
  1953. is reset, so save the explicit size we set above }
  1954. l:=oper.typesize;
  1955. Consume(AS_LPAREN);
  1956. BuildOperand(oper,true);
  1957. Consume(AS_RPAREN);
  1958. oper.setsize(l,true);
  1959. end;
  1960. end;
  1961. AS_SEPARATOR,
  1962. AS_END,
  1963. AS_COMMA,
  1964. AS_COLON:
  1965. begin
  1966. break;
  1967. end;
  1968. AS_RPAREN:
  1969. begin
  1970. if not istypecast then
  1971. begin
  1972. Message(asmr_e_syn_operand);
  1973. Consume(AS_RPAREN);
  1974. end
  1975. else
  1976. break;
  1977. end;
  1978. else
  1979. begin
  1980. Message(asmr_e_syn_operand);
  1981. RecoverConsume(true);
  1982. break;
  1983. end;
  1984. end;
  1985. until false;
  1986. { End of operand, update size if a typecast is forced }
  1987. if (oper.typesize<>0) and
  1988. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1989. oper.SetSize(oper.typesize,true);
  1990. {$ifdef i8086}
  1991. { references to a procedure/function entry, without an explicit segment
  1992. override, are added an CS: override by default (this is Turbo Pascal 7
  1993. compatible) }
  1994. if (oper.opr.typ=OPR_REFERENCE) and assigned(oper.opr.ref.symbol) and
  1995. (oper.opr.ref.symbol.typ=AT_FUNCTION) and (oper.opr.ref.segment=NR_NO) then
  1996. oper.opr.ref.segment:=NR_CS;
  1997. {$endif i8086}
  1998. end;
  1999. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  2000. var
  2001. PrefixOp,OverrideOp: tasmop;
  2002. operandnum : longint;
  2003. t: TRegister;
  2004. is_far_const:boolean;
  2005. i:byte;
  2006. tmp: toperand;
  2007. di_param, si_param: ShortInt;
  2008. {$ifdef i8086}
  2009. hsymbol: TAsmSymbol;
  2010. hoffset: ASizeInt;
  2011. href_farproc_entry: Boolean;
  2012. {$endif i8086}
  2013. begin
  2014. PrefixOp:=A_None;
  2015. OverrideOp:=A_None;
  2016. is_far_const:=false;
  2017. { prefix seg opcode / prefix opcode }
  2018. repeat
  2019. if is_prefix(actopcode) then
  2020. with instr do
  2021. begin
  2022. PrefixOp:=ActOpcode;
  2023. opcode:=ActOpcode;
  2024. condition:=ActCondition;
  2025. opsize:=ActOpsize;
  2026. ConcatInstruction(curlist);
  2027. consume(AS_OPCODE);
  2028. end
  2029. else
  2030. if is_override(actopcode) then
  2031. with instr do
  2032. begin
  2033. OverrideOp:=ActOpcode;
  2034. opcode:=ActOpcode;
  2035. condition:=ActCondition;
  2036. opsize:=ActOpsize;
  2037. ConcatInstruction(curlist);
  2038. consume(AS_OPCODE);
  2039. end
  2040. else
  2041. break;
  2042. { allow for newline after prefix or override }
  2043. while actasmtoken=AS_SEPARATOR do
  2044. consume(AS_SEPARATOR);
  2045. until (actasmtoken<>AS_OPCODE);
  2046. { opcode }
  2047. if (actasmtoken <> AS_OPCODE) then
  2048. begin
  2049. Message(asmr_e_invalid_or_missing_opcode);
  2050. RecoverConsume(false);
  2051. exit;
  2052. end;
  2053. { Fill the instr object with the current state }
  2054. with instr do
  2055. begin
  2056. Opcode:=ActOpcode;
  2057. condition:=ActCondition;
  2058. opsize:=ActOpsize;
  2059. { Valid combination of prefix/override and instruction ? }
  2060. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  2061. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  2062. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  2063. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  2064. end;
  2065. { pushf/popf/pusha/popa have to default to 16 bit in Intel mode
  2066. (Intel manual and Delphi-compatbile) -- setting the opsize for
  2067. these instructions doesn't change anything in the internal assember,
  2068. so change the opcode }
  2069. if (instr.opcode=A_POPF) then
  2070. instr.opcode:=A_POPFW
  2071. else if (instr.opcode=A_PUSHF) then
  2072. instr.opcode:=A_PUSHFW
  2073. {$ifndef x86_64}
  2074. else if (instr.opcode=A_PUSHA) then
  2075. instr.opcode:=A_PUSHAW
  2076. else if (instr.opcode=A_POPA) then
  2077. instr.opcode:=A_POPAW
  2078. {$endif x86_64}
  2079. {$ifdef i8086}
  2080. { ret is converted to retn or retf, depending on the call model of the
  2081. current procedure (BP7 compatible) }
  2082. else if (instr.opcode=A_RET) then
  2083. begin
  2084. if is_proc_far(current_procinfo.procdef) and
  2085. not (po_interrupt in current_procinfo.procdef.procoptions) then
  2086. instr.opcode:=A_RETF
  2087. else
  2088. instr.opcode:=A_RETN;
  2089. end
  2090. {$endif i8086}
  2091. ;
  2092. { We are reading operands, so opcode will be an AS_ID }
  2093. { process operands backwards to get them in AT&T order }
  2094. operandnum:=max_operands;
  2095. is_far_const:=false;
  2096. Consume(AS_OPCODE);
  2097. { Zero operand opcode ? }
  2098. if actasmtoken in [AS_SEPARATOR,AS_END] then
  2099. exit;
  2100. { Read Operands }
  2101. repeat
  2102. case actasmtoken of
  2103. { End of asm operands for this opcode }
  2104. AS_END,
  2105. AS_SEPARATOR :
  2106. break;
  2107. { Operand delimiter }
  2108. AS_COMMA :
  2109. begin
  2110. { should have something before the comma }
  2111. if instr.operands[operandnum].opr.typ=OPR_NONE then
  2112. Message(asmr_e_syntax_error);
  2113. if operandnum <= 1 then
  2114. Message(asmr_e_too_many_operands)
  2115. else
  2116. Dec(operandnum);
  2117. Consume(AS_COMMA);
  2118. end;
  2119. {Far constant, i.e. jmp $0000:$11111111.}
  2120. AS_COLON:
  2121. begin
  2122. is_far_const:=true;
  2123. if operandnum<max_operands then
  2124. message(asmr_e_too_many_operands)
  2125. else
  2126. dec(operandnum);
  2127. consume(AS_COLON);
  2128. end;
  2129. { Type specifier }
  2130. AS_NEAR,
  2131. AS_FAR :
  2132. begin
  2133. if actasmtoken = AS_NEAR then
  2134. begin
  2135. {$ifndef i8086}
  2136. Message(asmr_w_near_ignored);
  2137. {$endif not i8086}
  2138. instr.opsize:=S_NEAR;
  2139. end
  2140. else
  2141. begin
  2142. {$ifndef i8086}
  2143. Message(asmr_w_far_ignored);
  2144. {$endif not i8086}
  2145. instr.opsize:=S_FAR;
  2146. end;
  2147. Consume(actasmtoken);
  2148. if actasmtoken=AS_PTR then
  2149. begin
  2150. Consume(AS_PTR);
  2151. instr.Operands[operandnum].InitRef;
  2152. end;
  2153. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  2154. end;
  2155. else
  2156. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  2157. end; { end case }
  2158. until false;
  2159. { shift operands to start from 1, exchange to make sure they are destroyed correctly }
  2160. for i:=operandnum to max_operands do
  2161. begin
  2162. tmp:=instr.operands[i+1-operandnum];
  2163. instr.operands[i+1-operandnum]:=instr.operands[i];
  2164. instr.operands[i]:=tmp;
  2165. end;
  2166. operandnum:=(max_operands+1)-operandnum;
  2167. instr.ops:=operandnum;
  2168. { Check operands }
  2169. for i:=1 to operandnum do
  2170. begin
  2171. if is_far_const and
  2172. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  2173. message(asmr_e_expr_illegal)
  2174. else
  2175. if instr.operands[i].opr.typ=OPR_NONE then
  2176. Message(asmr_e_syntax_error);
  2177. end;
  2178. { Check for invalid ES: overrides }
  2179. if is_x86_parameterized_string_op(instr.opcode) then
  2180. begin
  2181. si_param:=get_x86_string_op_si_param(instr.opcode);
  2182. if si_param<>-1 then
  2183. si_param:=x86_parameterized_string_op_param_count(instr.opcode)-si_param;
  2184. di_param:=get_x86_string_op_di_param(instr.opcode);
  2185. if di_param<>-1 then
  2186. begin
  2187. di_param:=x86_parameterized_string_op_param_count(instr.opcode)-di_param;
  2188. if di_param<=operandnum then
  2189. with instr.operands[di_param] do
  2190. if (opr.typ=OPR_REFERENCE) and
  2191. (opr.ref.segment<>NR_NO) and
  2192. (opr.ref.segment<>NR_ES) then
  2193. Message(asmr_e_cannot_override_es_segment);
  2194. end;
  2195. { if two memory parameters, check whether their address sizes are equal }
  2196. if (si_param<>-1) and (di_param<>-1) and
  2197. (si_param<=operandnum) and (di_param<=operandnum) and
  2198. (instr.operands[si_param].opr.typ=OPR_REFERENCE) and
  2199. (instr.operands[di_param].opr.typ=OPR_REFERENCE) then
  2200. begin
  2201. if get_ref_address_size(instr.operands[si_param].opr.ref)<>
  2202. get_ref_address_size(instr.operands[di_param].opr.ref) then
  2203. Message(asmr_e_address_sizes_do_not_match);
  2204. end;
  2205. end;
  2206. { e.g. for "push dword 1", "push word 6" }
  2207. if (instr.ops=1) and
  2208. (instr.operands[1].typesize<>0) then
  2209. instr.operands[1].setsize(instr.operands[1].typesize,false);
  2210. {$ifdef i8086}
  2211. for i:=1 to operandnum do
  2212. with instr.operands[i].opr do
  2213. begin
  2214. { convert 'call/jmp [proc/label]' to 'call/jmp proc/label'. Ugly,
  2215. but Turbo Pascal 7 compatible. }
  2216. if (instr.opcode in [A_CALL,A_JMP]) and (typ=OPR_REFERENCE) and
  2217. assigned(ref.symbol) and (ref.symbol.typ in [AT_FUNCTION,AT_LABEL,AT_ADDR]) and
  2218. (ref.base=NR_NO) and (ref.index=NR_NO) then
  2219. begin
  2220. hsymbol:=ref.symbol;
  2221. hoffset:=ref.offset;
  2222. href_farproc_entry:=ref_farproc_entry;
  2223. typ:=OPR_SYMBOL;
  2224. symbol:=hsymbol;
  2225. symofs:=hoffset;
  2226. symseg:=False;
  2227. sym_farproc_entry:=href_farproc_entry;
  2228. end;
  2229. { convert 'call/jmp symbol' to 'call/jmp far symbol' for symbols that are an entry point of a far procedure }
  2230. if (instr.opcode in [A_CALL,A_JMP]) and (instr.opsize=S_NO) and
  2231. (typ=OPR_SYMBOL) and sym_farproc_entry then
  2232. instr.opsize:=S_FAR;
  2233. { convert 'call/jmp dword [something]' to 'call/jmp far [something]' (BP7 compatibility) }
  2234. if (instr.opcode in [A_CALL,A_JMP]) and (instr.opsize=S_NO) and
  2235. (typ in [OPR_LOCAL,OPR_REFERENCE]) and (instr.operands[i].size=OS_32) then
  2236. instr.opsize:=S_FAR;
  2237. end;
  2238. {$endif i8086}
  2239. if (MemRefInfo(instr.opcode).ExistsSSEAVX) and
  2240. (MemRefInfo(instr.opcode).MemRefSize in MemRefSizeInfoVMems) then
  2241. begin
  2242. for i:=1 to operandnum do
  2243. begin
  2244. if (instr.operands[i].opr.typ = OPR_REFERENCE) and
  2245. (getregtype(instr.operands[i].opr.ref.base) = R_MMREGISTER) and
  2246. (instr.operands[i].opr.ref.index = NR_NO) then
  2247. begin
  2248. instr.operands[i].opr.ref.index := instr.operands[i].opr.ref.base;
  2249. instr.operands[i].opr.ref.base := NR_NO;
  2250. end
  2251. else if (instr.operands[i].opr.typ = OPR_REFERENCE) and
  2252. (getregtype(instr.operands[i].opr.ref.base) = R_MMREGISTER) and
  2253. (getregtype(instr.operands[i].opr.ref.index) = R_INTREGISTER) and
  2254. (getsubreg(instr.operands[i].opr.ref.index) = R_SUBADDR) then
  2255. begin
  2256. // exchange base- and index-register
  2257. // e.g. VGATHERDPD XMM0, [XMM1 + RAX], XMM2 =>> VGATHERDPD XMM0, [RAX + XMM1], XMM2
  2258. // e.g. VGATHERDPD XMM0, [XMM1 + RAX * 2], XMM2 =>> not supported
  2259. // e.g. VGATHERDPD XMM0, [XMM1 + RAX + 16], XMM2 =>> VGATHERDPD XMM0, [RAX + XMM1 + 16]
  2260. if instr.operands[i].opr.ref.scalefactor > 1 then Message(asmr_e_invalid_reference_syntax)
  2261. else
  2262. begin
  2263. t := instr.operands[i].opr.ref.base;
  2264. instr.operands[i].opr.ref.base := instr.operands[i].opr.ref.index;
  2265. instr.operands[i].opr.ref.index := t;
  2266. end;
  2267. end;
  2268. end;
  2269. end;
  2270. end;
  2271. Procedure tx86intreader.BuildConstant(constsize: byte);
  2272. var
  2273. asmsymtyp : tasmsymtype;
  2274. asmsym,
  2275. expr: string;
  2276. value : tcgint;
  2277. isseg: boolean;
  2278. is_farproc_entry : boolean;
  2279. Begin
  2280. Repeat
  2281. Case actasmtoken of
  2282. AS_STRING:
  2283. Begin
  2284. { DD and DW cases }
  2285. if constsize <> 1 then
  2286. Begin
  2287. if Not PadZero(actasmpattern,constsize) then
  2288. Message(scan_f_string_exceeds_line);
  2289. end;
  2290. expr:=actasmpattern;
  2291. Consume(AS_STRING);
  2292. Case actasmtoken of
  2293. AS_COMMA:
  2294. Consume(AS_COMMA);
  2295. AS_END,
  2296. AS_SEPARATOR: ;
  2297. else
  2298. Message(asmr_e_invalid_string_expression);
  2299. end;
  2300. ConcatString(curlist,expr);
  2301. end;
  2302. AS_PLUS,
  2303. AS_MINUS,
  2304. AS_LPAREN,
  2305. AS_NOT,
  2306. AS_INTNUM,
  2307. {$ifdef i8086}
  2308. AS_SEG,
  2309. {$endif i8086}
  2310. AS_ID :
  2311. Begin
  2312. BuildConstSymbolExpression(false,false,false,value,asmsym,asmsymtyp,isseg,is_farproc_entry);
  2313. if asmsym<>'' then
  2314. begin
  2315. if (not isseg) and (constsize<>sizeof(pint)) then
  2316. Message1(asmr_w_const32bit_for_address,asmsym);
  2317. {$ifdef i8086}
  2318. if asmsym='@DATA' then
  2319. begin
  2320. if not isseg then
  2321. Message(asmr_e_CODE_or_DATA_without_SEG);
  2322. if constsize<2 then
  2323. Message1(asmr_e_const16bit_for_segment,asmsym);
  2324. if current_settings.x86memorymodel=mm_huge then
  2325. curlist.concat(Tai_const.Create_fardataseg)
  2326. else
  2327. curlist.concat(Tai_const.Create_dgroup);
  2328. if constsize>2 then
  2329. ConcatConstant(curlist,0,constsize-2);
  2330. end
  2331. else if asmsym='@CODE' then
  2332. begin
  2333. if not isseg then
  2334. Message(asmr_e_CODE_or_DATA_without_SEG);
  2335. if constsize<2 then
  2336. Message1(asmr_e_const16bit_for_segment,asmsym);
  2337. curlist.concat(Tai_const.Create_seg_name(current_procinfo.procdef.mangledname));
  2338. if constsize>2 then
  2339. ConcatConstant(curlist,0,constsize-2);
  2340. end
  2341. else if isseg then
  2342. begin
  2343. if constsize<2 then
  2344. Message1(asmr_e_const16bit_for_segment,asmsym);
  2345. curlist.concat(Tai_const.Create_seg_name(asmsym));
  2346. if constsize>2 then
  2347. ConcatConstant(curlist,0,constsize-2);
  2348. end
  2349. else
  2350. {$endif i8086}
  2351. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value);
  2352. end
  2353. else
  2354. ConcatConstant(curlist,value,constsize);
  2355. end;
  2356. AS_COMMA:
  2357. begin
  2358. Consume(AS_COMMA);
  2359. end;
  2360. AS_ALIGN,
  2361. AS_DB,
  2362. AS_DW,
  2363. AS_DD,
  2364. AS_DQ,
  2365. AS_OPCODE,
  2366. AS_END,
  2367. AS_SEPARATOR:
  2368. break;
  2369. else
  2370. begin
  2371. Message(asmr_e_syn_constant);
  2372. RecoverConsume(false);
  2373. end
  2374. end;
  2375. Until false;
  2376. end;
  2377. function tx86intreader.Assemble: tlinkedlist;
  2378. Var
  2379. hl : tasmlabel;
  2380. instr : Tx86Instruction;
  2381. Begin
  2382. Message1(asmr_d_start_reading,'intel');
  2383. inexpression:=FALSE;
  2384. firsttoken:=TRUE;
  2385. { sets up all opcode and register tables in uppercase
  2386. done in the construtor now
  2387. if not _asmsorted then
  2388. Begin
  2389. SetupTables;
  2390. _asmsorted:=TRUE;
  2391. end;
  2392. }
  2393. curlist:=TAsmList.Create;
  2394. { we might need to know which parameters are passed in registers }
  2395. if not parse_generic then
  2396. current_procinfo.generate_parameter_info;
  2397. { start tokenizer }
  2398. gettoken;
  2399. { main loop }
  2400. repeat
  2401. case actasmtoken of
  2402. AS_LLABEL:
  2403. Begin
  2404. if CreateLocalLabel(actasmpattern,hl,true) then
  2405. ConcatLabel(curlist,hl);
  2406. Consume(AS_LLABEL);
  2407. end;
  2408. AS_LABEL:
  2409. Begin
  2410. if SearchLabel(upper(actasmpattern),hl,true) then
  2411. ConcatLabel(curlist,hl)
  2412. else
  2413. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  2414. Consume(AS_LABEL);
  2415. end;
  2416. AS_DW :
  2417. Begin
  2418. inexpression:=true;
  2419. Consume(AS_DW);
  2420. BuildConstant(2);
  2421. inexpression:=false;
  2422. end;
  2423. AS_DB :
  2424. Begin
  2425. inexpression:=true;
  2426. Consume(AS_DB);
  2427. BuildConstant(1);
  2428. inexpression:=false;
  2429. end;
  2430. AS_DD :
  2431. Begin
  2432. inexpression:=true;
  2433. Consume(AS_DD);
  2434. BuildConstant(4);
  2435. inexpression:=false;
  2436. end;
  2437. {$ifdef cpu64bitaddr}
  2438. AS_DQ:
  2439. Begin
  2440. inexpression:=true;
  2441. Consume(AS_DQ);
  2442. BuildConstant(8);
  2443. inexpression:=false;
  2444. end;
  2445. {$endif cpu64bitaddr}
  2446. AS_ALIGN:
  2447. Begin
  2448. Consume(AS_ALIGN);
  2449. ConcatAlign(curlist,BuildConstExpression);
  2450. if actasmtoken<>AS_SEPARATOR then
  2451. Consume(AS_SEPARATOR);
  2452. end;
  2453. AS_OPCODE :
  2454. Begin
  2455. instr:=Tx86Instruction.Create(Tx86Operand);
  2456. BuildOpcode(instr);
  2457. with instr do
  2458. begin
  2459. CheckNonCommutativeOpcodes;
  2460. AddReferenceSizes;
  2461. SetInstructionOpsize;
  2462. CheckOperandSizes;
  2463. ConcatInstruction(curlist);
  2464. end;
  2465. instr.Free;
  2466. end;
  2467. AS_SEPARATOR :
  2468. Begin
  2469. Consume(AS_SEPARATOR);
  2470. end;
  2471. AS_END :
  2472. break; { end assembly block }
  2473. else
  2474. Begin
  2475. Message(asmr_e_syntax_error);
  2476. RecoverConsume(false);
  2477. end;
  2478. end; { end case }
  2479. until false;
  2480. { check that all referenced local labels are defined }
  2481. checklocallabels;
  2482. { Return the list in an asmnode }
  2483. assemble:=curlist;
  2484. Message1(asmr_d_finish_reading,'intel');
  2485. end;
  2486. end.