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