rax86int.pas 94 KB

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