raatt.pas 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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,node;
  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_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','%','<<','>>','!','&','|','^','~','@','lo','hi');
  68. type
  69. tattreader = class(tasmreader)
  70. actasmtoken : tasmtoken;
  71. prevasmtoken : tasmtoken;
  72. procedure SetupTables;
  73. procedure BuildConstant(maxvalue: longint);
  74. procedure BuildConstantOperand(oper : toperand);
  75. procedure BuildRealConstant(typ : tfloattype);
  76. procedure BuildStringConstant(asciiz: boolean);
  77. procedure BuildRecordOffsetSize(const expr: string;var offset:longint;var size:longint);
  78. procedure BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:longint;var asmsym:string);
  79. function BuildConstExpression(allowref,betweenbracket:boolean): longint;
  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. procedure tattreader.SetupTables;
  107. { creates uppercased symbol tables for speed access }
  108. var
  109. i : tasmop;
  110. str2opentry: tstr2opentry;
  111. Begin
  112. { opcodes }
  113. iasmops:=TDictionary.Create;
  114. iasmops.delete_doubles:=true;
  115. for i:=firstop to lastop do
  116. begin
  117. str2opentry:=tstr2opentry.createname(upper(gas_op2str[i]));
  118. str2opentry.op:=i;
  119. iasmops.insert(str2opentry);
  120. end;
  121. end;
  122. function tattreader.is_asmdirective(const s: string):boolean;
  123. var
  124. i : tasmtoken;
  125. hs : string;
  126. Begin
  127. { GNU as is also not casesensitive with this }
  128. hs:=lower(s);
  129. for i:=firstdirective to lastdirective do
  130. if hs=token2str[i] then
  131. begin
  132. actasmtoken:=i;
  133. is_asmdirective:=true;
  134. exit;
  135. end;
  136. is_asmdirective:=false;
  137. end;
  138. function tattreader.is_register(const s:string):boolean;
  139. begin
  140. is_register:=false;
  141. actasmregister:=gas_regnum_search(lower(s));
  142. if actasmregister<>NR_NO then
  143. begin
  144. is_register:=true;
  145. actasmtoken:=AS_REGISTER;
  146. end;
  147. end;
  148. function tattreader.is_locallabel(const s: string):boolean;
  149. begin
  150. is_locallabel:=(length(s)>=2) and (s[1]='.') and (s[2]='L');
  151. end;
  152. procedure tattreader.handlepercent;
  153. begin
  154. c:=current_scanner.asmgetchar;
  155. actasmtoken:=AS_MOD;
  156. end;
  157. procedure tattreader.GetToken;
  158. var
  159. len : longint;
  160. srsym : tsym;
  161. srsymtable : tsymtable;
  162. begin
  163. { save old token and reset new token }
  164. prevasmtoken:=actasmtoken;
  165. actasmtoken:=AS_NONE;
  166. { reset }
  167. actasmpattern:='';
  168. { while space and tab , continue scan... }
  169. while c in [' ',#9] do
  170. c:=current_scanner.asmgetchar;
  171. { get token pos }
  172. {$ifdef arm}
  173. if not (c in [#10,#13,';']) then
  174. current_scanner.gettokenpos;
  175. {$else arm}
  176. if not (c in [#10,#13,'{',';']) then
  177. current_scanner.gettokenpos;
  178. {$endif arm}
  179. { Local Label, Label, Directive, Prefix or Opcode }
  180. {$ifdef arm}
  181. if firsttoken and not(c in [#10,#13,';']) then
  182. {$else arm}
  183. if firsttoken and not(c in [#10,#13,'{',';']) then
  184. {$endif arm}
  185. begin
  186. firsttoken:=FALSE;
  187. len:=0;
  188. { directive or local label }
  189. if c = '.' then
  190. begin
  191. inc(len);
  192. actasmpattern[len]:=c;
  193. { Let us point to the next character }
  194. c:=current_scanner.asmgetchar;
  195. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  196. begin
  197. inc(len);
  198. actasmpattern[len]:=c;
  199. c:=current_scanner.asmgetchar;
  200. end;
  201. actasmpattern[0]:=chr(len);
  202. { this is a local label... }
  203. if (c=':') and is_locallabel(actasmpattern) then
  204. Begin
  205. { local variables are case sensitive }
  206. actasmtoken:=AS_LLABEL;
  207. c:=current_scanner.asmgetchar;
  208. firsttoken:=true;
  209. exit;
  210. end
  211. { must be a directive }
  212. else
  213. Begin
  214. { directives are case sensitive!! }
  215. if is_asmdirective(actasmpattern) then
  216. exit;
  217. Message1(asmr_e_not_directive_or_local_symbol,actasmpattern);
  218. end;
  219. end;
  220. { only opcodes and global labels are allowed now. }
  221. while c in ['A'..'Z','a'..'z','0'..'9','_'] do
  222. begin
  223. inc(len);
  224. actasmpattern[len]:=c;
  225. c:=current_scanner.asmgetchar;
  226. end;
  227. actasmpattern[0]:=chr(len);
  228. { Label ? }
  229. if c = ':' then
  230. begin
  231. actasmtoken:=AS_LABEL;
  232. { let us point to the next character }
  233. c:=current_scanner.asmgetchar;
  234. firsttoken:=true;
  235. exit;
  236. end;
  237. {$ifdef POWERPC}
  238. { some PowerPC instructions can have the postfix -, + or .
  239. this code could be moved to is_asmopcode but I think
  240. it's better to ifdef it here (FK)
  241. }
  242. case c of
  243. '.', '-', '+':
  244. begin
  245. actasmpattern:=actasmpattern+c;
  246. c:=current_scanner.asmgetchar;
  247. end
  248. end;
  249. {$endif POWERPC}
  250. { Opcode ? }
  251. If is_asmopcode(upper(actasmpattern)) then
  252. Begin
  253. uppervar(actasmpattern);
  254. exit;
  255. end;
  256. { End of assemblerblock ? }
  257. if upper(actasmpattern) = 'END' then
  258. begin
  259. actasmtoken:=AS_END;
  260. exit;
  261. end;
  262. message1(asmr_e_unknown_opcode,actasmpattern);
  263. actasmtoken:=AS_NONE;
  264. end
  265. else { else firsttoken }
  266. { Here we must handle all possible cases }
  267. begin
  268. case c of
  269. '.' : { possiblities : - local label reference , such as in jmp @local1 }
  270. { - field of object/record }
  271. { - directive. }
  272. begin
  273. if (prevasmtoken in [AS_ID,AS_RPAREN]) then
  274. begin
  275. c:=current_scanner.asmgetchar;
  276. actasmtoken:=AS_DOT;
  277. exit;
  278. end;
  279. actasmpattern:=c;
  280. c:=current_scanner.asmgetchar;
  281. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  282. begin
  283. actasmpattern:=actasmpattern + c;
  284. c:=current_scanner.asmgetchar;
  285. end;
  286. if is_asmdirective(actasmpattern) then
  287. exit;
  288. { local label references and directives }
  289. { are case sensitive }
  290. actasmtoken:=AS_ID;
  291. exit;
  292. end;
  293. { identifier, register, prefix or directive }
  294. '_','A'..'Z','a'..'z':
  295. begin
  296. len:=0;
  297. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  298. begin
  299. inc(len);
  300. actasmpattern[len]:=c;
  301. c:=current_scanner.asmgetchar;
  302. end;
  303. actasmpattern[0]:=chr(len);
  304. uppervar(actasmpattern);
  305. {$ifdef x86}
  306. { only x86 architectures have instruction prefixes }
  307. { Opcode, can only be when the previous was a prefix }
  308. If is_prefix(actopcode) and is_asmopcode(actasmpattern) then
  309. Begin
  310. uppervar(actasmpattern);
  311. exit;
  312. end;
  313. {$endif x86}
  314. { check for end which is a reserved word unlike the opcodes }
  315. if actasmpattern = 'END' then
  316. Begin
  317. actasmtoken:=AS_END;
  318. exit;
  319. end;
  320. if actasmpattern = 'TYPE' then
  321. Begin
  322. actasmtoken:=AS_TYPE;
  323. exit;
  324. end;
  325. if is_register(actasmpattern) then
  326. begin
  327. actasmtoken:=AS_REGISTER;
  328. exit;
  329. end;
  330. { if next is a '.' and this is a unitsym then we also need to
  331. parse the identifier }
  332. if (c='.') then
  333. begin
  334. searchsym(actasmpattern,srsym,srsymtable);
  335. if assigned(srsym) and
  336. (srsym.typ=unitsym) and
  337. (srsym.owner.unitid=0) 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(ValDecimal(actasmpattern));
  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(ValBinary(actasmpattern));
  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(ValHexaDecimal(actasmpattern));
  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(ValOctal(actasmpattern));
  454. actasmtoken:=AS_INTNUM;
  455. exit;
  456. end;
  457. else { octal number zero value...}
  458. Begin
  459. actasmpattern:=tostr(ValOctal(actasmpattern));
  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(maxvalue: longint);
  695. var
  696. asmsym,
  697. expr: string;
  698. value : longint;
  699. Begin
  700. Repeat
  701. Case actasmtoken of
  702. AS_STRING:
  703. Begin
  704. expr:=actasmpattern;
  705. if length(expr) > 1 then
  706. Message(asmr_e_string_not_allowed_as_const);
  707. Consume(AS_STRING);
  708. Case actasmtoken of
  709. AS_COMMA: Consume(AS_COMMA);
  710. AS_END,
  711. AS_SEPARATOR: ;
  712. else
  713. Message(asmr_e_invalid_string_expression);
  714. end; { end case }
  715. ConcatString(curlist,expr);
  716. end;
  717. AS_INTNUM,
  718. AS_PLUS,
  719. AS_MINUS,
  720. AS_LPAREN,
  721. AS_NOT,
  722. AS_ID :
  723. Begin
  724. BuildConstSymbolExpression(false,false,false,value,asmsym);
  725. if asmsym<>'' then
  726. begin
  727. if maxvalue<>longint($ffffffff) then
  728. Message(asmr_w_32bit_const_for_address);
  729. ConcatConstSymbol(curlist,asmsym,value)
  730. end
  731. else
  732. ConcatConstant(curlist,value,maxvalue);
  733. end;
  734. AS_COMMA:
  735. Consume(AS_COMMA);
  736. AS_END,
  737. AS_SEPARATOR:
  738. break;
  739. else
  740. begin
  741. Message(asmr_e_syn_constant);
  742. RecoverConsume(false);
  743. end
  744. end; { end case }
  745. Until false;
  746. end;
  747. Procedure tattreader.BuildRealConstant(typ : tfloattype);
  748. var
  749. expr : string;
  750. r : bestreal;
  751. code : integer;
  752. negativ : boolean;
  753. errorflag: boolean;
  754. Begin
  755. errorflag:=FALSE;
  756. Repeat
  757. negativ:=false;
  758. expr:='';
  759. if actasmtoken=AS_PLUS then
  760. Consume(AS_PLUS)
  761. else
  762. if actasmtoken=AS_MINUS then
  763. begin
  764. negativ:=true;
  765. consume(AS_MINUS);
  766. end;
  767. Case actasmtoken of
  768. AS_INTNUM:
  769. Begin
  770. expr:=actasmpattern;
  771. Consume(AS_INTNUM);
  772. if negativ then
  773. expr:='-'+expr;
  774. val(expr,r,code);
  775. if code<>0 then
  776. Begin
  777. r:=0;
  778. Message(asmr_e_invalid_float_expr);
  779. End;
  780. ConcatRealConstant(curlist,r,typ);
  781. end;
  782. AS_REALNUM:
  783. Begin
  784. expr:=actasmpattern;
  785. Consume(AS_REALNUM);
  786. { in ATT syntax you have 0d in front of the real }
  787. { should this be forced ? yes i think so, as to }
  788. { conform to gas as much as possible. }
  789. if (expr[1]='0') and (upper(expr[2])='D') then
  790. Delete(expr,1,2);
  791. if negativ then
  792. expr:='-'+expr;
  793. val(expr,r,code);
  794. if code<>0 then
  795. Begin
  796. r:=0;
  797. Message(asmr_e_invalid_float_expr);
  798. End;
  799. ConcatRealConstant(curlist,r,typ);
  800. end;
  801. AS_COMMA:
  802. begin
  803. Consume(AS_COMMA);
  804. end;
  805. AS_END,
  806. AS_SEPARATOR:
  807. begin
  808. break;
  809. end;
  810. else
  811. Begin
  812. Consume(actasmtoken);
  813. if not errorflag then
  814. Message(asmr_e_invalid_float_expr);
  815. errorflag:=TRUE;
  816. end;
  817. end;
  818. Until false;
  819. end;
  820. Procedure tattreader.BuildStringConstant(asciiz: boolean);
  821. var
  822. expr: string;
  823. errorflag : boolean;
  824. Begin
  825. errorflag:=FALSE;
  826. Repeat
  827. Case actasmtoken of
  828. AS_STRING:
  829. Begin
  830. expr:=actasmpattern;
  831. if asciiz then
  832. expr:=expr+#0;
  833. ConcatPasString(curlist,expr);
  834. Consume(AS_STRING);
  835. end;
  836. AS_COMMA:
  837. begin
  838. Consume(AS_COMMA);
  839. end;
  840. AS_END,
  841. AS_SEPARATOR:
  842. begin
  843. break;
  844. end;
  845. else
  846. Begin
  847. Consume(actasmtoken);
  848. if not errorflag then
  849. Message(asmr_e_invalid_string_expression);
  850. errorflag:=TRUE;
  851. end;
  852. end;
  853. Until false;
  854. end;
  855. Function tattreader.Assemble: tlinkedlist;
  856. Var
  857. hl : tasmlabel;
  858. commname : string;
  859. lasTSec : TSection;
  860. l1,l2 : longint;
  861. Begin
  862. Message1(asmr_d_start_reading,'GNU AS');
  863. firsttoken:=TRUE;
  864. { sets up all opcode and register tables in uppercase }
  865. if not _asmsorted then
  866. Begin
  867. SetupTables;
  868. _asmsorted:=TRUE;
  869. end;
  870. curlist:=TAAsmoutput.Create;
  871. lasTSec:=sec_code;
  872. { setup label linked list }
  873. LocalLabelList:=TLocalLabelList.Create;
  874. { start tokenizer }
  875. c:=current_scanner.asmgetcharstart;
  876. gettoken;
  877. { main loop }
  878. repeat
  879. case actasmtoken of
  880. AS_LLABEL:
  881. Begin
  882. if CreateLocalLabel(actasmpattern,hl,true) then
  883. ConcatLabel(curlist,hl);
  884. Consume(AS_LLABEL);
  885. end;
  886. AS_LABEL:
  887. Begin
  888. if SearchLabel(upper(actasmpattern),hl,true) then
  889. ConcatLabel(curlist,hl)
  890. else
  891. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  892. Consume(AS_LABEL);
  893. end;
  894. AS_DW:
  895. Begin
  896. Consume(AS_DW);
  897. BuildConstant($ffff);
  898. end;
  899. AS_DATA:
  900. Begin
  901. curList.Concat(Tai_section.Create(sec_data));
  902. lasTSec:=sec_data;
  903. Consume(AS_DATA);
  904. end;
  905. AS_TEXT:
  906. Begin
  907. curList.Concat(Tai_section.Create(sec_code));
  908. lasTSec:=sec_code;
  909. Consume(AS_TEXT);
  910. end;
  911. AS_DB:
  912. Begin
  913. Consume(AS_DB);
  914. BuildConstant($ff);
  915. end;
  916. AS_DD:
  917. Begin
  918. Consume(AS_DD);
  919. BuildConstant(longint($ffffffff));
  920. end;
  921. AS_DQ:
  922. Begin
  923. Consume(AS_DQ);
  924. BuildRealConstant(s64comp);
  925. end;
  926. AS_SINGLE:
  927. Begin
  928. Consume(AS_SINGLE);
  929. BuildRealConstant(s32real);
  930. end;
  931. AS_DOUBLE:
  932. Begin
  933. Consume(AS_DOUBLE);
  934. BuildRealConstant(s64real);
  935. end;
  936. AS_EXTENDED:
  937. Begin
  938. Consume(AS_EXTENDED);
  939. BuildRealConstant(s80real);
  940. end;
  941. AS_GLOBAL:
  942. Begin
  943. Consume(AS_GLOBAL);
  944. if actasmtoken=AS_ID then
  945. ConcatPublic(curlist,actasmpattern);
  946. Consume(AS_ID);
  947. if actasmtoken<>AS_SEPARATOR then
  948. Consume(AS_SEPARATOR);
  949. end;
  950. AS_ALIGN:
  951. Begin
  952. Consume(AS_ALIGN);
  953. l1:=BuildConstExpression(false,false);
  954. if (target_info.system in [system_i386_GO32V2]) then
  955. begin
  956. l2:=1;
  957. if (l1>=0) and (l1<=16) then
  958. while (l1>0) do
  959. begin
  960. l2:=2*l2;
  961. dec(l1);
  962. end;
  963. l1:=l2;
  964. end;
  965. ConcatAlign(curlist,l1);
  966. Message(asmr_n_align_is_target_specific);
  967. if actasmtoken<>AS_SEPARATOR then
  968. Consume(AS_SEPARATOR);
  969. end;
  970. AS_BALIGN:
  971. Begin
  972. Consume(AS_BALIGN);
  973. ConcatAlign(curlist,BuildConstExpression(false,false));
  974. if actasmtoken<>AS_SEPARATOR then
  975. Consume(AS_SEPARATOR);
  976. end;
  977. AS_P2ALIGN:
  978. Begin
  979. Consume(AS_P2ALIGN);
  980. l1:=BuildConstExpression(false,false);
  981. l2:=1;
  982. if (l1>=0) and (l1<=16) then
  983. while (l1>0) do
  984. begin
  985. l2:=2*l2;
  986. dec(l1);
  987. end;
  988. l1:=l2;
  989. ConcatAlign(curlist,l1);
  990. if actasmtoken<>AS_SEPARATOR then
  991. Consume(AS_SEPARATOR);
  992. end;
  993. AS_ASCIIZ:
  994. Begin
  995. Consume(AS_ASCIIZ);
  996. BuildStringConstant(TRUE);
  997. end;
  998. AS_ASCII:
  999. Begin
  1000. Consume(AS_ASCII);
  1001. BuildStringConstant(FALSE);
  1002. end;
  1003. AS_LCOMM:
  1004. Begin
  1005. Consume(AS_LCOMM);
  1006. commname:=actasmpattern;
  1007. Consume(AS_ID);
  1008. Consume(AS_COMMA);
  1009. ConcatLocalBss(commname,BuildConstExpression(false,false));
  1010. if actasmtoken<>AS_SEPARATOR then
  1011. Consume(AS_SEPARATOR);
  1012. end;
  1013. AS_COMM:
  1014. Begin
  1015. Consume(AS_COMM);
  1016. commname:=actasmpattern;
  1017. Consume(AS_ID);
  1018. Consume(AS_COMMA);
  1019. ConcatGlobalBss(commname,BuildConstExpression(false,false));
  1020. if actasmtoken<>AS_SEPARATOR then
  1021. Consume(AS_SEPARATOR);
  1022. end;
  1023. AS_OPCODE:
  1024. Begin
  1025. HandleOpCode;
  1026. end;
  1027. AS_SEPARATOR:
  1028. Begin
  1029. Consume(AS_SEPARATOR);
  1030. end;
  1031. AS_END:
  1032. begin
  1033. break; { end assembly block }
  1034. end;
  1035. else
  1036. Begin
  1037. Message(asmr_e_syntax_error);
  1038. RecoverConsume(false);
  1039. end;
  1040. end;
  1041. until false;
  1042. { Check LocalLabelList }
  1043. LocalLabelList.CheckEmitted;
  1044. LocalLabelList.Free;
  1045. { are we back in the code section? }
  1046. if lasTSec<>sec_code then
  1047. begin
  1048. Message(asmr_w_assembler_code_not_returned_to_text);
  1049. curList.Concat(Tai_section.Create(sec_code));
  1050. end;
  1051. { Return the list in an asmnode }
  1052. assemble:=curlist;
  1053. Message1(asmr_d_finish_reading,'GNU AS');
  1054. end;
  1055. {*****************************************************************************
  1056. Parsing Helpers
  1057. *****************************************************************************}
  1058. Procedure tattreader.BuildRecordOffsetSize(const expr: string;var offset:longint;var size:longint);
  1059. { Description: This routine builds up a record offset after a AS_DOT }
  1060. { token is encountered. }
  1061. { On entry actasmtoken should be equal to AS_DOT }
  1062. var
  1063. s : string;
  1064. Begin
  1065. offset:=0;
  1066. size:=0;
  1067. s:=expr;
  1068. while (actasmtoken=AS_DOT) do
  1069. begin
  1070. Consume(AS_DOT);
  1071. if actasmtoken=AS_ID then
  1072. s:=s+'.'+actasmpattern;
  1073. if not Consume(AS_ID) then
  1074. begin
  1075. RecoverConsume(true);
  1076. break;
  1077. end;
  1078. end;
  1079. if not GetRecordOffsetSize(s,offset,size) then
  1080. Message(asmr_e_building_record_offset);
  1081. end;
  1082. procedure tattreader.BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:longint;var asmsym:string);
  1083. var
  1084. hs,tempstr,expr : string;
  1085. parenlevel,l,k : longint;
  1086. errorflag : boolean;
  1087. prevtok : tasmtoken;
  1088. sym : tsym;
  1089. srsymtable : tsymtable;
  1090. hl : tasmlabel;
  1091. Begin
  1092. asmsym:='';
  1093. value:=0;
  1094. errorflag:=FALSE;
  1095. tempstr:='';
  1096. expr:='';
  1097. parenlevel:=0;
  1098. Repeat
  1099. Case actasmtoken of
  1100. AS_LPAREN:
  1101. Begin
  1102. { Exit if ref? }
  1103. if allowref and (prevasmtoken in [AS_INTNUM,AS_ID]) then
  1104. break;
  1105. Consume(AS_LPAREN);
  1106. expr:=expr + '(';
  1107. inc(parenlevel);
  1108. end;
  1109. AS_RBRACKET:
  1110. begin
  1111. if betweenbracket then
  1112. break;
  1113. { write error only once. }
  1114. if not errorflag then
  1115. Message(asmr_e_invalid_constant_expression);
  1116. { consume tokens until we find COMMA or SEPARATOR }
  1117. Consume(actasmtoken);
  1118. errorflag:=TRUE;
  1119. end;
  1120. AS_RPAREN:
  1121. Begin
  1122. { end of ref ? }
  1123. if (parenlevel=0) and betweenbracket then
  1124. break;
  1125. Consume(AS_RPAREN);
  1126. expr:=expr + ')';
  1127. dec(parenlevel);
  1128. end;
  1129. AS_SHL:
  1130. Begin
  1131. Consume(AS_SHL);
  1132. expr:=expr + '<';
  1133. end;
  1134. AS_SHR:
  1135. Begin
  1136. Consume(AS_SHR);
  1137. expr:=expr + '>';
  1138. end;
  1139. AS_SLASH:
  1140. Begin
  1141. Consume(AS_SLASH);
  1142. expr:=expr + '/';
  1143. end;
  1144. AS_MOD:
  1145. Begin
  1146. Consume(AS_MOD);
  1147. expr:=expr + '%';
  1148. end;
  1149. AS_STAR:
  1150. Begin
  1151. Consume(AS_STAR);
  1152. expr:=expr + '*';
  1153. end;
  1154. AS_PLUS:
  1155. Begin
  1156. Consume(AS_PLUS);
  1157. expr:=expr + '+';
  1158. end;
  1159. AS_MINUS:
  1160. Begin
  1161. Consume(AS_MINUS);
  1162. expr:=expr + '-';
  1163. end;
  1164. AS_AND:
  1165. Begin
  1166. Consume(AS_AND);
  1167. expr:=expr + '&';
  1168. end;
  1169. AS_NOT:
  1170. Begin
  1171. Consume(AS_NOT);
  1172. expr:=expr + '~';
  1173. end;
  1174. AS_XOR:
  1175. Begin
  1176. Consume(AS_XOR);
  1177. expr:=expr + '^';
  1178. end;
  1179. AS_OR:
  1180. Begin
  1181. Consume(AS_OR);
  1182. expr:=expr + '|';
  1183. end;
  1184. AS_INTNUM:
  1185. Begin
  1186. expr:=expr + actasmpattern;
  1187. Consume(AS_INTNUM);
  1188. end;
  1189. AS_DOLLAR:
  1190. begin
  1191. Consume(AS_DOLLAR);
  1192. if actasmtoken<>AS_ID then
  1193. Message(asmr_e_dollar_without_identifier);
  1194. end;
  1195. AS_STRING:
  1196. Begin
  1197. l:=0;
  1198. case Length(actasmpattern) of
  1199. 1 :
  1200. l:=ord(actasmpattern[1]);
  1201. 2 :
  1202. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  1203. 3 :
  1204. l:=ord(actasmpattern[3]) +
  1205. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  1206. 4 :
  1207. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  1208. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  1209. else
  1210. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  1211. end;
  1212. str(l, tempstr);
  1213. expr:=expr + tempstr;
  1214. Consume(AS_STRING);
  1215. end;
  1216. AS_TYPE:
  1217. begin
  1218. l:=0;
  1219. Consume(AS_TYPE);
  1220. if actasmtoken<>AS_ID then
  1221. Message(asmr_e_type_without_identifier)
  1222. else
  1223. begin
  1224. tempstr:=actasmpattern;
  1225. Consume(AS_ID);
  1226. if actasmtoken=AS_DOT then
  1227. BuildRecordOffsetSize(tempstr,k,l)
  1228. else
  1229. begin
  1230. searchsym(tempstr,sym,srsymtable);
  1231. if assigned(sym) then
  1232. begin
  1233. case sym.typ of
  1234. varsym :
  1235. l:=tvarsym(sym).getsize;
  1236. typedconstsym :
  1237. l:=ttypedconstsym(sym).getsize;
  1238. typesym :
  1239. l:=ttypesym(sym).restype.def.size;
  1240. else
  1241. Message(asmr_e_wrong_sym_type);
  1242. end;
  1243. end
  1244. else
  1245. Message1(sym_e_unknown_id,tempstr);
  1246. end;
  1247. end;
  1248. str(l, tempstr);
  1249. expr:=expr + tempstr;
  1250. end;
  1251. AS_ID:
  1252. Begin
  1253. hs:='';
  1254. tempstr:=actasmpattern;
  1255. prevtok:=prevasmtoken;
  1256. consume(AS_ID);
  1257. if SearchIConstant(tempstr,l) then
  1258. begin
  1259. str(l, tempstr);
  1260. expr:=expr + tempstr;
  1261. end
  1262. else
  1263. begin
  1264. if is_locallabel(tempstr) then
  1265. begin
  1266. CreateLocalLabel(tempstr,hl,false);
  1267. hs:=hl.name
  1268. end
  1269. else
  1270. if SearchLabel(tempstr,hl,false) then
  1271. hs:=hl.name
  1272. else
  1273. begin
  1274. searchsym(tempstr,sym,srsymtable);
  1275. if assigned(sym) then
  1276. begin
  1277. case sym.typ of
  1278. varsym :
  1279. begin
  1280. if sym.owner.symtabletype in [localsymtable,parasymtable] then
  1281. Message(asmr_e_no_local_or_para_allowed);
  1282. hs:=tvarsym(sym).mangledname;
  1283. end;
  1284. typedconstsym :
  1285. hs:=ttypedconstsym(sym).mangledname;
  1286. procsym :
  1287. begin
  1288. if Tprocsym(sym).procdef_count>1 then
  1289. Message(asmr_w_calling_overload_func);
  1290. hs:=tprocsym(sym).first_procdef.mangledname;
  1291. end;
  1292. typesym :
  1293. begin
  1294. if not(ttypesym(sym).restype.def.deftype in [recorddef,objectdef]) then
  1295. Message(asmr_e_wrong_sym_type);
  1296. end;
  1297. else
  1298. Message(asmr_e_wrong_sym_type);
  1299. end;
  1300. end
  1301. else
  1302. Message1(sym_e_unknown_id,tempstr);
  1303. end;
  1304. { symbol found? }
  1305. if hs<>'' then
  1306. begin
  1307. if needofs and (prevtok<>AS_DOLLAR) then
  1308. Message(asmr_e_need_dollar);
  1309. if asmsym='' then
  1310. asmsym:=hs
  1311. else
  1312. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1313. if (expr='') or (expr[length(expr)]='+') then
  1314. begin
  1315. { don't remove the + if there could be a record field }
  1316. if actasmtoken<>AS_DOT then
  1317. delete(expr,length(expr),1);
  1318. end
  1319. else
  1320. Message(asmr_e_only_add_relocatable_symbol);
  1321. end;
  1322. if actasmtoken=AS_DOT then
  1323. begin
  1324. BuildRecordOffsetSize(tempstr,l,k);
  1325. str(l, tempstr);
  1326. expr:=expr + tempstr;
  1327. end
  1328. else
  1329. begin
  1330. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1331. delete(expr,length(expr),1);
  1332. end;
  1333. end;
  1334. { check if there are wrong operator used like / or mod etc. }
  1335. if (hs<>'') and
  1336. not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,
  1337. AS_LPAREN,AS_RPAREN,AS_RBRACKET,AS_END]) then
  1338. Message(asmr_e_only_add_relocatable_symbol);
  1339. end;
  1340. AS_END,
  1341. AS_SEPARATOR,
  1342. AS_COMMA:
  1343. break;
  1344. else
  1345. Begin
  1346. { write error only once. }
  1347. if not errorflag then
  1348. Message(asmr_e_invalid_constant_expression);
  1349. { consume tokens until we find COMMA or SEPARATOR }
  1350. Consume(actasmtoken);
  1351. errorflag:=TRUE;
  1352. end;
  1353. end;
  1354. Until false;
  1355. { calculate expression }
  1356. if not ErrorFlag then
  1357. value:=CalculateExpression(expr)
  1358. else
  1359. value:=0;
  1360. end;
  1361. function tattreader.BuildConstExpression(allowref,betweenbracket:boolean): longint;
  1362. var
  1363. l : longint;
  1364. hs : string;
  1365. begin
  1366. BuildConstSymbolExpression(allowref,betweenbracket,false,l,hs);
  1367. if hs<>'' then
  1368. Message(asmr_e_relocatable_symbol_not_allowed);
  1369. BuildConstExpression:=l;
  1370. end;
  1371. Procedure tattreader.BuildConstantOperand(oper : toperand);
  1372. var
  1373. l : longint;
  1374. tempstr : string;
  1375. begin
  1376. BuildConstSymbolExpression(false,false,true,l,tempstr);
  1377. if tempstr<>'' then
  1378. begin
  1379. oper.opr.typ:=OPR_SYMBOL;
  1380. oper.opr.symofs:=l;
  1381. oper.opr.symbol:=objectlibrary.newasmsymbol(tempstr);
  1382. end
  1383. else
  1384. begin
  1385. oper.opr.typ:=OPR_CONSTANT;
  1386. oper.opr.val:=l;
  1387. end;
  1388. end;
  1389. end.
  1390. {
  1391. $Log$
  1392. Revision 1.8 2003-12-25 01:25:43 peter
  1393. * sparc assembler reader updates
  1394. Revision 1.7 2003/12/08 17:43:57 florian
  1395. * fixed ldm/stm arm assembler reading
  1396. * fixed a_load_reg_reg with OS_8 on ARM
  1397. * non supported calling conventions cause only a warning now
  1398. Revision 1.6 2003/12/07 14:03:37 jonas
  1399. * go to the next character after consuming a "%"
  1400. Revision 1.5 2003/12/03 17:39:04 florian
  1401. * fixed several arm calling conventions issues
  1402. * fixed reference reading in the assembler reader
  1403. * fixed a_loadaddr_ref_reg
  1404. Revision 1.4 2003/11/29 16:27:19 jonas
  1405. * fixed several ppc assembler reader related problems
  1406. * local vars in assembler procedures now start at offset 4
  1407. * fixed second_int_to_bool (apparently an integer can be in LOC_JUMP??)
  1408. Revision 1.3 2003/11/17 23:23:47 florian
  1409. + first part of arm assembler reader
  1410. Revision 1.2 2003/11/15 19:00:10 florian
  1411. * fixed ppc assembler reader
  1412. Revision 1.1 2003/11/12 16:05:39 florian
  1413. * assembler readers OOPed
  1414. + typed currency constants
  1415. + typed 128 bit float constants if the CPU supports it
  1416. }