rax86int.pas 93 KB

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