ra386int.pas 71 KB

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