raatt.pas 47 KB

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