rax86int.pas 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672
  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,hasofs: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,hasofs: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. hasofs:=FALSE;
  748. errorflag:=FALSE;
  749. tempstr:='';
  750. expr:='';
  751. if startingminus then
  752. expr:='-';
  753. inexpression:=TRUE;
  754. parenlevel:=0;
  755. sym:=nil;
  756. needvmtofs:=FALSE;
  757. Repeat
  758. { Support ugly delphi constructs like: [ECX].1+2[EDX] }
  759. if isref and (actasmtoken=AS_LBRACKET) then
  760. break;
  761. Case actasmtoken of
  762. AS_LPAREN:
  763. Begin
  764. Consume(AS_LPAREN);
  765. expr:=expr + '(';
  766. inc(parenlevel);
  767. end;
  768. AS_RPAREN:
  769. Begin
  770. { Keep the AS_PAREN in actasmtoken, it is maybe a typecast }
  771. if parenlevel=0 then
  772. break;
  773. Consume(AS_RPAREN);
  774. expr:=expr + ')';
  775. dec(parenlevel);
  776. end;
  777. AS_SHL:
  778. Begin
  779. Consume(AS_SHL);
  780. expr:=expr + '<';
  781. end;
  782. AS_SHR:
  783. Begin
  784. Consume(AS_SHR);
  785. expr:=expr + '>';
  786. end;
  787. AS_SLASH:
  788. Begin
  789. Consume(AS_SLASH);
  790. expr:=expr + '/';
  791. end;
  792. AS_MOD:
  793. Begin
  794. Consume(AS_MOD);
  795. expr:=expr + '%';
  796. end;
  797. AS_STAR:
  798. Begin
  799. Consume(AS_STAR);
  800. if isref and (actasmtoken=AS_REGISTER) then
  801. break;
  802. expr:=expr + '*';
  803. end;
  804. AS_PLUS:
  805. Begin
  806. Consume(AS_PLUS);
  807. if isref and (actasmtoken=AS_REGISTER) then
  808. break;
  809. expr:=expr + '+';
  810. end;
  811. AS_MINUS:
  812. Begin
  813. Consume(AS_MINUS);
  814. expr:=expr + '-';
  815. end;
  816. AS_AND:
  817. Begin
  818. Consume(AS_AND);
  819. expr:=expr + '&';
  820. end;
  821. AS_NOT:
  822. Begin
  823. Consume(AS_NOT);
  824. expr:=expr + '~';
  825. end;
  826. AS_XOR:
  827. Begin
  828. Consume(AS_XOR);
  829. expr:=expr + '^';
  830. end;
  831. AS_OR:
  832. Begin
  833. Consume(AS_OR);
  834. expr:=expr + '|';
  835. end;
  836. AS_INTNUM:
  837. Begin
  838. expr:=expr + actasmpattern;
  839. Consume(AS_INTNUM);
  840. end;
  841. {$ifdef i8086}
  842. AS_SEG:
  843. begin
  844. isseg:=true;
  845. Consume(actasmtoken);
  846. if actasmtoken<>AS_ID then
  847. Message(asmr_e_seg_without_identifier);
  848. end;
  849. {$endif i8086}
  850. AS_VMTOFFSET,
  851. AS_OFFSET:
  852. begin
  853. if (actasmtoken = AS_OFFSET) then
  854. needofs:=true
  855. else
  856. needvmtofs:=true;
  857. Consume(actasmtoken);
  858. if actasmtoken<>AS_ID then
  859. Message(asmr_e_offset_without_identifier);
  860. end;
  861. AS_SIZEOF,
  862. AS_TYPE:
  863. begin
  864. l:=0;
  865. hasparen:=false;
  866. Consume(actasmtoken);
  867. if actasmtoken=AS_LPAREN then
  868. begin
  869. hasparen:=true;
  870. Consume(AS_LPAREN);
  871. end;
  872. if actasmtoken<>AS_ID then
  873. Message(asmr_e_type_without_identifier)
  874. else
  875. begin
  876. tempstr:=actasmpattern;
  877. Consume(AS_ID);
  878. if actasmtoken=AS_DOT then
  879. begin
  880. BuildRecordOffsetSize(tempstr,k,l,mangledname,false,hastypecast);
  881. if mangledname<>'' then
  882. { procsym }
  883. Message(asmr_e_wrong_sym_type);
  884. if hastypecast then
  885. end
  886. else
  887. begin
  888. asmsearchsym(tempstr,sym,srsymtable);
  889. if assigned(sym) then
  890. begin
  891. case sym.typ of
  892. staticvarsym,
  893. localvarsym,
  894. paravarsym :
  895. l:=tabstractvarsym(sym).getsize;
  896. typesym :
  897. l:=ttypesym(sym).typedef.size;
  898. else
  899. Message(asmr_e_wrong_sym_type);
  900. end;
  901. end
  902. else
  903. Message1(sym_e_unknown_id,tempstr);
  904. end;
  905. end;
  906. str(l, tempstr);
  907. expr:=expr + tempstr;
  908. if hasparen then
  909. Consume(AS_RPAREN);
  910. end;
  911. AS_PTR :
  912. begin
  913. { Support ugly delphi constructs like <constant> PTR [ref] }
  914. break;
  915. end;
  916. AS_STRING:
  917. begin
  918. l:=0;
  919. case Length(actasmpattern) of
  920. 1 :
  921. l:=ord(actasmpattern[1]);
  922. 2 :
  923. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  924. 3 :
  925. l:=ord(actasmpattern[3]) +
  926. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  927. 4 :
  928. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  929. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  930. else
  931. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  932. end;
  933. str(l, tempstr);
  934. expr:=expr + tempstr;
  935. Consume(AS_STRING);
  936. end;
  937. AS_ID:
  938. begin
  939. hs:='';
  940. hssymtyp:=AT_DATA;
  941. def:=nil;
  942. tempstr:=actasmpattern;
  943. prevtok:=prevasmtoken;
  944. { stop parsing a constant expression if we find an opcode after a
  945. non-operator like "db $66 mov eax,ebx" }
  946. if (prevtok in [AS_ID,AS_INTNUM,AS_RPAREN]) and
  947. is_asmopcode(actasmpattern) then
  948. break;
  949. consume(AS_ID);
  950. if (tempstr='@CODE') or (tempstr='@DATA') then
  951. begin
  952. if asmsym='' then
  953. begin
  954. asmsym:=tempstr;
  955. asmsymtyp:=AT_SECTION;
  956. end
  957. else
  958. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  959. end
  960. else if SearchIConstant(tempstr,l) then
  961. begin
  962. str(l, tempstr);
  963. expr:=expr + tempstr;
  964. end
  965. else
  966. begin
  967. if is_locallabel(tempstr) then
  968. begin
  969. CreateLocalLabel(tempstr,hl,false);
  970. hs:=hl.name;
  971. hssymtyp:=AT_FUNCTION;
  972. end
  973. else
  974. if SearchLabel(tempstr,hl,false) then
  975. begin
  976. hs:=hl.name;
  977. hssymtyp:=AT_FUNCTION;
  978. end
  979. else
  980. begin
  981. asmsearchsym(tempstr,sym,srsymtable);
  982. if assigned(sym) then
  983. begin
  984. case sym.typ of
  985. staticvarsym :
  986. begin
  987. hs:=tstaticvarsym(sym).mangledname;
  988. def:=tstaticvarsym(sym).vardef;
  989. end;
  990. localvarsym,
  991. paravarsym :
  992. begin
  993. Message(asmr_e_no_local_or_para_allowed);
  994. end;
  995. procsym :
  996. begin
  997. if Tprocsym(sym).ProcdefList.Count>1 then
  998. Message(asmr_w_calling_overload_func);
  999. hs:=tprocdef(tprocsym(sym).ProcdefList[0]).mangledname;
  1000. {$ifdef i8086}
  1001. is_farproc_entry:=is_proc_far(tprocdef(tprocsym(sym).ProcdefList[0]))
  1002. and not (po_interrupt in tprocdef(tprocsym(sym).ProcdefList[0]).procoptions);
  1003. {$endif i8086}
  1004. hssymtyp:=AT_FUNCTION;
  1005. end;
  1006. typesym :
  1007. begin
  1008. if not(ttypesym(sym).typedef.typ in [recorddef,objectdef]) then
  1009. Message(asmr_e_wrong_sym_type);
  1010. end;
  1011. fieldvarsym :
  1012. begin
  1013. tempstr:=upper(tdef(sym.owner.defowner).GetTypeName)+'.'+tempstr;
  1014. end;
  1015. else
  1016. Message(asmr_e_wrong_sym_type);
  1017. end;
  1018. end
  1019. else
  1020. Message1(sym_e_unknown_id,tempstr);
  1021. end;
  1022. { symbol found? }
  1023. if hs<>'' then
  1024. begin
  1025. if asmsym='' then
  1026. begin
  1027. asmsym:=hs;
  1028. asmsymtyp:=hssymtyp;
  1029. end
  1030. else
  1031. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1032. if (expr='') or (expr[length(expr)]='+') then
  1033. begin
  1034. { don't remove the + if there could be a record field }
  1035. if actasmtoken<>AS_DOT then
  1036. delete(expr,length(expr),1);
  1037. end
  1038. else
  1039. if needofs then
  1040. begin
  1041. if (prevtok<>AS_OFFSET) then
  1042. Message(asmr_e_need_offset);
  1043. end
  1044. else
  1045. Message(asmr_e_only_add_relocatable_symbol);
  1046. end;
  1047. if (actasmtoken=AS_DOT) or
  1048. (assigned(sym) and
  1049. (sym.typ = fieldvarsym) and
  1050. not(sp_static in sym.symoptions)) then
  1051. begin
  1052. BuildRecordOffsetSize(tempstr,l,k,hs,needvmtofs,hastypecast);
  1053. if hs <> '' then
  1054. hssymtyp:=AT_FUNCTION
  1055. else
  1056. begin
  1057. str(l, tempstr);
  1058. expr:=expr + tempstr;
  1059. end
  1060. end
  1061. else
  1062. begin
  1063. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1064. delete(expr,length(expr),1);
  1065. end;
  1066. if (actasmtoken=AS_LBRACKET) and
  1067. assigned(def) and
  1068. (def.typ=arraydef) then
  1069. begin
  1070. consume(AS_LBRACKET);
  1071. l:=BuildConstExpression;
  1072. if l<tarraydef(def).lowrange then
  1073. begin
  1074. Message(asmr_e_constant_out_of_bounds);
  1075. l:=0;
  1076. end
  1077. else
  1078. l:=(l-tarraydef(def).lowrange)*tarraydef(def).elesize;
  1079. str(l, tempstr);
  1080. expr:=expr + '+' + tempstr;
  1081. consume(AS_RBRACKET);
  1082. end;
  1083. end;
  1084. { check if there are wrong operator used like / or mod etc. }
  1085. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_END,AS_RBRACKET]) then
  1086. Message(asmr_e_only_add_relocatable_symbol);
  1087. end;
  1088. AS_ALIGN,
  1089. AS_DB,
  1090. AS_DW,
  1091. AS_DD,
  1092. AS_DQ,
  1093. AS_END,
  1094. AS_RBRACKET,
  1095. AS_SEPARATOR,
  1096. AS_COMMA,
  1097. AS_COLON:
  1098. break;
  1099. else
  1100. begin
  1101. { write error only once. }
  1102. if not errorflag then
  1103. Message(asmr_e_invalid_constant_expression);
  1104. { consume tokens until we find COMMA or SEPARATOR }
  1105. Consume(actasmtoken);
  1106. errorflag:=TRUE;
  1107. end;
  1108. end;
  1109. Until false;
  1110. { calculate expression }
  1111. if not ErrorFlag then
  1112. value:=CalculateExpression(expr)
  1113. else
  1114. value:=0;
  1115. { no longer in an expression }
  1116. inexpression:=FALSE;
  1117. end;
  1118. Function tx86intreader.BuildConstExpression:aint;
  1119. var
  1120. l : tcgint;
  1121. hs : string;
  1122. hssymtyp : TAsmsymtype;
  1123. isseg,is_farproc_entry,hasofs : boolean;
  1124. begin
  1125. BuildConstSymbolExpression(false,false,false,l,hs,hssymtyp,isseg,is_farproc_entry,hasofs);
  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,is_farproc_entry,hasofs : boolean;
  1136. begin
  1137. BuildConstSymbolExpression(false,true,startingminus,l,hs,hssymtyp,isseg,is_farproc_entry,hasofs);
  1138. if hs<>'' then
  1139. Message(asmr_e_relocatable_symbol_not_allowed);
  1140. BuildRefConstExpression:=l;
  1141. end;
  1142. procedure tx86intreader.BuildReference(oper : tx86operand);
  1143. var
  1144. scale : byte;
  1145. k,l : tcgint;
  1146. tempstr,hs : string;
  1147. tempsymtyp : tasmsymtype;
  1148. code : integer;
  1149. hreg : tregister;
  1150. GotStar,GotOffset,HadVar,
  1151. GotPlus,Negative : boolean;
  1152. hl : tasmlabel;
  1153. isseg: boolean;
  1154. is_farproc_entry,hasofs,
  1155. hastypecast: boolean;
  1156. Begin
  1157. Consume(AS_LBRACKET);
  1158. if not(oper.opr.typ in [OPR_LOCAL,OPR_REFERENCE]) then
  1159. oper.InitRef;
  1160. GotStar:=false;
  1161. GotPlus:=true;
  1162. GotOffset:=false;
  1163. Negative:=false;
  1164. Scale:=0;
  1165. repeat
  1166. if GotOffset and (actasmtoken<>AS_ID) then
  1167. Message(asmr_e_invalid_reference_syntax);
  1168. Case actasmtoken of
  1169. AS_ID, { Constant reference expression OR variable reference expression }
  1170. AS_VMTOFFSET:
  1171. Begin
  1172. if not GotPlus then
  1173. Message(asmr_e_invalid_reference_syntax);
  1174. GotStar:=false;
  1175. GotPlus:=false;
  1176. if (actasmtoken = AS_VMTOFFSET) or
  1177. (SearchIConstant(actasmpattern,l) or
  1178. SearchRecordType(actasmpattern)) then
  1179. begin
  1180. l:=BuildRefConstExpression(negative);
  1181. negative:=false; { "l" was negated if necessary }
  1182. GotPlus:=(prevasmtoken=AS_PLUS);
  1183. GotStar:=(prevasmtoken=AS_STAR);
  1184. case oper.opr.typ of
  1185. OPR_LOCAL :
  1186. begin
  1187. if GotStar then
  1188. Message(asmr_e_invalid_reference_syntax);
  1189. Inc(oper.opr.localsymofs,l);
  1190. end;
  1191. OPR_REFERENCE :
  1192. begin
  1193. if GotStar then
  1194. oper.opr.ref.scalefactor:=l
  1195. else
  1196. Inc(oper.opr.ref.offset,l);
  1197. end;
  1198. end;
  1199. end
  1200. else
  1201. Begin
  1202. if negative and not oper.hasvar then
  1203. Message(asmr_e_only_add_relocatable_symbol)
  1204. else if oper.hasvar and not GotOffset and
  1205. (not negative or assigned(oper.opr.ref.relsymbol)) then
  1206. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1207. HadVar:=oper.hasvar and GotOffset;
  1208. tempstr:=actasmpattern;
  1209. Consume(AS_ID);
  1210. { typecasting? }
  1211. if (actasmtoken=AS_LPAREN) and
  1212. SearchType(tempstr,l) then
  1213. begin
  1214. oper.hastype:=true;
  1215. oper.typesize:=l;
  1216. Consume(AS_LPAREN);
  1217. BuildOperand(oper,true);
  1218. Consume(AS_RPAREN);
  1219. end
  1220. else
  1221. if is_locallabel(tempstr) then
  1222. begin
  1223. CreateLocalLabel(tempstr,hl,false);
  1224. oper.InitRef;
  1225. oper.haslabelref:=true;
  1226. if not negative then
  1227. begin
  1228. oper.opr.ref.symbol:=hl;
  1229. oper.hasvar:=true;
  1230. end
  1231. else
  1232. oper.opr.ref.relsymbol:=hl;
  1233. {$ifdef i8086}
  1234. if oper.opr.ref.segment=NR_NO then
  1235. oper.opr.ref.segment:=NR_CS;
  1236. {$endif i8086}
  1237. end
  1238. else
  1239. if oper.SetupVar(tempstr,GotOffset) then
  1240. begin
  1241. { convert OPR_LOCAL register para into a reference base }
  1242. if (oper.opr.typ=OPR_LOCAL) and
  1243. AsmRegisterPara(oper.opr.localsym) then
  1244. oper.InitRefConvertLocal
  1245. else
  1246. begin
  1247. {$ifdef x86_64}
  1248. if actasmtoken=AS_WRT then
  1249. begin
  1250. if (oper.opr.typ=OPR_REFERENCE) then
  1251. begin
  1252. Consume(AS_WRT);
  1253. Consume(AS___GOTPCREL);
  1254. if (oper.opr.ref.base<>NR_NO) or
  1255. (oper.opr.ref.index<>NR_NO) or
  1256. (oper.opr.ref.offset<>0) then
  1257. Message(asmr_e_wrong_gotpcrel_intel_syntax);
  1258. if tf_no_pic_supported in target_info.flags then
  1259. Message(asmr_e_no_gotpcrel_support);
  1260. oper.opr.ref.refaddr:=addr_pic;
  1261. oper.opr.ref.base:=NR_RIP;
  1262. end
  1263. else
  1264. message(asmr_e_invalid_reference_syntax);
  1265. end;
  1266. {$endif x86_64}
  1267. end;
  1268. end
  1269. else
  1270. Message1(sym_e_unknown_id,tempstr);
  1271. { record.field ? }
  1272. if actasmtoken=AS_DOT then
  1273. begin
  1274. BuildRecordOffsetSize(tempstr,l,k,hs,false,hastypecast);
  1275. if (hs<>'') then
  1276. Message(asmr_e_invalid_symbol_ref);
  1277. case oper.opr.typ of
  1278. OPR_LOCAL :
  1279. inc(oper.opr.localsymofs,l);
  1280. OPR_REFERENCE :
  1281. inc(oper.opr.ref.offset,l);
  1282. end;
  1283. if hastypecast then
  1284. oper.hastype:=true;
  1285. oper.SetSize(k,false);
  1286. end;
  1287. if GotOffset then
  1288. begin
  1289. if oper.hasvar and (oper.opr.ref.base=current_procinfo.framepointer) then
  1290. begin
  1291. if (oper.opr.typ=OPR_REFERENCE) then
  1292. oper.opr.ref.base:=NR_NO;
  1293. oper.hasvar:=hadvar;
  1294. end
  1295. else
  1296. begin
  1297. if oper.hasvar and hadvar then
  1298. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1299. { should we allow ?? }
  1300. end;
  1301. end;
  1302. end;
  1303. GotOffset:=false;
  1304. end;
  1305. AS_PLUS :
  1306. Begin
  1307. Consume(AS_PLUS);
  1308. Negative:=false;
  1309. GotPlus:=true;
  1310. GotStar:=false;
  1311. Scale:=0;
  1312. end;
  1313. AS_DOT :
  1314. Begin
  1315. { Handle like a + }
  1316. Consume(AS_DOT);
  1317. Negative:=false;
  1318. GotPlus:=true;
  1319. GotStar:=false;
  1320. Scale:=0;
  1321. end;
  1322. AS_MINUS :
  1323. begin
  1324. Consume(AS_MINUS);
  1325. Negative:=true;
  1326. GotPlus:=true;
  1327. GotStar:=false;
  1328. Scale:=0;
  1329. end;
  1330. AS_STAR : { Scaling, with eax*4 order }
  1331. begin
  1332. Consume(AS_STAR);
  1333. hs:='';
  1334. l:=0;
  1335. case actasmtoken of
  1336. AS_ID,
  1337. AS_LPAREN :
  1338. l:=BuildConstExpression;
  1339. AS_INTNUM:
  1340. Begin
  1341. hs:=actasmpattern;
  1342. Consume(AS_INTNUM);
  1343. end;
  1344. AS_REGISTER :
  1345. begin
  1346. case oper.opr.typ of
  1347. OPR_REFERENCE :
  1348. begin
  1349. if oper.opr.ref.scalefactor=0 then
  1350. begin
  1351. if scale<>0 then
  1352. begin
  1353. oper.opr.ref.scalefactor:=scale;
  1354. scale:=0;
  1355. end
  1356. else
  1357. Message(asmr_e_wrong_scale_factor);
  1358. end
  1359. else
  1360. Message(asmr_e_invalid_reference_syntax);
  1361. end;
  1362. OPR_LOCAL :
  1363. begin
  1364. if oper.opr.localscale=0 then
  1365. begin
  1366. if scale<>0 then
  1367. begin
  1368. oper.opr.localscale:=scale;
  1369. scale:=0;
  1370. end
  1371. else
  1372. Message(asmr_e_wrong_scale_factor);
  1373. end
  1374. else
  1375. Message(asmr_e_invalid_reference_syntax);
  1376. end;
  1377. end;
  1378. end;
  1379. else
  1380. Message(asmr_e_invalid_reference_syntax);
  1381. end;
  1382. if actasmtoken<>AS_REGISTER then
  1383. begin
  1384. if hs<>'' then
  1385. val(hs,l,code);
  1386. case oper.opr.typ of
  1387. OPR_REFERENCE :
  1388. oper.opr.ref.scalefactor:=l;
  1389. OPR_LOCAL :
  1390. oper.opr.localscale:=l;
  1391. end;
  1392. if l>9 then
  1393. Message(asmr_e_wrong_scale_factor);
  1394. end;
  1395. GotPlus:=false;
  1396. GotStar:=false;
  1397. end;
  1398. AS_REGISTER :
  1399. begin
  1400. if not((GotPlus and (not Negative)) or
  1401. GotStar) then
  1402. Message(asmr_e_invalid_reference_syntax);
  1403. hreg:=actasmregister;
  1404. Consume(AS_REGISTER);
  1405. { this register will be the index:
  1406. 1. just read a *
  1407. 2. next token is a *
  1408. 3. base register is already used }
  1409. case oper.opr.typ of
  1410. OPR_LOCAL :
  1411. begin
  1412. if (oper.opr.localindexreg<>NR_NO) then
  1413. Message(asmr_e_multiple_index);
  1414. {$ifdef x86_64}
  1415. { Locals/parameters cannot be accessed RIP-relative. Need a dedicated error message here? }
  1416. if (hreg=NR_RIP) then
  1417. Message(asmr_e_no_local_or_para_allowed);
  1418. {$endif x86_64}
  1419. oper.opr.localindexreg:=hreg;
  1420. if scale<>0 then
  1421. begin
  1422. oper.opr.localscale:=scale;
  1423. scale:=0;
  1424. end;
  1425. end;
  1426. OPR_REFERENCE :
  1427. begin
  1428. if (GotStar) or
  1429. (actasmtoken=AS_STAR) or
  1430. (oper.opr.ref.base<>NR_NO) then
  1431. begin
  1432. if (oper.opr.ref.index<>NR_NO) then
  1433. Message(asmr_e_multiple_index);
  1434. oper.opr.ref.index:=hreg;
  1435. if scale<>0 then
  1436. begin
  1437. oper.opr.ref.scalefactor:=scale;
  1438. scale:=0;
  1439. end;
  1440. end
  1441. else
  1442. begin
  1443. oper.opr.ref.base:=hreg;
  1444. {$ifdef x86_64}
  1445. { non-GOT based RIP-relative accesses are also position-independent }
  1446. if (oper.opr.ref.base=NR_RIP) and
  1447. (oper.opr.ref.refaddr<>addr_pic) then
  1448. oper.opr.ref.refaddr:=addr_pic_no_got;
  1449. {$endif x86_64}
  1450. end;
  1451. end;
  1452. end;
  1453. GotPlus:=false;
  1454. GotStar:=false;
  1455. end;
  1456. AS_OFFSET :
  1457. begin
  1458. Consume(AS_OFFSET);
  1459. GotOffset:=true;
  1460. end;
  1461. AS_TYPE,
  1462. AS_NOT,
  1463. AS_STRING,
  1464. AS_INTNUM,
  1465. AS_LPAREN : { Constant reference expression }
  1466. begin
  1467. if not GotPlus and not GotStar then
  1468. Message(asmr_e_invalid_reference_syntax);
  1469. BuildConstSymbolExpression(true,true,GotPlus and negative,l,tempstr,tempsymtyp,isseg,is_farproc_entry,hasofs);
  1470. { already handled by BuildConstSymbolExpression(); must be
  1471. handled there to avoid [reg-1+1] being interpreted as
  1472. [reg-(1+1)] }
  1473. negative:=false;
  1474. if tempstr<>'' then
  1475. begin
  1476. if GotStar then
  1477. Message(asmr_e_only_add_relocatable_symbol);
  1478. if not assigned(oper.opr.ref.symbol) then
  1479. begin
  1480. oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr,tempsymtyp);
  1481. {$ifdef i8086}
  1482. if isseg then
  1483. begin
  1484. if not (oper.opr.ref.refaddr in [addr_fardataseg,addr_dgroup]) then
  1485. oper.opr.ref.refaddr:=addr_seg;
  1486. end
  1487. else if (tempsymtyp=AT_FUNCTION) and (oper.opr.ref.segment=NR_NO) then
  1488. oper.opr.ref.segment:=NR_CS;
  1489. {$endif i8086}
  1490. end
  1491. else
  1492. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1493. end;
  1494. case oper.opr.typ of
  1495. OPR_REFERENCE :
  1496. begin
  1497. if GotStar then
  1498. oper.opr.ref.scalefactor:=l
  1499. else if (prevasmtoken = AS_STAR) then
  1500. begin
  1501. if scale<>0 then
  1502. scale:=l*scale
  1503. else
  1504. scale:=l;
  1505. end
  1506. else
  1507. begin
  1508. Inc(oper.opr.ref.offset,l);
  1509. Inc(oper.opr.constoffset,l);
  1510. end;
  1511. end;
  1512. OPR_LOCAL :
  1513. begin
  1514. if GotStar then
  1515. oper.opr.localscale:=l
  1516. else if (prevasmtoken = AS_STAR) then
  1517. begin
  1518. if scale<>0 then
  1519. scale:=l*scale
  1520. else
  1521. scale:=l;
  1522. end
  1523. else
  1524. Inc(oper.opr.localsymofs,l);
  1525. end;
  1526. end;
  1527. GotPlus:=(prevasmtoken=AS_PLUS) or
  1528. (prevasmtoken=AS_MINUS);
  1529. if GotPlus then
  1530. negative := prevasmtoken = AS_MINUS;
  1531. GotStar:=(prevasmtoken=AS_STAR);
  1532. end;
  1533. AS_RBRACKET :
  1534. begin
  1535. if GotPlus or GotStar then
  1536. Message(asmr_e_invalid_reference_syntax);
  1537. Consume(AS_RBRACKET);
  1538. break;
  1539. end;
  1540. else
  1541. Begin
  1542. Message(asmr_e_invalid_reference_syntax);
  1543. RecoverConsume(true);
  1544. break;
  1545. end;
  1546. end;
  1547. until false;
  1548. end;
  1549. Procedure tx86intreader.BuildConstantOperand(oper: tx86operand);
  1550. var
  1551. l : tcgint;
  1552. tempstr : string;
  1553. tempsymtyp : tasmsymtype;
  1554. isseg,is_farproc_entry,hasofs : boolean;
  1555. begin
  1556. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1557. Message(asmr_e_invalid_operand_type);
  1558. BuildConstSymbolExpression(true,false,false,l,tempstr,tempsymtyp,isseg,is_farproc_entry,hasofs);
  1559. {$ifdef i8086}
  1560. if tempstr='@DATA' then
  1561. begin
  1562. if not isseg then
  1563. Message(asmr_e_CODE_or_DATA_without_SEG);
  1564. oper.SetupData;
  1565. end
  1566. else if tempstr='@CODE' then
  1567. begin
  1568. if not isseg then
  1569. Message(asmr_e_CODE_or_DATA_without_SEG);
  1570. oper.SetupCode;
  1571. end
  1572. else
  1573. {$endif i8086}
  1574. if tempstr<>'' then
  1575. begin
  1576. oper.opr.typ:=OPR_SYMBOL;
  1577. oper.opr.symofs:=l;
  1578. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr,tempsymtyp);
  1579. oper.opr.symseg:=isseg;
  1580. oper.opr.sym_farproc_entry:=is_farproc_entry;
  1581. end
  1582. else
  1583. if oper.opr.typ=OPR_NONE then
  1584. begin
  1585. oper.opr.typ:=OPR_CONSTANT;
  1586. oper.opr.val:=l;
  1587. end
  1588. else
  1589. inc(oper.opr.val,l);
  1590. end;
  1591. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1592. procedure AddLabelOperand(hl:tasmlabel);
  1593. begin
  1594. if (oper.opr.typ=OPR_NONE) and
  1595. is_calljmp(actopcode) then
  1596. begin
  1597. oper.opr.typ:=OPR_SYMBOL;
  1598. oper.opr.symbol:=hl;
  1599. end
  1600. else
  1601. begin
  1602. oper.InitRef;
  1603. oper.opr.ref.symbol:=hl;
  1604. oper.haslabelref:=true;
  1605. {$ifdef i8086}
  1606. if oper.opr.ref.segment=NR_NO then
  1607. oper.opr.ref.segment:=NR_CS;
  1608. {$endif i8086}
  1609. end;
  1610. end;
  1611. var
  1612. expr,
  1613. hs : string;
  1614. tempreg : tregister;
  1615. l : tcgint;
  1616. hl : tasmlabel;
  1617. toffset,
  1618. tsize : tcgint;
  1619. hastypecast: boolean;
  1620. begin
  1621. expr:='';
  1622. repeat
  1623. if actasmtoken=AS_DOT then
  1624. begin
  1625. if expr<>'' then
  1626. begin
  1627. BuildRecordOffsetSize(expr,toffset,tsize,hs,false,hastypecast);
  1628. if (oper.opr.typ<>OPR_NONE) and
  1629. (hs<>'') then
  1630. Message(asmr_e_wrong_sym_type);
  1631. oper.SetSize(tsize,true);
  1632. if hastypecast then
  1633. oper.hastype:=true;
  1634. { we have used the size of a field. Reset the typesize of the record }
  1635. oper.typesize:=0;
  1636. case oper.opr.typ of
  1637. OPR_LOCAL :
  1638. begin
  1639. { don't allow direct access to fields of parameters, because that
  1640. will generate buggy code. Allow it only for explicit typecasting
  1641. and when the parameter is in a register (delphi compatible) }
  1642. if (not oper.hastype) then
  1643. checklocalsubscript(oper.opr.localsym);
  1644. oper.opr.localforceref:=true;
  1645. inc(oper.opr.localsymofs,toffset);
  1646. oper.opr.localvarsize := tsize;
  1647. end;
  1648. OPR_CONSTANT :
  1649. inc(oper.opr.val,toffset);
  1650. OPR_REFERENCE :
  1651. begin
  1652. inc(oper.opr.ref.offset,toffset);
  1653. oper.opr.varsize := tsize;
  1654. end;
  1655. OPR_NONE :
  1656. begin
  1657. if (hs <> '') then
  1658. begin
  1659. oper.opr.typ:=OPR_SYMBOL;
  1660. oper.opr.symbol:=current_asmdata.RefAsmSymbol(hs,AT_FUNCTION);
  1661. end
  1662. else
  1663. begin
  1664. oper.opr.typ:=OPR_CONSTANT;
  1665. oper.opr.val:=toffset;
  1666. end;
  1667. end;
  1668. OPR_REGISTER :
  1669. Message(asmr_e_invalid_reference_syntax);
  1670. OPR_SYMBOL:
  1671. Message(asmr_e_invalid_symbol_ref);
  1672. else
  1673. internalerror(200309222);
  1674. end;
  1675. expr:='';
  1676. end
  1677. else
  1678. begin
  1679. { See it as a separator }
  1680. Consume(AS_DOT);
  1681. end;
  1682. end;
  1683. case actasmtoken of
  1684. {$ifndef i8086}
  1685. AS_SEG :
  1686. Begin
  1687. Message(asmr_e_seg_not_supported);
  1688. Consume(actasmtoken);
  1689. end;
  1690. {$else not i8086}
  1691. AS_SEG,
  1692. {$endif not i8086}
  1693. AS_OFFSET,
  1694. AS_SIZEOF,
  1695. AS_VMTOFFSET,
  1696. AS_TYPE,
  1697. AS_NOT,
  1698. AS_STRING,
  1699. AS_PLUS,
  1700. AS_MINUS,
  1701. AS_LPAREN,
  1702. AS_INTNUM :
  1703. begin
  1704. case oper.opr.typ of
  1705. OPR_REFERENCE :
  1706. {$ifndef x86_64}
  1707. { this is for the i386 scenario where you have
  1708. <load got into ebx>
  1709. mov eax, [ebx].offset globalvar
  1710. x86-64 uses RIP-based addresses (both for GOT and non-GOT
  1711. relative accesses)
  1712. }
  1713. if (actasmtoken=AS_OFFSET) and
  1714. (cs_create_pic in current_settings.moduleswitches) then
  1715. begin
  1716. Consume(AS_OFFSET);
  1717. oper.opr.ref.refaddr:=addr_pic;
  1718. BuildOperand(oper,false);
  1719. end
  1720. else
  1721. {$endif x86_64}
  1722. begin
  1723. l := BuildRefConstExpression;
  1724. inc(oper.opr.ref.offset,l);
  1725. inc(oper.opr.constoffset,l);
  1726. end;
  1727. OPR_LOCAL :
  1728. begin
  1729. l := BuildConstExpression;
  1730. inc(oper.opr.localsymofs,l);
  1731. inc(oper.opr.localconstoffset,l);
  1732. end;
  1733. OPR_NONE,
  1734. OPR_CONSTANT :
  1735. BuildConstantOperand(oper);
  1736. else
  1737. Message(asmr_e_invalid_operand_type);
  1738. end;
  1739. end;
  1740. AS_PTR :
  1741. begin
  1742. if not oper.hastype then
  1743. begin
  1744. if (oper.opr.typ=OPR_CONSTANT) then
  1745. begin
  1746. oper.typesize:=oper.opr.val;
  1747. { reset constant value of operand }
  1748. oper.opr.typ:=OPR_NONE;
  1749. oper.opr.val:=0;
  1750. end
  1751. else
  1752. Message(asmr_e_syn_operand);
  1753. end;
  1754. Consume(AS_PTR);
  1755. { in delphi mode, allow e.g. call dword ptr eax,
  1756. see also webtbs/tw18225.pp }
  1757. if not(m_delphi in current_settings.modeswitches) then
  1758. oper.InitRef;
  1759. { if the operand subscripts a record, the typesize will be
  1760. rest -> save it here and restore it afterwards }
  1761. l:=oper.typesize;
  1762. BuildOperand(oper,false);
  1763. oper.setsize(l,true);
  1764. end;
  1765. AS_ID : { A constant expression, or a Variable ref. }
  1766. Begin
  1767. { Label or Special symbol reference? }
  1768. if actasmpattern[1] = '@' then
  1769. Begin
  1770. if actasmpattern = '@RESULT' then
  1771. Begin
  1772. oper.SetupResult;
  1773. Consume(AS_ID);
  1774. expr:='result';
  1775. end
  1776. else
  1777. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1778. begin
  1779. {$ifdef i8086}
  1780. Message(asmr_e_CODE_or_DATA_without_SEG);
  1781. {$else i8086}
  1782. Message(asmr_w_CODE_and_DATA_not_supported);
  1783. {$endif i8086}
  1784. Consume(AS_ID);
  1785. end
  1786. else
  1787. { Local Label }
  1788. begin
  1789. CreateLocalLabel(actasmpattern,hl,false);
  1790. Consume(AS_ID);
  1791. AddLabelOperand(hl);
  1792. end;
  1793. end
  1794. else
  1795. { support result for delphi modes }
  1796. if (m_objpas in current_settings.modeswitches) and (actasmpattern='RESULT') then
  1797. begin
  1798. oper.SetUpResult;
  1799. Consume(AS_ID);
  1800. expr:='result';
  1801. end
  1802. { probably a variable or normal expression }
  1803. { or a procedure (such as in CALL ID) }
  1804. else
  1805. Begin
  1806. { is it a constant ? }
  1807. if SearchIConstant(actasmpattern,l) then
  1808. Begin
  1809. case oper.opr.typ of
  1810. OPR_REFERENCE :
  1811. begin
  1812. l := BuildRefConstExpression;
  1813. inc(oper.opr.ref.offset,l);
  1814. inc(oper.opr.constoffset,l);
  1815. end;
  1816. OPR_LOCAL :
  1817. begin
  1818. l := BuildRefConstExpression;
  1819. inc(oper.opr.localsymofs,l);
  1820. inc(oper.opr.localconstoffset,l);
  1821. end;
  1822. OPR_NONE,
  1823. OPR_CONSTANT :
  1824. BuildConstantOperand(oper);
  1825. else
  1826. Message(asmr_e_invalid_operand_type);
  1827. end;
  1828. end
  1829. else
  1830. { Check for pascal label }
  1831. if SearchLabel(actasmpattern,hl,false) then
  1832. begin
  1833. Consume(AS_ID);
  1834. AddLabelOperand(hl);
  1835. end
  1836. else
  1837. { is it a normal variable ? }
  1838. Begin
  1839. expr:=actasmpattern;
  1840. Consume(AS_ID);
  1841. { typecasting? }
  1842. if SearchType(expr,l) then
  1843. begin
  1844. oper.hastype:=true;
  1845. oper.typesize:=l;
  1846. case actasmtoken of
  1847. AS_LPAREN :
  1848. begin
  1849. { Support Type([Reference]) }
  1850. Consume(AS_LPAREN);
  1851. BuildOperand(oper,true);
  1852. { Delphi also supports Type(Register) and
  1853. interprets it the same as Type([Register]). }
  1854. if (oper.opr.typ = OPR_REGISTER) then
  1855. { This also sets base to the register. }
  1856. oper.InitRef;
  1857. Consume(AS_RPAREN);
  1858. end;
  1859. AS_LBRACKET :
  1860. begin
  1861. { Support Var.Type[Index] }
  1862. { Convert @label.Byte[1] to reference }
  1863. if oper.opr.typ=OPR_SYMBOL then
  1864. oper.initref;
  1865. end;
  1866. end;
  1867. end
  1868. else
  1869. begin
  1870. if not oper.SetupVar(expr,false) then
  1871. Begin
  1872. { not a variable, check special variables.. }
  1873. if expr = 'SELF' then
  1874. begin
  1875. oper.SetupSelf;
  1876. expr:='self';
  1877. end
  1878. else
  1879. begin
  1880. Message1(sym_e_unknown_id,expr);
  1881. expr:='';
  1882. end;
  1883. end;
  1884. { indexed access to variable? }
  1885. if actasmtoken=AS_LBRACKET then
  1886. begin
  1887. { ... then the operand size is not known anymore }
  1888. oper.size:=OS_NO;
  1889. BuildReference(oper);
  1890. end;
  1891. end;
  1892. end;
  1893. end;
  1894. end;
  1895. AS_REGISTER : { Register, a variable reference or a constant reference }
  1896. begin
  1897. { save the type of register used. }
  1898. tempreg:=actasmregister;
  1899. Consume(AS_REGISTER);
  1900. if actasmtoken = AS_COLON then
  1901. Begin
  1902. Consume(AS_COLON);
  1903. oper.InitRef;
  1904. oper.opr.ref.segment:=tempreg;
  1905. BuildReference(oper);
  1906. end
  1907. else
  1908. { Simple register }
  1909. begin
  1910. if (oper.opr.typ <> OPR_NONE) then
  1911. Message(asmr_e_syn_operand);
  1912. oper.opr.typ:=OPR_REGISTER;
  1913. oper.opr.reg:=tempreg;
  1914. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1915. end;
  1916. end;
  1917. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1918. Begin
  1919. BuildReference(oper);
  1920. end;
  1921. AS_DWORD,
  1922. AS_BYTE,
  1923. AS_WORD,
  1924. AS_TBYTE,
  1925. AS_DQWORD,
  1926. AS_QWORD,
  1927. AS_OWORD,
  1928. AS_XMMWORD,
  1929. AS_YWORD,
  1930. AS_YMMWORD:
  1931. begin
  1932. { Type specifier }
  1933. oper.hastype:=true;
  1934. oper.typesize:=0;
  1935. case actasmtoken of
  1936. AS_DWORD : oper.typesize:=4;
  1937. AS_WORD : oper.typesize:=2;
  1938. AS_BYTE : oper.typesize:=1;
  1939. AS_QWORD : oper.typesize:=8;
  1940. AS_DQWORD : oper.typesize:=16;
  1941. AS_TBYTE : oper.typesize:=10;
  1942. AS_OWORD,
  1943. AS_XMMWORD: oper.typesize:=16;
  1944. AS_YWORD,
  1945. AS_YMMWORD: oper.typesize:=32;
  1946. else
  1947. internalerror(2010061101);
  1948. end;
  1949. Consume(actasmtoken);
  1950. if (actasmtoken=AS_LPAREN) then
  1951. begin
  1952. { Support "xxx ptr [Reference]" }
  1953. { in case the expression subscripts a record, the typesize
  1954. is reset, so save the explicit size we set above }
  1955. l:=oper.typesize;
  1956. Consume(AS_LPAREN);
  1957. BuildOperand(oper,true);
  1958. Consume(AS_RPAREN);
  1959. oper.setsize(l,true);
  1960. end;
  1961. end;
  1962. AS_SEPARATOR,
  1963. AS_END,
  1964. AS_COMMA,
  1965. AS_COLON:
  1966. begin
  1967. break;
  1968. end;
  1969. AS_RPAREN:
  1970. begin
  1971. if not istypecast then
  1972. begin
  1973. Message(asmr_e_syn_operand);
  1974. Consume(AS_RPAREN);
  1975. end
  1976. else
  1977. break;
  1978. end;
  1979. else
  1980. begin
  1981. Message(asmr_e_syn_operand);
  1982. RecoverConsume(true);
  1983. break;
  1984. end;
  1985. end;
  1986. until false;
  1987. { End of operand, update size if a typecast is forced }
  1988. if (oper.typesize<>0) and
  1989. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1990. oper.SetSize(oper.typesize,true);
  1991. {$ifdef i8086}
  1992. { references to a procedure/function entry, without an explicit segment
  1993. override, are added an CS: override by default (this is Turbo Pascal 7
  1994. compatible) }
  1995. if (oper.opr.typ=OPR_REFERENCE) and assigned(oper.opr.ref.symbol) and
  1996. (oper.opr.ref.symbol.typ=AT_FUNCTION) and (oper.opr.ref.segment=NR_NO) then
  1997. oper.opr.ref.segment:=NR_CS;
  1998. {$endif i8086}
  1999. end;
  2000. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  2001. var
  2002. PrefixOp,OverrideOp: tasmop;
  2003. operandnum : longint;
  2004. t: TRegister;
  2005. is_far_const:boolean;
  2006. i:byte;
  2007. tmp: toperand;
  2008. di_param, si_param: ShortInt;
  2009. prefix_or_override_pending_concat: boolean = false;
  2010. {$ifdef i8086}
  2011. hsymbol: TAsmSymbol;
  2012. hoffset: ASizeInt;
  2013. href_farproc_entry: Boolean;
  2014. {$endif i8086}
  2015. begin
  2016. PrefixOp:=A_None;
  2017. OverrideOp:=A_None;
  2018. is_far_const:=false;
  2019. { prefix seg opcode / prefix opcode }
  2020. repeat
  2021. if is_prefix(actopcode) then
  2022. with instr do
  2023. begin
  2024. if prefix_or_override_pending_concat then
  2025. ConcatInstruction(curlist);
  2026. PrefixOp:=ActOpcode;
  2027. opcode:=ActOpcode;
  2028. condition:=ActCondition;
  2029. opsize:=ActOpsize;
  2030. prefix_or_override_pending_concat:=true;
  2031. consume(AS_OPCODE);
  2032. end
  2033. else
  2034. if is_override(actopcode) then
  2035. with instr do
  2036. begin
  2037. if prefix_or_override_pending_concat then
  2038. ConcatInstruction(curlist);
  2039. OverrideOp:=ActOpcode;
  2040. opcode:=ActOpcode;
  2041. condition:=ActCondition;
  2042. opsize:=ActOpsize;
  2043. prefix_or_override_pending_concat:=true;
  2044. consume(AS_OPCODE);
  2045. end
  2046. else
  2047. break;
  2048. { allow for newline after prefix or override }
  2049. while actasmtoken=AS_SEPARATOR do
  2050. consume(AS_SEPARATOR);
  2051. until (actasmtoken<>AS_OPCODE);
  2052. { opcode }
  2053. if (actasmtoken <> AS_OPCODE) then
  2054. begin
  2055. { allow a prefix or override to be used standalone, like an opcode
  2056. with zero operands; this is TP7 compatible and allows compiling
  2057. ugly code like 'seges; db $67,$66; lodsw' }
  2058. if prefix_or_override_pending_concat then
  2059. exit
  2060. else
  2061. begin
  2062. Message(asmr_e_invalid_or_missing_opcode);
  2063. RecoverConsume(false);
  2064. exit;
  2065. end;
  2066. end;
  2067. if prefix_or_override_pending_concat then
  2068. begin
  2069. instr.ConcatInstruction(curlist);
  2070. prefix_or_override_pending_concat:=false;
  2071. end;
  2072. { Fill the instr object with the current state }
  2073. with instr do
  2074. begin
  2075. Opcode:=ActOpcode;
  2076. condition:=ActCondition;
  2077. opsize:=ActOpsize;
  2078. { Valid combination of prefix/override and instruction ? }
  2079. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  2080. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  2081. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  2082. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  2083. end;
  2084. { pushf/popf/pusha/popa have to default to 16 bit in Intel mode
  2085. (Intel manual and Delphi-compatbile) -- setting the opsize for
  2086. these instructions doesn't change anything in the internal assember,
  2087. so change the opcode }
  2088. if (instr.opcode=A_POPF) then
  2089. instr.opcode:=A_POPFW
  2090. else if (instr.opcode=A_PUSHF) then
  2091. instr.opcode:=A_PUSHFW
  2092. {$ifndef x86_64}
  2093. else if (instr.opcode=A_PUSHA) then
  2094. instr.opcode:=A_PUSHAW
  2095. else if (instr.opcode=A_POPA) then
  2096. instr.opcode:=A_POPAW
  2097. {$endif x86_64}
  2098. {$ifdef i8086}
  2099. { ret is converted to retn or retf, depending on the call model of the
  2100. current procedure (BP7 compatible) }
  2101. else if (instr.opcode=A_RET) then
  2102. begin
  2103. if is_proc_far(current_procinfo.procdef) and
  2104. not (po_interrupt in current_procinfo.procdef.procoptions) then
  2105. instr.opcode:=A_RETF
  2106. else
  2107. instr.opcode:=A_RETN;
  2108. end
  2109. {$endif i8086}
  2110. ;
  2111. { We are reading operands, so opcode will be an AS_ID }
  2112. { process operands backwards to get them in AT&T order }
  2113. operandnum:=max_operands;
  2114. is_far_const:=false;
  2115. Consume(AS_OPCODE);
  2116. { Zero operand opcode ? }
  2117. if actasmtoken in [AS_SEPARATOR,AS_END] then
  2118. exit;
  2119. { Read Operands }
  2120. repeat
  2121. case actasmtoken of
  2122. { End of asm operands for this opcode }
  2123. AS_END,
  2124. AS_SEPARATOR :
  2125. break;
  2126. { Operand delimiter }
  2127. AS_COMMA :
  2128. begin
  2129. { should have something before the comma }
  2130. if instr.operands[operandnum].opr.typ=OPR_NONE then
  2131. Message(asmr_e_syntax_error);
  2132. if operandnum <= 1 then
  2133. Message(asmr_e_too_many_operands)
  2134. else
  2135. Dec(operandnum);
  2136. Consume(AS_COMMA);
  2137. end;
  2138. {Far constant, i.e. jmp $0000:$11111111.}
  2139. AS_COLON:
  2140. begin
  2141. is_far_const:=true;
  2142. if operandnum<max_operands then
  2143. message(asmr_e_too_many_operands)
  2144. else
  2145. dec(operandnum);
  2146. consume(AS_COLON);
  2147. end;
  2148. { Type specifier }
  2149. AS_NEAR,
  2150. AS_FAR :
  2151. begin
  2152. if actasmtoken = AS_NEAR then
  2153. begin
  2154. {$ifndef i8086}
  2155. Message(asmr_w_near_ignored);
  2156. {$endif not i8086}
  2157. instr.opsize:=S_NEAR;
  2158. end
  2159. else
  2160. begin
  2161. {$ifndef i8086}
  2162. Message(asmr_w_far_ignored);
  2163. {$endif not i8086}
  2164. instr.opsize:=S_FAR;
  2165. end;
  2166. Consume(actasmtoken);
  2167. if actasmtoken=AS_PTR then
  2168. begin
  2169. Consume(AS_PTR);
  2170. instr.Operands[operandnum].InitRef;
  2171. end;
  2172. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  2173. end;
  2174. else
  2175. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  2176. end; { end case }
  2177. until false;
  2178. { shift operands to start from 1, exchange to make sure they are destroyed correctly }
  2179. for i:=operandnum to max_operands do
  2180. begin
  2181. tmp:=instr.operands[i+1-operandnum];
  2182. instr.operands[i+1-operandnum]:=instr.operands[i];
  2183. instr.operands[i]:=tmp;
  2184. end;
  2185. operandnum:=(max_operands+1)-operandnum;
  2186. instr.ops:=operandnum;
  2187. { Check operands }
  2188. for i:=1 to operandnum do
  2189. begin
  2190. if is_far_const and
  2191. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  2192. message(asmr_e_expr_illegal)
  2193. else
  2194. if instr.operands[i].opr.typ=OPR_NONE then
  2195. Message(asmr_e_syntax_error);
  2196. end;
  2197. { Check for invalid ES: overrides }
  2198. if is_x86_parameterized_string_op(instr.opcode) then
  2199. begin
  2200. si_param:=get_x86_string_op_si_param(instr.opcode);
  2201. if si_param<>-1 then
  2202. si_param:=x86_parameterized_string_op_param_count(instr.opcode)-si_param;
  2203. di_param:=get_x86_string_op_di_param(instr.opcode);
  2204. if di_param<>-1 then
  2205. begin
  2206. di_param:=x86_parameterized_string_op_param_count(instr.opcode)-di_param;
  2207. if di_param<=operandnum then
  2208. with instr.operands[di_param] do
  2209. if (opr.typ=OPR_REFERENCE) and
  2210. (opr.ref.segment<>NR_NO) and
  2211. (opr.ref.segment<>NR_ES) then
  2212. Message(asmr_e_cannot_override_es_segment);
  2213. end;
  2214. { if two memory parameters, check whether their address sizes are equal }
  2215. if (si_param<>-1) and (di_param<>-1) and
  2216. (si_param<=operandnum) and (di_param<=operandnum) and
  2217. (instr.operands[si_param].opr.typ=OPR_REFERENCE) and
  2218. (instr.operands[di_param].opr.typ=OPR_REFERENCE) then
  2219. begin
  2220. if get_ref_address_size(instr.operands[si_param].opr.ref)<>
  2221. get_ref_address_size(instr.operands[di_param].opr.ref) then
  2222. Message(asmr_e_address_sizes_do_not_match);
  2223. end;
  2224. end;
  2225. { e.g. for "push dword 1", "push word 6" }
  2226. if (instr.ops=1) and
  2227. (instr.operands[1].typesize<>0) then
  2228. instr.operands[1].setsize(instr.operands[1].typesize,false);
  2229. {$ifdef i8086}
  2230. for i:=1 to operandnum do
  2231. with instr.operands[i].opr do
  2232. begin
  2233. { convert 'call/jmp [proc/label]' to 'call/jmp proc/label'. Ugly,
  2234. but Turbo Pascal 7 compatible. }
  2235. if (instr.opcode in [A_CALL,A_JMP]) and
  2236. (instr.operands[i].haslabelref or instr.operands[i].hasproc)
  2237. and (typ=OPR_REFERENCE) and
  2238. assigned(ref.symbol) and (ref.symbol.typ in [AT_FUNCTION,AT_LABEL,AT_ADDR]) and
  2239. (ref.base=NR_NO) and (ref.index=NR_NO) then
  2240. begin
  2241. hsymbol:=ref.symbol;
  2242. hoffset:=ref.offset;
  2243. href_farproc_entry:=ref_farproc_entry;
  2244. typ:=OPR_SYMBOL;
  2245. symbol:=hsymbol;
  2246. symofs:=hoffset;
  2247. symseg:=False;
  2248. sym_farproc_entry:=href_farproc_entry;
  2249. end;
  2250. { convert 'call/jmp symbol' to 'call/jmp far symbol' for symbols that are an entry point of a far procedure }
  2251. if (instr.opcode in [A_CALL,A_JMP]) and (instr.opsize=S_NO) and
  2252. (typ=OPR_SYMBOL) and sym_farproc_entry then
  2253. instr.opsize:=S_FAR;
  2254. { convert 'call/jmp dword [something]' to 'call/jmp far [something]' (BP7 compatibility) }
  2255. if (instr.opcode in [A_CALL,A_JMP]) and (instr.opsize=S_NO) and
  2256. (typ in [OPR_LOCAL,OPR_REFERENCE]) and (instr.operands[i].size=OS_32) then
  2257. instr.opsize:=S_FAR;
  2258. end;
  2259. {$endif i8086}
  2260. if (MemRefInfo(instr.opcode).ExistsSSEAVX) and
  2261. (MemRefInfo(instr.opcode).MemRefSize in MemRefSizeInfoVMems) then
  2262. begin
  2263. for i:=1 to operandnum do
  2264. begin
  2265. if (instr.operands[i].opr.typ = OPR_REFERENCE) and
  2266. (getregtype(instr.operands[i].opr.ref.base) = R_MMREGISTER) and
  2267. (instr.operands[i].opr.ref.index = NR_NO) then
  2268. begin
  2269. instr.operands[i].opr.ref.index := instr.operands[i].opr.ref.base;
  2270. instr.operands[i].opr.ref.base := NR_NO;
  2271. end
  2272. else if (instr.operands[i].opr.typ = OPR_REFERENCE) and
  2273. (getregtype(instr.operands[i].opr.ref.base) = R_MMREGISTER) and
  2274. (getregtype(instr.operands[i].opr.ref.index) = R_INTREGISTER) and
  2275. (getsubreg(instr.operands[i].opr.ref.index) = R_SUBADDR) then
  2276. begin
  2277. // exchange base- and index-register
  2278. // e.g. VGATHERDPD XMM0, [XMM1 + RAX], XMM2 =>> VGATHERDPD XMM0, [RAX + XMM1], XMM2
  2279. // e.g. VGATHERDPD XMM0, [XMM1 + RAX * 2], XMM2 =>> not supported
  2280. // e.g. VGATHERDPD XMM0, [XMM1 + RAX + 16], XMM2 =>> VGATHERDPD XMM0, [RAX + XMM1 + 16]
  2281. if instr.operands[i].opr.ref.scalefactor > 1 then Message(asmr_e_invalid_reference_syntax)
  2282. else
  2283. begin
  2284. t := instr.operands[i].opr.ref.base;
  2285. instr.operands[i].opr.ref.base := instr.operands[i].opr.ref.index;
  2286. instr.operands[i].opr.ref.index := t;
  2287. end;
  2288. end;
  2289. end;
  2290. end;
  2291. end;
  2292. Procedure tx86intreader.BuildConstant(constsize: byte);
  2293. var
  2294. asmsymtyp : tasmsymtype;
  2295. asmsym,
  2296. expr: string;
  2297. value : tcgint;
  2298. isseg,is_farproc_entry,hasofs : boolean;
  2299. Begin
  2300. Repeat
  2301. Case actasmtoken of
  2302. AS_STRING:
  2303. Begin
  2304. { DD and DW cases }
  2305. if constsize <> 1 then
  2306. Begin
  2307. if Not PadZero(actasmpattern,constsize) then
  2308. Message(scan_f_string_exceeds_line);
  2309. end;
  2310. expr:=actasmpattern;
  2311. Consume(AS_STRING);
  2312. Case actasmtoken of
  2313. AS_COMMA:
  2314. Consume(AS_COMMA);
  2315. AS_END,
  2316. AS_SEPARATOR: ;
  2317. else
  2318. Message(asmr_e_invalid_string_expression);
  2319. end;
  2320. ConcatString(curlist,expr);
  2321. end;
  2322. AS_PLUS,
  2323. AS_MINUS,
  2324. AS_LPAREN,
  2325. AS_NOT,
  2326. AS_INTNUM,
  2327. {$ifdef i8086}
  2328. AS_SEG,
  2329. {$endif i8086}
  2330. AS_ID :
  2331. Begin
  2332. BuildConstSymbolExpression(false,false,false,value,asmsym,asmsymtyp,isseg,is_farproc_entry,hasofs);
  2333. if asmsym<>'' then
  2334. begin
  2335. if (not isseg) and (constsize<>sizeof(pint)) then
  2336. Message1(asmr_w_const32bit_for_address,asmsym);
  2337. {$ifdef i8086}
  2338. if asmsym='@DATA' then
  2339. begin
  2340. if not isseg then
  2341. Message(asmr_e_CODE_or_DATA_without_SEG);
  2342. if constsize<2 then
  2343. Message1(asmr_e_const16bit_for_segment,asmsym);
  2344. if current_settings.x86memorymodel=mm_huge then
  2345. curlist.concat(Tai_const.Create_fardataseg)
  2346. else
  2347. curlist.concat(Tai_const.Create_dgroup);
  2348. if constsize>2 then
  2349. ConcatConstant(curlist,0,constsize-2);
  2350. end
  2351. else if asmsym='@CODE' then
  2352. begin
  2353. if not isseg then
  2354. Message(asmr_e_CODE_or_DATA_without_SEG);
  2355. if constsize<2 then
  2356. Message1(asmr_e_const16bit_for_segment,asmsym);
  2357. curlist.concat(Tai_const.Create_seg_name(current_procinfo.procdef.mangledname));
  2358. if constsize>2 then
  2359. ConcatConstant(curlist,0,constsize-2);
  2360. end
  2361. else if isseg then
  2362. begin
  2363. if constsize<2 then
  2364. Message1(asmr_e_const16bit_for_segment,asmsym);
  2365. curlist.concat(Tai_const.Create_seg_name(asmsym));
  2366. if constsize>2 then
  2367. ConcatConstant(curlist,0,constsize-2);
  2368. end
  2369. else
  2370. {$endif i8086}
  2371. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value,constsize);
  2372. end
  2373. else
  2374. ConcatConstant(curlist,value,constsize);
  2375. end;
  2376. AS_COMMA:
  2377. begin
  2378. Consume(AS_COMMA);
  2379. end;
  2380. AS_ALIGN,
  2381. AS_DB,
  2382. AS_DW,
  2383. AS_DD,
  2384. AS_DQ,
  2385. AS_OPCODE,
  2386. AS_END,
  2387. AS_SEPARATOR:
  2388. break;
  2389. else
  2390. begin
  2391. Message(asmr_e_syn_constant);
  2392. RecoverConsume(false);
  2393. end
  2394. end;
  2395. Until false;
  2396. end;
  2397. function tx86intreader.Assemble: tlinkedlist;
  2398. Var
  2399. hl : tasmlabel;
  2400. instr : Tx86Instruction;
  2401. tmpsym: tsym;
  2402. tmpsrsymtable: TSymtable;
  2403. Begin
  2404. Message1(asmr_d_start_reading,'intel');
  2405. inexpression:=FALSE;
  2406. firsttoken:=TRUE;
  2407. { sets up all opcode and register tables in uppercase
  2408. done in the construtor now
  2409. if not _asmsorted then
  2410. Begin
  2411. SetupTables;
  2412. _asmsorted:=TRUE;
  2413. end;
  2414. }
  2415. curlist:=TAsmList.Create;
  2416. { we might need to know which parameters are passed in registers }
  2417. if not parse_generic then
  2418. current_procinfo.generate_parameter_info;
  2419. { start tokenizer }
  2420. gettoken;
  2421. { main loop }
  2422. repeat
  2423. case actasmtoken of
  2424. AS_LLABEL:
  2425. Begin
  2426. if CreateLocalLabel(actasmpattern,hl,true) then
  2427. ConcatLabel(curlist,hl);
  2428. Consume(AS_LLABEL);
  2429. end;
  2430. AS_LABEL:
  2431. Begin
  2432. if SearchLabel(upper(actasmpattern),hl,true) then
  2433. begin
  2434. if hl.is_public then
  2435. ConcatPublic(curlist,actasmpattern_origcase);
  2436. ConcatLabel(curlist,hl);
  2437. end
  2438. else
  2439. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  2440. Consume(AS_LABEL);
  2441. end;
  2442. AS_DW :
  2443. Begin
  2444. inexpression:=true;
  2445. Consume(AS_DW);
  2446. BuildConstant(2);
  2447. inexpression:=false;
  2448. end;
  2449. AS_DB :
  2450. Begin
  2451. inexpression:=true;
  2452. Consume(AS_DB);
  2453. BuildConstant(1);
  2454. inexpression:=false;
  2455. end;
  2456. AS_DD :
  2457. Begin
  2458. inexpression:=true;
  2459. Consume(AS_DD);
  2460. BuildConstant(4);
  2461. inexpression:=false;
  2462. end;
  2463. {$ifdef cpu64bitaddr}
  2464. AS_DQ:
  2465. Begin
  2466. inexpression:=true;
  2467. Consume(AS_DQ);
  2468. BuildConstant(8);
  2469. inexpression:=false;
  2470. end;
  2471. {$endif cpu64bitaddr}
  2472. AS_PUBLIC:
  2473. Begin
  2474. Consume(AS_PUBLIC);
  2475. repeat
  2476. if actasmtoken=AS_ID then
  2477. begin
  2478. if (actasmpattern<>'') and (actasmpattern[1]='@') then
  2479. Message1(asmr_e_local_label_cannot_be_declared_public,actasmpattern)
  2480. else if SearchLabel(upper(actasmpattern),hl,false) then
  2481. begin
  2482. if not hl.is_public then
  2483. begin
  2484. hl.is_public:=true;
  2485. asmsearchsym(upper(actasmpattern),tmpsym,tmpsrsymtable);
  2486. if tlabelsym(tmpsym).defined then
  2487. Message1(asmr_e_public_must_be_used_before_label_definition,actasmpattern);
  2488. end;
  2489. end
  2490. else
  2491. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  2492. end;
  2493. Consume(AS_ID);
  2494. if actasmtoken=AS_COMMA then
  2495. begin
  2496. Consume(AS_COMMA);
  2497. if actasmtoken<>AS_ID then
  2498. Consume(AS_ID);
  2499. end;
  2500. until actasmtoken=AS_SEPARATOR;
  2501. end;
  2502. AS_ALIGN:
  2503. Begin
  2504. Consume(AS_ALIGN);
  2505. ConcatAlign(curlist,BuildConstExpression);
  2506. if actasmtoken<>AS_SEPARATOR then
  2507. Consume(AS_SEPARATOR);
  2508. end;
  2509. AS_OPCODE :
  2510. Begin
  2511. instr:=Tx86Instruction.Create(Tx86Operand);
  2512. BuildOpcode(instr);
  2513. with instr do
  2514. begin
  2515. CheckNonCommutativeOpcodes;
  2516. AddReferenceSizes;
  2517. SetInstructionOpsize;
  2518. CheckOperandSizes;
  2519. ConcatInstruction(curlist);
  2520. end;
  2521. instr.Free;
  2522. end;
  2523. AS_SEPARATOR :
  2524. Begin
  2525. Consume(AS_SEPARATOR);
  2526. end;
  2527. AS_END :
  2528. break; { end assembly block }
  2529. else
  2530. Begin
  2531. Message(asmr_e_syntax_error);
  2532. RecoverConsume(false);
  2533. end;
  2534. end; { end case }
  2535. until false;
  2536. { check that all referenced local labels are defined }
  2537. checklocallabels;
  2538. { Return the list in an asmnode }
  2539. assemble:=curlist;
  2540. Message1(asmr_d_finish_reading,'intel');
  2541. end;
  2542. end.