raatt.pas 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  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(constsize: longint);
  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);
  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 is_register(actasmpattern) then
  327. begin
  328. actasmtoken:=AS_REGISTER;
  329. exit;
  330. end;
  331. { if next is a '.' and this is a unitsym then we also need to
  332. parse the identifier }
  333. if (c='.') then
  334. begin
  335. searchsym(actasmpattern,srsym,srsymtable);
  336. if assigned(srsym) and
  337. (srsym.typ=unitsym) and
  338. (srsym.owner.unitid=0) then
  339. begin
  340. actasmpattern:=actasmpattern+c;
  341. c:=current_scanner.asmgetchar;
  342. while c in ['A'..'Z','a'..'z','0'..'9','_','$'] do
  343. begin
  344. actasmpattern:=actasmpattern + upcase(c);
  345. c:=current_scanner.asmgetchar;
  346. end;
  347. end;
  348. end;
  349. actasmtoken:=AS_ID;
  350. exit;
  351. end;
  352. '%' : { register or modulo }
  353. handlepercent;
  354. '1'..'9': { integer number }
  355. begin
  356. len:=0;
  357. while c in ['0'..'9'] do
  358. Begin
  359. inc(len);
  360. actasmpattern[len]:=c;
  361. c:=current_scanner.asmgetchar;
  362. end;
  363. actasmpattern[0]:=chr(len);
  364. actasmpattern:=tostr(ValDecimal(actasmpattern));
  365. actasmtoken:=AS_INTNUM;
  366. exit;
  367. end;
  368. '0' : { octal,hexa,real or binary number. }
  369. begin
  370. actasmpattern:=c;
  371. c:=current_scanner.asmgetchar;
  372. case upcase(c) of
  373. 'B': { binary }
  374. Begin
  375. c:=current_scanner.asmgetchar;
  376. while c in ['0','1'] do
  377. Begin
  378. actasmpattern:=actasmpattern + c;
  379. c:=current_scanner.asmgetchar;
  380. end;
  381. actasmpattern:=tostr(ValBinary(actasmpattern));
  382. actasmtoken:=AS_INTNUM;
  383. exit;
  384. end;
  385. 'D': { real }
  386. Begin
  387. c:=current_scanner.asmgetchar;
  388. { get ridd of the 0d }
  389. if (c in ['+','-']) then
  390. begin
  391. actasmpattern:=c;
  392. c:=current_scanner.asmgetchar;
  393. end
  394. else
  395. actasmpattern:='';
  396. while c in ['0'..'9'] do
  397. Begin
  398. actasmpattern:=actasmpattern + c;
  399. c:=current_scanner.asmgetchar;
  400. end;
  401. if c='.' then
  402. begin
  403. actasmpattern:=actasmpattern + c;
  404. c:=current_scanner.asmgetchar;
  405. while c in ['0'..'9'] do
  406. Begin
  407. actasmpattern:=actasmpattern + c;
  408. c:=current_scanner.asmgetchar;
  409. end;
  410. if upcase(c) = 'E' then
  411. begin
  412. actasmpattern:=actasmpattern + c;
  413. c:=current_scanner.asmgetchar;
  414. if (c in ['+','-']) then
  415. begin
  416. actasmpattern:=actasmpattern + c;
  417. c:=current_scanner.asmgetchar;
  418. end;
  419. while c in ['0'..'9'] do
  420. Begin
  421. actasmpattern:=actasmpattern + c;
  422. c:=current_scanner.asmgetchar;
  423. end;
  424. end;
  425. actasmtoken:=AS_REALNUM;
  426. exit;
  427. end
  428. else
  429. begin
  430. Message1(asmr_e_invalid_float_const,actasmpattern+c);
  431. actasmtoken:=AS_NONE;
  432. end;
  433. end;
  434. 'X': { hexadecimal }
  435. Begin
  436. c:=current_scanner.asmgetchar;
  437. while c in ['0'..'9','a'..'f','A'..'F'] do
  438. Begin
  439. actasmpattern:=actasmpattern + c;
  440. c:=current_scanner.asmgetchar;
  441. end;
  442. actasmpattern:=tostr(ValHexaDecimal(actasmpattern));
  443. actasmtoken:=AS_INTNUM;
  444. exit;
  445. end;
  446. '1'..'7': { octal }
  447. begin
  448. actasmpattern:=actasmpattern + c;
  449. while c in ['0'..'7'] do
  450. Begin
  451. actasmpattern:=actasmpattern + c;
  452. c:=current_scanner.asmgetchar;
  453. end;
  454. actasmpattern:=tostr(ValOctal(actasmpattern));
  455. actasmtoken:=AS_INTNUM;
  456. exit;
  457. end;
  458. else { octal number zero value...}
  459. Begin
  460. actasmpattern:=tostr(ValOctal(actasmpattern));
  461. actasmtoken:=AS_INTNUM;
  462. exit;
  463. end;
  464. end; { end case }
  465. end;
  466. '&' :
  467. begin
  468. c:=current_scanner.asmgetchar;
  469. actasmtoken:=AS_AND;
  470. end;
  471. '''' : { char }
  472. begin
  473. current_scanner.in_asm_string:=true;
  474. actasmpattern:='';
  475. repeat
  476. c:=current_scanner.asmgetchar;
  477. case c of
  478. '\' :
  479. begin
  480. { copy also the next char so \" is parsed correctly }
  481. actasmpattern:=actasmpattern+c;
  482. c:=current_scanner.asmgetchar;
  483. actasmpattern:=actasmpattern+c;
  484. end;
  485. '''' :
  486. begin
  487. c:=current_scanner.asmgetchar;
  488. break;
  489. end;
  490. #10,#13:
  491. Message(scan_f_string_exceeds_line);
  492. else
  493. actasmpattern:=actasmpattern+c;
  494. end;
  495. until false;
  496. actasmpattern:=EscapeToPascal(actasmpattern);
  497. actasmtoken:=AS_STRING;
  498. current_scanner.in_asm_string:=false;
  499. exit;
  500. end;
  501. '"' : { string }
  502. begin
  503. current_scanner.in_asm_string:=true;
  504. actasmpattern:='';
  505. repeat
  506. c:=current_scanner.asmgetchar;
  507. case c of
  508. '\' :
  509. begin
  510. { copy also the next char so \" is parsed correctly }
  511. actasmpattern:=actasmpattern+c;
  512. c:=current_scanner.asmgetchar;
  513. actasmpattern:=actasmpattern+c;
  514. end;
  515. '"' :
  516. begin
  517. c:=current_scanner.asmgetchar;
  518. break;
  519. end;
  520. #10,#13:
  521. Message(scan_f_string_exceeds_line);
  522. else
  523. actasmpattern:=actasmpattern+c;
  524. end;
  525. until false;
  526. actasmpattern:=EscapeToPascal(actasmpattern);
  527. actasmtoken:=AS_STRING;
  528. current_scanner.in_asm_string:=false;
  529. exit;
  530. end;
  531. '$' :
  532. begin
  533. actasmtoken:=AS_DOLLAR;
  534. c:=current_scanner.asmgetchar;
  535. exit;
  536. end;
  537. '#' :
  538. begin
  539. actasmtoken:=AS_HASH;
  540. c:=current_scanner.asmgetchar;
  541. exit;
  542. end;
  543. '[' :
  544. begin
  545. actasmtoken:=AS_LBRACKET;
  546. c:=current_scanner.asmgetchar;
  547. exit;
  548. end;
  549. ']' :
  550. begin
  551. actasmtoken:=AS_RBRACKET;
  552. c:=current_scanner.asmgetchar;
  553. exit;
  554. end;
  555. {$ifdef arm}
  556. // the arm assembler uses { ... } for register sets
  557. '{' :
  558. begin
  559. actasmtoken:=AS_LSBRACKET;
  560. c:=current_scanner.asmgetchar;
  561. exit;
  562. end;
  563. '}' :
  564. begin
  565. actasmtoken:=AS_RSBRACKET;
  566. c:=current_scanner.asmgetchar;
  567. exit;
  568. end;
  569. {$endif arm}
  570. ',' :
  571. begin
  572. actasmtoken:=AS_COMMA;
  573. c:=current_scanner.asmgetchar;
  574. exit;
  575. end;
  576. '<' :
  577. begin
  578. actasmtoken:=AS_SHL;
  579. c:=current_scanner.asmgetchar;
  580. if c = '<' then
  581. c:=current_scanner.asmgetchar;
  582. exit;
  583. end;
  584. '>' :
  585. begin
  586. actasmtoken:=AS_SHL;
  587. c:=current_scanner.asmgetchar;
  588. if c = '>' then
  589. c:=current_scanner.asmgetchar;
  590. exit;
  591. end;
  592. '|' :
  593. begin
  594. actasmtoken:=AS_OR;
  595. c:=current_scanner.asmgetchar;
  596. exit;
  597. end;
  598. '^' :
  599. begin
  600. actasmtoken:=AS_XOR;
  601. c:=current_scanner.asmgetchar;
  602. exit;
  603. end;
  604. '(' :
  605. begin
  606. actasmtoken:=AS_LPAREN;
  607. c:=current_scanner.asmgetchar;
  608. exit;
  609. end;
  610. ')' :
  611. begin
  612. actasmtoken:=AS_RPAREN;
  613. c:=current_scanner.asmgetchar;
  614. exit;
  615. end;
  616. ':' :
  617. begin
  618. actasmtoken:=AS_COLON;
  619. c:=current_scanner.asmgetchar;
  620. exit;
  621. end;
  622. '+' :
  623. begin
  624. actasmtoken:=AS_PLUS;
  625. c:=current_scanner.asmgetchar;
  626. exit;
  627. end;
  628. '-' :
  629. begin
  630. actasmtoken:=AS_MINUS;
  631. c:=current_scanner.asmgetchar;
  632. exit;
  633. end;
  634. '*' :
  635. begin
  636. actasmtoken:=AS_STAR;
  637. c:=current_scanner.asmgetchar;
  638. exit;
  639. end;
  640. '/' :
  641. begin
  642. actasmtoken:=AS_SLASH;
  643. c:=current_scanner.asmgetchar;
  644. exit;
  645. end;
  646. '!' :
  647. begin
  648. actasmtoken:=AS_NOT;
  649. c:=current_scanner.asmgetchar;
  650. exit;
  651. end;
  652. '@' :
  653. begin
  654. actasmtoken:=AS_AT;
  655. c:=current_scanner.asmgetchar;
  656. exit;
  657. end;
  658. {$ifndef arm}
  659. '{',
  660. {$endif arm}
  661. #13,#10,';' :
  662. begin
  663. { the comment is read by asmgetchar }
  664. c:=current_scanner.asmgetchar;
  665. firsttoken:=TRUE;
  666. actasmtoken:=AS_SEPARATOR;
  667. exit;
  668. end;
  669. else
  670. current_scanner.illegal_char(c);
  671. end;
  672. end;
  673. end;
  674. function tattreader.consume(t : tasmtoken):boolean;
  675. begin
  676. Consume:=true;
  677. if t<>actasmtoken then
  678. begin
  679. Message2(scan_f_syn_expected,token2str[t],token2str[actasmtoken]);
  680. Consume:=false;
  681. end;
  682. repeat
  683. gettoken;
  684. until actasmtoken<>AS_NONE;
  685. end;
  686. procedure tattreader.RecoverConsume(allowcomma:boolean);
  687. begin
  688. While not (actasmtoken in [AS_SEPARATOR,AS_END]) do
  689. begin
  690. if allowcomma and (actasmtoken=AS_COMMA) then
  691. break;
  692. Consume(actasmtoken);
  693. end;
  694. end;
  695. Procedure tattreader.BuildConstant(constsize: longint);
  696. var
  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_NOT,
  723. AS_ID :
  724. Begin
  725. BuildConstSymbolExpression(false,false,false,value,asmsym);
  726. if asmsym<>'' then
  727. begin
  728. if constsize<>sizeof(aint) then
  729. Message(asmr_w_32bit_const_for_address);
  730. ConcatConstSymbol(curlist,asmsym,value)
  731. end
  732. else
  733. ConcatConstant(curlist,value,constsize);
  734. end;
  735. AS_COMMA:
  736. Consume(AS_COMMA);
  737. AS_END,
  738. AS_SEPARATOR:
  739. break;
  740. else
  741. begin
  742. Message(asmr_e_syn_constant);
  743. RecoverConsume(false);
  744. end
  745. end; { end case }
  746. Until false;
  747. end;
  748. Procedure tattreader.BuildRealConstant(typ : tfloattype);
  749. var
  750. expr : string;
  751. r : bestreal;
  752. code : integer;
  753. negativ : boolean;
  754. errorflag: boolean;
  755. Begin
  756. errorflag:=FALSE;
  757. Repeat
  758. negativ:=false;
  759. expr:='';
  760. if actasmtoken=AS_PLUS then
  761. Consume(AS_PLUS)
  762. else
  763. if actasmtoken=AS_MINUS then
  764. begin
  765. negativ:=true;
  766. consume(AS_MINUS);
  767. end;
  768. Case actasmtoken of
  769. AS_INTNUM:
  770. Begin
  771. expr:=actasmpattern;
  772. Consume(AS_INTNUM);
  773. if negativ then
  774. expr:='-'+expr;
  775. val(expr,r,code);
  776. if code<>0 then
  777. Begin
  778. r:=0;
  779. Message(asmr_e_invalid_float_expr);
  780. End;
  781. ConcatRealConstant(curlist,r,typ);
  782. end;
  783. AS_REALNUM:
  784. Begin
  785. expr:=actasmpattern;
  786. Consume(AS_REALNUM);
  787. { in ATT syntax you have 0d in front of the real }
  788. { should this be forced ? yes i think so, as to }
  789. { conform to gas as much as possible. }
  790. if (expr[1]='0') and (upper(expr[2])='D') then
  791. Delete(expr,1,2);
  792. if negativ then
  793. expr:='-'+expr;
  794. val(expr,r,code);
  795. if code<>0 then
  796. Begin
  797. r:=0;
  798. Message(asmr_e_invalid_float_expr);
  799. End;
  800. ConcatRealConstant(curlist,r,typ);
  801. end;
  802. AS_COMMA:
  803. begin
  804. Consume(AS_COMMA);
  805. end;
  806. AS_END,
  807. AS_SEPARATOR:
  808. begin
  809. break;
  810. end;
  811. else
  812. Begin
  813. Consume(actasmtoken);
  814. if not errorflag then
  815. Message(asmr_e_invalid_float_expr);
  816. errorflag:=TRUE;
  817. end;
  818. end;
  819. Until false;
  820. end;
  821. Procedure tattreader.BuildStringConstant(asciiz: boolean);
  822. var
  823. expr: string;
  824. errorflag : boolean;
  825. Begin
  826. errorflag:=FALSE;
  827. Repeat
  828. Case actasmtoken of
  829. AS_STRING:
  830. Begin
  831. expr:=actasmpattern;
  832. if asciiz then
  833. expr:=expr+#0;
  834. ConcatPasString(curlist,expr);
  835. Consume(AS_STRING);
  836. end;
  837. AS_COMMA:
  838. begin
  839. Consume(AS_COMMA);
  840. end;
  841. AS_END,
  842. AS_SEPARATOR:
  843. begin
  844. break;
  845. end;
  846. else
  847. Begin
  848. Consume(actasmtoken);
  849. if not errorflag then
  850. Message(asmr_e_invalid_string_expression);
  851. errorflag:=TRUE;
  852. end;
  853. end;
  854. Until false;
  855. end;
  856. Function tattreader.Assemble: tlinkedlist;
  857. Var
  858. hl : tasmlabel;
  859. commname : string;
  860. lasTSec : TAsmSectionType;
  861. l1,l2 : longint;
  862. Begin
  863. Message1(asmr_d_start_reading,'GNU AS');
  864. firsttoken:=TRUE;
  865. { sets up all opcode and register tables in uppercase }
  866. if not _asmsorted then
  867. Begin
  868. SetupTables;
  869. _asmsorted:=TRUE;
  870. end;
  871. curlist:=TAAsmoutput.Create;
  872. lasTSec:=sec_code;
  873. { setup label linked list }
  874. LocalLabelList:=TLocalLabelList.Create;
  875. { start tokenizer }
  876. c:=current_scanner.asmgetcharstart;
  877. gettoken;
  878. { main loop }
  879. repeat
  880. case actasmtoken of
  881. AS_LLABEL:
  882. Begin
  883. if CreateLocalLabel(actasmpattern,hl,true) then
  884. ConcatLabel(curlist,hl);
  885. Consume(AS_LLABEL);
  886. end;
  887. AS_LABEL:
  888. Begin
  889. if SearchLabel(upper(actasmpattern),hl,true) then
  890. ConcatLabel(curlist,hl)
  891. else
  892. Message1(asmr_e_unknown_label_identifier,actasmpattern);
  893. Consume(AS_LABEL);
  894. end;
  895. AS_DW:
  896. Begin
  897. Consume(AS_DW);
  898. BuildConstant(2);
  899. end;
  900. AS_DATA:
  901. Begin
  902. new_section(curList,sec_data,lower(current_procinfo.procdef.mangledname),0);
  903. lasTSec:=sec_data;
  904. Consume(AS_DATA);
  905. end;
  906. AS_TEXT:
  907. Begin
  908. new_section(curList,sec_code,lower(current_procinfo.procdef.mangledname),0);
  909. lasTSec:=sec_code;
  910. Consume(AS_TEXT);
  911. end;
  912. AS_DB:
  913. Begin
  914. Consume(AS_DB);
  915. BuildConstant(1);
  916. end;
  917. AS_DD:
  918. Begin
  919. Consume(AS_DD);
  920. BuildConstant(4);
  921. end;
  922. AS_DQ:
  923. Begin
  924. Consume(AS_DQ);
  925. {$ifdef cpu64bit}
  926. BuildConstant(8);
  927. {$else cpu64bit}
  928. BuildRealConstant(s64comp);
  929. {$endif cpu64bit}
  930. end;
  931. AS_SINGLE:
  932. Begin
  933. Consume(AS_SINGLE);
  934. BuildRealConstant(s32real);
  935. end;
  936. AS_DOUBLE:
  937. Begin
  938. Consume(AS_DOUBLE);
  939. BuildRealConstant(s64real);
  940. end;
  941. AS_EXTENDED:
  942. Begin
  943. Consume(AS_EXTENDED);
  944. BuildRealConstant(s80real);
  945. end;
  946. AS_GLOBAL:
  947. Begin
  948. Consume(AS_GLOBAL);
  949. if actasmtoken=AS_ID then
  950. ConcatPublic(curlist,actasmpattern);
  951. Consume(AS_ID);
  952. if actasmtoken<>AS_SEPARATOR then
  953. Consume(AS_SEPARATOR);
  954. end;
  955. AS_ALIGN:
  956. Begin
  957. Consume(AS_ALIGN);
  958. l1:=BuildConstExpression(false,false);
  959. if (target_info.system in [system_i386_GO32V2]) then
  960. begin
  961. l2:=1;
  962. if (l1>=0) and (l1<=16) then
  963. while (l1>0) do
  964. begin
  965. l2:=2*l2;
  966. dec(l1);
  967. end;
  968. l1:=l2;
  969. end;
  970. ConcatAlign(curlist,l1);
  971. Message(asmr_n_align_is_target_specific);
  972. if actasmtoken<>AS_SEPARATOR then
  973. Consume(AS_SEPARATOR);
  974. end;
  975. AS_BALIGN:
  976. Begin
  977. Consume(AS_BALIGN);
  978. ConcatAlign(curlist,BuildConstExpression(false,false));
  979. if actasmtoken<>AS_SEPARATOR then
  980. Consume(AS_SEPARATOR);
  981. end;
  982. AS_P2ALIGN:
  983. Begin
  984. Consume(AS_P2ALIGN);
  985. l1:=BuildConstExpression(false,false);
  986. l2:=1;
  987. if (l1>=0) and (l1<=16) then
  988. while (l1>0) do
  989. begin
  990. l2:=2*l2;
  991. dec(l1);
  992. end;
  993. l1:=l2;
  994. ConcatAlign(curlist,l1);
  995. if actasmtoken<>AS_SEPARATOR then
  996. Consume(AS_SEPARATOR);
  997. end;
  998. AS_ASCIIZ:
  999. Begin
  1000. Consume(AS_ASCIIZ);
  1001. BuildStringConstant(TRUE);
  1002. end;
  1003. AS_ASCII:
  1004. Begin
  1005. Consume(AS_ASCII);
  1006. BuildStringConstant(FALSE);
  1007. end;
  1008. AS_LCOMM:
  1009. Begin
  1010. Consume(AS_LCOMM);
  1011. commname:=actasmpattern;
  1012. Consume(AS_ID);
  1013. Consume(AS_COMMA);
  1014. ConcatLocalBss(commname,BuildConstExpression(false,false));
  1015. if actasmtoken<>AS_SEPARATOR then
  1016. Consume(AS_SEPARATOR);
  1017. end;
  1018. AS_COMM:
  1019. Begin
  1020. Consume(AS_COMM);
  1021. commname:=actasmpattern;
  1022. Consume(AS_ID);
  1023. Consume(AS_COMMA);
  1024. ConcatGlobalBss(commname,BuildConstExpression(false,false));
  1025. if actasmtoken<>AS_SEPARATOR then
  1026. Consume(AS_SEPARATOR);
  1027. end;
  1028. AS_OPCODE:
  1029. Begin
  1030. HandleOpCode;
  1031. end;
  1032. AS_SEPARATOR:
  1033. Begin
  1034. Consume(AS_SEPARATOR);
  1035. end;
  1036. AS_END:
  1037. begin
  1038. break; { end assembly block }
  1039. end;
  1040. else
  1041. Begin
  1042. Message(asmr_e_syntax_error);
  1043. RecoverConsume(false);
  1044. end;
  1045. end;
  1046. until false;
  1047. { Check LocalLabelList }
  1048. LocalLabelList.CheckEmitted;
  1049. LocalLabelList.Free;
  1050. { are we back in the code section? }
  1051. if lasTSec<>sec_code then
  1052. begin
  1053. Message(asmr_w_assembler_code_not_returned_to_text);
  1054. new_section(curList,sec_code,lower(current_procinfo.procdef.mangledname),0);
  1055. end;
  1056. { Return the list in an asmnode }
  1057. assemble:=curlist;
  1058. Message1(asmr_d_finish_reading,'GNU AS');
  1059. end;
  1060. {*****************************************************************************
  1061. Parsing Helpers
  1062. *****************************************************************************}
  1063. Procedure tattreader.BuildRecordOffsetSize(const expr: string;var offset:aint;var size:aint);
  1064. { Description: This routine builds up a record offset after a AS_DOT }
  1065. { token is encountered. }
  1066. { On entry actasmtoken should be equal to AS_DOT }
  1067. var
  1068. s : string;
  1069. Begin
  1070. offset:=0;
  1071. size:=0;
  1072. s:=expr;
  1073. while (actasmtoken=AS_DOT) do
  1074. begin
  1075. Consume(AS_DOT);
  1076. if actasmtoken=AS_ID then
  1077. s:=s+'.'+actasmpattern;
  1078. if not Consume(AS_ID) then
  1079. begin
  1080. RecoverConsume(true);
  1081. break;
  1082. end;
  1083. end;
  1084. if not GetRecordOffsetSize(s,offset,size) then
  1085. Message(asmr_e_building_record_offset);
  1086. end;
  1087. procedure tattreader.BuildConstSymbolExpression(allowref,betweenbracket,needofs:boolean;var value:aint;var asmsym:string);
  1088. var
  1089. hs,tempstr,expr : string;
  1090. parenlevel : longint;
  1091. l,k : aint;
  1092. errorflag : boolean;
  1093. prevtok : tasmtoken;
  1094. sym : tsym;
  1095. srsymtable : tsymtable;
  1096. hl : tasmlabel;
  1097. Begin
  1098. asmsym:='';
  1099. value:=0;
  1100. errorflag:=FALSE;
  1101. tempstr:='';
  1102. expr:='';
  1103. parenlevel:=0;
  1104. Repeat
  1105. Case actasmtoken of
  1106. AS_LPAREN:
  1107. Begin
  1108. { Exit if ref? }
  1109. if allowref and (prevasmtoken in [AS_INTNUM,AS_ID]) then
  1110. break;
  1111. Consume(AS_LPAREN);
  1112. expr:=expr + '(';
  1113. inc(parenlevel);
  1114. end;
  1115. AS_RBRACKET:
  1116. begin
  1117. if betweenbracket then
  1118. break;
  1119. { write error only once. }
  1120. if not errorflag then
  1121. Message(asmr_e_invalid_constant_expression);
  1122. { consume tokens until we find COMMA or SEPARATOR }
  1123. Consume(actasmtoken);
  1124. errorflag:=TRUE;
  1125. end;
  1126. AS_RPAREN:
  1127. Begin
  1128. { end of ref ? }
  1129. if (parenlevel=0) and betweenbracket then
  1130. break;
  1131. Consume(AS_RPAREN);
  1132. expr:=expr + ')';
  1133. dec(parenlevel);
  1134. end;
  1135. AS_SHL:
  1136. Begin
  1137. Consume(AS_SHL);
  1138. expr:=expr + '<';
  1139. end;
  1140. AS_SHR:
  1141. Begin
  1142. Consume(AS_SHR);
  1143. expr:=expr + '>';
  1144. end;
  1145. AS_SLASH:
  1146. Begin
  1147. Consume(AS_SLASH);
  1148. expr:=expr + '/';
  1149. end;
  1150. AS_MOD:
  1151. Begin
  1152. Consume(AS_MOD);
  1153. expr:=expr + '%';
  1154. end;
  1155. AS_STAR:
  1156. Begin
  1157. Consume(AS_STAR);
  1158. expr:=expr + '*';
  1159. end;
  1160. AS_PLUS:
  1161. Begin
  1162. Consume(AS_PLUS);
  1163. expr:=expr + '+';
  1164. end;
  1165. AS_MINUS:
  1166. Begin
  1167. Consume(AS_MINUS);
  1168. expr:=expr + '-';
  1169. end;
  1170. AS_AND:
  1171. Begin
  1172. Consume(AS_AND);
  1173. expr:=expr + '&';
  1174. end;
  1175. AS_NOT:
  1176. Begin
  1177. Consume(AS_NOT);
  1178. expr:=expr + '~';
  1179. end;
  1180. AS_XOR:
  1181. Begin
  1182. Consume(AS_XOR);
  1183. expr:=expr + '^';
  1184. end;
  1185. AS_OR:
  1186. Begin
  1187. Consume(AS_OR);
  1188. expr:=expr + '|';
  1189. end;
  1190. AS_INTNUM:
  1191. Begin
  1192. expr:=expr + actasmpattern;
  1193. Consume(AS_INTNUM);
  1194. end;
  1195. AS_DOLLAR:
  1196. begin
  1197. Consume(AS_DOLLAR);
  1198. if actasmtoken<>AS_ID then
  1199. Message(asmr_e_dollar_without_identifier);
  1200. end;
  1201. AS_STRING:
  1202. Begin
  1203. l:=0;
  1204. case Length(actasmpattern) of
  1205. 1 :
  1206. l:=ord(actasmpattern[1]);
  1207. 2 :
  1208. l:=ord(actasmpattern[2]) + ord(actasmpattern[1]) shl 8;
  1209. 3 :
  1210. l:=ord(actasmpattern[3]) +
  1211. Ord(actasmpattern[2]) shl 8 + ord(actasmpattern[1]) shl 16;
  1212. 4 :
  1213. l:=ord(actasmpattern[4]) + ord(actasmpattern[3]) shl 8 +
  1214. Ord(actasmpattern[2]) shl 16 + ord(actasmpattern[1]) shl 24;
  1215. else
  1216. Message1(asmr_e_invalid_string_as_opcode_operand,actasmpattern);
  1217. end;
  1218. str(l, tempstr);
  1219. expr:=expr + tempstr;
  1220. Consume(AS_STRING);
  1221. end;
  1222. AS_TYPE:
  1223. begin
  1224. l:=0;
  1225. Consume(AS_TYPE);
  1226. if actasmtoken<>AS_ID then
  1227. Message(asmr_e_type_without_identifier)
  1228. else
  1229. begin
  1230. tempstr:=actasmpattern;
  1231. Consume(AS_ID);
  1232. if actasmtoken=AS_DOT then
  1233. BuildRecordOffsetSize(tempstr,k,l)
  1234. else
  1235. begin
  1236. searchsym(tempstr,sym,srsymtable);
  1237. if assigned(sym) then
  1238. begin
  1239. case sym.typ of
  1240. varsym :
  1241. l:=tvarsym(sym).getsize;
  1242. typedconstsym :
  1243. l:=ttypedconstsym(sym).getsize;
  1244. typesym :
  1245. l:=ttypesym(sym).restype.def.size;
  1246. else
  1247. Message(asmr_e_wrong_sym_type);
  1248. end;
  1249. end
  1250. else
  1251. Message1(sym_e_unknown_id,tempstr);
  1252. end;
  1253. end;
  1254. str(l, tempstr);
  1255. expr:=expr + tempstr;
  1256. end;
  1257. AS_ID:
  1258. Begin
  1259. hs:='';
  1260. tempstr:=actasmpattern;
  1261. prevtok:=prevasmtoken;
  1262. consume(AS_ID);
  1263. if SearchIConstant(tempstr,l) then
  1264. begin
  1265. str(l, tempstr);
  1266. expr:=expr + tempstr;
  1267. end
  1268. else
  1269. begin
  1270. if is_locallabel(tempstr) then
  1271. begin
  1272. CreateLocalLabel(tempstr,hl,false);
  1273. hs:=hl.name
  1274. end
  1275. else
  1276. if SearchLabel(tempstr,hl,false) then
  1277. hs:=hl.name
  1278. else
  1279. begin
  1280. searchsym(tempstr,sym,srsymtable);
  1281. if assigned(sym) then
  1282. begin
  1283. case sym.typ of
  1284. varsym :
  1285. with Tvarsym(sym) do
  1286. begin
  1287. if owner.symtabletype in [localsymtable,parasymtable] then
  1288. Message(asmr_e_no_local_or_para_allowed);
  1289. hs:=mangledname;
  1290. end;
  1291. typedconstsym :
  1292. hs:=ttypedconstsym(sym).mangledname;
  1293. procsym :
  1294. with Tprocsym(sym) do
  1295. begin
  1296. if procdef_count>1 then
  1297. message(asmr_w_calling_overload_func);
  1298. hs:=first_procdef.mangledname;
  1299. end;
  1300. typesym :
  1301. begin
  1302. if not(ttypesym(sym).restype.def.deftype in [recorddef,objectdef]) then
  1303. Message(asmr_e_wrong_sym_type);
  1304. end;
  1305. else
  1306. Message(asmr_e_wrong_sym_type);
  1307. end;
  1308. end
  1309. else
  1310. Message1(sym_e_unknown_id,tempstr);
  1311. end;
  1312. { symbol found? }
  1313. if hs<>'' then
  1314. begin
  1315. if needofs and (prevtok<>AS_DOLLAR) then
  1316. Message(asmr_e_need_dollar);
  1317. if asmsym='' then
  1318. asmsym:=hs
  1319. else
  1320. Message(asmr_e_cant_have_multiple_relocatable_symbols);
  1321. if (expr='') or (expr[length(expr)]='+') then
  1322. begin
  1323. { don't remove the + if there could be a record field }
  1324. if actasmtoken<>AS_DOT then
  1325. delete(expr,length(expr),1);
  1326. end
  1327. else
  1328. Message(asmr_e_only_add_relocatable_symbol);
  1329. end;
  1330. if actasmtoken=AS_DOT then
  1331. begin
  1332. BuildRecordOffsetSize(tempstr,l,k);
  1333. str(l, tempstr);
  1334. expr:=expr + tempstr;
  1335. end
  1336. else
  1337. begin
  1338. if (expr='') or (expr[length(expr)] in ['+','-','/','*']) then
  1339. delete(expr,length(expr),1);
  1340. end;
  1341. end;
  1342. { check if there are wrong operator used like / or mod etc. }
  1343. if (hs<>'') and
  1344. not(actasmtoken in [AS_MINUS,AS_PLUS,AS_COMMA,AS_SEPARATOR,
  1345. AS_LPAREN,AS_RPAREN,AS_RBRACKET,AS_END]) then
  1346. Message(asmr_e_only_add_relocatable_symbol);
  1347. end;
  1348. AS_END,
  1349. AS_SEPARATOR,
  1350. AS_COMMA:
  1351. break;
  1352. else
  1353. Begin
  1354. { write error only once. }
  1355. if not errorflag then
  1356. Message(asmr_e_invalid_constant_expression);
  1357. { consume tokens until we find COMMA or SEPARATOR }
  1358. Consume(actasmtoken);
  1359. errorflag:=TRUE;
  1360. end;
  1361. end;
  1362. Until false;
  1363. { calculate expression }
  1364. if not ErrorFlag then
  1365. value:=CalculateExpression(expr)
  1366. else
  1367. value:=0;
  1368. end;
  1369. function tattreader.BuildConstExpression(allowref,betweenbracket:boolean): aint;
  1370. var
  1371. l : aint;
  1372. hs : string;
  1373. begin
  1374. BuildConstSymbolExpression(allowref,betweenbracket,false,l,hs);
  1375. if hs<>'' then
  1376. Message(asmr_e_relocatable_symbol_not_allowed);
  1377. BuildConstExpression:=l;
  1378. end;
  1379. Procedure tattreader.BuildConstantOperand(oper : toperand);
  1380. var
  1381. l : aint;
  1382. tempstr : string;
  1383. begin
  1384. BuildConstSymbolExpression(false,false,true,l,tempstr);
  1385. if tempstr<>'' then
  1386. begin
  1387. oper.opr.typ:=OPR_SYMBOL;
  1388. oper.opr.symofs:=l;
  1389. oper.opr.symbol:=objectlibrary.newasmsymbol(tempstr,AB_EXTERNAL,AT_FUNCTION);
  1390. end
  1391. else
  1392. begin
  1393. oper.opr.typ:=OPR_CONSTANT;
  1394. oper.opr.val:=l;
  1395. end;
  1396. end;
  1397. end.
  1398. {
  1399. $Log$
  1400. Revision 1.12 2004-06-20 08:55:30 florian
  1401. * logs truncated
  1402. Revision 1.11 2004/06/16 20:07:09 florian
  1403. * dwarf branch merged
  1404. Revision 1.10.2.3 2004/05/01 23:36:47 peter
  1405. * assembler reader 64bit fixes
  1406. Revision 1.10.2.2 2004/04/10 12:36:41 peter
  1407. * fixed alignment issues
  1408. Revision 1.10.2.1 2004/04/08 18:33:22 peter
  1409. * rewrite of TAsmSection
  1410. Revision 1.10 2004/03/02 00:36:33 olle
  1411. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1412. }