raatt.pas 49 KB

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