rax86int.pas 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660
  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. 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);
  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: boolean;
  1555. is_farproc_entry : boolean;
  1556. begin
  1557. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1558. Message(asmr_e_invalid_operand_type);
  1559. BuildConstSymbolExpression(true,false,false,l,tempstr,tempsymtyp,isseg,is_farproc_entry);
  1560. {$ifdef i8086}
  1561. if tempstr='@DATA' then
  1562. begin
  1563. if not isseg then
  1564. Message(asmr_e_CODE_or_DATA_without_SEG);
  1565. oper.SetupData;
  1566. end
  1567. else if tempstr='@CODE' then
  1568. begin
  1569. if not isseg then
  1570. Message(asmr_e_CODE_or_DATA_without_SEG);
  1571. oper.SetupCode;
  1572. end
  1573. else
  1574. {$endif i8086}
  1575. if tempstr<>'' then
  1576. begin
  1577. oper.opr.typ:=OPR_SYMBOL;
  1578. oper.opr.symofs:=l;
  1579. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr,tempsymtyp);
  1580. oper.opr.symseg:=isseg;
  1581. oper.opr.sym_farproc_entry:=is_farproc_entry;
  1582. end
  1583. else
  1584. if oper.opr.typ=OPR_NONE then
  1585. begin
  1586. oper.opr.typ:=OPR_CONSTANT;
  1587. oper.opr.val:=l;
  1588. end
  1589. else
  1590. inc(oper.opr.val,l);
  1591. end;
  1592. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1593. procedure AddLabelOperand(hl:tasmlabel);
  1594. begin
  1595. if (oper.opr.typ=OPR_NONE) and
  1596. is_calljmp(actopcode) then
  1597. begin
  1598. oper.opr.typ:=OPR_SYMBOL;
  1599. oper.opr.symbol:=hl;
  1600. end
  1601. else
  1602. begin
  1603. oper.InitRef;
  1604. oper.opr.ref.symbol:=hl;
  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) and
  1643. (oper.opr.localsym.typ=paravarsym) and
  1644. (not(po_assembler in current_procinfo.procdef.procoptions) or
  1645. (tparavarsym(oper.opr.localsym).paraloc[calleeside].location^.loc<>LOC_REGISTER) or
  1646. (not is_implicit_pointer_object_type(oper.opr.localsym.vardef) and
  1647. not paramanager.push_addr_param(oper.opr.localsym.varspez,oper.opr.localsym.vardef,current_procinfo.procdef.proccalloption))) then
  1648. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1649. oper.opr.localforceref:=true;
  1650. inc(oper.opr.localsymofs,toffset);
  1651. oper.opr.localvarsize := tsize;
  1652. end;
  1653. OPR_CONSTANT :
  1654. inc(oper.opr.val,toffset);
  1655. OPR_REFERENCE :
  1656. begin
  1657. inc(oper.opr.ref.offset,toffset);
  1658. oper.opr.varsize := tsize;
  1659. end;
  1660. OPR_NONE :
  1661. begin
  1662. if (hs <> '') then
  1663. begin
  1664. oper.opr.typ:=OPR_SYMBOL;
  1665. oper.opr.symbol:=current_asmdata.RefAsmSymbol(hs,AT_FUNCTION);
  1666. end
  1667. else
  1668. begin
  1669. oper.opr.typ:=OPR_CONSTANT;
  1670. oper.opr.val:=toffset;
  1671. end;
  1672. end;
  1673. OPR_REGISTER :
  1674. Message(asmr_e_invalid_reference_syntax);
  1675. OPR_SYMBOL:
  1676. Message(asmr_e_invalid_symbol_ref);
  1677. else
  1678. internalerror(200309222);
  1679. end;
  1680. expr:='';
  1681. end
  1682. else
  1683. begin
  1684. { See it as a separator }
  1685. Consume(AS_DOT);
  1686. end;
  1687. end;
  1688. case actasmtoken of
  1689. {$ifndef i8086}
  1690. AS_SEG :
  1691. Begin
  1692. Message(asmr_e_seg_not_supported);
  1693. Consume(actasmtoken);
  1694. end;
  1695. {$else not i8086}
  1696. AS_SEG,
  1697. {$endif not i8086}
  1698. AS_OFFSET,
  1699. AS_SIZEOF,
  1700. AS_VMTOFFSET,
  1701. AS_TYPE,
  1702. AS_NOT,
  1703. AS_STRING,
  1704. AS_PLUS,
  1705. AS_MINUS,
  1706. AS_LPAREN,
  1707. AS_INTNUM :
  1708. begin
  1709. case oper.opr.typ of
  1710. OPR_REFERENCE :
  1711. {$ifndef x86_64}
  1712. { this is for the i386 scenario where you have
  1713. <load got into ebx>
  1714. mov eax, [ebx].offset globalvar
  1715. x86-64 uses RIP-based addresses (both for GOT and non-GOT
  1716. relative accesses)
  1717. }
  1718. if (actasmtoken=AS_OFFSET) and
  1719. (cs_create_pic in current_settings.moduleswitches) then
  1720. begin
  1721. Consume(AS_OFFSET);
  1722. oper.opr.ref.refaddr:=addr_pic;
  1723. BuildOperand(oper,false);
  1724. end
  1725. else
  1726. {$endif x86_64}
  1727. begin
  1728. l := BuildRefConstExpression;
  1729. inc(oper.opr.ref.offset,l);
  1730. inc(oper.opr.constoffset,l);
  1731. end;
  1732. OPR_LOCAL :
  1733. begin
  1734. l := BuildConstExpression;
  1735. inc(oper.opr.localsymofs,l);
  1736. inc(oper.opr.localconstoffset,l);
  1737. end;
  1738. OPR_NONE,
  1739. OPR_CONSTANT :
  1740. BuildConstantOperand(oper);
  1741. else
  1742. Message(asmr_e_invalid_operand_type);
  1743. end;
  1744. end;
  1745. AS_PTR :
  1746. begin
  1747. if not oper.hastype then
  1748. begin
  1749. if (oper.opr.typ=OPR_CONSTANT) then
  1750. begin
  1751. oper.typesize:=oper.opr.val;
  1752. { reset constant value of operand }
  1753. oper.opr.typ:=OPR_NONE;
  1754. oper.opr.val:=0;
  1755. end
  1756. else
  1757. Message(asmr_e_syn_operand);
  1758. end;
  1759. Consume(AS_PTR);
  1760. { in delphi mode, allow e.g. call dword ptr eax,
  1761. see also webtbs/tw18225.pp }
  1762. if not(m_delphi in current_settings.modeswitches) then
  1763. oper.InitRef;
  1764. { if the operand subscripts a record, the typesize will be
  1765. rest -> save it here and restore it afterwards }
  1766. l:=oper.typesize;
  1767. BuildOperand(oper,false);
  1768. oper.setsize(l,true);
  1769. end;
  1770. AS_ID : { A constant expression, or a Variable ref. }
  1771. Begin
  1772. { Label or Special symbol reference? }
  1773. if actasmpattern[1] = '@' then
  1774. Begin
  1775. if actasmpattern = '@RESULT' then
  1776. Begin
  1777. oper.SetupResult;
  1778. Consume(AS_ID);
  1779. expr:='result';
  1780. end
  1781. else
  1782. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1783. begin
  1784. {$ifdef i8086}
  1785. Message(asmr_e_CODE_or_DATA_without_SEG);
  1786. {$else i8086}
  1787. Message(asmr_w_CODE_and_DATA_not_supported);
  1788. {$endif i8086}
  1789. Consume(AS_ID);
  1790. end
  1791. else
  1792. { Local Label }
  1793. begin
  1794. CreateLocalLabel(actasmpattern,hl,false);
  1795. Consume(AS_ID);
  1796. AddLabelOperand(hl);
  1797. end;
  1798. end
  1799. else
  1800. { support result for delphi modes }
  1801. if (m_objpas in current_settings.modeswitches) and (actasmpattern='RESULT') then
  1802. begin
  1803. oper.SetUpResult;
  1804. Consume(AS_ID);
  1805. expr:='result';
  1806. end
  1807. { probably a variable or normal expression }
  1808. { or a procedure (such as in CALL ID) }
  1809. else
  1810. Begin
  1811. { is it a constant ? }
  1812. if SearchIConstant(actasmpattern,l) then
  1813. Begin
  1814. case oper.opr.typ of
  1815. OPR_REFERENCE :
  1816. begin
  1817. l := BuildRefConstExpression;
  1818. inc(oper.opr.ref.offset,l);
  1819. inc(oper.opr.constoffset,l);
  1820. end;
  1821. OPR_LOCAL :
  1822. begin
  1823. l := BuildRefConstExpression;
  1824. inc(oper.opr.localsymofs,l);
  1825. inc(oper.opr.localconstoffset,l);
  1826. end;
  1827. OPR_NONE,
  1828. OPR_CONSTANT :
  1829. BuildConstantOperand(oper);
  1830. else
  1831. Message(asmr_e_invalid_operand_type);
  1832. end;
  1833. end
  1834. else
  1835. { Check for pascal label }
  1836. if SearchLabel(actasmpattern,hl,false) then
  1837. begin
  1838. Consume(AS_ID);
  1839. AddLabelOperand(hl);
  1840. end
  1841. else
  1842. { is it a normal variable ? }
  1843. Begin
  1844. expr:=actasmpattern;
  1845. Consume(AS_ID);
  1846. { typecasting? }
  1847. if SearchType(expr,l) then
  1848. begin
  1849. oper.hastype:=true;
  1850. oper.typesize:=l;
  1851. case actasmtoken of
  1852. AS_LPAREN :
  1853. begin
  1854. { Support Type([Reference]) }
  1855. Consume(AS_LPAREN);
  1856. BuildOperand(oper,true);
  1857. { Delphi also supports Type(Register) and
  1858. interprets it the same as Type([Register]). }
  1859. if (oper.opr.typ = OPR_REGISTER) then
  1860. { This also sets base to the register. }
  1861. oper.InitRef;
  1862. Consume(AS_RPAREN);
  1863. end;
  1864. AS_LBRACKET :
  1865. begin
  1866. { Support Var.Type[Index] }
  1867. { Convert @label.Byte[1] to reference }
  1868. if oper.opr.typ=OPR_SYMBOL then
  1869. oper.initref;
  1870. end;
  1871. end;
  1872. end
  1873. else
  1874. begin
  1875. if not oper.SetupVar(expr,false) then
  1876. Begin
  1877. { not a variable, check special variables.. }
  1878. if expr = 'SELF' then
  1879. begin
  1880. oper.SetupSelf;
  1881. expr:='self';
  1882. end
  1883. else
  1884. begin
  1885. Message1(sym_e_unknown_id,expr);
  1886. expr:='';
  1887. end;
  1888. end;
  1889. { indexed access to variable? }
  1890. if actasmtoken=AS_LBRACKET then
  1891. begin
  1892. { ... then the operand size is not known anymore }
  1893. oper.size:=OS_NO;
  1894. BuildReference(oper);
  1895. end;
  1896. end;
  1897. end;
  1898. end;
  1899. end;
  1900. AS_REGISTER : { Register, a variable reference or a constant reference }
  1901. begin
  1902. { save the type of register used. }
  1903. tempreg:=actasmregister;
  1904. Consume(AS_REGISTER);
  1905. if actasmtoken = AS_COLON then
  1906. Begin
  1907. Consume(AS_COLON);
  1908. oper.InitRef;
  1909. oper.opr.ref.segment:=tempreg;
  1910. BuildReference(oper);
  1911. end
  1912. else
  1913. { Simple register }
  1914. begin
  1915. if (oper.opr.typ <> OPR_NONE) then
  1916. Message(asmr_e_syn_operand);
  1917. oper.opr.typ:=OPR_REGISTER;
  1918. oper.opr.reg:=tempreg;
  1919. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1920. end;
  1921. end;
  1922. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1923. Begin
  1924. BuildReference(oper);
  1925. end;
  1926. AS_DWORD,
  1927. AS_BYTE,
  1928. AS_WORD,
  1929. AS_TBYTE,
  1930. AS_DQWORD,
  1931. AS_QWORD,
  1932. AS_OWORD,
  1933. AS_XMMWORD,
  1934. AS_YWORD,
  1935. AS_YMMWORD:
  1936. begin
  1937. { Type specifier }
  1938. oper.hastype:=true;
  1939. oper.typesize:=0;
  1940. case actasmtoken of
  1941. AS_DWORD : oper.typesize:=4;
  1942. AS_WORD : oper.typesize:=2;
  1943. AS_BYTE : oper.typesize:=1;
  1944. AS_QWORD : oper.typesize:=8;
  1945. AS_DQWORD : oper.typesize:=16;
  1946. AS_TBYTE : oper.typesize:=10;
  1947. AS_OWORD,
  1948. AS_XMMWORD: oper.typesize:=16;
  1949. AS_YWORD,
  1950. AS_YMMWORD: oper.typesize:=32;
  1951. else
  1952. internalerror(2010061101);
  1953. end;
  1954. Consume(actasmtoken);
  1955. if (actasmtoken=AS_LPAREN) then
  1956. begin
  1957. { Support "xxx ptr [Reference]" }
  1958. { in case the expression subscripts a record, the typesize
  1959. is reset, so save the explicit size we set above }
  1960. l:=oper.typesize;
  1961. Consume(AS_LPAREN);
  1962. BuildOperand(oper,true);
  1963. Consume(AS_RPAREN);
  1964. oper.setsize(l,true);
  1965. end;
  1966. end;
  1967. AS_SEPARATOR,
  1968. AS_END,
  1969. AS_COMMA,
  1970. AS_COLON:
  1971. begin
  1972. break;
  1973. end;
  1974. AS_RPAREN:
  1975. begin
  1976. if not istypecast then
  1977. begin
  1978. Message(asmr_e_syn_operand);
  1979. Consume(AS_RPAREN);
  1980. end
  1981. else
  1982. break;
  1983. end;
  1984. else
  1985. begin
  1986. Message(asmr_e_syn_operand);
  1987. RecoverConsume(true);
  1988. break;
  1989. end;
  1990. end;
  1991. until false;
  1992. { End of operand, update size if a typecast is forced }
  1993. if (oper.typesize<>0) and
  1994. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1995. oper.SetSize(oper.typesize,true);
  1996. {$ifdef i8086}
  1997. { references to a procedure/function entry, without an explicit segment
  1998. override, are added an CS: override by default (this is Turbo Pascal 7
  1999. compatible) }
  2000. if (oper.opr.typ=OPR_REFERENCE) and assigned(oper.opr.ref.symbol) and
  2001. (oper.opr.ref.symbol.typ=AT_FUNCTION) and (oper.opr.ref.segment=NR_NO) then
  2002. oper.opr.ref.segment:=NR_CS;
  2003. {$endif i8086}
  2004. end;
  2005. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  2006. var
  2007. PrefixOp,OverrideOp: tasmop;
  2008. operandnum : longint;
  2009. t: TRegister;
  2010. is_far_const:boolean;
  2011. i:byte;
  2012. tmp: toperand;
  2013. di_param, si_param: ShortInt;
  2014. {$ifdef i8086}
  2015. hsymbol: TAsmSymbol;
  2016. hoffset: ASizeInt;
  2017. href_farproc_entry: Boolean;
  2018. {$endif i8086}
  2019. begin
  2020. PrefixOp:=A_None;
  2021. OverrideOp:=A_None;
  2022. is_far_const:=false;
  2023. { prefix seg opcode / prefix opcode }
  2024. repeat
  2025. if is_prefix(actopcode) then
  2026. with instr do
  2027. begin
  2028. PrefixOp:=ActOpcode;
  2029. opcode:=ActOpcode;
  2030. condition:=ActCondition;
  2031. opsize:=ActOpsize;
  2032. ConcatInstruction(curlist);
  2033. consume(AS_OPCODE);
  2034. end
  2035. else
  2036. if is_override(actopcode) then
  2037. with instr do
  2038. begin
  2039. OverrideOp:=ActOpcode;
  2040. opcode:=ActOpcode;
  2041. condition:=ActCondition;
  2042. opsize:=ActOpsize;
  2043. ConcatInstruction(curlist);
  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. Message(asmr_e_invalid_or_missing_opcode);
  2056. RecoverConsume(false);
  2057. exit;
  2058. end;
  2059. { Fill the instr object with the current state }
  2060. with instr do
  2061. begin
  2062. Opcode:=ActOpcode;
  2063. condition:=ActCondition;
  2064. opsize:=ActOpsize;
  2065. { Valid combination of prefix/override and instruction ? }
  2066. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  2067. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  2068. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  2069. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  2070. end;
  2071. { pushf/popf/pusha/popa have to default to 16 bit in Intel mode
  2072. (Intel manual and Delphi-compatbile) -- setting the opsize for
  2073. these instructions doesn't change anything in the internal assember,
  2074. so change the opcode }
  2075. if (instr.opcode=A_POPF) then
  2076. instr.opcode:=A_POPFW
  2077. else if (instr.opcode=A_PUSHF) then
  2078. instr.opcode:=A_PUSHFW
  2079. {$ifndef x86_64}
  2080. else if (instr.opcode=A_PUSHA) then
  2081. instr.opcode:=A_PUSHAW
  2082. else if (instr.opcode=A_POPA) then
  2083. instr.opcode:=A_POPAW
  2084. {$endif x86_64}
  2085. {$ifdef i8086}
  2086. { ret is converted to retn or retf, depending on the call model of the
  2087. current procedure (BP7 compatible) }
  2088. else if (instr.opcode=A_RET) then
  2089. begin
  2090. if is_proc_far(current_procinfo.procdef) and
  2091. not (po_interrupt in current_procinfo.procdef.procoptions) then
  2092. instr.opcode:=A_RETF
  2093. else
  2094. instr.opcode:=A_RETN;
  2095. end
  2096. {$endif i8086}
  2097. ;
  2098. { We are reading operands, so opcode will be an AS_ID }
  2099. { process operands backwards to get them in AT&T order }
  2100. operandnum:=max_operands;
  2101. is_far_const:=false;
  2102. Consume(AS_OPCODE);
  2103. { Zero operand opcode ? }
  2104. if actasmtoken in [AS_SEPARATOR,AS_END] then
  2105. exit;
  2106. { Read Operands }
  2107. repeat
  2108. case actasmtoken of
  2109. { End of asm operands for this opcode }
  2110. AS_END,
  2111. AS_SEPARATOR :
  2112. break;
  2113. { Operand delimiter }
  2114. AS_COMMA :
  2115. begin
  2116. { should have something before the comma }
  2117. if instr.operands[operandnum].opr.typ=OPR_NONE then
  2118. Message(asmr_e_syntax_error);
  2119. if operandnum <= 1 then
  2120. Message(asmr_e_too_many_operands)
  2121. else
  2122. Dec(operandnum);
  2123. Consume(AS_COMMA);
  2124. end;
  2125. {Far constant, i.e. jmp $0000:$11111111.}
  2126. AS_COLON:
  2127. begin
  2128. is_far_const:=true;
  2129. if operandnum<max_operands then
  2130. message(asmr_e_too_many_operands)
  2131. else
  2132. dec(operandnum);
  2133. consume(AS_COLON);
  2134. end;
  2135. { Type specifier }
  2136. AS_NEAR,
  2137. AS_FAR :
  2138. begin
  2139. if actasmtoken = AS_NEAR then
  2140. begin
  2141. {$ifndef i8086}
  2142. Message(asmr_w_near_ignored);
  2143. {$endif not i8086}
  2144. instr.opsize:=S_NEAR;
  2145. end
  2146. else
  2147. begin
  2148. {$ifndef i8086}
  2149. Message(asmr_w_far_ignored);
  2150. {$endif not i8086}
  2151. instr.opsize:=S_FAR;
  2152. end;
  2153. Consume(actasmtoken);
  2154. if actasmtoken=AS_PTR then
  2155. begin
  2156. Consume(AS_PTR);
  2157. instr.Operands[operandnum].InitRef;
  2158. end;
  2159. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  2160. end;
  2161. else
  2162. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  2163. end; { end case }
  2164. until false;
  2165. { shift operands to start from 1, exchange to make sure they are destroyed correctly }
  2166. for i:=operandnum to max_operands do
  2167. begin
  2168. tmp:=instr.operands[i+1-operandnum];
  2169. instr.operands[i+1-operandnum]:=instr.operands[i];
  2170. instr.operands[i]:=tmp;
  2171. end;
  2172. operandnum:=(max_operands+1)-operandnum;
  2173. instr.ops:=operandnum;
  2174. { Check operands }
  2175. for i:=1 to operandnum do
  2176. begin
  2177. if is_far_const and
  2178. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  2179. message(asmr_e_expr_illegal)
  2180. else
  2181. if instr.operands[i].opr.typ=OPR_NONE then
  2182. Message(asmr_e_syntax_error);
  2183. end;
  2184. { Check for invalid ES: overrides }
  2185. if is_x86_parameterized_string_op(instr.opcode) then
  2186. begin
  2187. si_param:=get_x86_string_op_si_param(instr.opcode);
  2188. if si_param<>-1 then
  2189. si_param:=x86_parameterized_string_op_param_count(instr.opcode)-si_param;
  2190. di_param:=get_x86_string_op_di_param(instr.opcode);
  2191. if di_param<>-1 then
  2192. begin
  2193. di_param:=x86_parameterized_string_op_param_count(instr.opcode)-di_param;
  2194. if di_param<=operandnum then
  2195. with instr.operands[di_param] do
  2196. if (opr.typ=OPR_REFERENCE) and
  2197. (opr.ref.segment<>NR_NO) and
  2198. (opr.ref.segment<>NR_ES) then
  2199. Message(asmr_e_cannot_override_es_segment);
  2200. end;
  2201. { if two memory parameters, check whether their address sizes are equal }
  2202. if (si_param<>-1) and (di_param<>-1) and
  2203. (si_param<=operandnum) and (di_param<=operandnum) and
  2204. (instr.operands[si_param].opr.typ=OPR_REFERENCE) and
  2205. (instr.operands[di_param].opr.typ=OPR_REFERENCE) then
  2206. begin
  2207. if get_ref_address_size(instr.operands[si_param].opr.ref)<>
  2208. get_ref_address_size(instr.operands[di_param].opr.ref) then
  2209. Message(asmr_e_address_sizes_do_not_match);
  2210. end;
  2211. end;
  2212. { e.g. for "push dword 1", "push word 6" }
  2213. if (instr.ops=1) and
  2214. (instr.operands[1].typesize<>0) then
  2215. instr.operands[1].setsize(instr.operands[1].typesize,false);
  2216. {$ifdef i8086}
  2217. for i:=1 to operandnum do
  2218. with instr.operands[i].opr do
  2219. begin
  2220. { convert 'call/jmp [proc/label]' to 'call/jmp proc/label'. Ugly,
  2221. but Turbo Pascal 7 compatible. }
  2222. if (instr.opcode in [A_CALL,A_JMP]) and
  2223. (instr.operands[i].haslabelref or instr.operands[i].hasproc)
  2224. and (typ=OPR_REFERENCE) and
  2225. assigned(ref.symbol) and (ref.symbol.typ in [AT_FUNCTION,AT_LABEL,AT_ADDR]) and
  2226. (ref.base=NR_NO) and (ref.index=NR_NO) then
  2227. begin
  2228. hsymbol:=ref.symbol;
  2229. hoffset:=ref.offset;
  2230. href_farproc_entry:=ref_farproc_entry;
  2231. typ:=OPR_SYMBOL;
  2232. symbol:=hsymbol;
  2233. symofs:=hoffset;
  2234. symseg:=False;
  2235. sym_farproc_entry:=href_farproc_entry;
  2236. end;
  2237. { convert 'call/jmp symbol' to 'call/jmp far symbol' for symbols that are an entry point of a far procedure }
  2238. if (instr.opcode in [A_CALL,A_JMP]) and (instr.opsize=S_NO) and
  2239. (typ=OPR_SYMBOL) and sym_farproc_entry then
  2240. instr.opsize:=S_FAR;
  2241. { convert 'call/jmp dword [something]' to 'call/jmp far [something]' (BP7 compatibility) }
  2242. if (instr.opcode in [A_CALL,A_JMP]) and (instr.opsize=S_NO) and
  2243. (typ in [OPR_LOCAL,OPR_REFERENCE]) and (instr.operands[i].size=OS_32) then
  2244. instr.opsize:=S_FAR;
  2245. end;
  2246. {$endif i8086}
  2247. if (MemRefInfo(instr.opcode).ExistsSSEAVX) and
  2248. (MemRefInfo(instr.opcode).MemRefSize in MemRefSizeInfoVMems) then
  2249. begin
  2250. for i:=1 to operandnum do
  2251. begin
  2252. if (instr.operands[i].opr.typ = OPR_REFERENCE) and
  2253. (getregtype(instr.operands[i].opr.ref.base) = R_MMREGISTER) and
  2254. (instr.operands[i].opr.ref.index = NR_NO) then
  2255. begin
  2256. instr.operands[i].opr.ref.index := instr.operands[i].opr.ref.base;
  2257. instr.operands[i].opr.ref.base := NR_NO;
  2258. end
  2259. else if (instr.operands[i].opr.typ = OPR_REFERENCE) and
  2260. (getregtype(instr.operands[i].opr.ref.base) = R_MMREGISTER) and
  2261. (getregtype(instr.operands[i].opr.ref.index) = R_INTREGISTER) and
  2262. (getsubreg(instr.operands[i].opr.ref.index) = R_SUBADDR) then
  2263. begin
  2264. // exchange base- and index-register
  2265. // e.g. VGATHERDPD XMM0, [XMM1 + RAX], XMM2 =>> VGATHERDPD XMM0, [RAX + XMM1], XMM2
  2266. // e.g. VGATHERDPD XMM0, [XMM1 + RAX * 2], XMM2 =>> not supported
  2267. // e.g. VGATHERDPD XMM0, [XMM1 + RAX + 16], XMM2 =>> VGATHERDPD XMM0, [RAX + XMM1 + 16]
  2268. if instr.operands[i].opr.ref.scalefactor > 1 then Message(asmr_e_invalid_reference_syntax)
  2269. else
  2270. begin
  2271. t := instr.operands[i].opr.ref.base;
  2272. instr.operands[i].opr.ref.base := instr.operands[i].opr.ref.index;
  2273. instr.operands[i].opr.ref.index := t;
  2274. end;
  2275. end;
  2276. end;
  2277. end;
  2278. end;
  2279. Procedure tx86intreader.BuildConstant(constsize: byte);
  2280. var
  2281. asmsymtyp : tasmsymtype;
  2282. asmsym,
  2283. expr: string;
  2284. value : tcgint;
  2285. isseg: boolean;
  2286. is_farproc_entry : boolean;
  2287. Begin
  2288. Repeat
  2289. Case actasmtoken of
  2290. AS_STRING:
  2291. Begin
  2292. { DD and DW cases }
  2293. if constsize <> 1 then
  2294. Begin
  2295. if Not PadZero(actasmpattern,constsize) then
  2296. Message(scan_f_string_exceeds_line);
  2297. end;
  2298. expr:=actasmpattern;
  2299. Consume(AS_STRING);
  2300. Case actasmtoken of
  2301. AS_COMMA:
  2302. Consume(AS_COMMA);
  2303. AS_END,
  2304. AS_SEPARATOR: ;
  2305. else
  2306. Message(asmr_e_invalid_string_expression);
  2307. end;
  2308. ConcatString(curlist,expr);
  2309. end;
  2310. AS_PLUS,
  2311. AS_MINUS,
  2312. AS_LPAREN,
  2313. AS_NOT,
  2314. AS_INTNUM,
  2315. {$ifdef i8086}
  2316. AS_SEG,
  2317. {$endif i8086}
  2318. AS_ID :
  2319. Begin
  2320. BuildConstSymbolExpression(false,false,false,value,asmsym,asmsymtyp,isseg,is_farproc_entry);
  2321. if asmsym<>'' then
  2322. begin
  2323. if (not isseg) and (constsize<>sizeof(pint)) then
  2324. Message1(asmr_w_const32bit_for_address,asmsym);
  2325. {$ifdef i8086}
  2326. if asmsym='@DATA' then
  2327. begin
  2328. if not isseg then
  2329. Message(asmr_e_CODE_or_DATA_without_SEG);
  2330. if constsize<2 then
  2331. Message1(asmr_e_const16bit_for_segment,asmsym);
  2332. if current_settings.x86memorymodel=mm_huge then
  2333. curlist.concat(Tai_const.Create_fardataseg)
  2334. else
  2335. curlist.concat(Tai_const.Create_dgroup);
  2336. if constsize>2 then
  2337. ConcatConstant(curlist,0,constsize-2);
  2338. end
  2339. else if asmsym='@CODE' then
  2340. begin
  2341. if not isseg then
  2342. Message(asmr_e_CODE_or_DATA_without_SEG);
  2343. if constsize<2 then
  2344. Message1(asmr_e_const16bit_for_segment,asmsym);
  2345. curlist.concat(Tai_const.Create_seg_name(current_procinfo.procdef.mangledname));
  2346. if constsize>2 then
  2347. ConcatConstant(curlist,0,constsize-2);
  2348. end
  2349. else if isseg then
  2350. begin
  2351. if constsize<2 then
  2352. Message1(asmr_e_const16bit_for_segment,asmsym);
  2353. curlist.concat(Tai_const.Create_seg_name(asmsym));
  2354. if constsize>2 then
  2355. ConcatConstant(curlist,0,constsize-2);
  2356. end
  2357. else
  2358. {$endif i8086}
  2359. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value);
  2360. end
  2361. else
  2362. ConcatConstant(curlist,value,constsize);
  2363. end;
  2364. AS_COMMA:
  2365. begin
  2366. Consume(AS_COMMA);
  2367. end;
  2368. AS_ALIGN,
  2369. AS_DB,
  2370. AS_DW,
  2371. AS_DD,
  2372. AS_DQ,
  2373. AS_OPCODE,
  2374. AS_END,
  2375. AS_SEPARATOR:
  2376. break;
  2377. else
  2378. begin
  2379. Message(asmr_e_syn_constant);
  2380. RecoverConsume(false);
  2381. end
  2382. end;
  2383. Until false;
  2384. end;
  2385. function tx86intreader.Assemble: tlinkedlist;
  2386. Var
  2387. hl : tasmlabel;
  2388. instr : Tx86Instruction;
  2389. tmpsym: tsym;
  2390. tmpsrsymtable: TSymtable;
  2391. Begin
  2392. Message1(asmr_d_start_reading,'intel');
  2393. inexpression:=FALSE;
  2394. firsttoken:=TRUE;
  2395. { sets up all opcode and register tables in uppercase
  2396. done in the construtor now
  2397. if not _asmsorted then
  2398. Begin
  2399. SetupTables;
  2400. _asmsorted:=TRUE;
  2401. end;
  2402. }
  2403. curlist:=TAsmList.Create;
  2404. { we might need to know which parameters are passed in registers }
  2405. if not parse_generic then
  2406. current_procinfo.generate_parameter_info;
  2407. { start tokenizer }
  2408. gettoken;
  2409. { main loop }
  2410. repeat
  2411. case actasmtoken of
  2412. AS_LLABEL:
  2413. Begin
  2414. if CreateLocalLabel(actasmpattern,hl,true) then
  2415. ConcatLabel(curlist,hl);
  2416. Consume(AS_LLABEL);
  2417. end;
  2418. AS_LABEL:
  2419. Begin
  2420. if SearchLabel(upper(actasmpattern),hl,true) then
  2421. begin
  2422. if hl.is_public then
  2423. ConcatPublic(curlist,actasmpattern_origcase);
  2424. ConcatLabel(curlist,hl);
  2425. end
  2426. else
  2427. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  2428. Consume(AS_LABEL);
  2429. end;
  2430. AS_DW :
  2431. Begin
  2432. inexpression:=true;
  2433. Consume(AS_DW);
  2434. BuildConstant(2);
  2435. inexpression:=false;
  2436. end;
  2437. AS_DB :
  2438. Begin
  2439. inexpression:=true;
  2440. Consume(AS_DB);
  2441. BuildConstant(1);
  2442. inexpression:=false;
  2443. end;
  2444. AS_DD :
  2445. Begin
  2446. inexpression:=true;
  2447. Consume(AS_DD);
  2448. BuildConstant(4);
  2449. inexpression:=false;
  2450. end;
  2451. {$ifdef cpu64bitaddr}
  2452. AS_DQ:
  2453. Begin
  2454. inexpression:=true;
  2455. Consume(AS_DQ);
  2456. BuildConstant(8);
  2457. inexpression:=false;
  2458. end;
  2459. {$endif cpu64bitaddr}
  2460. AS_PUBLIC:
  2461. Begin
  2462. Consume(AS_PUBLIC);
  2463. repeat
  2464. if actasmtoken=AS_ID then
  2465. begin
  2466. if (actasmpattern<>'') and (actasmpattern[1]='@') then
  2467. Message1(asmr_e_local_label_cannot_be_declared_public,actasmpattern)
  2468. else if SearchLabel(upper(actasmpattern),hl,false) then
  2469. begin
  2470. if not hl.is_public then
  2471. begin
  2472. hl.is_public:=true;
  2473. asmsearchsym(upper(actasmpattern),tmpsym,tmpsrsymtable);
  2474. if tlabelsym(tmpsym).defined then
  2475. Message1(asmr_e_public_must_be_used_before_label_definition,actasmpattern);
  2476. end;
  2477. end
  2478. else
  2479. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  2480. end;
  2481. Consume(AS_ID);
  2482. if actasmtoken=AS_COMMA then
  2483. begin
  2484. Consume(AS_COMMA);
  2485. if actasmtoken<>AS_ID then
  2486. Consume(AS_ID);
  2487. end;
  2488. until actasmtoken=AS_SEPARATOR;
  2489. end;
  2490. AS_ALIGN:
  2491. Begin
  2492. Consume(AS_ALIGN);
  2493. ConcatAlign(curlist,BuildConstExpression);
  2494. if actasmtoken<>AS_SEPARATOR then
  2495. Consume(AS_SEPARATOR);
  2496. end;
  2497. AS_OPCODE :
  2498. Begin
  2499. instr:=Tx86Instruction.Create(Tx86Operand);
  2500. BuildOpcode(instr);
  2501. with instr do
  2502. begin
  2503. CheckNonCommutativeOpcodes;
  2504. AddReferenceSizes;
  2505. SetInstructionOpsize;
  2506. CheckOperandSizes;
  2507. ConcatInstruction(curlist);
  2508. end;
  2509. instr.Free;
  2510. end;
  2511. AS_SEPARATOR :
  2512. Begin
  2513. Consume(AS_SEPARATOR);
  2514. end;
  2515. AS_END :
  2516. break; { end assembly block }
  2517. else
  2518. Begin
  2519. Message(asmr_e_syntax_error);
  2520. RecoverConsume(false);
  2521. end;
  2522. end; { end case }
  2523. until false;
  2524. { check that all referenced local labels are defined }
  2525. checklocallabels;
  2526. { Return the list in an asmnode }
  2527. assemble:=curlist;
  2528. Message1(asmr_d_finish_reading,'intel');
  2529. end;
  2530. end.