rax86int.pas 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161
  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_END,
  35. {------------------ Assembler Operators --------------------}
  36. AS_BYTE,AS_WORD,AS_DWORD,AS_QWORD,AS_TBYTE,AS_DQWORD,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);
  39. type
  40. tx86intreader = class(tasmreader)
  41. actasmtoken : tasmtoken;
  42. prevasmtoken : tasmtoken;
  43. ActOpsize : topsize;
  44. constructor create;override;
  45. function is_asmopcode(const s: string):boolean;
  46. function is_asmoperator(const s: string):boolean;
  47. function is_asmdirective(const s: string):boolean;
  48. function is_register(const s:string):boolean;
  49. function is_locallabel(const s:string):boolean;
  50. function Assemble: tlinkedlist;override;
  51. procedure GetToken;
  52. function consume(t : tasmtoken):boolean;
  53. procedure RecoverConsume(allowcomma:boolean);
  54. procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
  55. procedure BuildConstSymbolExpression(needofs,isref:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  56. function BuildConstExpression:aint;
  57. function BuildRefConstExpression:aint;
  58. procedure BuildReference(oper : tx86operand);
  59. procedure BuildOperand(oper: tx86operand;istypecast:boolean);
  60. procedure BuildConstantOperand(oper: tx86operand);
  61. procedure BuildOpCode(instr : tx86instruction);
  62. procedure BuildConstant(constsize: byte);
  63. end;
  64. implementation
  65. uses
  66. { common }
  67. cutils,
  68. { global }
  69. globals,verbose,
  70. systems,
  71. { aasm }
  72. aasmtai,aasmdata,aasmcpu,
  73. { symtable }
  74. symconst,symbase,symtype,symsym,symdef,symtable,
  75. { parser }
  76. scanner,
  77. { register allocator }
  78. rabase,rautils,itx86int,
  79. { codegen }
  80. cgbase,cgobj,procinfo
  81. ;
  82. type
  83. tasmkeyword = string[9];
  84. const
  85. { These tokens should be modified accordingly to the modifications }
  86. { in the different enumerations. }
  87. firstdirective = AS_ALIGN;
  88. lastdirective = AS_END;
  89. firstoperator = AS_BYTE;
  90. lastoperator = AS_XOR;
  91. _count_asmdirectives = longint(lastdirective)-longint(firstdirective);
  92. _count_asmoperators = longint(lastoperator)-longint(firstoperator);
  93. _asmdirectives : array[0.._count_asmdirectives] of tasmkeyword =
  94. ('ALIGN','DB','DW','DD','END');
  95. { problems with shl,shr,not,and,or and xor, they are }
  96. { context sensitive. }
  97. _asmoperators : array[0.._count_asmoperators] of tasmkeyword = (
  98. 'BYTE','WORD','DWORD','QWORD','TBYTE','DQWORD','NEAR','FAR','HIGH',
  99. 'LOW','OFFSET','SIZEOF','VMTOFFSET','SEG','TYPE','PTR','MOD','SHL','SHR','NOT','AND',
  100. 'OR','XOR');
  101. token2str : array[tasmtoken] of string[10] = (
  102. '','Label','LLabel','String','Integer',
  103. ',','[',']','(',
  104. ')',':','.','+','-','*',
  105. ';','identifier','register','opcode','/',
  106. '','','','','END',
  107. '','','','','','','','','',
  108. '','','sizeof','vmtoffset','','type','ptr','mod','shl','shr','not',
  109. 'and','or','xor'
  110. );
  111. var
  112. inexpression : boolean;
  113. constructor tx86intreader.create;
  114. var
  115. i : tasmop;
  116. Begin
  117. inherited create;
  118. iasmops:=TFPHashList.create;
  119. for i:=firstop to lastop do
  120. iasmops.Add(upper(std_op2str[i]),Pointer(PtrInt(i)));
  121. end;
  122. {---------------------------------------------------------------------}
  123. { Routines for the tokenizing }
  124. {---------------------------------------------------------------------}
  125. function tx86intreader.is_asmopcode(const s: string):boolean;
  126. var
  127. cond : string[4];
  128. cnd : tasmcond;
  129. j: longint;
  130. Begin
  131. is_asmopcode:=FALSE;
  132. actopcode:=A_None;
  133. actcondition:=C_None;
  134. actopsize:=S_NO;
  135. { Search opcodes }
  136. actopcode:=tasmop(PtrInt(iasmops.Find(s)));
  137. if actopcode<>A_NONE then
  138. begin
  139. actasmtoken:=AS_OPCODE;
  140. result:=TRUE;
  141. exit;
  142. end;
  143. { not found yet, check condition opcodes }
  144. j:=0;
  145. while (j<CondAsmOps) do
  146. begin
  147. if Copy(s,1,Length(CondAsmOpStr[j]))=CondAsmOpStr[j] then
  148. begin
  149. cond:=Copy(s,Length(CondAsmOpStr[j])+1,255);
  150. if cond<>'' then
  151. begin
  152. for cnd:=low(TasmCond) to high(TasmCond) do
  153. if Cond=Upper(cond2str[cnd]) then
  154. begin
  155. actopcode:=CondASmOp[j];
  156. actcondition:=cnd;
  157. is_asmopcode:=TRUE;
  158. actasmtoken:=AS_OPCODE;
  159. exit
  160. end;
  161. end;
  162. end;
  163. inc(j);
  164. end;
  165. end;
  166. function tx86intreader.is_asmoperator(const s: string):boolean;
  167. var
  168. i : longint;
  169. Begin
  170. for i:=0 to _count_asmoperators do
  171. if s=_asmoperators[i] then
  172. begin
  173. actasmtoken:=tasmtoken(longint(firstoperator)+i);
  174. is_asmoperator:=true;
  175. exit;
  176. end;
  177. is_asmoperator:=false;
  178. end;
  179. Function tx86intreader.is_asmdirective(const s: string):boolean;
  180. var
  181. i : longint;
  182. Begin
  183. for i:=0 to _count_asmdirectives do
  184. if s=_asmdirectives[i] then
  185. begin
  186. actasmtoken:=tasmtoken(longint(firstdirective)+i);
  187. is_asmdirective:=true;
  188. exit;
  189. end;
  190. is_asmdirective:=false;
  191. end;
  192. function tx86intreader.is_register(const s:string):boolean;
  193. begin
  194. is_register:=false;
  195. actasmregister:=masm_regnum_search(lower(s));
  196. if actasmregister<>NR_NO then
  197. begin
  198. is_register:=true;
  199. actasmtoken:=AS_REGISTER;
  200. end;
  201. end;
  202. function tx86intreader.is_locallabel(const s:string):boolean;
  203. begin
  204. is_locallabel:=(length(s)>1) and (s[1]='@');
  205. end;
  206. Procedure tx86intreader.GetToken;
  207. var
  208. len : longint;
  209. forcelabel : boolean;
  210. srsym : tsym;
  211. srsymtable : TSymtable;
  212. begin
  213. { save old token and reset new token }
  214. prevasmtoken:=actasmtoken;
  215. actasmtoken:=AS_NONE;
  216. { reset }
  217. forcelabel:=FALSE;
  218. actasmpattern:='';
  219. { while space and tab , continue scan... }
  220. while (c in [' ',#9]) do
  221. c:=current_scanner.asmgetchar;
  222. { get token pos }
  223. if not (c in [#10,#13,'{',';']) then
  224. current_scanner.gettokenpos;
  225. { Local Label, Label, Directive, Prefix or Opcode }
  226. if firsttoken and not (c in [#10,#13,'{',';']) then
  227. begin
  228. firsttoken:=FALSE;
  229. len:=0;
  230. while c in ['A'..'Z','a'..'z','0'..'9','_','@'] do
  231. begin
  232. { if there is an at_sign, then this must absolutely be a label }
  233. if c = '@' then
  234. forcelabel:=TRUE;
  235. inc(len);
  236. actasmpattern[len]:=c;
  237. c:=current_scanner.asmgetchar;
  238. end;
  239. actasmpattern[0]:=chr(len);
  240. uppervar(actasmpattern);
  241. { allow spaces }
  242. while (c in [' ',#9]) do
  243. c:=current_scanner.asmgetchar;
  244. { label ? }
  245. if c = ':' then
  246. begin
  247. if actasmpattern[1]='@' then
  248. actasmtoken:=AS_LLABEL
  249. else
  250. actasmtoken:=AS_LABEL;
  251. { let us point to the next character }
  252. c:=current_scanner.asmgetchar;
  253. firsttoken:=true;
  254. exit;
  255. end;
  256. { Are we trying to create an identifier with }
  257. { an at-sign...? }
  258. if forcelabel then
  259. Message(asmr_e_none_label_contain_at);
  260. { opcode ? }
  261. If is_asmopcode(actasmpattern) then
  262. Begin
  263. { check if we are in an expression }
  264. { then continue with asm directives }
  265. if not inexpression then
  266. exit;
  267. end;
  268. if is_asmdirective(actasmpattern) then
  269. exit;
  270. message1(asmr_e_unknown_opcode,actasmpattern);
  271. actasmtoken:=AS_NONE;
  272. exit;
  273. end
  274. else { else firsttoken }
  275. begin
  276. case c of
  277. '@' : { possiblities : - local label reference , such as in jmp @local1 }
  278. { - @Result, @Code or @Data special variables. }
  279. begin
  280. actasmpattern:=c;
  281. c:=current_scanner.asmgetchar;
  282. while c in ['A'..'Z','a'..'z','0'..'9','_','@'] do
  283. begin
  284. actasmpattern:=actasmpattern + c;
  285. c:=current_scanner.asmgetchar;
  286. end;
  287. uppervar(actasmpattern);
  288. actasmtoken:=AS_ID;
  289. exit;
  290. end;
  291. 'A'..'Z','a'..'z','_': { identifier, register, opcode, prefix or directive }
  292. begin
  293. actasmpattern:=c;
  294. c:=current_scanner.asmgetchar;
  295. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  296. begin
  297. actasmpattern:=actasmpattern + c;
  298. c:=current_scanner.asmgetchar;
  299. end;
  300. uppervar(actasmpattern);
  301. { after prefix we allow also a new opcode }
  302. If is_prefix(actopcode) and is_asmopcode(actasmpattern) then
  303. Begin
  304. { if we are not in a constant }
  305. { expression than this is an }
  306. { opcode. }
  307. if not inexpression then
  308. exit;
  309. end;
  310. { support st(X) for fpu registers }
  311. if (actasmpattern = 'ST') and (c='(') then
  312. Begin
  313. actasmpattern:=actasmpattern+c;
  314. c:=current_scanner.asmgetchar;
  315. { allow spaces }
  316. while (c in [' ',#9]) do
  317. c:=current_scanner.asmgetchar;
  318. if c in ['0'..'7'] then
  319. actasmpattern:=actasmpattern + c
  320. else
  321. Message(asmr_e_invalid_fpu_register);
  322. c:=current_scanner.asmgetchar;
  323. { allow spaces }
  324. while (c in [' ',#9]) do
  325. c:=current_scanner.asmgetchar;
  326. if c <> ')' then
  327. Message(asmr_e_invalid_fpu_register)
  328. else
  329. Begin
  330. actasmpattern:=actasmpattern + c;
  331. c:=current_scanner.asmgetchar;
  332. end;
  333. end;
  334. if is_register(actasmpattern) then
  335. exit;
  336. if is_asmdirective(actasmpattern) then
  337. exit;
  338. if is_asmoperator(actasmpattern) then
  339. exit;
  340. { allow spaces }
  341. while (c in [' ',#9]) do
  342. c:=current_scanner.asmgetchar;
  343. { if next is a '.' and this is a unitsym then we also need to
  344. parse the identifier }
  345. if (c='.') then
  346. begin
  347. searchsym(actasmpattern,srsym,srsymtable);
  348. if assigned(srsym) and
  349. (srsym.typ=unitsym) and
  350. (srsym.owner.symtabletype in [staticsymtable,globalsymtable]) and
  351. srsym.owner.iscurrentunit then
  352. begin
  353. { Add . to create System.Identifier }
  354. actasmpattern:=actasmpattern+c;
  355. c:=current_scanner.asmgetchar;
  356. { Delphi allows System.@Halt, just ignore the @ }
  357. if c='@' then
  358. c:=current_scanner.asmgetchar;
  359. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  360. begin
  361. actasmpattern:=actasmpattern + upcase(c);
  362. c:=current_scanner.asmgetchar;
  363. end;
  364. end;
  365. end;
  366. actasmtoken:=AS_ID;
  367. exit;
  368. end;
  369. '''' : { string or character }
  370. begin
  371. actasmpattern:='';
  372. current_scanner.in_asm_string:=true;
  373. repeat
  374. if c = '''' then
  375. begin
  376. c:=current_scanner.asmgetchar;
  377. if c in [#10,#13] then
  378. begin
  379. Message(scan_f_string_exceeds_line);
  380. break;
  381. end;
  382. repeat
  383. if c='''' then
  384. begin
  385. c:=current_scanner.asmgetchar;
  386. if c='''' then
  387. begin
  388. actasmpattern:=actasmpattern+'''';
  389. c:=current_scanner.asmgetchar;
  390. if c in [#10,#13] then
  391. begin
  392. Message(scan_f_string_exceeds_line);
  393. break;
  394. end;
  395. end
  396. else
  397. break;
  398. end
  399. else
  400. begin
  401. actasmpattern:=actasmpattern+c;
  402. c:=current_scanner.asmgetchar;
  403. if c in [#10,#13] then
  404. begin
  405. Message(scan_f_string_exceeds_line);
  406. break
  407. end;
  408. end;
  409. until false; { end repeat }
  410. end
  411. else
  412. break; { end if }
  413. until false;
  414. current_scanner.in_asm_string:=false;
  415. actasmtoken:=AS_STRING;
  416. exit;
  417. end;
  418. '"' : { string or character }
  419. begin
  420. current_scanner.in_asm_string:=true;
  421. actasmpattern:='';
  422. repeat
  423. if c = '"' then
  424. begin
  425. c:=current_scanner.asmgetchar;
  426. if c in [#10,#13] then
  427. begin
  428. Message(scan_f_string_exceeds_line);
  429. break;
  430. end;
  431. repeat
  432. if c='"' then
  433. begin
  434. c:=current_scanner.asmgetchar;
  435. if c='"' then
  436. begin
  437. actasmpattern:=actasmpattern+'"';
  438. c:=current_scanner.asmgetchar;
  439. if c in [#10,#13] then
  440. begin
  441. Message(scan_f_string_exceeds_line);
  442. break;
  443. end;
  444. end
  445. else
  446. break;
  447. end
  448. else
  449. begin
  450. actasmpattern:=actasmpattern+c;
  451. c:=current_scanner.asmgetchar;
  452. if c in [#10,#13] then
  453. begin
  454. Message(scan_f_string_exceeds_line);
  455. break
  456. end;
  457. end;
  458. until false; { end repeat }
  459. end
  460. else
  461. break; { end if }
  462. until false;
  463. current_scanner.in_asm_string:=false;
  464. actasmtoken:=AS_STRING;
  465. exit;
  466. end;
  467. '$' :
  468. begin
  469. c:=current_scanner.asmgetchar;
  470. while c in ['0'..'9','A'..'F','a'..'f'] do
  471. begin
  472. actasmpattern:=actasmpattern + c;
  473. c:=current_scanner.asmgetchar;
  474. end;
  475. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  476. actasmtoken:=AS_INTNUM;
  477. exit;
  478. end;
  479. '&' : { identifier }
  480. begin
  481. actasmpattern:='';
  482. c:=current_scanner.asmgetchar;
  483. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  484. begin
  485. actasmpattern:=actasmpattern + c;
  486. c:=current_scanner.asmgetchar;
  487. end;
  488. uppervar(actasmpattern);
  489. actasmtoken:=AS_ID;
  490. exit;
  491. end;
  492. ',' :
  493. begin
  494. actasmtoken:=AS_COMMA;
  495. c:=current_scanner.asmgetchar;
  496. exit;
  497. end;
  498. '[' :
  499. begin
  500. actasmtoken:=AS_LBRACKET;
  501. c:=current_scanner.asmgetchar;
  502. exit;
  503. end;
  504. ']' :
  505. begin
  506. actasmtoken:=AS_RBRACKET;
  507. c:=current_scanner.asmgetchar;
  508. exit;
  509. end;
  510. '(' :
  511. begin
  512. actasmtoken:=AS_LPAREN;
  513. c:=current_scanner.asmgetchar;
  514. exit;
  515. end;
  516. ')' :
  517. begin
  518. actasmtoken:=AS_RPAREN;
  519. c:=current_scanner.asmgetchar;
  520. exit;
  521. end;
  522. ':' :
  523. begin
  524. actasmtoken:=AS_COLON;
  525. c:=current_scanner.asmgetchar;
  526. exit;
  527. end;
  528. '.' :
  529. begin
  530. actasmtoken:=AS_DOT;
  531. c:=current_scanner.asmgetchar;
  532. exit;
  533. end;
  534. '+' :
  535. begin
  536. actasmtoken:=AS_PLUS;
  537. c:=current_scanner.asmgetchar;
  538. exit;
  539. end;
  540. '-' :
  541. begin
  542. actasmtoken:=AS_MINUS;
  543. c:=current_scanner.asmgetchar;
  544. exit;
  545. end;
  546. '*' :
  547. begin
  548. actasmtoken:=AS_STAR;
  549. c:=current_scanner.asmgetchar;
  550. exit;
  551. end;
  552. '/' :
  553. begin
  554. actasmtoken:=AS_SLASH;
  555. c:=current_scanner.asmgetchar;
  556. exit;
  557. end;
  558. '0'..'9':
  559. begin
  560. actasmpattern:=c;
  561. c:=current_scanner.asmgetchar;
  562. { Get the possible characters }
  563. while c in ['0'..'9','A'..'F','a'..'f'] do
  564. begin
  565. actasmpattern:=actasmpattern + c;
  566. c:=current_scanner.asmgetchar;
  567. end;
  568. { Get ending character }
  569. uppervar(actasmpattern);
  570. c:=upcase(c);
  571. { possibly a binary number. }
  572. if (actasmpattern[length(actasmpattern)] = 'B') and (c <> 'H') then
  573. Begin
  574. { Delete the last binary specifier }
  575. delete(actasmpattern,length(actasmpattern),1);
  576. actasmpattern:=tostr(ParseVal(actasmpattern,2));
  577. actasmtoken:=AS_INTNUM;
  578. exit;
  579. end
  580. else
  581. Begin
  582. case c of
  583. 'O' :
  584. Begin
  585. actasmpattern:=tostr(ParseVal(actasmpattern,8));
  586. actasmtoken:=AS_INTNUM;
  587. c:=current_scanner.asmgetchar;
  588. exit;
  589. end;
  590. 'H' :
  591. Begin
  592. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  593. actasmtoken:=AS_INTNUM;
  594. c:=current_scanner.asmgetchar;
  595. exit;
  596. end;
  597. else { must be an integer number }
  598. begin
  599. actasmpattern:=tostr(ParseVal(actasmpattern,10));
  600. actasmtoken:=AS_INTNUM;
  601. exit;
  602. end;
  603. end;
  604. end;
  605. end;
  606. ';','{',#13,#10 :
  607. begin
  608. c:=current_scanner.asmgetchar;
  609. firsttoken:=TRUE;
  610. actasmtoken:=AS_SEPARATOR;
  611. exit;
  612. end;
  613. else
  614. current_scanner.illegal_char(c);
  615. end;
  616. end;
  617. end;
  618. function tx86intreader.consume(t : tasmtoken):boolean;
  619. begin
  620. Consume:=true;
  621. if t<>actasmtoken then
  622. begin
  623. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  624. Consume:=false;
  625. end;
  626. repeat
  627. gettoken;
  628. until actasmtoken<>AS_NONE;
  629. end;
  630. procedure tx86intreader.RecoverConsume(allowcomma:boolean);
  631. begin
  632. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  633. begin
  634. if allowcomma and (actasmtoken=AS_COMMA) then
  635. break;
  636. Consume(actasmtoken);
  637. end;
  638. end;
  639. {*****************************************************************************
  640. Parsing Helpers
  641. *****************************************************************************}
  642. { This routine builds up a record offset after a AS_DOT
  643. token is encountered.
  644. On entry actasmtoken should be equal to AS_DOT }
  645. Procedure tx86intreader.BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
  646. var
  647. s: string;
  648. Begin
  649. offset:=0;
  650. size:=0;
  651. s:=expr;
  652. while (actasmtoken=AS_DOT) do
  653. begin
  654. Consume(AS_DOT);
  655. if actasmtoken in [AS_BYTE,AS_ID,AS_WORD,AS_DWORD,AS_QWORD] then
  656. begin
  657. s:=s+'.'+actasmpattern;
  658. consume(actasmtoken);
  659. end
  660. else
  661. begin
  662. Consume(AS_ID);
  663. RecoverConsume(true);
  664. break;
  665. end;
  666. end;
  667. if not GetRecordOffsetSize(s,offset,size,mangledname,needvmtofs) then
  668. Message(asmr_e_building_record_offset);
  669. end;
  670. Procedure tx86intreader.BuildConstSymbolExpression(needofs,isref:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  671. var
  672. tempstr,expr,hs,mangledname : string;
  673. parenlevel : longint;
  674. l,k : aint;
  675. hasparen,
  676. errorflag,
  677. needvmtofs : boolean;
  678. prevtok : tasmtoken;
  679. hl : tasmlabel;
  680. hssymtyp : Tasmsymtype;
  681. def : tdef;
  682. sym : tsym;
  683. srsymtable : TSymtable;
  684. Begin
  685. { reset }
  686. value:=0;
  687. asmsym:='';
  688. asmsymtyp:=AT_DATA;
  689. errorflag:=FALSE;
  690. tempstr:='';
  691. expr:='';
  692. inexpression:=TRUE;
  693. parenlevel:=0;
  694. sym:=nil;
  695. needvmtofs:=FALSE;
  696. Repeat
  697. { Support ugly delphi constructs like: [ECX].1+2[EDX] }
  698. if isref and (actasmtoken=AS_LBRACKET) then
  699. break;
  700. Case actasmtoken of
  701. AS_LPAREN:
  702. Begin
  703. Consume(AS_LPAREN);
  704. expr:=expr + '(';
  705. inc(parenlevel);
  706. end;
  707. AS_RPAREN:
  708. Begin
  709. { Keep the AS_PAREN in actasmtoken, it is maybe a typecast }
  710. if parenlevel=0 then
  711. break;
  712. Consume(AS_RPAREN);
  713. expr:=expr + ')';
  714. dec(parenlevel);
  715. end;
  716. AS_SHL:
  717. Begin
  718. Consume(AS_SHL);
  719. expr:=expr + '<';
  720. end;
  721. AS_SHR:
  722. Begin
  723. Consume(AS_SHR);
  724. expr:=expr + '>';
  725. end;
  726. AS_SLASH:
  727. Begin
  728. Consume(AS_SLASH);
  729. expr:=expr + '/';
  730. end;
  731. AS_MOD:
  732. Begin
  733. Consume(AS_MOD);
  734. expr:=expr + '%';
  735. end;
  736. AS_STAR:
  737. Begin
  738. Consume(AS_STAR);
  739. if isref and (actasmtoken=AS_REGISTER) then
  740. break;
  741. expr:=expr + '*';
  742. end;
  743. AS_PLUS:
  744. Begin
  745. Consume(AS_PLUS);
  746. if isref and (actasmtoken=AS_REGISTER) then
  747. break;
  748. expr:=expr + '+';
  749. end;
  750. AS_MINUS:
  751. Begin
  752. Consume(AS_MINUS);
  753. expr:=expr + '-';
  754. end;
  755. AS_AND:
  756. Begin
  757. Consume(AS_AND);
  758. expr:=expr + '&';
  759. end;
  760. AS_NOT:
  761. Begin
  762. Consume(AS_NOT);
  763. expr:=expr + '~';
  764. end;
  765. AS_XOR:
  766. Begin
  767. Consume(AS_XOR);
  768. expr:=expr + '^';
  769. end;
  770. AS_OR:
  771. Begin
  772. Consume(AS_OR);
  773. expr:=expr + '|';
  774. end;
  775. AS_INTNUM:
  776. Begin
  777. expr:=expr + actasmpattern;
  778. Consume(AS_INTNUM);
  779. end;
  780. AS_VMTOFFSET,
  781. AS_OFFSET:
  782. begin
  783. if (actasmtoken = AS_OFFSET) then
  784. needofs:=true
  785. else
  786. needvmtofs:=true;
  787. Consume(actasmtoken);
  788. if actasmtoken<>AS_ID then
  789. Message(asmr_e_offset_without_identifier);
  790. end;
  791. AS_SIZEOF,
  792. AS_TYPE:
  793. begin
  794. l:=0;
  795. hasparen:=false;
  796. Consume(actasmtoken);
  797. if actasmtoken=AS_LPAREN then
  798. begin
  799. hasparen:=true;
  800. Consume(AS_LPAREN);
  801. end;
  802. if actasmtoken<>AS_ID then
  803. Message(asmr_e_type_without_identifier)
  804. else
  805. begin
  806. tempstr:=actasmpattern;
  807. Consume(AS_ID);
  808. if actasmtoken=AS_DOT then
  809. begin
  810. BuildRecordOffsetSize(tempstr,k,l,mangledname,false);
  811. if mangledname<>'' then
  812. { procsym }
  813. Message(asmr_e_wrong_sym_type);
  814. end
  815. else
  816. begin
  817. searchsym(tempstr,sym,srsymtable);
  818. if assigned(sym) then
  819. begin
  820. case sym.typ of
  821. staticvarsym,
  822. localvarsym,
  823. paravarsym :
  824. l:=tabstractvarsym(sym).getsize;
  825. typesym :
  826. l:=ttypesym(sym).typedef.size;
  827. else
  828. Message(asmr_e_wrong_sym_type);
  829. end;
  830. end
  831. else
  832. Message1(sym_e_unknown_id,tempstr);
  833. end;
  834. end;
  835. str(l, tempstr);
  836. expr:=expr + tempstr;
  837. if hasparen then
  838. Consume(AS_RPAREN);
  839. end;
  840. AS_PTR :
  841. begin
  842. { Support ugly delphi constructs like <constant> PTR [ref] }
  843. break;
  844. end;
  845. AS_STRING:
  846. begin
  847. l:=0;
  848. case Length(actasmpattern) of
  849. 1 :
  850. l:=ord(actasmpattern[1]);
  851. 2 :
  852. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  853. 3 :
  854. l:=ord(actasmpattern[3]) +
  855. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  856. 4 :
  857. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  858. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  859. else
  860. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  861. end;
  862. str(l, tempstr);
  863. expr:=expr + tempstr;
  864. Consume(AS_STRING);
  865. end;
  866. AS_ID:
  867. begin
  868. hs:='';
  869. hssymtyp:=AT_DATA;
  870. def:=nil;
  871. tempstr:=actasmpattern;
  872. prevtok:=prevasmtoken;
  873. { stop parsing a constant expression if we find an opcode after a
  874. non-operator like "db $66 mov eax,ebx" }
  875. if (prevtok in [AS_ID,AS_INTNUM,AS_RPAREN]) and
  876. is_asmopcode(actasmpattern) then
  877. break;
  878. consume(AS_ID);
  879. if SearchIConstant(tempstr,l) then
  880. begin
  881. str(l, tempstr);
  882. expr:=expr + tempstr;
  883. end
  884. else
  885. begin
  886. if is_locallabel(tempstr) then
  887. begin
  888. CreateLocalLabel(tempstr,hl,false);
  889. hs:=hl.name;
  890. hssymtyp:=AT_FUNCTION;
  891. end
  892. else
  893. if SearchLabel(tempstr,hl,false) then
  894. begin
  895. hs:=hl.name;
  896. hssymtyp:=AT_FUNCTION;
  897. end
  898. else
  899. begin
  900. searchsym(tempstr,sym,srsymtable);
  901. if assigned(sym) then
  902. begin
  903. case sym.typ of
  904. staticvarsym :
  905. begin
  906. hs:=tstaticvarsym(sym).mangledname;
  907. def:=tstaticvarsym(sym).vardef;
  908. end;
  909. localvarsym,
  910. paravarsym :
  911. begin
  912. Message(asmr_e_no_local_or_para_allowed);
  913. end;
  914. procsym :
  915. begin
  916. if Tprocsym(sym).ProcdefList.Count>1 then
  917. Message(asmr_w_calling_overload_func);
  918. hs:=tprocdef(tprocsym(sym).ProcdefList[0]).mangledname;
  919. hssymtyp:=AT_FUNCTION;
  920. end;
  921. typesym :
  922. begin
  923. if not(ttypesym(sym).typedef.typ in [recorddef,objectdef]) then
  924. Message(asmr_e_wrong_sym_type);
  925. end;
  926. fieldvarsym :
  927. begin
  928. tempstr:=upper(tdef(sym.owner.defowner).GetTypeName)+'.'+tempstr;
  929. end;
  930. else
  931. Message(asmr_e_wrong_sym_type);
  932. end;
  933. end
  934. else
  935. Message1(sym_e_unknown_id,tempstr);
  936. end;
  937. { symbol found? }
  938. if hs<>'' then
  939. begin
  940. if asmsym='' then
  941. begin
  942. asmsym:=hs;
  943. asmsymtyp:=hssymtyp;
  944. end
  945. else
  946. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  947. if (expr='') or (expr[length(expr)]='+') then
  948. begin
  949. { don't remove the + if there could be a record field }
  950. if actasmtoken<>AS_DOT then
  951. delete(expr,length(expr),1);
  952. end
  953. else
  954. if needofs then
  955. begin
  956. if (prevtok<>AS_OFFSET) then
  957. Message(asmr_e_need_offset);
  958. end
  959. else
  960. Message(asmr_e_only_add_relocatable_symbol);
  961. end;
  962. if (actasmtoken=AS_DOT) or
  963. (assigned(sym) and
  964. (sym.typ = fieldvarsym)) then
  965. begin
  966. BuildRecordOffsetSize(tempstr,l,k,hs,needvmtofs);
  967. if hs <> '' then
  968. hssymtyp:=AT_FUNCTION
  969. else
  970. begin
  971. str(l, tempstr);
  972. expr:=expr + tempstr;
  973. end
  974. end
  975. else
  976. begin
  977. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  978. delete(expr,length(expr),1);
  979. end;
  980. if (actasmtoken=AS_LBRACKET) and
  981. assigned(def) and
  982. (def.typ=arraydef) then
  983. begin
  984. consume(AS_LBRACKET);
  985. l:=BuildConstExpression;
  986. if l<tarraydef(def).lowrange then
  987. begin
  988. Message(asmr_e_constant_out_of_bounds);
  989. l:=0;
  990. end
  991. else
  992. l:=(l-tarraydef(def).lowrange)*tarraydef(def).elesize;
  993. str(l, tempstr);
  994. expr:=expr + '+' + tempstr;
  995. consume(AS_RBRACKET);
  996. end;
  997. end;
  998. { check if there are wrong operator used like / or mod etc. }
  999. if (hs<>'') and not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,AS_END,AS_RBRACKET]) then
  1000. Message(asmr_e_only_add_relocatable_symbol);
  1001. end;
  1002. AS_ALIGN,
  1003. AS_DB,
  1004. AS_DW,
  1005. AS_DD,
  1006. AS_END,
  1007. AS_RBRACKET,
  1008. AS_SEPARATOR,
  1009. AS_COMMA,
  1010. AS_COLON:
  1011. break;
  1012. else
  1013. begin
  1014. { write error only once. }
  1015. if not errorflag then
  1016. Message(asmr_e_invalid_constant_expression);
  1017. { consume tokens until we find COMMA or SEPARATOR }
  1018. Consume(actasmtoken);
  1019. errorflag:=TRUE;
  1020. end;
  1021. end;
  1022. Until false;
  1023. { calculate expression }
  1024. if not ErrorFlag then
  1025. value:=CalculateExpression(expr)
  1026. else
  1027. value:=0;
  1028. { no longer in an expression }
  1029. inexpression:=FALSE;
  1030. end;
  1031. Function tx86intreader.BuildConstExpression:aint;
  1032. var
  1033. l : aint;
  1034. hs : string;
  1035. hssymtyp : TAsmsymtype;
  1036. begin
  1037. BuildConstSymbolExpression(false,false,l,hs,hssymtyp);
  1038. if hs<>'' then
  1039. Message(asmr_e_relocatable_symbol_not_allowed);
  1040. BuildConstExpression:=l;
  1041. end;
  1042. Function tx86intreader.BuildRefConstExpression:aint;
  1043. var
  1044. l : aint;
  1045. hs : string;
  1046. hssymtyp : TAsmsymtype;
  1047. begin
  1048. BuildConstSymbolExpression(false,true,l,hs,hssymtyp);
  1049. if hs<>'' then
  1050. Message(asmr_e_relocatable_symbol_not_allowed);
  1051. BuildRefConstExpression:=l;
  1052. end;
  1053. procedure tx86intreader.BuildReference(oper : tx86operand);
  1054. var
  1055. scale : byte;
  1056. k,l : aint;
  1057. tempstr,hs : string;
  1058. tempsymtyp : tasmsymtype;
  1059. code : integer;
  1060. hreg : tregister;
  1061. GotStar,GotOffset,HadVar,
  1062. GotPlus,Negative : boolean;
  1063. hl : tasmlabel;
  1064. Begin
  1065. Consume(AS_LBRACKET);
  1066. if not(oper.opr.typ in [OPR_LOCAL,OPR_REFERENCE]) then
  1067. oper.InitRef;
  1068. GotStar:=false;
  1069. GotPlus:=true;
  1070. GotOffset:=false;
  1071. Negative:=false;
  1072. Scale:=0;
  1073. repeat
  1074. if GotOffset and (actasmtoken<>AS_ID) then
  1075. Message(asmr_e_invalid_reference_syntax);
  1076. Case actasmtoken of
  1077. AS_ID, { Constant reference expression OR variable reference expression }
  1078. AS_VMTOFFSET:
  1079. Begin
  1080. if not GotPlus then
  1081. Message(asmr_e_invalid_reference_syntax);
  1082. GotStar:=false;
  1083. GotPlus:=false;
  1084. if (actasmtoken = AS_VMTOFFSET) or
  1085. (SearchIConstant(actasmpattern,l) or
  1086. SearchRecordType(actasmpattern)) then
  1087. begin
  1088. l:=BuildRefConstExpression;
  1089. GotPlus:=(prevasmtoken=AS_PLUS);
  1090. GotStar:=(prevasmtoken=AS_STAR);
  1091. case oper.opr.typ of
  1092. OPR_LOCAL :
  1093. begin
  1094. if GotStar then
  1095. Message(asmr_e_invalid_reference_syntax);
  1096. if negative then
  1097. Dec(oper.opr.localsymofs,l)
  1098. else
  1099. Inc(oper.opr.localsymofs,l);
  1100. end;
  1101. OPR_REFERENCE :
  1102. begin
  1103. if GotStar then
  1104. oper.opr.ref.scalefactor:=l
  1105. else
  1106. begin
  1107. if negative then
  1108. Dec(oper.opr.ref.offset,l)
  1109. else
  1110. Inc(oper.opr.ref.offset,l);
  1111. end;
  1112. end;
  1113. end;
  1114. end
  1115. else
  1116. Begin
  1117. if oper.hasvar and not GotOffset then
  1118. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1119. HadVar:=oper.hasvar and GotOffset;
  1120. if negative then
  1121. Message(asmr_e_only_add_relocatable_symbol);
  1122. tempstr:=actasmpattern;
  1123. Consume(AS_ID);
  1124. { typecasting? }
  1125. if (actasmtoken=AS_LPAREN) and
  1126. SearchType(tempstr,l) then
  1127. begin
  1128. oper.hastype:=true;
  1129. oper.typesize:=l;
  1130. Consume(AS_LPAREN);
  1131. BuildOperand(oper,true);
  1132. Consume(AS_RPAREN);
  1133. end
  1134. else
  1135. if is_locallabel(tempstr) then
  1136. begin
  1137. CreateLocalLabel(tempstr,hl,false);
  1138. oper.InitRef;
  1139. oper.opr.ref.symbol:=hl;
  1140. oper.hasvar:=true;
  1141. end
  1142. else
  1143. if oper.SetupVar(tempstr,GotOffset) then
  1144. begin
  1145. { force OPR_LOCAL to be a reference }
  1146. if oper.opr.typ=OPR_LOCAL then
  1147. oper.opr.localforceref:=true;
  1148. end
  1149. else
  1150. Message1(sym_e_unknown_id,tempstr);
  1151. { record.field ? }
  1152. if actasmtoken=AS_DOT then
  1153. begin
  1154. BuildRecordOffsetSize(tempstr,l,k,hs,false);
  1155. if (hs<>'') then
  1156. Message(asmr_e_invalid_symbol_ref);
  1157. case oper.opr.typ of
  1158. OPR_LOCAL :
  1159. inc(oper.opr.localsymofs,l);
  1160. OPR_REFERENCE :
  1161. inc(oper.opr.ref.offset,l);
  1162. end;
  1163. end;
  1164. if GotOffset then
  1165. begin
  1166. if oper.hasvar and (oper.opr.ref.base=current_procinfo.framepointer) then
  1167. begin
  1168. if (oper.opr.typ=OPR_REFERENCE) then
  1169. oper.opr.ref.base:=NR_NO;
  1170. oper.hasvar:=hadvar;
  1171. end
  1172. else
  1173. begin
  1174. if oper.hasvar and hadvar then
  1175. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1176. { should we allow ?? }
  1177. end;
  1178. end;
  1179. end;
  1180. GotOffset:=false;
  1181. end;
  1182. AS_PLUS :
  1183. Begin
  1184. Consume(AS_PLUS);
  1185. Negative:=false;
  1186. GotPlus:=true;
  1187. GotStar:=false;
  1188. Scale:=0;
  1189. end;
  1190. AS_DOT :
  1191. Begin
  1192. { Handle like a + }
  1193. Consume(AS_DOT);
  1194. Negative:=false;
  1195. GotPlus:=true;
  1196. GotStar:=false;
  1197. Scale:=0;
  1198. end;
  1199. AS_MINUS :
  1200. begin
  1201. Consume(AS_MINUS);
  1202. Negative:=true;
  1203. GotPlus:=true;
  1204. GotStar:=false;
  1205. Scale:=0;
  1206. end;
  1207. AS_STAR : { Scaling, with eax*4 order }
  1208. begin
  1209. Consume(AS_STAR);
  1210. hs:='';
  1211. l:=0;
  1212. case actasmtoken of
  1213. AS_LPAREN :
  1214. l:=BuildConstExpression;
  1215. AS_INTNUM:
  1216. Begin
  1217. hs:=actasmpattern;
  1218. Consume(AS_INTNUM);
  1219. end;
  1220. AS_REGISTER :
  1221. begin
  1222. case oper.opr.typ of
  1223. OPR_REFERENCE :
  1224. begin
  1225. if oper.opr.ref.scalefactor=0 then
  1226. begin
  1227. if scale<>0 then
  1228. begin
  1229. oper.opr.ref.scalefactor:=scale;
  1230. scale:=0;
  1231. end
  1232. else
  1233. Message(asmr_e_wrong_scale_factor);
  1234. end
  1235. else
  1236. Message(asmr_e_invalid_reference_syntax);
  1237. end;
  1238. OPR_LOCAL :
  1239. begin
  1240. if oper.opr.localscale=0 then
  1241. begin
  1242. if scale<>0 then
  1243. begin
  1244. oper.opr.localscale:=scale;
  1245. scale:=0;
  1246. end
  1247. else
  1248. Message(asmr_e_wrong_scale_factor);
  1249. end
  1250. else
  1251. Message(asmr_e_invalid_reference_syntax);
  1252. end;
  1253. end;
  1254. end;
  1255. else
  1256. Message(asmr_e_invalid_reference_syntax);
  1257. end;
  1258. if actasmtoken<>AS_REGISTER then
  1259. begin
  1260. if hs<>'' then
  1261. val(hs,l,code);
  1262. case oper.opr.typ of
  1263. OPR_REFERENCE :
  1264. oper.opr.ref.scalefactor:=l;
  1265. OPR_LOCAL :
  1266. oper.opr.localscale:=l;
  1267. end;
  1268. if l>9 then
  1269. Message(asmr_e_wrong_scale_factor);
  1270. end;
  1271. GotPlus:=false;
  1272. GotStar:=false;
  1273. end;
  1274. AS_REGISTER :
  1275. begin
  1276. if not((GotPlus and (not Negative)) or
  1277. GotStar) then
  1278. Message(asmr_e_invalid_reference_syntax);
  1279. hreg:=actasmregister;
  1280. Consume(AS_REGISTER);
  1281. { this register will be the index:
  1282. 1. just read a *
  1283. 2. next token is a *
  1284. 3. base register is already used }
  1285. case oper.opr.typ of
  1286. OPR_LOCAL :
  1287. begin
  1288. if (oper.opr.localindexreg<>NR_NO) then
  1289. Message(asmr_e_multiple_index);
  1290. oper.opr.localindexreg:=hreg;
  1291. if scale<>0 then
  1292. begin
  1293. oper.opr.localscale:=scale;
  1294. scale:=0;
  1295. end;
  1296. end;
  1297. OPR_REFERENCE :
  1298. begin
  1299. if (GotStar) or
  1300. (actasmtoken=AS_STAR) or
  1301. (oper.opr.ref.base<>NR_NO) then
  1302. begin
  1303. if (oper.opr.ref.index<>NR_NO) then
  1304. Message(asmr_e_multiple_index);
  1305. oper.opr.ref.index:=hreg;
  1306. if scale<>0 then
  1307. begin
  1308. oper.opr.ref.scalefactor:=scale;
  1309. scale:=0;
  1310. end;
  1311. end
  1312. else
  1313. oper.opr.ref.base:=hreg;
  1314. end;
  1315. end;
  1316. GotPlus:=false;
  1317. GotStar:=false;
  1318. end;
  1319. AS_OFFSET :
  1320. begin
  1321. Consume(AS_OFFSET);
  1322. GotOffset:=true;
  1323. end;
  1324. AS_TYPE,
  1325. AS_NOT,
  1326. AS_STRING,
  1327. AS_INTNUM,
  1328. AS_LPAREN : { Constant reference expression }
  1329. begin
  1330. if not GotPlus and not GotStar then
  1331. Message(asmr_e_invalid_reference_syntax);
  1332. BuildConstSymbolExpression(true,true,l,tempstr,tempsymtyp);
  1333. if tempstr<>'' then
  1334. begin
  1335. if GotStar then
  1336. Message(asmr_e_only_add_relocatable_symbol);
  1337. if not assigned(oper.opr.ref.symbol) then
  1338. oper.opr.ref.symbol:=current_asmdata.RefAsmSymbol(tempstr)
  1339. else
  1340. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1341. end;
  1342. case oper.opr.typ of
  1343. OPR_REFERENCE :
  1344. begin
  1345. if GotStar then
  1346. oper.opr.ref.scalefactor:=l
  1347. else if (prevasmtoken = AS_STAR) then
  1348. begin
  1349. if scale<>0 then
  1350. scale:=l*scale
  1351. else
  1352. scale:=l;
  1353. end
  1354. else
  1355. begin
  1356. if negative then
  1357. Dec(oper.opr.ref.offset,l)
  1358. else
  1359. Inc(oper.opr.ref.offset,l);
  1360. end;
  1361. end;
  1362. OPR_LOCAL :
  1363. begin
  1364. if GotStar then
  1365. oper.opr.localscale:=l
  1366. else if (prevasmtoken = AS_STAR) then
  1367. begin
  1368. if scale<>0 then
  1369. scale:=l*scale
  1370. else
  1371. scale:=l;
  1372. end
  1373. else
  1374. begin
  1375. if negative then
  1376. Dec(oper.opr.localsymofs,l)
  1377. else
  1378. Inc(oper.opr.localsymofs,l);
  1379. end;
  1380. end;
  1381. end;
  1382. GotPlus:=(prevasmtoken=AS_PLUS) or
  1383. (prevasmtoken=AS_MINUS);
  1384. if GotPlus then
  1385. negative := prevasmtoken = AS_MINUS;
  1386. GotStar:=(prevasmtoken=AS_STAR);
  1387. end;
  1388. AS_RBRACKET :
  1389. begin
  1390. if GotPlus or GotStar then
  1391. Message(asmr_e_invalid_reference_syntax);
  1392. Consume(AS_RBRACKET);
  1393. break;
  1394. end;
  1395. else
  1396. Begin
  1397. Message(asmr_e_invalid_reference_syntax);
  1398. RecoverConsume(true);
  1399. break;
  1400. end;
  1401. end;
  1402. until false;
  1403. end;
  1404. Procedure tx86intreader.BuildConstantOperand(oper: tx86operand);
  1405. var
  1406. l : aint;
  1407. tempstr : string;
  1408. tempsymtyp : tasmsymtype;
  1409. begin
  1410. if not (oper.opr.typ in [OPR_NONE,OPR_CONSTANT]) then
  1411. Message(asmr_e_invalid_operand_type);
  1412. BuildConstSymbolExpression(true,false,l,tempstr,tempsymtyp);
  1413. if tempstr<>'' then
  1414. begin
  1415. oper.opr.typ:=OPR_SYMBOL;
  1416. oper.opr.symofs:=l;
  1417. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr);
  1418. end
  1419. else
  1420. if oper.opr.typ=OPR_NONE then
  1421. begin
  1422. oper.opr.typ:=OPR_CONSTANT;
  1423. oper.opr.val:=l;
  1424. end
  1425. else
  1426. inc(oper.opr.val,l);
  1427. end;
  1428. Procedure tx86intreader.BuildOperand(oper: tx86operand;istypecast:boolean);
  1429. procedure AddLabelOperand(hl:tasmlabel);
  1430. begin
  1431. if (oper.opr.typ=OPR_NONE) and
  1432. is_calljmp(actopcode) then
  1433. begin
  1434. oper.opr.typ:=OPR_SYMBOL;
  1435. oper.opr.symbol:=hl;
  1436. end
  1437. else
  1438. begin
  1439. oper.InitRef;
  1440. oper.opr.ref.symbol:=hl;
  1441. end;
  1442. end;
  1443. var
  1444. expr,
  1445. hs : string;
  1446. tempreg : tregister;
  1447. l : aint;
  1448. hl : tasmlabel;
  1449. toffset,
  1450. tsize : aint;
  1451. begin
  1452. expr:='';
  1453. repeat
  1454. if actasmtoken=AS_DOT then
  1455. begin
  1456. if expr<>'' then
  1457. begin
  1458. BuildRecordOffsetSize(expr,toffset,tsize,hs,false);
  1459. if (oper.opr.typ<>OPR_NONE) and
  1460. (hs<>'') then
  1461. Message(asmr_e_wrong_sym_type);
  1462. oper.SetSize(tsize,true);
  1463. { we have used the size of a field. Reset the typesize of the record }
  1464. oper.typesize:=0;
  1465. case oper.opr.typ of
  1466. OPR_LOCAL :
  1467. begin
  1468. { don't allow direct access to fields of parameters, becuase that
  1469. will generate buggy code. Allow it only for explicit typecasting
  1470. and when the parameter is in a register (delphi compatible) }
  1471. if (not oper.hastype) and
  1472. (oper.opr.localsym.owner.symtabletype=parasymtable) and
  1473. (current_procinfo.procdef.proccalloption<>pocall_register) then
  1474. Message(asmr_e_cannot_access_field_directly_for_parameters);
  1475. inc(oper.opr.localsymofs,toffset)
  1476. end;
  1477. OPR_CONSTANT :
  1478. inc(oper.opr.val,toffset);
  1479. OPR_REFERENCE :
  1480. inc(oper.opr.ref.offset,toffset);
  1481. OPR_NONE :
  1482. begin
  1483. if (hs <> '') then
  1484. begin
  1485. oper.opr.typ:=OPR_SYMBOL;
  1486. oper.opr.symbol:=current_asmdata.RefAsmSymbol(hs);
  1487. end
  1488. else
  1489. begin
  1490. oper.opr.typ:=OPR_CONSTANT;
  1491. oper.opr.val:=toffset;
  1492. end;
  1493. end;
  1494. OPR_SYMBOL:
  1495. Message(asmr_e_invalid_symbol_ref);
  1496. else
  1497. internalerror(200309222);
  1498. end;
  1499. expr:='';
  1500. end
  1501. else
  1502. begin
  1503. { See it as a separator }
  1504. Consume(AS_DOT);
  1505. end;
  1506. end;
  1507. case actasmtoken of
  1508. AS_OFFSET,
  1509. AS_SIZEOF,
  1510. AS_VMTOFFSET,
  1511. AS_TYPE,
  1512. AS_NOT,
  1513. AS_STRING,
  1514. AS_PLUS,
  1515. AS_MINUS,
  1516. AS_LPAREN,
  1517. AS_INTNUM :
  1518. begin
  1519. case oper.opr.typ of
  1520. OPR_REFERENCE :
  1521. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1522. OPR_LOCAL :
  1523. inc(oper.opr.localsymofs,BuildConstExpression);
  1524. OPR_NONE,
  1525. OPR_CONSTANT :
  1526. BuildConstantOperand(oper);
  1527. else
  1528. Message(asmr_e_invalid_operand_type);
  1529. end;
  1530. end;
  1531. AS_PTR :
  1532. begin
  1533. if not oper.hastype then
  1534. begin
  1535. if (oper.opr.typ=OPR_CONSTANT) then
  1536. begin
  1537. oper.typesize:=oper.opr.val;
  1538. { reset constant value of operand }
  1539. oper.opr.typ:=OPR_NONE;
  1540. oper.opr.val:=0;
  1541. end
  1542. else
  1543. Message(asmr_e_syn_operand);
  1544. end;
  1545. Consume(AS_PTR);
  1546. oper.InitRef;
  1547. BuildOperand(oper,false);
  1548. end;
  1549. AS_ID : { A constant expression, or a Variable ref. }
  1550. Begin
  1551. { Label or Special symbol reference? }
  1552. if actasmpattern[1] = '@' then
  1553. Begin
  1554. if actasmpattern = '@RESULT' then
  1555. Begin
  1556. oper.SetupResult;
  1557. Consume(AS_ID);
  1558. end
  1559. else
  1560. if (actasmpattern = '@CODE') or (actasmpattern = '@DATA') then
  1561. begin
  1562. Message(asmr_w_CODE_and_DATA_not_supported);
  1563. Consume(AS_ID);
  1564. end
  1565. else
  1566. { Local Label }
  1567. begin
  1568. CreateLocalLabel(actasmpattern,hl,false);
  1569. Consume(AS_ID);
  1570. AddLabelOperand(hl);
  1571. end;
  1572. end
  1573. else
  1574. { support result for delphi modes }
  1575. if (m_objpas in current_settings.modeswitches) and (actasmpattern='RESULT') then
  1576. begin
  1577. oper.SetUpResult;
  1578. Consume(AS_ID);
  1579. end
  1580. { probably a variable or normal expression }
  1581. { or a procedure (such as in CALL ID) }
  1582. else
  1583. Begin
  1584. { is it a constant ? }
  1585. if SearchIConstant(actasmpattern,l) then
  1586. Begin
  1587. case oper.opr.typ of
  1588. OPR_REFERENCE :
  1589. inc(oper.opr.ref.offset,BuildRefConstExpression);
  1590. OPR_LOCAL :
  1591. inc(oper.opr.localsymofs,BuildRefConstExpression);
  1592. OPR_NONE,
  1593. OPR_CONSTANT :
  1594. BuildConstantOperand(oper);
  1595. else
  1596. Message(asmr_e_invalid_operand_type);
  1597. end;
  1598. end
  1599. else
  1600. { Check for pascal label }
  1601. if SearchLabel(actasmpattern,hl,false) then
  1602. begin
  1603. Consume(AS_ID);
  1604. AddLabelOperand(hl);
  1605. end
  1606. else
  1607. { is it a normal variable ? }
  1608. Begin
  1609. expr:=actasmpattern;
  1610. Consume(AS_ID);
  1611. { typecasting? }
  1612. if SearchType(expr,l) then
  1613. begin
  1614. oper.hastype:=true;
  1615. oper.typesize:=l;
  1616. case actasmtoken of
  1617. AS_LPAREN :
  1618. begin
  1619. { Support Type([Reference]) }
  1620. Consume(AS_LPAREN);
  1621. BuildOperand(oper,true);
  1622. Consume(AS_RPAREN);
  1623. end;
  1624. AS_LBRACKET :
  1625. begin
  1626. { Support Var.Type[Index] }
  1627. { Convert @label.Byte[1] to reference }
  1628. if oper.opr.typ=OPR_SYMBOL then
  1629. oper.initref;
  1630. end;
  1631. end;
  1632. end
  1633. else
  1634. begin
  1635. if not oper.SetupVar(expr,false) then
  1636. Begin
  1637. { not a variable, check special variables.. }
  1638. if expr = 'SELF' then
  1639. oper.SetupSelf
  1640. else
  1641. Message1(sym_e_unknown_id,expr);
  1642. expr:='';
  1643. end;
  1644. end;
  1645. end;
  1646. end;
  1647. end;
  1648. AS_REGISTER : { Register, a variable reference or a constant reference }
  1649. begin
  1650. { save the type of register used. }
  1651. tempreg:=actasmregister;
  1652. Consume(AS_REGISTER);
  1653. if actasmtoken = AS_COLON then
  1654. Begin
  1655. Consume(AS_COLON);
  1656. oper.InitRef;
  1657. oper.opr.ref.segment:=tempreg;
  1658. BuildReference(oper);
  1659. end
  1660. else
  1661. { Simple register }
  1662. begin
  1663. if not (oper.opr.typ in [OPR_NONE,OPR_REGISTER]) then
  1664. Message(asmr_e_invalid_operand_type);
  1665. oper.opr.typ:=OPR_REGISTER;
  1666. oper.opr.reg:=tempreg;
  1667. oper.SetSize(tcgsize2size[reg_cgsize(oper.opr.reg)],true);
  1668. end;
  1669. end;
  1670. AS_LBRACKET: { a variable reference, register ref. or a constant reference }
  1671. Begin
  1672. BuildReference(oper);
  1673. end;
  1674. AS_SEG :
  1675. Begin
  1676. Message(asmr_e_seg_not_supported);
  1677. Consume(actasmtoken);
  1678. end;
  1679. AS_DWORD,
  1680. AS_BYTE,
  1681. AS_WORD,
  1682. AS_TBYTE,
  1683. AS_DQWORD,
  1684. AS_QWORD :
  1685. begin
  1686. { Type specifier }
  1687. oper.hastype:=true;
  1688. oper.typesize:=0;
  1689. case actasmtoken of
  1690. AS_DWORD : oper.typesize:=4;
  1691. AS_WORD : oper.typesize:=2;
  1692. AS_BYTE : oper.typesize:=1;
  1693. AS_QWORD : oper.typesize:=8;
  1694. AS_DQWORD : oper.typesize:=16;
  1695. AS_TBYTE : oper.typesize:=10;
  1696. end;
  1697. Consume(actasmtoken);
  1698. if (actasmtoken=AS_LPAREN) then
  1699. begin
  1700. { Support Type([Reference]) }
  1701. Consume(AS_LPAREN);
  1702. BuildOperand(oper,true);
  1703. Consume(AS_RPAREN);
  1704. end;
  1705. end;
  1706. AS_SEPARATOR,
  1707. AS_END,
  1708. AS_COMMA,
  1709. AS_COLON:
  1710. begin
  1711. break;
  1712. end;
  1713. AS_RPAREN:
  1714. begin
  1715. if not istypecast then
  1716. begin
  1717. Message(asmr_e_syn_operand);
  1718. Consume(AS_RPAREN);
  1719. end
  1720. else
  1721. break;
  1722. end;
  1723. else
  1724. begin
  1725. Message(asmr_e_syn_operand);
  1726. RecoverConsume(true);
  1727. break;
  1728. end;
  1729. end;
  1730. until false;
  1731. { End of operand, update size if a typecast is forced }
  1732. if (oper.typesize<>0) and
  1733. (oper.opr.typ in [OPR_REFERENCE,OPR_LOCAL]) then
  1734. oper.SetSize(oper.typesize,true);
  1735. end;
  1736. Procedure tx86intreader.BuildOpCode(instr : tx86instruction);
  1737. var
  1738. PrefixOp,OverrideOp: tasmop;
  1739. operandnum : longint;
  1740. is_far_const:boolean;
  1741. i:byte;
  1742. begin
  1743. PrefixOp:=A_None;
  1744. OverrideOp:=A_None;
  1745. is_far_const:=false;
  1746. { prefix seg opcode / prefix opcode }
  1747. repeat
  1748. if is_prefix(actopcode) then
  1749. with instr do
  1750. begin
  1751. OpOrder:=op_intel;
  1752. PrefixOp:=ActOpcode;
  1753. opcode:=ActOpcode;
  1754. condition:=ActCondition;
  1755. opsize:=ActOpsize;
  1756. ConcatInstruction(curlist);
  1757. consume(AS_OPCODE);
  1758. end
  1759. else
  1760. if is_override(actopcode) then
  1761. with instr do
  1762. begin
  1763. OpOrder:=op_intel;
  1764. OverrideOp:=ActOpcode;
  1765. opcode:=ActOpcode;
  1766. condition:=ActCondition;
  1767. opsize:=ActOpsize;
  1768. ConcatInstruction(curlist);
  1769. consume(AS_OPCODE);
  1770. end
  1771. else
  1772. break;
  1773. { allow for newline after prefix or override }
  1774. while actasmtoken=AS_SEPARATOR do
  1775. consume(AS_SEPARATOR);
  1776. until (actasmtoken<>AS_OPCODE);
  1777. { opcode }
  1778. if (actasmtoken <> AS_OPCODE) then
  1779. begin
  1780. Message(asmr_e_invalid_or_missing_opcode);
  1781. RecoverConsume(false);
  1782. exit;
  1783. end;
  1784. { Fill the instr object with the current state }
  1785. with instr do
  1786. begin
  1787. OpOrder:=op_intel;
  1788. Opcode:=ActOpcode;
  1789. condition:=ActCondition;
  1790. opsize:=ActOpsize;
  1791. { Valid combination of prefix/override and instruction ? }
  1792. if (prefixop<>A_NONE) and (NOT CheckPrefix(PrefixOp,actopcode)) then
  1793. Message1(asmr_e_invalid_prefix_and_opcode,actasmpattern);
  1794. if (overrideop<>A_NONE) and (NOT CheckOverride(OverrideOp,ActOpcode)) then
  1795. Message1(asmr_e_invalid_override_and_opcode,actasmpattern);
  1796. end;
  1797. { We are reading operands, so opcode will be an AS_ID }
  1798. operandnum:=1;
  1799. is_far_const:=false;
  1800. Consume(AS_OPCODE);
  1801. { Zero operand opcode ? }
  1802. if actasmtoken in [AS_SEPARATOR,AS_END] then
  1803. begin
  1804. operandnum:=0;
  1805. exit;
  1806. end;
  1807. { Read Operands }
  1808. repeat
  1809. case actasmtoken of
  1810. { End of asm operands for this opcode }
  1811. AS_END,
  1812. AS_SEPARATOR :
  1813. break;
  1814. { Operand delimiter }
  1815. AS_COMMA :
  1816. begin
  1817. if operandnum > Max_Operands then
  1818. Message(asmr_e_too_many_operands)
  1819. else
  1820. Inc(operandnum);
  1821. Consume(AS_COMMA);
  1822. end;
  1823. {Far constant, i.e. jmp $0000:$11111111.}
  1824. AS_COLON:
  1825. begin
  1826. is_far_const:=true;
  1827. if operandnum>1 then
  1828. message(asmr_e_too_many_operands)
  1829. else
  1830. inc(operandnum);
  1831. consume(AS_COLON);
  1832. end;
  1833. { Type specifier }
  1834. AS_NEAR,
  1835. AS_FAR :
  1836. begin
  1837. if actasmtoken = AS_NEAR then
  1838. begin
  1839. Message(asmr_w_near_ignored);
  1840. instr.opsize:=S_NEAR;
  1841. end
  1842. else
  1843. begin
  1844. Message(asmr_w_far_ignored);
  1845. instr.opsize:=S_FAR;
  1846. end;
  1847. Consume(actasmtoken);
  1848. if actasmtoken=AS_PTR then
  1849. begin
  1850. Consume(AS_PTR);
  1851. instr.Operands[operandnum].InitRef;
  1852. end;
  1853. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1854. end;
  1855. else
  1856. BuildOperand(instr.Operands[operandnum] as tx86operand,false);
  1857. end; { end case }
  1858. until false;
  1859. instr.ops:=operandnum;
  1860. { Check operands }
  1861. for i:=1 to operandnum do
  1862. begin
  1863. if is_far_const and
  1864. (instr.operands[i].opr.typ<>OPR_CONSTANT) then
  1865. message(asmr_e_expr_illegal)
  1866. else
  1867. if instr.operands[i].opr.typ=OPR_NONE then
  1868. Message(asmr_e_syntax_error);
  1869. end;
  1870. end;
  1871. Procedure tx86intreader.BuildConstant(constsize: byte);
  1872. var
  1873. asmsymtyp : tasmsymtype;
  1874. asmsym,
  1875. expr: string;
  1876. value : aint;
  1877. Begin
  1878. Repeat
  1879. Case actasmtoken of
  1880. AS_STRING:
  1881. Begin
  1882. { DD and DW cases }
  1883. if constsize <> 1 then
  1884. Begin
  1885. if Not PadZero(actasmpattern,constsize) then
  1886. Message(scan_f_string_exceeds_line);
  1887. end;
  1888. expr:=actasmpattern;
  1889. Consume(AS_STRING);
  1890. Case actasmtoken of
  1891. AS_COMMA:
  1892. Consume(AS_COMMA);
  1893. AS_END,
  1894. AS_SEPARATOR: ;
  1895. else
  1896. Message(asmr_e_invalid_string_expression);
  1897. end;
  1898. ConcatString(curlist,expr);
  1899. end;
  1900. AS_PLUS,
  1901. AS_MINUS,
  1902. AS_LPAREN,
  1903. AS_NOT,
  1904. AS_INTNUM,
  1905. AS_ID :
  1906. Begin
  1907. BuildConstSymbolExpression(false,false,value,asmsym,asmsymtyp);
  1908. if asmsym<>'' then
  1909. begin
  1910. if constsize<>sizeof(aint) then
  1911. Message1(asmr_w_const32bit_for_address,asmsym);
  1912. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  1913. end
  1914. else
  1915. ConcatConstant(curlist,value,constsize);
  1916. end;
  1917. AS_COMMA:
  1918. begin
  1919. Consume(AS_COMMA);
  1920. end;
  1921. AS_ALIGN,
  1922. AS_DB,
  1923. AS_DW,
  1924. AS_DD,
  1925. AS_OPCODE,
  1926. AS_END,
  1927. AS_SEPARATOR:
  1928. break;
  1929. else
  1930. begin
  1931. Message(asmr_e_syn_constant);
  1932. RecoverConsume(false);
  1933. end
  1934. end;
  1935. Until false;
  1936. end;
  1937. function tx86intreader.Assemble: tlinkedlist;
  1938. Var
  1939. hl : tasmlabel;
  1940. instr : Tx86Instruction;
  1941. Begin
  1942. Message1(asmr_d_start_reading,'intel');
  1943. inexpression:=FALSE;
  1944. firsttoken:=TRUE;
  1945. { sets up all opcode and register tables in uppercase
  1946. done in the construtor now
  1947. if not _asmsorted then
  1948. Begin
  1949. SetupTables;
  1950. _asmsorted:=TRUE;
  1951. end;
  1952. }
  1953. curlist:=TAsmList.Create;
  1954. { setup label linked list }
  1955. LocalLabelList:=TLocalLabelList.Create;
  1956. { start tokenizer }
  1957. c:=current_scanner.asmgetcharstart;
  1958. gettoken;
  1959. { main loop }
  1960. repeat
  1961. case actasmtoken of
  1962. AS_LLABEL:
  1963. Begin
  1964. if CreateLocalLabel(actasmpattern,hl,true) then
  1965. ConcatLabel(curlist,hl);
  1966. Consume(AS_LLABEL);
  1967. end;
  1968. AS_LABEL:
  1969. Begin
  1970. if SearchLabel(upper(actasmpattern),hl,true) then
  1971. ConcatLabel(curlist,hl)
  1972. else
  1973. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  1974. Consume(AS_LABEL);
  1975. end;
  1976. AS_DW :
  1977. Begin
  1978. inexpression:=true;
  1979. Consume(AS_DW);
  1980. BuildConstant(2);
  1981. inexpression:=false;
  1982. end;
  1983. AS_DB :
  1984. Begin
  1985. inexpression:=true;
  1986. Consume(AS_DB);
  1987. BuildConstant(1);
  1988. inexpression:=false;
  1989. end;
  1990. AS_DD :
  1991. Begin
  1992. inexpression:=true;
  1993. Consume(AS_DD);
  1994. BuildConstant(4);
  1995. inexpression:=false;
  1996. end;
  1997. AS_ALIGN:
  1998. Begin
  1999. Consume(AS_ALIGN);
  2000. ConcatAlign(curlist,BuildConstExpression);
  2001. if actasmtoken<>AS_SEPARATOR then
  2002. Consume(AS_SEPARATOR);
  2003. end;
  2004. AS_OPCODE :
  2005. Begin
  2006. instr:=Tx86Instruction.Create(Tx86Operand);
  2007. BuildOpcode(instr);
  2008. with instr do
  2009. begin
  2010. { We need AT&T style operands }
  2011. Swapoperands;
  2012. { Must be done with args in ATT order }
  2013. CheckNonCommutativeOpcodes;
  2014. AddReferenceSizes;
  2015. SetInstructionOpsize;
  2016. CheckOperandSizes;
  2017. ConcatInstruction(curlist);
  2018. end;
  2019. instr.Free;
  2020. end;
  2021. AS_SEPARATOR :
  2022. Begin
  2023. Consume(AS_SEPARATOR);
  2024. end;
  2025. AS_END :
  2026. break; { end assembly block }
  2027. else
  2028. Begin
  2029. Message(asmr_e_syntax_error);
  2030. RecoverConsume(false);
  2031. end;
  2032. end; { end case }
  2033. until false;
  2034. { Check LocalLabelList }
  2035. LocalLabelList.CheckEmitted;
  2036. LocalLabelList.Free;
  2037. { Return the list in an asmnode }
  2038. assemble:=curlist;
  2039. Message1(asmr_d_finish_reading,'intel');
  2040. end;
  2041. end.