raatt.pas 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Carl Eric Codere and Peter Vreman
  4. Does the parsing for the GAS styled inline assembler.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit raatt;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cutils,cclasses,
  24. { global }
  25. globtype,
  26. { aasm }
  27. cpubase,cpuinfo,aasmbase,aasmtai,aasmcpu,
  28. { assembler reader }
  29. rabase,
  30. rasm,
  31. rautils,
  32. { symtable }
  33. symconst,
  34. { cg }
  35. cgbase;
  36. type
  37. tasmtoken = (
  38. AS_NONE,AS_LABEL,AS_LLABEL,AS_STRING,AS_INTNUM,
  39. AS_REALNUM,AS_COMMA,AS_LPAREN,
  40. AS_RPAREN,AS_COLON,AS_DOT,AS_PLUS,AS_MINUS,AS_STAR,
  41. AS_SEPARATOR,AS_ID,AS_REGISTER,AS_OPCODE,AS_SLASH,AS_DOLLAR,
  42. AS_HASH,AS_LSBRACKET,AS_RSBRACKET,AS_LBRACKET,AS_RBRACKET,
  43. {------------------ Assembler directives --------------------}
  44. AS_DB,AS_DW,AS_DD,AS_DQ,AS_GLOBAL,
  45. AS_ALIGN,AS_BALIGN,AS_P2ALIGN,AS_ASCII,
  46. AS_ASCIIZ,AS_LCOMM,AS_COMM,AS_SINGLE,AS_DOUBLE,AS_EXTENDED,
  47. AS_DATA,AS_TEXT,AS_END,
  48. {------------------ Assembler Operators --------------------}
  49. AS_TYPE,AS_SIZEOF,AS_MOD,AS_SHL,AS_SHR,AS_NOT,AS_AND,AS_OR,AS_XOR,AS_NOR,AS_AT,
  50. AS_LO,AS_HI);
  51. tasmkeyword = string[10];
  52. const
  53. { These tokens should be modified accordingly to the modifications }
  54. { in the different enumerations. }
  55. firstdirective = AS_DB;
  56. lastdirective = AS_END;
  57. token2str : array[tasmtoken] of tasmkeyword=(
  58. '','Label','LLabel','string','integer',
  59. 'float',',','(',
  60. ')',':','.','+','-','*',
  61. ';','identifier','register','opcode','/','$',
  62. '#','{','}','[',']',
  63. '.byte','.word','.long','.quad','.globl',
  64. '.align','.balign','.p2align','.ascii',
  65. '.asciz','.lcomm','.comm','.single','.double','.tfloat',
  66. '.data','.text','END',
  67. 'TYPE','SIZEOF','%','<<','>>','!','&','|','^','~','@','lo','hi');
  68. type
  69. tattreader = class(tasmreader)
  70. actasmtoken : tasmtoken;
  71. prevasmtoken : tasmtoken;
  72. procedure SetupTables;
  73. procedure BuildConstant(constsize: byte);
  74. procedure BuildConstantOperand(oper : toperand);
  75. procedure BuildRealConstant(typ : tfloattype);
  76. procedure BuildStringConstant(asciiz: boolean);
  77. procedure BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint);
  78. procedure BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  79. function BuildConstExpression(allowref,betweenbracket:boolean): aint;
  80. function Assemble: tlinkedlist;override;
  81. procedure handleopcode;virtual;abstract;
  82. function is_asmopcode(const s: string) : boolean;virtual;abstract;
  83. Function is_asmdirective(const s: string):boolean;
  84. function is_register(const s:string):boolean;virtual;
  85. function is_locallabel(const s: string):boolean;
  86. procedure GetToken;
  87. function consume(t : tasmtoken):boolean;
  88. procedure RecoverConsume(allowcomma:boolean);
  89. procedure handlepercent;virtual;
  90. end;
  91. tcattreader = class of tattreader;
  92. var
  93. cattreader : tcattreader;
  94. implementation
  95. uses
  96. { globals }
  97. verbose,systems,
  98. { input }
  99. scanner,
  100. { symtable }
  101. symbase,symtype,symsym,symtable,
  102. {$ifdef x86}
  103. rax86,
  104. {$endif x86}
  105. itcpugas,
  106. procinfo;
  107. procedure tattreader.SetupTables;
  108. { creates uppercased symbol tables for speed access }
  109. var
  110. i : tasmop;
  111. str2opentry: tstr2opentry;
  112. Begin
  113. { opcodes }
  114. iasmops:=TDictionary.Create;
  115. iasmops.delete_doubles:=true;
  116. for i:=firstop to lastop do
  117. begin
  118. str2opentry:=tstr2opentry.createname(upper(gas_op2str[i]));
  119. str2opentry.op:=i;
  120. iasmops.insert(str2opentry);
  121. end;
  122. end;
  123. function tattreader.is_asmdirective(const s: string):boolean;
  124. var
  125. i : tasmtoken;
  126. hs : string;
  127. Begin
  128. { GNU as is also not casesensitive with this }
  129. hs:=lower(s);
  130. for i:=firstdirective to lastdirective do
  131. if hs=token2str[i] then
  132. begin
  133. actasmtoken:=i;
  134. is_asmdirective:=true;
  135. exit;
  136. end;
  137. is_asmdirective:=false;
  138. end;
  139. function tattreader.is_register(const s:string):boolean;
  140. begin
  141. is_register:=false;
  142. actasmregister:=gas_regnum_search(lower(s));
  143. if actasmregister<>NR_NO then
  144. begin
  145. is_register:=true;
  146. actasmtoken:=AS_REGISTER;
  147. end;
  148. end;
  149. function tattreader.is_locallabel(const s: string):boolean;
  150. begin
  151. is_locallabel:=(length(s)>=2) and (s[1]='.') and (s[2]='L');
  152. end;
  153. procedure tattreader.handlepercent;
  154. begin
  155. c:=current_scanner.asmgetchar;
  156. actasmtoken:=AS_MOD;
  157. end;
  158. procedure tattreader.GetToken;
  159. var
  160. len : longint;
  161. srsym : tsym;
  162. srsymtable : tsymtable;
  163. begin
  164. { save old token and reset new token }
  165. prevasmtoken:=actasmtoken;
  166. actasmtoken:=AS_NONE;
  167. { reset }
  168. actasmpattern:='';
  169. { while space and tab , continue scan... }
  170. while c in [' ',#9] do
  171. c:=current_scanner.asmgetchar;
  172. { get token pos }
  173. {$ifdef arm}
  174. if not (c in [#10,#13,';']) then
  175. current_scanner.gettokenpos;
  176. {$else arm}
  177. if not (c in [#10,#13,'{',';']) then
  178. current_scanner.gettokenpos;
  179. {$endif arm}
  180. { Local Label, Label, Directive, Prefix or Opcode }
  181. {$ifdef arm}
  182. if firsttoken and not(c in [#10,#13,';']) then
  183. {$else arm}
  184. if firsttoken and not(c in [#10,#13,'{',';']) then
  185. {$endif arm}
  186. begin
  187. firsttoken:=FALSE;
  188. len:=0;
  189. { directive or local label }
  190. if c = '.' then
  191. begin
  192. inc(len);
  193. actasmpattern[len]:=c;
  194. { Let us point to the next character }
  195. c:=current_scanner.asmgetchar;
  196. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  197. begin
  198. inc(len);
  199. actasmpattern[len]:=c;
  200. c:=current_scanner.asmgetchar;
  201. end;
  202. actasmpattern[0]:=chr(len);
  203. { this is a local label... }
  204. if (c=':') and is_locallabel(actasmpattern) then
  205. Begin
  206. { local variables are case sensitive }
  207. actasmtoken:=AS_LLABEL;
  208. c:=current_scanner.asmgetchar;
  209. firsttoken:=true;
  210. exit;
  211. end
  212. { must be a directive }
  213. else
  214. Begin
  215. { directives are case sensitive!! }
  216. if is_asmdirective(actasmpattern) then
  217. exit;
  218. Message1(asmr_e_not_directive_or_local_symbol,actasmpattern);
  219. end;
  220. end;
  221. { only opcodes and global labels are allowed now. }
  222. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  223. begin
  224. inc(len);
  225. actasmpattern[len]:=c;
  226. c:=current_scanner.asmgetchar;
  227. end;
  228. actasmpattern[0]:=chr(len);
  229. { Label ? }
  230. if c = ':' then
  231. begin
  232. actasmtoken:=AS_LABEL;
  233. { let us point to the next character }
  234. c:=current_scanner.asmgetchar;
  235. firsttoken:=true;
  236. exit;
  237. end;
  238. {$ifdef POWERPC}
  239. { some PowerPC instructions can have the postfix -, + or .
  240. this code could be moved to is_asmopcode but I think
  241. it's better to ifdef it here (FK)
  242. }
  243. case c of
  244. '.', '-', '+':
  245. begin
  246. actasmpattern:=actasmpattern+c;
  247. c:=current_scanner.asmgetchar;
  248. end
  249. end;
  250. {$endif POWERPC}
  251. { Opcode ? }
  252. If is_asmopcode(upper(actasmpattern)) then
  253. Begin
  254. uppervar(actasmpattern);
  255. exit;
  256. end;
  257. { End of assemblerblock ? }
  258. if upper(actasmpattern) = 'END' then
  259. begin
  260. actasmtoken:=AS_END;
  261. exit;
  262. end;
  263. message1(asmr_e_unknown_opcode,actasmpattern);
  264. actasmtoken:=AS_NONE;
  265. end
  266. else { else firsttoken }
  267. { Here we must handle all possible cases }
  268. begin
  269. case c of
  270. '.' : { possiblities : - local label reference , such as in jmp @local1 }
  271. { - field of object/record }
  272. { - directive. }
  273. begin
  274. if (prevasmtoken in [AS_ID,AS_RPAREN]) then
  275. begin
  276. c:=current_scanner.asmgetchar;
  277. actasmtoken:=AS_DOT;
  278. exit;
  279. end;
  280. actasmpattern:=c;
  281. c:=current_scanner.asmgetchar;
  282. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  283. begin
  284. actasmpattern:=actasmpattern + c;
  285. c:=current_scanner.asmgetchar;
  286. end;
  287. if is_asmdirective(actasmpattern) then
  288. exit;
  289. { local label references and directives }
  290. { are case sensitive }
  291. actasmtoken:=AS_ID;
  292. exit;
  293. end;
  294. { identifier, register, prefix or directive }
  295. '_','A'..'Z','a'..'z':
  296. begin
  297. len:=0;
  298. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  299. begin
  300. inc(len);
  301. actasmpattern[len]:=c;
  302. c:=current_scanner.asmgetchar;
  303. end;
  304. actasmpattern[0]:=chr(len);
  305. uppervar(actasmpattern);
  306. {$ifdef x86}
  307. { only x86 architectures have instruction prefixes }
  308. { Opcode, can only be when the previous was a prefix }
  309. If is_prefix(actopcode) and is_asmopcode(actasmpattern) then
  310. Begin
  311. uppervar(actasmpattern);
  312. exit;
  313. end;
  314. {$endif x86}
  315. { check for end which is a reserved word unlike the opcodes }
  316. if actasmpattern = 'END' then
  317. Begin
  318. actasmtoken:=AS_END;
  319. exit;
  320. end;
  321. if actasmpattern = 'TYPE' then
  322. Begin
  323. actasmtoken:=AS_TYPE;
  324. exit;
  325. end;
  326. if actasmpattern = 'SIZEOF' then
  327. Begin
  328. actasmtoken:=AS_SIZEOF;
  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_ID :
  733. Begin
  734. BuildConstSymbolExpression(false,false,false,value,asmsym,asmsymtyp);
  735. if asmsym<>'' then
  736. begin
  737. if constsize<>sizeof(aint) then
  738. Message(asmr_w_32bit_const_for_address);
  739. ConcatConstSymbol(curlist,asmsym,asmsymtyp,value)
  740. end
  741. else
  742. ConcatConstant(curlist,value,constsize);
  743. end;
  744. AS_COMMA:
  745. Consume(AS_COMMA);
  746. AS_END,
  747. AS_SEPARATOR:
  748. break;
  749. else
  750. begin
  751. Message(asmr_e_syn_constant);
  752. RecoverConsume(false);
  753. end
  754. end; { end case }
  755. Until false;
  756. end;
  757. Procedure tattreader.BuildRealConstant(typ : tfloattype);
  758. var
  759. expr : string;
  760. r : bestreal;
  761. code : integer;
  762. negativ : boolean;
  763. errorflag: boolean;
  764. Begin
  765. errorflag:=FALSE;
  766. Repeat
  767. negativ:=false;
  768. expr:='';
  769. if actasmtoken=AS_PLUS then
  770. Consume(AS_PLUS)
  771. else
  772. if actasmtoken=AS_MINUS then
  773. begin
  774. negativ:=true;
  775. consume(AS_MINUS);
  776. end;
  777. Case actasmtoken of
  778. AS_INTNUM:
  779. Begin
  780. expr:=actasmpattern;
  781. Consume(AS_INTNUM);
  782. if negativ then
  783. expr:='-'+expr;
  784. val(expr,r,code);
  785. if code<>0 then
  786. Begin
  787. r:=0;
  788. Message(asmr_e_invalid_float_expr);
  789. End;
  790. ConcatRealConstant(curlist,r,typ);
  791. end;
  792. AS_REALNUM:
  793. Begin
  794. expr:=actasmpattern;
  795. Consume(AS_REALNUM);
  796. { in ATT syntax you have 0d in front of the real }
  797. { should this be forced ? yes i think so, as to }
  798. { conform to gas as much as possible. }
  799. if (expr[1]='0') and (upper(expr[2])='D') then
  800. Delete(expr,1,2);
  801. if negativ then
  802. expr:='-'+expr;
  803. val(expr,r,code);
  804. if code<>0 then
  805. Begin
  806. r:=0;
  807. Message(asmr_e_invalid_float_expr);
  808. End;
  809. ConcatRealConstant(curlist,r,typ);
  810. end;
  811. AS_COMMA:
  812. begin
  813. Consume(AS_COMMA);
  814. end;
  815. AS_END,
  816. AS_SEPARATOR:
  817. begin
  818. break;
  819. end;
  820. else
  821. Begin
  822. Consume(actasmtoken);
  823. if not errorflag then
  824. Message(asmr_e_invalid_float_expr);
  825. errorflag:=TRUE;
  826. end;
  827. end;
  828. Until false;
  829. end;
  830. Procedure tattreader.BuildStringConstant(asciiz: boolean);
  831. var
  832. expr: string;
  833. errorflag : boolean;
  834. Begin
  835. errorflag:=FALSE;
  836. Repeat
  837. Case actasmtoken of
  838. AS_STRING:
  839. Begin
  840. expr:=actasmpattern;
  841. if asciiz then
  842. expr:=expr+#0;
  843. ConcatPasString(curlist,expr);
  844. Consume(AS_STRING);
  845. end;
  846. AS_COMMA:
  847. begin
  848. Consume(AS_COMMA);
  849. end;
  850. AS_END,
  851. AS_SEPARATOR:
  852. begin
  853. break;
  854. end;
  855. else
  856. Begin
  857. Consume(actasmtoken);
  858. if not errorflag then
  859. Message(asmr_e_invalid_string_expression);
  860. errorflag:=TRUE;
  861. end;
  862. end;
  863. Until false;
  864. end;
  865. Function tattreader.Assemble: tlinkedlist;
  866. Var
  867. hl : tasmlabel;
  868. commname : string;
  869. lasTSec : TAsmSectionType;
  870. l1,l2 : longint;
  871. Begin
  872. Message1(asmr_d_start_reading,'GNU AS');
  873. firsttoken:=TRUE;
  874. { sets up all opcode and register tables in uppercase }
  875. if not _asmsorted then
  876. Begin
  877. SetupTables;
  878. _asmsorted:=TRUE;
  879. end;
  880. curlist:=TAAsmoutput.Create;
  881. lasTSec:=sec_code;
  882. { setup label linked list }
  883. LocalLabelList:=TLocalLabelList.Create;
  884. { start tokenizer }
  885. c:=current_scanner.asmgetcharstart;
  886. gettoken;
  887. { main loop }
  888. repeat
  889. case actasmtoken of
  890. AS_LLABEL:
  891. Begin
  892. if CreateLocalLabel(actasmpattern,hl,true) then
  893. ConcatLabel(curlist,hl);
  894. Consume(AS_LLABEL);
  895. end;
  896. AS_LABEL:
  897. Begin
  898. if SearchLabel(upper(actasmpattern),hl,true) then
  899. ConcatLabel(curlist,hl)
  900. else
  901. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  902. Consume(AS_LABEL);
  903. end;
  904. AS_DW:
  905. Begin
  906. Consume(AS_DW);
  907. BuildConstant(2);
  908. end;
  909. AS_DATA:
  910. Begin
  911. new_section(curList,sec_data,lower(current_procinfo.procdef.mangledname),0);
  912. lasTSec:=sec_data;
  913. Consume(AS_DATA);
  914. end;
  915. AS_TEXT:
  916. Begin
  917. new_section(curList,sec_code,lower(current_procinfo.procdef.mangledname),0);
  918. lasTSec:=sec_code;
  919. Consume(AS_TEXT);
  920. end;
  921. AS_DB:
  922. Begin
  923. Consume(AS_DB);
  924. BuildConstant(1);
  925. end;
  926. AS_DD:
  927. Begin
  928. Consume(AS_DD);
  929. BuildConstant(4);
  930. end;
  931. AS_DQ:
  932. Begin
  933. Consume(AS_DQ);
  934. {$ifdef cpu64bit}
  935. BuildConstant(8);
  936. {$else cpu64bit}
  937. BuildRealConstant(s64comp);
  938. {$endif cpu64bit}
  939. end;
  940. AS_SINGLE:
  941. Begin
  942. Consume(AS_SINGLE);
  943. BuildRealConstant(s32real);
  944. end;
  945. AS_DOUBLE:
  946. Begin
  947. Consume(AS_DOUBLE);
  948. BuildRealConstant(s64real);
  949. end;
  950. AS_EXTENDED:
  951. Begin
  952. Consume(AS_EXTENDED);
  953. BuildRealConstant(s80real);
  954. end;
  955. AS_GLOBAL:
  956. Begin
  957. Consume(AS_GLOBAL);
  958. if actasmtoken=AS_ID then
  959. ConcatPublic(curlist,actasmpattern);
  960. Consume(AS_ID);
  961. if actasmtoken<>AS_SEPARATOR then
  962. Consume(AS_SEPARATOR);
  963. end;
  964. AS_ALIGN:
  965. Begin
  966. Consume(AS_ALIGN);
  967. l1:=BuildConstExpression(false,false);
  968. if (target_info.system in [system_i386_GO32V2]) then
  969. begin
  970. l2:=1;
  971. if (l1>=0) and (l1<=16) then
  972. while (l1>0) do
  973. begin
  974. l2:=2*l2;
  975. dec(l1);
  976. end;
  977. l1:=l2;
  978. end;
  979. ConcatAlign(curlist,l1);
  980. Message(asmr_n_align_is_target_specific);
  981. if actasmtoken<>AS_SEPARATOR then
  982. Consume(AS_SEPARATOR);
  983. end;
  984. AS_BALIGN:
  985. Begin
  986. Consume(AS_BALIGN);
  987. ConcatAlign(curlist,BuildConstExpression(false,false));
  988. if actasmtoken<>AS_SEPARATOR then
  989. Consume(AS_SEPARATOR);
  990. end;
  991. AS_P2ALIGN:
  992. Begin
  993. Consume(AS_P2ALIGN);
  994. l1:=BuildConstExpression(false,false);
  995. l2:=1;
  996. if (l1>=0) and (l1<=16) then
  997. while (l1>0) do
  998. begin
  999. l2:=2*l2;
  1000. dec(l1);
  1001. end;
  1002. l1:=l2;
  1003. ConcatAlign(curlist,l1);
  1004. if actasmtoken<>AS_SEPARATOR then
  1005. Consume(AS_SEPARATOR);
  1006. end;
  1007. AS_ASCIIZ:
  1008. Begin
  1009. Consume(AS_ASCIIZ);
  1010. BuildStringConstant(TRUE);
  1011. end;
  1012. AS_ASCII:
  1013. Begin
  1014. Consume(AS_ASCII);
  1015. BuildStringConstant(FALSE);
  1016. end;
  1017. AS_LCOMM:
  1018. Begin
  1019. Consume(AS_LCOMM);
  1020. commname:=actasmpattern;
  1021. Consume(AS_ID);
  1022. Consume(AS_COMMA);
  1023. ConcatLocalBss(commname,BuildConstExpression(false,false));
  1024. if actasmtoken<>AS_SEPARATOR then
  1025. Consume(AS_SEPARATOR);
  1026. end;
  1027. AS_COMM:
  1028. Begin
  1029. Consume(AS_COMM);
  1030. commname:=actasmpattern;
  1031. Consume(AS_ID);
  1032. Consume(AS_COMMA);
  1033. ConcatGlobalBss(commname,BuildConstExpression(false,false));
  1034. if actasmtoken<>AS_SEPARATOR then
  1035. Consume(AS_SEPARATOR);
  1036. end;
  1037. AS_OPCODE:
  1038. Begin
  1039. HandleOpCode;
  1040. end;
  1041. AS_SEPARATOR:
  1042. Begin
  1043. Consume(AS_SEPARATOR);
  1044. end;
  1045. AS_END:
  1046. begin
  1047. break; { end assembly block }
  1048. end;
  1049. else
  1050. Begin
  1051. Message(asmr_e_syntax_error);
  1052. RecoverConsume(false);
  1053. end;
  1054. end;
  1055. until false;
  1056. { Check LocalLabelList }
  1057. LocalLabelList.CheckEmitted;
  1058. LocalLabelList.Free;
  1059. { are we back in the code section? }
  1060. if lasTSec<>sec_code then
  1061. begin
  1062. Message(asmr_w_assembler_code_not_returned_to_text);
  1063. new_section(curList,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1064. end;
  1065. { Return the list in an asmnode }
  1066. assemble:=curlist;
  1067. Message1(asmr_d_finish_reading,'GNU AS');
  1068. end;
  1069. {*****************************************************************************
  1070. Parsing Helpers
  1071. *****************************************************************************}
  1072. Procedure tattreader.BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint);
  1073. { Description: This routine builds up a record offset after a AS_DOT }
  1074. { token is encountered. }
  1075. { On entry actasmtoken should be equal to AS_DOT }
  1076. var
  1077. s : string;
  1078. Begin
  1079. offset:=0;
  1080. size:=0;
  1081. s:=expr;
  1082. while (actasmtoken=AS_DOT) do
  1083. begin
  1084. Consume(AS_DOT);
  1085. if actasmtoken=AS_ID then
  1086. s:=s+'.'+actasmpattern;
  1087. if not Consume(AS_ID) then
  1088. begin
  1089. RecoverConsume(true);
  1090. break;
  1091. end;
  1092. end;
  1093. if not GetRecordOffsetSize(s,offset,size) then
  1094. Message(asmr_e_building_record_offset);
  1095. end;
  1096. procedure tattreader.BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:aint;var asmsym:string;var asmsymtyp:TAsmsymtype);
  1097. var
  1098. hssymtyp : TAsmSymType;
  1099. hs,tempstr,expr : string;
  1100. parenlevel : longint;
  1101. l,k : aint;
  1102. errorflag : boolean;
  1103. prevtok : tasmtoken;
  1104. sym : tsym;
  1105. srsymtable : tsymtable;
  1106. hl : tasmlabel;
  1107. Begin
  1108. asmsym:='';
  1109. asmsymtyp:=AT_DATA;
  1110. value:=0;
  1111. errorflag:=FALSE;
  1112. tempstr:='';
  1113. expr:='';
  1114. parenlevel:=0;
  1115. Repeat
  1116. Case actasmtoken of
  1117. AS_LPAREN:
  1118. Begin
  1119. { Exit if ref? }
  1120. if allowref and (prevasmtoken in [AS_INTNUM,AS_ID]) then
  1121. break;
  1122. Consume(AS_LPAREN);
  1123. expr:=expr + '(';
  1124. inc(parenlevel);
  1125. end;
  1126. AS_RBRACKET:
  1127. begin
  1128. if betweenbracket then
  1129. break;
  1130. { write error only once. }
  1131. if not errorflag then
  1132. Message(asmr_e_invalid_constant_expression);
  1133. { consume tokens until we find COMMA or SEPARATOR }
  1134. Consume(actasmtoken);
  1135. errorflag:=TRUE;
  1136. end;
  1137. AS_RPAREN:
  1138. Begin
  1139. { end of ref ? }
  1140. if (parenlevel=0) and betweenbracket then
  1141. break;
  1142. Consume(AS_RPAREN);
  1143. expr:=expr + ')';
  1144. dec(parenlevel);
  1145. end;
  1146. AS_SHL:
  1147. Begin
  1148. Consume(AS_SHL);
  1149. expr:=expr + '<';
  1150. end;
  1151. AS_SHR:
  1152. Begin
  1153. Consume(AS_SHR);
  1154. expr:=expr + '>';
  1155. end;
  1156. AS_SLASH:
  1157. Begin
  1158. Consume(AS_SLASH);
  1159. expr:=expr + '/';
  1160. end;
  1161. AS_MOD:
  1162. Begin
  1163. Consume(AS_MOD);
  1164. expr:=expr + '%';
  1165. end;
  1166. AS_STAR:
  1167. Begin
  1168. Consume(AS_STAR);
  1169. expr:=expr + '*';
  1170. end;
  1171. AS_PLUS:
  1172. Begin
  1173. Consume(AS_PLUS);
  1174. expr:=expr + '+';
  1175. end;
  1176. AS_MINUS:
  1177. Begin
  1178. Consume(AS_MINUS);
  1179. expr:=expr + '-';
  1180. end;
  1181. AS_AND:
  1182. Begin
  1183. Consume(AS_AND);
  1184. expr:=expr + '&';
  1185. end;
  1186. AS_NOT:
  1187. Begin
  1188. Consume(AS_NOT);
  1189. expr:=expr + '~';
  1190. end;
  1191. AS_XOR:
  1192. Begin
  1193. Consume(AS_XOR);
  1194. expr:=expr + '^';
  1195. end;
  1196. AS_OR:
  1197. Begin
  1198. Consume(AS_OR);
  1199. expr:=expr + '|';
  1200. end;
  1201. AS_INTNUM:
  1202. Begin
  1203. expr:=expr + actasmpattern;
  1204. Consume(AS_INTNUM);
  1205. end;
  1206. AS_DOLLAR:
  1207. begin
  1208. Consume(AS_DOLLAR);
  1209. if actasmtoken<>AS_ID then
  1210. Message(asmr_e_dollar_without_identifier);
  1211. end;
  1212. AS_STRING:
  1213. Begin
  1214. l:=0;
  1215. case Length(actasmpattern) of
  1216. 1 :
  1217. l:=ord(actasmpattern[1]);
  1218. 2 :
  1219. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  1220. 3 :
  1221. l:=ord(actasmpattern[3]) +
  1222. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  1223. 4 :
  1224. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  1225. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  1226. else
  1227. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  1228. end;
  1229. str(l, tempstr);
  1230. expr:=expr + tempstr;
  1231. Consume(AS_STRING);
  1232. end;
  1233. AS_SIZEOF,
  1234. AS_TYPE:
  1235. begin
  1236. l:=0;
  1237. Consume(actasmtoken);
  1238. if actasmtoken<>AS_ID then
  1239. Message(asmr_e_type_without_identifier)
  1240. else
  1241. begin
  1242. tempstr:=actasmpattern;
  1243. Consume(AS_ID);
  1244. if actasmtoken=AS_DOT then
  1245. BuildRecordOffsetSize(tempstr,k,l)
  1246. else
  1247. begin
  1248. searchsym(tempstr,sym,srsymtable);
  1249. if assigned(sym) then
  1250. begin
  1251. case sym.typ of
  1252. globalvarsym,
  1253. localvarsym,
  1254. paravarsym :
  1255. l:=tabstractvarsym(sym).getsize;
  1256. typedconstsym :
  1257. l:=ttypedconstsym(sym).getsize;
  1258. typesym :
  1259. l:=ttypesym(sym).restype.def.size;
  1260. else
  1261. Message(asmr_e_wrong_sym_type);
  1262. end;
  1263. end
  1264. else
  1265. Message1(sym_e_unknown_id,tempstr);
  1266. end;
  1267. end;
  1268. str(l, tempstr);
  1269. expr:=expr + tempstr;
  1270. end;
  1271. AS_ID:
  1272. Begin
  1273. hs:='';
  1274. hssymtyp:=AT_DATA;
  1275. tempstr:=actasmpattern;
  1276. prevtok:=prevasmtoken;
  1277. consume(AS_ID);
  1278. if SearchIConstant(tempstr,l) then
  1279. begin
  1280. str(l, tempstr);
  1281. expr:=expr + tempstr;
  1282. end
  1283. else
  1284. begin
  1285. if is_locallabel(tempstr) then
  1286. begin
  1287. CreateLocalLabel(tempstr,hl,false);
  1288. hs:=hl.name;
  1289. hssymtyp:=AT_FUNCTION;
  1290. end
  1291. else
  1292. if SearchLabel(tempstr,hl,false) then
  1293. begin
  1294. hs:=hl.name;
  1295. hssymtyp:=AT_FUNCTION;
  1296. end
  1297. else
  1298. begin
  1299. searchsym(tempstr,sym,srsymtable);
  1300. if assigned(sym) then
  1301. begin
  1302. case sym.typ of
  1303. globalvarsym :
  1304. hs:=tglobalvarsym(sym).mangledname;
  1305. localvarsym,
  1306. paravarsym :
  1307. Message(asmr_e_no_local_or_para_allowed);
  1308. typedconstsym :
  1309. hs:=ttypedconstsym(sym).mangledname;
  1310. procsym :
  1311. with Tprocsym(sym) do
  1312. begin
  1313. if procdef_count>1 then
  1314. message(asmr_w_calling_overload_func);
  1315. hs:=first_procdef.mangledname;
  1316. hssymtyp:=AT_FUNCTION;
  1317. end;
  1318. typesym :
  1319. begin
  1320. if not(ttypesym(sym).restype.def.deftype in [recorddef,objectdef]) then
  1321. Message(asmr_e_wrong_sym_type);
  1322. end;
  1323. else
  1324. Message(asmr_e_wrong_sym_type);
  1325. end;
  1326. end
  1327. else
  1328. Message1(sym_e_unknown_id,tempstr);
  1329. end;
  1330. { symbol found? }
  1331. if hs<>'' then
  1332. begin
  1333. if needofs and (prevtok<>AS_DOLLAR) then
  1334. Message(asmr_e_need_dollar);
  1335. if asmsym='' then
  1336. begin
  1337. asmsym:=hs;
  1338. asmsymtyp:=hssymtyp;
  1339. end
  1340. else
  1341. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1342. if (expr='') or (expr[length(expr)]='+') then
  1343. begin
  1344. { don't remove the + if there could be a record field }
  1345. if actasmtoken<>AS_DOT then
  1346. delete(expr,length(expr),1);
  1347. end
  1348. else
  1349. Message(asmr_e_only_add_relocatable_symbol);
  1350. end;
  1351. if actasmtoken=AS_DOT then
  1352. begin
  1353. BuildRecordOffsetSize(tempstr,l,k);
  1354. str(l, tempstr);
  1355. expr:=expr + tempstr;
  1356. end
  1357. else
  1358. begin
  1359. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1360. delete(expr,length(expr),1);
  1361. end;
  1362. end;
  1363. { check if there are wrong operator used like / or mod etc. }
  1364. if (hs<>'') and
  1365. not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,
  1366. AS_LPAREN,AS_RPAREN,AS_RBRACKET,AS_END]) then
  1367. Message(asmr_e_only_add_relocatable_symbol);
  1368. end;
  1369. AS_END,
  1370. AS_SEPARATOR,
  1371. AS_COMMA:
  1372. break;
  1373. else
  1374. Begin
  1375. { write error only once. }
  1376. if not errorflag then
  1377. Message(asmr_e_invalid_constant_expression);
  1378. { consume tokens until we find COMMA or SEPARATOR }
  1379. Consume(actasmtoken);
  1380. errorflag:=TRUE;
  1381. end;
  1382. end;
  1383. Until false;
  1384. { calculate expression }
  1385. if not ErrorFlag then
  1386. value:=CalculateExpression(expr)
  1387. else
  1388. value:=0;
  1389. end;
  1390. function tattreader.BuildConstExpression(allowref,betweenbracket:boolean): aint;
  1391. var
  1392. l : aint;
  1393. hs : string;
  1394. hssymtyp : TAsmSymType;
  1395. begin
  1396. BuildConstSymbolExpression(allowref,betweenbracket,false,l,hs,hssymtyp);
  1397. if hs<>'' then
  1398. Message(asmr_e_relocatable_symbol_not_allowed);
  1399. BuildConstExpression:=l;
  1400. end;
  1401. Procedure tattreader.BuildConstantOperand(oper : toperand);
  1402. var
  1403. l : aint;
  1404. tempstr : string;
  1405. tempsymtyp : TAsmSymType;
  1406. begin
  1407. BuildConstSymbolExpression(false,false,true,l,tempstr,tempsymtyp);
  1408. if tempstr<>'' then
  1409. begin
  1410. oper.opr.typ:=OPR_SYMBOL;
  1411. oper.opr.symofs:=l;
  1412. oper.opr.symbol:=objectlibrary.newasmsymbol(tempstr,AB_EXTERNAL,tempsymtyp);
  1413. end
  1414. else
  1415. begin
  1416. oper.opr.typ:=OPR_CONSTANT;
  1417. oper.opr.val:=l;
  1418. end;
  1419. end;
  1420. end.
  1421. {
  1422. $Log$
  1423. Revision 1.18 2005-01-20 17:05:53 peter
  1424. * use val() for decoding integers
  1425. Revision 1.17 2005/01/19 22:19:41 peter
  1426. * unit mapping rewrite
  1427. * new derefmap added
  1428. Revision 1.16 2004/12/22 17:09:55 peter
  1429. * support sizeof()
  1430. * fix typecasting a constant like dword(4)
  1431. Revision 1.15 2004/11/29 18:50:15 peter
  1432. * os2 fixes for import
  1433. * asmsymtype support for intel reader
  1434. Revision 1.14 2004/11/21 15:35:23 peter
  1435. * float routines all use internproc and compilerproc helpers
  1436. Revision 1.13 2004/11/08 22:09:59 peter
  1437. * tvarsym splitted
  1438. Revision 1.12 2004/06/20 08:55:30 florian
  1439. * logs truncated
  1440. Revision 1.11 2004/06/16 20:07:09 florian
  1441. * dwarf branch merged
  1442. Revision 1.10.2.3 2004/05/01 23:36:47 peter
  1443. * assembler reader 64bit fixes
  1444. Revision 1.10.2.2 2004/04/10 12:36:41 peter
  1445. * fixed alignment issues
  1446. Revision 1.10.2.1 2004/04/08 18:33:22 peter
  1447. * rewrite of TAsmSection
  1448. Revision 1.10 2004/03/02 00:36:33 olle
  1449. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1450. }