raatt.pas 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549
  1. {
  2. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  3. Does the parsing for the GAS 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 raatt;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cutils,cclasses,
  23. { global }
  24. globtype,
  25. { aasm }
  26. cpubase,cpuinfo,aasmbase,aasmtai,aasmdata,aasmcpu,
  27. { assembler reader }
  28. rabase,
  29. rasm,
  30. rautils,
  31. { symtable }
  32. symconst,
  33. { cg }
  34. cgbase;
  35. type
  36. tasmtoken = (
  37. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_INTNUM,
  38. AS_REALNUM,AS_COMMA,AS_LPAREN,
  39. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
  40. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,AS_DOLLAR,
  41. AS_HASH,AS_LSBRACKET,AS_RSBRACKET,AS_LBRACKET,AS_RBRACKET,
  42. {------------------ Assembler directives --------------------}
  43. AS_DB,AS_DW,AS_DD,AS_DQ,AS_GLOBAL,
  44. AS_ALIGN,AS_BALIGN,AS_P2ALIGN,AS_ASCII,
  45. AS_ASCIIZ,AS_LCOMM,AS_COMM,AS_SINGLE,AS_DOUBLE,AS_EXTENDED,
  46. AS_DATA,AS_TEXT,AS_INIT,AS_END,
  47. {------------------ Assembler Operators --------------------}
  48. AS_TYPE,AS_SIZEOF,AS_VMTOFFSET,AS_MOD,AS_SHL,AS_SHR,AS_NOT,AS_AND,AS_OR,AS_XOR,AS_NOR,AS_AT,
  49. AS_LO,AS_HI);
  50. tasmkeyword = string[10];
  51. const
  52. { These tokens should be modified accordingly to the modifications }
  53. { in the different enumerations. }
  54. firstdirective = AS_DB;
  55. lastdirective = AS_END;
  56. token2str : array[tasmtoken] of tasmkeyword=(
  57. '','Label','LLabel','string','integer',
  58. 'float',',','(',
  59. ')',':','.','+','-','*',
  60. ';','identifier','register','opcode','/','$',
  61. '#','{','}','[',']',
  62. '.byte','.word','.long','.quad','.globl',
  63. '.align','.balign','.p2align','.ascii',
  64. '.asciz','.lcomm','.comm','.single','.double','.tfloat',
  65. '.data','.text','.init','END',
  66. 'TYPE','SIZEOF','VMTOFFSET','%','<<','>>','!','&','|','^','~','@','lo','hi');
  67. type
  68. tattreader = class(tasmreader)
  69. actasmtoken : tasmtoken;
  70. prevasmtoken : tasmtoken;
  71. procedure SetupTables;
  72. procedure BuildConstant(constsize: byte);
  73. procedure BuildConstantOperand(oper : toperand);
  74. procedure BuildRealConstant(typ : tfloattype);
  75. procedure BuildStringConstant(asciiz: boolean);
  76. procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
  77. procedure BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  78. function BuildConstExpression(allowref,betweenbracket:boolean): aint;
  79. function Assemble: tlinkedlist;override;
  80. procedure handleopcode;virtual;abstract;
  81. function is_asmopcode(const s: string) : boolean;virtual;abstract;
  82. Function is_asmdirective(const s: string):boolean;
  83. function is_register(const s:string):boolean;virtual;
  84. function is_locallabel(const s: string):boolean;
  85. procedure GetToken;
  86. function consume(t : tasmtoken):boolean;
  87. procedure RecoverConsume(allowcomma:boolean);
  88. procedure handlepercent;virtual;
  89. end;
  90. tcattreader = class of tattreader;
  91. var
  92. cattreader : tcattreader;
  93. implementation
  94. uses
  95. { globals }
  96. verbose,systems,
  97. { input }
  98. scanner,
  99. { symtable }
  100. symbase,symtype,symsym,symdef,symtable,
  101. {$ifdef x86}
  102. rax86,
  103. {$endif x86}
  104. itcpugas,
  105. procinfo;
  106. procedure tattreader.SetupTables;
  107. var
  108. i : tasmop;
  109. Begin
  110. iasmops:=TFPHashList.create;
  111. for i:=firstop to lastop do
  112. iasmops.Add(upper(gas_op2str[i]),Pointer(PtrInt(i)));
  113. end;
  114. function tattreader.is_asmdirective(const s: string):boolean;
  115. var
  116. i : tasmtoken;
  117. hs : string;
  118. Begin
  119. { GNU as is also not casesensitive with this }
  120. hs:=lower(s);
  121. for i:=firstdirective to lastdirective do
  122. if hs=token2str[i] then
  123. begin
  124. actasmtoken:=i;
  125. is_asmdirective:=true;
  126. exit;
  127. end;
  128. is_asmdirective:=false;
  129. end;
  130. function tattreader.is_register(const s:string):boolean;
  131. begin
  132. is_register:=false;
  133. actasmregister:=gas_regnum_search(lower(s));
  134. if actasmregister<>NR_NO then
  135. begin
  136. is_register:=true;
  137. actasmtoken:=AS_REGISTER;
  138. end;
  139. end;
  140. function tattreader.is_locallabel(const s: string):boolean;
  141. begin
  142. is_locallabel:=(length(s)>=2) and (s[1]='.') and (s[2]='L');
  143. end;
  144. procedure tattreader.handlepercent;
  145. begin
  146. c:=current_scanner.asmgetchar;
  147. actasmtoken:=AS_MOD;
  148. end;
  149. procedure tattreader.GetToken;
  150. var
  151. len : longint;
  152. srsym : tsym;
  153. srsymtable : TSymtable;
  154. begin
  155. { save old token and reset new token }
  156. prevasmtoken:=actasmtoken;
  157. actasmtoken:=AS_NONE;
  158. { reset }
  159. actasmpattern:='';
  160. { while space and tab , continue scan... }
  161. while c in [' ',#9] do
  162. c:=current_scanner.asmgetchar;
  163. { get token pos }
  164. if not (c in [#10,#13,'{',';']) then
  165. current_scanner.gettokenpos;
  166. { Local Label, Label, Directive, Prefix or Opcode }
  167. if firsttoken and not(c in [#10,#13,'{',';']) then
  168. begin
  169. firsttoken:=FALSE;
  170. len:=0;
  171. { directive or local label }
  172. if c = '.' then
  173. begin
  174. inc(len);
  175. actasmpattern[len]:=c;
  176. { Let us point to the next character }
  177. c:=current_scanner.asmgetchar;
  178. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  179. begin
  180. inc(len);
  181. actasmpattern[len]:=c;
  182. c:=current_scanner.asmgetchar;
  183. end;
  184. actasmpattern[0]:=chr(len);
  185. { this is a local label... }
  186. if (c=':') and is_locallabel(actasmpattern) then
  187. Begin
  188. { local variables are case sensitive }
  189. actasmtoken:=AS_LLABEL;
  190. c:=current_scanner.asmgetchar;
  191. firsttoken:=true;
  192. exit;
  193. end
  194. { must be a directive }
  195. else
  196. Begin
  197. { directives are case sensitive!! }
  198. if is_asmdirective(actasmpattern) then
  199. exit;
  200. Message1(asmr_e_not_directive_or_local_symbol,actasmpattern);
  201. end;
  202. end;
  203. { only opcodes and global labels are allowed now. }
  204. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  205. begin
  206. inc(len);
  207. actasmpattern[len]:=c;
  208. c:=current_scanner.asmgetchar;
  209. end;
  210. actasmpattern[0]:=chr(len);
  211. { Label ? }
  212. if c = ':' then
  213. begin
  214. actasmtoken:=AS_LABEL;
  215. { let us point to the next character }
  216. c:=current_scanner.asmgetchar;
  217. firsttoken:=true;
  218. exit;
  219. end;
  220. {$ifdef POWERPC}
  221. { some PowerPC instructions can have the postfix -, + or .
  222. this code could be moved to is_asmopcode but I think
  223. it's better to ifdef it here (FK)
  224. }
  225. case c of
  226. '.', '-', '+':
  227. begin
  228. actasmpattern:=actasmpattern+c;
  229. c:=current_scanner.asmgetchar;
  230. end
  231. end;
  232. {$endif POWERPC}
  233. {$ifdef POWERPC64}
  234. { some PowerPC instructions can have the postfix -, + or .
  235. this code could be moved to is_asmopcode but I think
  236. it's better to ifdef it here (FK)
  237. }
  238. case c of
  239. '.', '-', '+':
  240. begin
  241. actasmpattern:=actasmpattern+c;
  242. c:=current_scanner.asmgetchar;
  243. end
  244. end;
  245. {$endif POWERPC64}
  246. { Opcode ? }
  247. If is_asmopcode(upper(actasmpattern)) then
  248. Begin
  249. uppervar(actasmpattern);
  250. exit;
  251. end;
  252. { End of assemblerblock ? }
  253. if upper(actasmpattern) = 'END' then
  254. begin
  255. actasmtoken:=AS_END;
  256. exit;
  257. end;
  258. message1(asmr_e_unknown_opcode,actasmpattern);
  259. actasmtoken:=AS_NONE;
  260. end
  261. else { else firsttoken }
  262. { Here we must handle all possible cases }
  263. begin
  264. case c of
  265. '.' : { possiblities : - local label reference , such as in jmp @local1 }
  266. { - field of object/record }
  267. { - directive. }
  268. begin
  269. if (prevasmtoken in [AS_ID,AS_RPAREN]) then
  270. begin
  271. c:=current_scanner.asmgetchar;
  272. actasmtoken:=AS_DOT;
  273. exit;
  274. end;
  275. actasmpattern:=c;
  276. c:=current_scanner.asmgetchar;
  277. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  278. begin
  279. actasmpattern:=actasmpattern + c;
  280. c:=current_scanner.asmgetchar;
  281. end;
  282. if is_asmdirective(actasmpattern) then
  283. exit;
  284. { local label references and directives }
  285. { are case sensitive }
  286. actasmtoken:=AS_ID;
  287. exit;
  288. end;
  289. { identifier, register, prefix or directive }
  290. '_','A'..'Z','a'..'z':
  291. begin
  292. len:=0;
  293. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  294. begin
  295. inc(len);
  296. actasmpattern[len]:=c;
  297. c:=current_scanner.asmgetchar;
  298. end;
  299. actasmpattern[0]:=chr(len);
  300. uppervar(actasmpattern);
  301. {$ifdef x86}
  302. { only x86 architectures have instruction prefixes }
  303. { Opcode, can only be when the previous was a prefix }
  304. If is_prefix(actopcode) and is_asmopcode(actasmpattern) then
  305. Begin
  306. uppervar(actasmpattern);
  307. exit;
  308. end;
  309. {$endif x86}
  310. { check for end which is a reserved word unlike the opcodes }
  311. if actasmpattern = 'END' then
  312. Begin
  313. actasmtoken:=AS_END;
  314. exit;
  315. end;
  316. if actasmpattern = 'TYPE' then
  317. Begin
  318. actasmtoken:=AS_TYPE;
  319. exit;
  320. end;
  321. if actasmpattern = 'SIZEOF' then
  322. Begin
  323. actasmtoken:=AS_SIZEOF;
  324. exit;
  325. end;
  326. if actasmpattern = 'VMTOFFSET' then
  327. Begin
  328. actasmtoken:=AS_VMTOFFSET;
  329. exit;
  330. end;
  331. if is_register(actasmpattern) then
  332. begin
  333. actasmtoken:=AS_REGISTER;
  334. exit;
  335. end;
  336. { if next is a '.' and this is a unitsym then we also need to
  337. parse the identifier }
  338. if (c='.') then
  339. begin
  340. searchsym(actasmpattern,srsym,srsymtable);
  341. if assigned(srsym) and
  342. (srsym.typ=unitsym) and
  343. (srsym.owner.symtabletype in [staticsymtable,globalsymtable]) and
  344. srsym.owner.iscurrentunit then
  345. begin
  346. actasmpattern:=actasmpattern+c;
  347. c:=current_scanner.asmgetchar;
  348. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  349. begin
  350. actasmpattern:=actasmpattern + upcase(c);
  351. c:=current_scanner.asmgetchar;
  352. end;
  353. end;
  354. end;
  355. actasmtoken:=AS_ID;
  356. exit;
  357. end;
  358. '%' : { register or modulo }
  359. handlepercent;
  360. '1'..'9': { integer number }
  361. begin
  362. len:=0;
  363. while c in ['0'..'9'] do
  364. Begin
  365. inc(len);
  366. actasmpattern[len]:=c;
  367. c:=current_scanner.asmgetchar;
  368. end;
  369. actasmpattern[0]:=chr(len);
  370. actasmpattern:=tostr(ParseVal(actasmpattern,10));
  371. actasmtoken:=AS_INTNUM;
  372. exit;
  373. end;
  374. '0' : { octal,hexa,real or binary number. }
  375. begin
  376. actasmpattern:=c;
  377. c:=current_scanner.asmgetchar;
  378. case upcase(c) of
  379. 'B': { binary }
  380. Begin
  381. c:=current_scanner.asmgetchar;
  382. while c in ['0','1'] do
  383. Begin
  384. actasmpattern:=actasmpattern + c;
  385. c:=current_scanner.asmgetchar;
  386. end;
  387. actasmpattern:=tostr(ParseVal(actasmpattern,2));
  388. actasmtoken:=AS_INTNUM;
  389. exit;
  390. end;
  391. 'D': { real }
  392. Begin
  393. c:=current_scanner.asmgetchar;
  394. { get ridd of the 0d }
  395. if (c in ['+','-']) then
  396. begin
  397. actasmpattern:=c;
  398. c:=current_scanner.asmgetchar;
  399. end
  400. else
  401. actasmpattern:='';
  402. while c in ['0'..'9'] do
  403. Begin
  404. actasmpattern:=actasmpattern + c;
  405. c:=current_scanner.asmgetchar;
  406. end;
  407. if c='.' then
  408. begin
  409. actasmpattern:=actasmpattern + c;
  410. c:=current_scanner.asmgetchar;
  411. while c in ['0'..'9'] do
  412. Begin
  413. actasmpattern:=actasmpattern + c;
  414. c:=current_scanner.asmgetchar;
  415. end;
  416. if upcase(c) = 'E' then
  417. begin
  418. actasmpattern:=actasmpattern + c;
  419. c:=current_scanner.asmgetchar;
  420. if (c in ['+','-']) then
  421. begin
  422. actasmpattern:=actasmpattern + c;
  423. c:=current_scanner.asmgetchar;
  424. end;
  425. while c in ['0'..'9'] do
  426. Begin
  427. actasmpattern:=actasmpattern + c;
  428. c:=current_scanner.asmgetchar;
  429. end;
  430. end;
  431. actasmtoken:=AS_REALNUM;
  432. exit;
  433. end
  434. else
  435. begin
  436. Message1(asmr_e_invalid_float_const,actasmpattern+c);
  437. actasmtoken:=AS_NONE;
  438. end;
  439. end;
  440. 'X': { hexadecimal }
  441. Begin
  442. c:=current_scanner.asmgetchar;
  443. while c in ['0'..'9','a'..'f','A'..'F'] do
  444. Begin
  445. actasmpattern:=actasmpattern + c;
  446. c:=current_scanner.asmgetchar;
  447. end;
  448. actasmpattern:=tostr(ParseVal(actasmpattern,16));
  449. actasmtoken:=AS_INTNUM;
  450. exit;
  451. end;
  452. '1'..'7': { octal }
  453. begin
  454. actasmpattern:=actasmpattern + c;
  455. while c in ['0'..'7'] do
  456. Begin
  457. actasmpattern:=actasmpattern + c;
  458. c:=current_scanner.asmgetchar;
  459. end;
  460. actasmpattern:=tostr(ParseVal(actasmpattern,8));
  461. actasmtoken:=AS_INTNUM;
  462. exit;
  463. end;
  464. else { octal number zero value...}
  465. Begin
  466. actasmpattern:=tostr(ParseVal(actasmpattern,8));
  467. actasmtoken:=AS_INTNUM;
  468. exit;
  469. end;
  470. end; { end case }
  471. end;
  472. '&' :
  473. begin
  474. c:=current_scanner.asmgetchar;
  475. actasmtoken:=AS_AND;
  476. end;
  477. '''' : { char }
  478. begin
  479. current_scanner.in_asm_string:=true;
  480. actasmpattern:='';
  481. repeat
  482. c:=current_scanner.asmgetchar;
  483. case c of
  484. '\' :
  485. begin
  486. { copy also the next char so \" is parsed correctly }
  487. actasmpattern:=actasmpattern+c;
  488. c:=current_scanner.asmgetchar;
  489. actasmpattern:=actasmpattern+c;
  490. end;
  491. '''' :
  492. begin
  493. c:=current_scanner.asmgetchar;
  494. break;
  495. end;
  496. #10,#13:
  497. Message(scan_f_string_exceeds_line);
  498. else
  499. actasmpattern:=actasmpattern+c;
  500. end;
  501. until false;
  502. actasmpattern:=EscapeToPascal(actasmpattern);
  503. actasmtoken:=AS_STRING;
  504. current_scanner.in_asm_string:=false;
  505. exit;
  506. end;
  507. '"' : { string }
  508. begin
  509. current_scanner.in_asm_string:=true;
  510. actasmpattern:='';
  511. repeat
  512. c:=current_scanner.asmgetchar;
  513. case c of
  514. '\' :
  515. begin
  516. { copy also the next char so \" is parsed correctly }
  517. actasmpattern:=actasmpattern+c;
  518. c:=current_scanner.asmgetchar;
  519. actasmpattern:=actasmpattern+c;
  520. end;
  521. '"' :
  522. begin
  523. c:=current_scanner.asmgetchar;
  524. break;
  525. end;
  526. #10,#13:
  527. Message(scan_f_string_exceeds_line);
  528. else
  529. actasmpattern:=actasmpattern+c;
  530. end;
  531. until false;
  532. actasmpattern:=EscapeToPascal(actasmpattern);
  533. actasmtoken:=AS_STRING;
  534. current_scanner.in_asm_string:=false;
  535. exit;
  536. end;
  537. '$' :
  538. begin
  539. actasmtoken:=AS_DOLLAR;
  540. c:=current_scanner.asmgetchar;
  541. exit;
  542. end;
  543. '#' :
  544. begin
  545. actasmtoken:=AS_HASH;
  546. c:=current_scanner.asmgetchar;
  547. exit;
  548. end;
  549. '[' :
  550. begin
  551. actasmtoken:=AS_LBRACKET;
  552. c:=current_scanner.asmgetchar;
  553. exit;
  554. end;
  555. ']' :
  556. begin
  557. actasmtoken:=AS_RBRACKET;
  558. c:=current_scanner.asmgetchar;
  559. exit;
  560. end;
  561. {$ifdef arm}
  562. // the arm assembler uses { ... } for register sets
  563. '{' :
  564. begin
  565. actasmtoken:=AS_LSBRACKET;
  566. c:=current_scanner.asmgetchar;
  567. exit;
  568. end;
  569. '}' :
  570. begin
  571. actasmtoken:=AS_RSBRACKET;
  572. c:=current_scanner.asmgetchar;
  573. exit;
  574. end;
  575. {$endif arm}
  576. ',' :
  577. begin
  578. actasmtoken:=AS_COMMA;
  579. c:=current_scanner.asmgetchar;
  580. exit;
  581. end;
  582. '<' :
  583. begin
  584. actasmtoken:=AS_SHL;
  585. c:=current_scanner.asmgetchar;
  586. if c = '<' then
  587. c:=current_scanner.asmgetchar;
  588. exit;
  589. end;
  590. '>' :
  591. begin
  592. actasmtoken:=AS_SHL;
  593. c:=current_scanner.asmgetchar;
  594. if c = '>' then
  595. c:=current_scanner.asmgetchar;
  596. exit;
  597. end;
  598. '|' :
  599. begin
  600. actasmtoken:=AS_OR;
  601. c:=current_scanner.asmgetchar;
  602. exit;
  603. end;
  604. '^' :
  605. begin
  606. actasmtoken:=AS_XOR;
  607. c:=current_scanner.asmgetchar;
  608. exit;
  609. end;
  610. '(' :
  611. begin
  612. actasmtoken:=AS_LPAREN;
  613. c:=current_scanner.asmgetchar;
  614. exit;
  615. end;
  616. ')' :
  617. begin
  618. actasmtoken:=AS_RPAREN;
  619. c:=current_scanner.asmgetchar;
  620. exit;
  621. end;
  622. ':' :
  623. begin
  624. actasmtoken:=AS_COLON;
  625. c:=current_scanner.asmgetchar;
  626. exit;
  627. end;
  628. '+' :
  629. begin
  630. actasmtoken:=AS_PLUS;
  631. c:=current_scanner.asmgetchar;
  632. exit;
  633. end;
  634. '-' :
  635. begin
  636. actasmtoken:=AS_MINUS;
  637. c:=current_scanner.asmgetchar;
  638. exit;
  639. end;
  640. '*' :
  641. begin
  642. actasmtoken:=AS_STAR;
  643. c:=current_scanner.asmgetchar;
  644. exit;
  645. end;
  646. '/' :
  647. begin
  648. actasmtoken:=AS_SLASH;
  649. c:=current_scanner.asmgetchar;
  650. exit;
  651. end;
  652. '!' :
  653. begin
  654. actasmtoken:=AS_NOT;
  655. c:=current_scanner.asmgetchar;
  656. exit;
  657. end;
  658. '@' :
  659. begin
  660. actasmtoken:=AS_AT;
  661. c:=current_scanner.asmgetchar;
  662. exit;
  663. end;
  664. {$ifndef arm}
  665. '{',
  666. {$endif arm}
  667. #13,#10,';' :
  668. begin
  669. { the comment is read by asmgetchar }
  670. c:=current_scanner.asmgetchar;
  671. firsttoken:=TRUE;
  672. actasmtoken:=AS_SEPARATOR;
  673. exit;
  674. end;
  675. else
  676. current_scanner.illegal_char(c);
  677. end;
  678. end;
  679. end;
  680. function tattreader.consume(t : tasmtoken):boolean;
  681. begin
  682. Consume:=true;
  683. if t<>actasmtoken then
  684. begin
  685. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  686. Consume:=false;
  687. end;
  688. repeat
  689. gettoken;
  690. until actasmtoken<>AS_NONE;
  691. end;
  692. procedure tattreader.RecoverConsume(allowcomma:boolean);
  693. begin
  694. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  695. begin
  696. if allowcomma and (actasmtoken=AS_COMMA) then
  697. break;
  698. Consume(actasmtoken);
  699. end;
  700. end;
  701. Procedure tattreader.BuildConstant(constsize: byte);
  702. var
  703. asmsymtyp : TAsmSymType;
  704. asmsym,
  705. expr: string;
  706. value : aint;
  707. Begin
  708. Repeat
  709. Case actasmtoken of
  710. AS_STRING:
  711. Begin
  712. expr:=actasmpattern;
  713. if length(expr) > 1 then
  714. Message(asmr_e_string_not_allowed_as_const);
  715. Consume(AS_STRING);
  716. Case actasmtoken of
  717. AS_COMMA: Consume(AS_COMMA);
  718. AS_END,
  719. AS_SEPARATOR: ;
  720. else
  721. Message(asmr_e_invalid_string_expression);
  722. end; { end case }
  723. ConcatString(curlist,expr);
  724. end;
  725. AS_INTNUM,
  726. AS_PLUS,
  727. AS_MINUS,
  728. AS_LPAREN,
  729. AS_TYPE,
  730. AS_SIZEOF,
  731. AS_NOT,
  732. AS_VMTOFFSET,
  733. AS_ID :
  734. Begin
  735. BuildConstSymbolExpression(false,false,false,value,asmsym,asmsymtyp);
  736. if asmsym<>'' then
  737. begin
  738. if constsize<>sizeof(aint) then
  739. Message(asmr_w_32bit_const_for_address);
  740. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  741. end
  742. else
  743. ConcatConstant(curlist,value,constsize);
  744. end;
  745. AS_COMMA:
  746. Consume(AS_COMMA);
  747. AS_END,
  748. AS_SEPARATOR:
  749. break;
  750. else
  751. begin
  752. Message(asmr_e_syn_constant);
  753. RecoverConsume(false);
  754. end
  755. end; { end case }
  756. Until false;
  757. end;
  758. Procedure tattreader.BuildRealConstant(typ : tfloattype);
  759. var
  760. expr : string;
  761. r : bestreal;
  762. code : integer;
  763. negativ : boolean;
  764. errorflag: boolean;
  765. Begin
  766. errorflag:=FALSE;
  767. Repeat
  768. negativ:=false;
  769. expr:='';
  770. if actasmtoken=AS_PLUS then
  771. Consume(AS_PLUS)
  772. else
  773. if actasmtoken=AS_MINUS then
  774. begin
  775. negativ:=true;
  776. consume(AS_MINUS);
  777. end;
  778. Case actasmtoken of
  779. AS_INTNUM:
  780. Begin
  781. expr:=actasmpattern;
  782. Consume(AS_INTNUM);
  783. if negativ then
  784. expr:='-'+expr;
  785. val(expr,r,code);
  786. if code<>0 then
  787. Begin
  788. r:=0;
  789. Message(asmr_e_invalid_float_expr);
  790. End;
  791. ConcatRealConstant(curlist,r,typ);
  792. end;
  793. AS_REALNUM:
  794. Begin
  795. expr:=actasmpattern;
  796. Consume(AS_REALNUM);
  797. { in ATT syntax you have 0d in front of the real }
  798. { should this be forced ? yes i think so, as to }
  799. { conform to gas as much as possible. }
  800. if (expr[1]='0') and (upper(expr[2])='D') then
  801. Delete(expr,1,2);
  802. if negativ then
  803. expr:='-'+expr;
  804. val(expr,r,code);
  805. if code<>0 then
  806. Begin
  807. r:=0;
  808. Message(asmr_e_invalid_float_expr);
  809. End;
  810. ConcatRealConstant(curlist,r,typ);
  811. end;
  812. AS_COMMA:
  813. begin
  814. Consume(AS_COMMA);
  815. end;
  816. AS_END,
  817. AS_SEPARATOR:
  818. begin
  819. break;
  820. end;
  821. else
  822. Begin
  823. Consume(actasmtoken);
  824. if not errorflag then
  825. Message(asmr_e_invalid_float_expr);
  826. errorflag:=TRUE;
  827. end;
  828. end;
  829. Until false;
  830. end;
  831. Procedure tattreader.BuildStringConstant(asciiz: boolean);
  832. var
  833. expr: string;
  834. errorflag : boolean;
  835. Begin
  836. errorflag:=FALSE;
  837. Repeat
  838. Case actasmtoken of
  839. AS_STRING:
  840. Begin
  841. expr:=actasmpattern;
  842. if asciiz then
  843. expr:=expr+#0;
  844. ConcatPasString(curlist,expr);
  845. Consume(AS_STRING);
  846. end;
  847. AS_COMMA:
  848. begin
  849. Consume(AS_COMMA);
  850. end;
  851. AS_END,
  852. AS_SEPARATOR:
  853. begin
  854. break;
  855. end;
  856. else
  857. Begin
  858. Consume(actasmtoken);
  859. if not errorflag then
  860. Message(asmr_e_invalid_string_expression);
  861. errorflag:=TRUE;
  862. end;
  863. end;
  864. Until false;
  865. end;
  866. Function tattreader.Assemble: tlinkedlist;
  867. Var
  868. hl : tasmlabel;
  869. commname : string;
  870. lasTSec : TAsmSectiontype;
  871. l1,l2 : longint;
  872. Begin
  873. Message1(asmr_d_start_reading,'GNU AS');
  874. firsttoken:=TRUE;
  875. { sets up all opcode and register tables in uppercase }
  876. if not _asmsorted then
  877. Begin
  878. SetupTables;
  879. _asmsorted:=TRUE;
  880. end;
  881. curlist:=TAsmList.Create;
  882. lasTSec:=sec_code;
  883. { setup label linked list }
  884. LocalLabelList:=TLocalLabelList.Create;
  885. { start tokenizer }
  886. c:=current_scanner.asmgetcharstart;
  887. gettoken;
  888. { main loop }
  889. repeat
  890. case actasmtoken of
  891. AS_LLABEL:
  892. Begin
  893. if CreateLocalLabel(actasmpattern,hl,true) then
  894. ConcatLabel(curlist,hl);
  895. Consume(AS_LLABEL);
  896. end;
  897. AS_LABEL:
  898. Begin
  899. if SearchLabel(upper(actasmpattern),hl,true) then
  900. ConcatLabel(curlist,hl)
  901. else
  902. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  903. Consume(AS_LABEL);
  904. end;
  905. AS_DW:
  906. Begin
  907. Consume(AS_DW);
  908. BuildConstant(2);
  909. end;
  910. AS_DATA:
  911. Begin
  912. new_section(curList,sec_data,lower(current_procinfo.procdef.mangledname),0);
  913. lasTSec:=sec_data;
  914. Consume(AS_DATA);
  915. end;
  916. AS_TEXT:
  917. Begin
  918. new_section(curList,sec_code,lower(current_procinfo.procdef.mangledname),0);
  919. lasTSec:=sec_code;
  920. Consume(AS_TEXT);
  921. end;
  922. AS_INIT:
  923. Begin
  924. new_section(curList,sec_init,lower(current_procinfo.procdef.mangledname),0);
  925. lasTSec:=sec_init;
  926. Consume(AS_INIT);
  927. end;
  928. AS_DB:
  929. Begin
  930. Consume(AS_DB);
  931. BuildConstant(1);
  932. end;
  933. AS_DD:
  934. Begin
  935. Consume(AS_DD);
  936. BuildConstant(4);
  937. end;
  938. AS_DQ:
  939. Begin
  940. Consume(AS_DQ);
  941. {$ifdef cpu64bit}
  942. BuildConstant(8);
  943. {$else cpu64bit}
  944. BuildRealConstant(s64comp);
  945. {$endif cpu64bit}
  946. end;
  947. AS_SINGLE:
  948. Begin
  949. Consume(AS_SINGLE);
  950. BuildRealConstant(s32real);
  951. end;
  952. AS_DOUBLE:
  953. Begin
  954. Consume(AS_DOUBLE);
  955. BuildRealConstant(s64real);
  956. end;
  957. AS_EXTENDED:
  958. Begin
  959. Consume(AS_EXTENDED);
  960. BuildRealConstant(s80real);
  961. end;
  962. AS_GLOBAL:
  963. Begin
  964. Consume(AS_GLOBAL);
  965. if actasmtoken=AS_ID then
  966. ConcatPublic(curlist,actasmpattern);
  967. Consume(AS_ID);
  968. if actasmtoken<>AS_SEPARATOR then
  969. Consume(AS_SEPARATOR);
  970. end;
  971. AS_ALIGN:
  972. Begin
  973. Consume(AS_ALIGN);
  974. l1:=BuildConstExpression(false,false);
  975. if (target_info.system in [system_i386_GO32V2]) then
  976. begin
  977. l2:=1;
  978. if (l1>=0) and (l1<=16) then
  979. while (l1>0) do
  980. begin
  981. l2:=2*l2;
  982. dec(l1);
  983. end;
  984. l1:=l2;
  985. end;
  986. ConcatAlign(curlist,l1);
  987. Message(asmr_n_align_is_target_specific);
  988. if actasmtoken<>AS_SEPARATOR then
  989. Consume(AS_SEPARATOR);
  990. end;
  991. AS_BALIGN:
  992. Begin
  993. Consume(AS_BALIGN);
  994. ConcatAlign(curlist,BuildConstExpression(false,false));
  995. if actasmtoken<>AS_SEPARATOR then
  996. Consume(AS_SEPARATOR);
  997. end;
  998. AS_P2ALIGN:
  999. Begin
  1000. Consume(AS_P2ALIGN);
  1001. l1:=BuildConstExpression(false,false);
  1002. l2:=1;
  1003. if (l1>=0) and (l1<=16) then
  1004. while (l1>0) do
  1005. begin
  1006. l2:=2*l2;
  1007. dec(l1);
  1008. end;
  1009. l1:=l2;
  1010. ConcatAlign(curlist,l1);
  1011. if actasmtoken<>AS_SEPARATOR then
  1012. Consume(AS_SEPARATOR);
  1013. end;
  1014. AS_ASCIIZ:
  1015. Begin
  1016. Consume(AS_ASCIIZ);
  1017. BuildStringConstant(TRUE);
  1018. end;
  1019. AS_ASCII:
  1020. Begin
  1021. Consume(AS_ASCII);
  1022. BuildStringConstant(FALSE);
  1023. end;
  1024. AS_LCOMM:
  1025. Begin
  1026. Consume(AS_LCOMM);
  1027. commname:=actasmpattern;
  1028. Consume(AS_ID);
  1029. Consume(AS_COMMA);
  1030. curList.concat(Tai_datablock.Create(commname,BuildConstExpression(false,false)));
  1031. if actasmtoken<>AS_SEPARATOR then
  1032. Consume(AS_SEPARATOR);
  1033. end;
  1034. AS_COMM:
  1035. Begin
  1036. Consume(AS_COMM);
  1037. commname:=actasmpattern;
  1038. Consume(AS_ID);
  1039. Consume(AS_COMMA);
  1040. curList.concat(Tai_datablock.Create_global(commname,BuildConstExpression(false,false)));
  1041. if actasmtoken<>AS_SEPARATOR then
  1042. Consume(AS_SEPARATOR);
  1043. end;
  1044. AS_OPCODE:
  1045. Begin
  1046. HandleOpCode;
  1047. end;
  1048. AS_SEPARATOR:
  1049. Begin
  1050. Consume(AS_SEPARATOR);
  1051. end;
  1052. AS_END:
  1053. begin
  1054. break; { end assembly block }
  1055. end;
  1056. else
  1057. Begin
  1058. Message(asmr_e_syntax_error);
  1059. RecoverConsume(false);
  1060. end;
  1061. end;
  1062. until false;
  1063. { Check LocalLabelList }
  1064. LocalLabelList.CheckEmitted;
  1065. LocalLabelList.Free;
  1066. { are we back in the code section? }
  1067. if lasTSec<>sec_code then
  1068. begin
  1069. Message(asmr_w_assembler_code_not_returned_to_text);
  1070. new_section(curList,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1071. end;
  1072. { Return the list in an asmnode }
  1073. assemble:=curlist;
  1074. Message1(asmr_d_finish_reading,'GNU AS');
  1075. end;
  1076. {*****************************************************************************
  1077. Parsing Helpers
  1078. *****************************************************************************}
  1079. Procedure tattreader.BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint; var mangledname: string; needvmtofs: boolean);
  1080. { Description: This routine builds up a record offset after a AS_DOT }
  1081. { token is encountered. }
  1082. { On entry actasmtoken should be equal to AS_DOT }
  1083. var
  1084. s : string;
  1085. Begin
  1086. offset:=0;
  1087. size:=0;
  1088. s:=expr;
  1089. while (actasmtoken=AS_DOT) do
  1090. begin
  1091. Consume(AS_DOT);
  1092. if actasmtoken=AS_ID then
  1093. s:=s+'.'+actasmpattern;
  1094. if not Consume(AS_ID) then
  1095. begin
  1096. RecoverConsume(true);
  1097. break;
  1098. end;
  1099. end;
  1100. if not GetRecordOffsetSize(s,offset,size,mangledname,needvmtofs) then
  1101. Message(asmr_e_building_record_offset);
  1102. end;
  1103. procedure tattreader.BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  1104. var
  1105. hssymtyp : TAsmSymType;
  1106. hs,tempstr,expr,mangledname : string;
  1107. parenlevel : longint;
  1108. l,k : aint;
  1109. errorflag : boolean;
  1110. prevtok : tasmtoken;
  1111. sym : tsym;
  1112. srsymtable : TSymtable;
  1113. hl : tasmlabel;
  1114. Begin
  1115. asmsym:='';
  1116. asmsymtyp:=AT_DATA;
  1117. value:=0;
  1118. errorflag:=FALSE;
  1119. tempstr:='';
  1120. expr:='';
  1121. parenlevel:=0;
  1122. Repeat
  1123. Case actasmtoken of
  1124. AS_LPAREN:
  1125. Begin
  1126. { Exit if ref? }
  1127. if allowref and (prevasmtoken in [AS_INTNUM,AS_ID]) then
  1128. break;
  1129. Consume(AS_LPAREN);
  1130. expr:=expr + '(';
  1131. inc(parenlevel);
  1132. end;
  1133. AS_RBRACKET:
  1134. begin
  1135. if betweenbracket then
  1136. break;
  1137. { write error only once. }
  1138. if not errorflag then
  1139. Message(asmr_e_invalid_constant_expression);
  1140. { consume tokens until we find COMMA or SEPARATOR }
  1141. Consume(actasmtoken);
  1142. errorflag:=TRUE;
  1143. end;
  1144. AS_RPAREN:
  1145. Begin
  1146. { end of ref ? }
  1147. if (parenlevel=0) and betweenbracket then
  1148. break;
  1149. Consume(AS_RPAREN);
  1150. expr:=expr + ')';
  1151. dec(parenlevel);
  1152. end;
  1153. AS_SHL:
  1154. Begin
  1155. Consume(AS_SHL);
  1156. expr:=expr + '<';
  1157. end;
  1158. AS_SHR:
  1159. Begin
  1160. Consume(AS_SHR);
  1161. expr:=expr + '>';
  1162. end;
  1163. AS_SLASH:
  1164. Begin
  1165. Consume(AS_SLASH);
  1166. expr:=expr + '/';
  1167. end;
  1168. AS_MOD:
  1169. Begin
  1170. Consume(AS_MOD);
  1171. expr:=expr + '%';
  1172. end;
  1173. AS_STAR:
  1174. Begin
  1175. Consume(AS_STAR);
  1176. expr:=expr + '*';
  1177. end;
  1178. AS_PLUS:
  1179. Begin
  1180. Consume(AS_PLUS);
  1181. expr:=expr + '+';
  1182. end;
  1183. AS_MINUS:
  1184. Begin
  1185. Consume(AS_MINUS);
  1186. expr:=expr + '-';
  1187. end;
  1188. AS_AND:
  1189. Begin
  1190. Consume(AS_AND);
  1191. expr:=expr + '&';
  1192. end;
  1193. AS_NOT:
  1194. Begin
  1195. Consume(AS_NOT);
  1196. expr:=expr + '~';
  1197. end;
  1198. AS_XOR:
  1199. Begin
  1200. Consume(AS_XOR);
  1201. expr:=expr + '^';
  1202. end;
  1203. AS_OR:
  1204. Begin
  1205. Consume(AS_OR);
  1206. expr:=expr + '|';
  1207. end;
  1208. AS_INTNUM:
  1209. Begin
  1210. expr:=expr + actasmpattern;
  1211. Consume(AS_INTNUM);
  1212. end;
  1213. AS_DOLLAR:
  1214. begin
  1215. Consume(AS_DOLLAR);
  1216. if actasmtoken<>AS_ID then
  1217. Message(asmr_e_dollar_without_identifier);
  1218. end;
  1219. AS_STRING:
  1220. Begin
  1221. l:=0;
  1222. case Length(actasmpattern) of
  1223. 1 :
  1224. l:=ord(actasmpattern[1]);
  1225. 2 :
  1226. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  1227. 3 :
  1228. l:=ord(actasmpattern[3]) +
  1229. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  1230. 4 :
  1231. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  1232. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  1233. else
  1234. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  1235. end;
  1236. str(l, tempstr);
  1237. expr:=expr + tempstr;
  1238. Consume(AS_STRING);
  1239. end;
  1240. AS_SIZEOF,
  1241. AS_TYPE:
  1242. begin
  1243. l:=0;
  1244. Consume(actasmtoken);
  1245. if actasmtoken<>AS_ID then
  1246. Message(asmr_e_type_without_identifier)
  1247. else
  1248. begin
  1249. tempstr:=actasmpattern;
  1250. Consume(AS_ID);
  1251. if actasmtoken=AS_DOT then
  1252. begin
  1253. BuildRecordOffsetSize(tempstr,k,l,mangledname,false);
  1254. if mangledname<>'' then
  1255. Message(asmr_e_wrong_sym_type);
  1256. end
  1257. else
  1258. begin
  1259. searchsym(tempstr,sym,srsymtable);
  1260. if assigned(sym) then
  1261. begin
  1262. case sym.typ of
  1263. staticvarsym,
  1264. localvarsym,
  1265. paravarsym :
  1266. l:=tabstractvarsym(sym).getsize;
  1267. typesym :
  1268. l:=ttypesym(sym).typedef.size;
  1269. else
  1270. Message(asmr_e_wrong_sym_type);
  1271. end;
  1272. end
  1273. else
  1274. Message1(sym_e_unknown_id,tempstr);
  1275. end;
  1276. end;
  1277. str(l, tempstr);
  1278. expr:=expr + tempstr;
  1279. end;
  1280. AS_VMTOFFSET:
  1281. begin
  1282. Consume(actasmtoken);
  1283. if actasmtoken<>AS_ID then
  1284. Message(asmr_e_type_without_identifier)
  1285. else
  1286. begin
  1287. tempstr:=actasmpattern;
  1288. consume(AS_ID);
  1289. BuildRecordOffsetSize(tempstr,k,l,mangledname,true);
  1290. if (mangledname <> '') then
  1291. Message(asmr_e_wrong_sym_type);
  1292. str(k,tempstr);
  1293. expr := expr + tempstr;
  1294. end
  1295. end;
  1296. AS_ID:
  1297. Begin
  1298. hs:='';
  1299. hssymtyp:=AT_DATA;
  1300. tempstr:=actasmpattern;
  1301. prevtok:=prevasmtoken;
  1302. consume(AS_ID);
  1303. if SearchIConstant(tempstr,l) then
  1304. begin
  1305. str(l, tempstr);
  1306. expr:=expr + tempstr;
  1307. end
  1308. else
  1309. begin
  1310. if is_locallabel(tempstr) then
  1311. begin
  1312. CreateLocalLabel(tempstr,hl,false);
  1313. hs:=hl.name;
  1314. hssymtyp:=AT_LABEL;
  1315. end
  1316. else
  1317. if SearchLabel(tempstr,hl,false) then
  1318. begin
  1319. hs:=hl.name;
  1320. hssymtyp:=AT_FUNCTION;
  1321. end
  1322. else
  1323. begin
  1324. searchsym(tempstr,sym,srsymtable);
  1325. if assigned(sym) then
  1326. begin
  1327. case sym.typ of
  1328. staticvarsym :
  1329. hs:=tstaticvarsym(sym).mangledname;
  1330. localvarsym,
  1331. paravarsym :
  1332. Message(asmr_e_no_local_or_para_allowed);
  1333. procsym :
  1334. begin
  1335. if Tprocsym(sym).ProcdefList.Count>1 then
  1336. Message(asmr_w_calling_overload_func);
  1337. hs:=tprocdef(tprocsym(sym).ProcdefList[0]).mangledname;
  1338. hssymtyp:=AT_FUNCTION;
  1339. end;
  1340. typesym :
  1341. begin
  1342. if not(ttypesym(sym).typedef.typ in [recorddef,objectdef]) then
  1343. Message(asmr_e_wrong_sym_type);
  1344. end;
  1345. else
  1346. Message(asmr_e_wrong_sym_type);
  1347. end;
  1348. end
  1349. else
  1350. Message1(sym_e_unknown_id,tempstr);
  1351. end;
  1352. { symbol found? }
  1353. if hs<>'' then
  1354. begin
  1355. if needofs and (prevtok<>AS_DOLLAR) then
  1356. Message(asmr_e_need_dollar);
  1357. if asmsym='' then
  1358. begin
  1359. asmsym:=hs;
  1360. asmsymtyp:=hssymtyp;
  1361. end
  1362. else
  1363. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1364. if (expr='') or (expr[length(expr)]='+') then
  1365. begin
  1366. { don't remove the + if there could be a record field }
  1367. if actasmtoken<>AS_DOT then
  1368. delete(expr,length(expr),1);
  1369. end
  1370. else
  1371. Message(asmr_e_only_add_relocatable_symbol);
  1372. end;
  1373. if actasmtoken=AS_DOT then
  1374. begin
  1375. BuildRecordOffsetSize(tempstr,l,k,hs,false);
  1376. if (hs<>'') then
  1377. hssymtyp:=AT_FUNCTION
  1378. else
  1379. begin
  1380. str(l, tempstr);
  1381. expr:=expr + tempstr;
  1382. end
  1383. end
  1384. else
  1385. begin
  1386. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1387. delete(expr,length(expr),1);
  1388. end;
  1389. end;
  1390. { check if there are wrong operator used like / or mod etc. }
  1391. if (hs<>'') and
  1392. not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,
  1393. AS_LPAREN,AS_RPAREN,AS_RBRACKET,AS_END]) then
  1394. Message(asmr_e_only_add_relocatable_symbol);
  1395. end;
  1396. AS_END,
  1397. AS_SEPARATOR,
  1398. AS_COMMA:
  1399. break;
  1400. else
  1401. Begin
  1402. { write error only once. }
  1403. if not errorflag then
  1404. Message(asmr_e_invalid_constant_expression);
  1405. { consume tokens until we find COMMA or SEPARATOR }
  1406. Consume(actasmtoken);
  1407. errorflag:=TRUE;
  1408. end;
  1409. end;
  1410. Until false;
  1411. { calculate expression }
  1412. if not ErrorFlag then
  1413. value:=CalculateExpression(expr)
  1414. else
  1415. value:=0;
  1416. end;
  1417. function tattreader.BuildConstExpression(allowref,betweenbracket:boolean): aint;
  1418. var
  1419. l : aint;
  1420. hs : string;
  1421. hssymtyp : TAsmSymType;
  1422. begin
  1423. BuildConstSymbolExpression(allowref,betweenbracket,false,l,hs,hssymtyp);
  1424. if hs<>'' then
  1425. Message(asmr_e_relocatable_symbol_not_allowed);
  1426. BuildConstExpression:=l;
  1427. end;
  1428. Procedure tattreader.BuildConstantOperand(oper : toperand);
  1429. var
  1430. l : aint;
  1431. tempstr : string;
  1432. tempsymtyp : TAsmSymType;
  1433. begin
  1434. BuildConstSymbolExpression(false,false,true,l,tempstr,tempsymtyp);
  1435. if tempstr<>'' then
  1436. begin
  1437. oper.opr.typ:=OPR_SYMBOL;
  1438. oper.opr.symofs:=l;
  1439. oper.opr.symbol:=current_asmdata.RefAsmSymbol(tempstr);
  1440. end
  1441. else
  1442. begin
  1443. oper.opr.typ:=OPR_CONSTANT;
  1444. oper.opr.val:=l;
  1445. end;
  1446. end;
  1447. end.