aggas.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by the Free Pascal team
  4. This unit implements generic GNU assembler (v2.8 or later)
  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. { Base unit for writing GNU assembler output.
  19. }
  20. unit aggas;
  21. {$i fpcdefs.inc}
  22. interface
  23. uses
  24. cclasses,
  25. globals,
  26. aasmbase,aasmtai,aasmcpu,
  27. assemble;
  28. type
  29. {# This is a derived class which is used to write
  30. GAS styled assembler.
  31. The WriteInstruction() method must be overriden
  32. to write a single instruction to the assembler
  33. file.
  34. }
  35. TGNUAssembler=class(texternalassembler)
  36. public
  37. procedure WriteTree(p:TAAsmoutput);override;
  38. procedure WriteAsmList;override;
  39. procedure WriteExtraHeader;virtual;
  40. {$ifdef GDB}
  41. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  42. procedure WriteFileEndInfo;
  43. {$endif}
  44. procedure WriteInstruction(hp: tai); virtual; abstract;
  45. end;
  46. const
  47. regname_count=45;
  48. regname_count_bsstart=32; {Largest power of 2 out of regname_count.}
  49. implementation
  50. uses
  51. {$ifdef Delphi}
  52. dmisc,
  53. {$else Delphi}
  54. dos,
  55. {$endif Delphi}
  56. cutils,globtype,systems,
  57. fmodule,finput,verbose,cpubase
  58. {$ifdef GDB}
  59. {$ifdef delphi}
  60. ,sysutils
  61. {$else}
  62. ,strings
  63. {$endif}
  64. ,gdb
  65. {$endif GDB}
  66. {$ifdef x86}
  67. ,itx86att
  68. {$endif}
  69. {$ifdef powerpc}
  70. ,itppcgas
  71. {$endif}
  72. {$ifdef arm}
  73. ,itarmgas
  74. {$endif}
  75. ;
  76. const
  77. line_length = 70;
  78. var
  79. {$ifdef GDB}
  80. n_line : byte; { different types of source lines }
  81. linecount,
  82. includecount : longint;
  83. funcname : pchar;
  84. stabslastfileinfo : tfileposinfo;
  85. {$endif}
  86. lasTSec : TSection; { last section type written }
  87. lastfileinfo : tfileposinfo;
  88. infile,
  89. lastinfile : tinputfile;
  90. symendcount : longint;
  91. type
  92. t80bitarray = array[0..9] of byte;
  93. t64bitarray = array[0..7] of byte;
  94. t32bitarray = array[0..3] of byte;
  95. {****************************************************************************}
  96. { Support routines }
  97. {****************************************************************************}
  98. function fixline(s:string):string;
  99. {
  100. return s with all leading and ending spaces and tabs removed
  101. }
  102. var
  103. i,j,k : integer;
  104. begin
  105. i:=length(s);
  106. while (i>0) and (s[i] in [#9,' ']) do
  107. dec(i);
  108. j:=1;
  109. while (j<i) and (s[j] in [#9,' ']) do
  110. inc(j);
  111. for k:=j to i do
  112. if s[k] in [#0..#31,#127..#255] then
  113. s[k]:='.';
  114. fixline:=Copy(s,j,i-j+1);
  115. end;
  116. function single2str(d : single) : string;
  117. var
  118. hs : string;
  119. begin
  120. str(d,hs);
  121. { replace space with + }
  122. if hs[1]=' ' then
  123. hs[1]:='+';
  124. single2str:='0d'+hs
  125. end;
  126. function double2str(d : double) : string;
  127. var
  128. hs : string;
  129. begin
  130. str(d,hs);
  131. { replace space with + }
  132. if hs[1]=' ' then
  133. hs[1]:='+';
  134. double2str:='0d'+hs
  135. end;
  136. function extended2str(e : extended) : string;
  137. var
  138. hs : string;
  139. begin
  140. str(e,hs);
  141. { replace space with + }
  142. if hs[1]=' ' then
  143. hs[1]:='+';
  144. extended2str:='0d'+hs
  145. end;
  146. { convert floating point values }
  147. { to correct endian }
  148. procedure swap64bitarray(var t: t64bitarray);
  149. var
  150. b: byte;
  151. begin
  152. b:= t[7];
  153. t[7] := t[0];
  154. t[0] := b;
  155. b := t[6];
  156. t[6] := t[1];
  157. t[1] := b;
  158. b:= t[5];
  159. t[5] := t[2];
  160. t[2] := b;
  161. b:= t[4];
  162. t[4] := t[3];
  163. t[3] := b;
  164. end;
  165. procedure swap32bitarray(var t: t32bitarray);
  166. var
  167. b: byte;
  168. begin
  169. b:= t[1];
  170. t[1]:= t[2];
  171. t[2]:= b;
  172. b:= t[0];
  173. t[0]:= t[3];
  174. t[3]:= b;
  175. end;
  176. const
  177. ait_const2str : array[ait_const_32bit..ait_const_8bit] of string[8]=
  178. (#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  179. function ait_section2str(s:TSection):string;
  180. begin
  181. ait_section2str:=target_asm.secnames[s];
  182. {$ifdef GDB}
  183. { this is needed for line info in data }
  184. funcname:=nil;
  185. case s of
  186. sec_code : n_line:=n_textline;
  187. sec_data : n_line:=n_dataline;
  188. sec_bss : n_line:=n_bssline;
  189. else n_line:=n_dataline;
  190. end;
  191. {$endif GDB}
  192. LasTSec:=s;
  193. end;
  194. {****************************************************************************}
  195. { GNU Assembler writer }
  196. {****************************************************************************}
  197. {$ifdef GDB}
  198. procedure TGNUAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  199. var
  200. curr_n : byte;
  201. begin
  202. if not ((cs_debuginfo in aktmoduleswitches) or
  203. (cs_gdb_lineinfo in aktglobalswitches)) then
  204. exit;
  205. { file changed ? (must be before line info) }
  206. if (fileinfo.fileindex<>0) and
  207. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  208. begin
  209. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  210. if assigned(infile) then
  211. begin
  212. if includecount=0 then
  213. curr_n:=n_sourcefile
  214. else
  215. curr_n:=n_includefile;
  216. if (infile.path^<>'') then
  217. begin
  218. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  219. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  220. end;
  221. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  222. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  223. AsmWriteLn(target_asm.labelprefix+'text'+ToStr(IncludeCount)+':');
  224. inc(includecount);
  225. { force new line info }
  226. stabslastfileinfo.line:=-1;
  227. end;
  228. end;
  229. { line changed ? }
  230. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  231. begin
  232. if (n_line=n_textline) and assigned(funcname) and
  233. (target_info.use_function_relative_addresses) then
  234. begin
  235. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  236. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  237. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  238. AsmWritePChar(FuncName);
  239. AsmLn;
  240. inc(linecount);
  241. end
  242. else
  243. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  244. end;
  245. stabslastfileinfo:=fileinfo;
  246. end;
  247. procedure TGNUAssembler.WriteFileEndInfo;
  248. begin
  249. if not ((cs_debuginfo in aktmoduleswitches) or
  250. (cs_gdb_lineinfo in aktglobalswitches)) then
  251. exit;
  252. AsmLn;
  253. AsmWriteLn(ait_section2str(sec_code));
  254. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,'+target_asm.labelprefix+'etext');
  255. AsmWriteLn(target_asm.labelprefix+'etext:');
  256. end;
  257. {$endif GDB}
  258. procedure TGNUAssembler.WriteTree(p:TAAsmoutput);
  259. const
  260. allocstr : array[boolean] of string[10]=(' released',' allocated');
  261. var
  262. ch : char;
  263. hp : tai;
  264. hp1 : tailineinfo;
  265. consttyp : taitype;
  266. s : string;
  267. found : boolean;
  268. i,pos,l : longint;
  269. InlineLevel : longint;
  270. co : comp;
  271. sin : single;
  272. d : double;
  273. {$ifdef cpuextended}
  274. e : extended;
  275. {$endif cpuextended}
  276. do_line : boolean;
  277. begin
  278. if not assigned(p) then
  279. exit;
  280. InlineLevel:=0;
  281. { lineinfo is only needed for codesegment (PFV) }
  282. do_line:=(cs_asm_source in aktglobalswitches) or
  283. ((cs_lineinfo in aktmoduleswitches)
  284. and (p=codesegment));
  285. hp:=tai(p.first);
  286. while assigned(hp) do
  287. begin
  288. if not(hp.typ in SkipLineInfo) then
  289. begin
  290. hp1 := hp as tailineinfo;
  291. aktfilepos:=hp1.fileinfo;
  292. {$ifdef GDB}
  293. { write stabs }
  294. if (cs_debuginfo in aktmoduleswitches) or
  295. (cs_gdb_lineinfo in aktglobalswitches) then
  296. WriteFileLineInfo(hp1.fileinfo);
  297. {$endif GDB}
  298. { no line info for inlined code }
  299. if do_line and (inlinelevel=0) then
  300. begin
  301. { load infile }
  302. if lastfileinfo.fileindex<>hp1.fileinfo.fileindex then
  303. begin
  304. infile:=current_module.sourcefiles.get_file(hp1.fileinfo.fileindex);
  305. if assigned(infile) then
  306. begin
  307. { open only if needed !! }
  308. if (cs_asm_source in aktglobalswitches) then
  309. infile.open;
  310. end;
  311. { avoid unnecessary reopens of the same file !! }
  312. lastfileinfo.fileindex:=hp1.fileinfo.fileindex;
  313. { be sure to change line !! }
  314. lastfileinfo.line:=-1;
  315. end;
  316. { write source }
  317. if (cs_asm_source in aktglobalswitches) and
  318. assigned(infile) then
  319. begin
  320. if (infile<>lastinfile) then
  321. begin
  322. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  323. if assigned(lastinfile) then
  324. lastinfile.close;
  325. end;
  326. if (hp1.fileinfo.line<>lastfileinfo.line) and
  327. ((hp1.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  328. begin
  329. if (hp1.fileinfo.line<>0) and
  330. ((infile.linebuf^[hp1.fileinfo.line]>=0) or (InlineLevel>0)) then
  331. AsmWriteLn(target_asm.comment+'['+tostr(hp1.fileinfo.line)+'] '+
  332. fixline(infile.GetLineStr(hp1.fileinfo.line)));
  333. { set it to a negative value !
  334. to make that is has been read already !! PM }
  335. if (infile.linebuf^[hp1.fileinfo.line]>=0) then
  336. infile.linebuf^[hp1.fileinfo.line]:=-infile.linebuf^[hp1.fileinfo.line]-1;
  337. end;
  338. end;
  339. lastfileinfo:=hp1.fileinfo;
  340. lastinfile:=infile;
  341. end;
  342. end;
  343. case hp.typ of
  344. ait_comment :
  345. Begin
  346. AsmWrite(target_asm.comment);
  347. AsmWritePChar(tai_comment(hp).str);
  348. AsmLn;
  349. End;
  350. ait_regalloc :
  351. begin
  352. if (cs_asm_regalloc in aktglobalswitches) then
  353. AsmWriteLn(#9+target_asm.comment+'Register '+gas_regname(Tai_regalloc(hp).reg)+
  354. allocstr[tai_regalloc(hp).allocation]);
  355. end;
  356. ait_tempalloc :
  357. begin
  358. if (cs_asm_tempalloc in aktglobalswitches) then
  359. begin
  360. {$ifdef EXTDEBUG}
  361. if assigned(tai_tempalloc(hp).problem) then
  362. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  363. tostr(tai_tempalloc(hp).tempsize)+' '+tai_tempalloc(hp).problem^)
  364. else
  365. {$endif EXTDEBUG}
  366. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  367. tostr(tai_tempalloc(hp).tempsize)+allocstr[tai_tempalloc(hp).allocation]);
  368. end;
  369. end;
  370. ait_align :
  371. begin
  372. AsmWrite(#9'.balign '+tostr(tai_align(hp).aligntype));
  373. if tai_align(hp).use_op then
  374. AsmWrite(','+tostr(tai_align(hp).fillop));
  375. AsmLn;
  376. end;
  377. ait_section :
  378. begin
  379. if tai_section(hp).sec<>sec_none then
  380. begin
  381. AsmLn;
  382. AsmWriteLn(ait_section2str(tai_section(hp).sec));
  383. {$ifdef GDB}
  384. lastfileinfo.line:=-1;
  385. {$endif GDB}
  386. end
  387. else
  388. begin
  389. {$ifdef EXTDEBUG}
  390. AsmWrite(target_asm.comment);
  391. AsmWriteln(' sec_none');
  392. {$endif EXTDEBUG}
  393. end;
  394. end;
  395. ait_datablock :
  396. begin
  397. if tai_datablock(hp).is_global then
  398. AsmWrite(#9'.comm'#9)
  399. else
  400. AsmWrite(#9'.lcomm'#9);
  401. AsmWrite(tai_datablock(hp).sym.name);
  402. AsmWriteLn(','+tostr(tai_datablock(hp).size));
  403. end;
  404. ait_const_32bit,
  405. ait_const_16bit,
  406. ait_const_8bit :
  407. begin
  408. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  409. consttyp:=hp.typ;
  410. l:=0;
  411. repeat
  412. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  413. if found then
  414. begin
  415. hp:=tai(hp.next);
  416. s:=','+tostr(tai_const(hp).value);
  417. AsmWrite(s);
  418. inc(l,length(s));
  419. end;
  420. until (not found) or (l>line_length);
  421. AsmLn;
  422. end;
  423. ait_const_symbol :
  424. begin
  425. AsmWrite(#9'.long'#9);
  426. AsmWrite(tai_const_symbol(hp).sym.name);
  427. if tai_const_symbol(hp).offset>0 then
  428. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  429. else if tai_const_symbol(hp).offset<0 then
  430. AsmWrite(tostr(tai_const_symbol(hp).offset));
  431. AsmLn;
  432. end;
  433. ait_const_rva :
  434. begin
  435. AsmWrite(#9'.rva'#9);
  436. AsmWriteLn(tai_const_symbol(hp).sym.name);
  437. end;
  438. {$ifdef cpuextended}
  439. ait_real_80bit :
  440. begin
  441. if do_line then
  442. AsmWriteLn(target_asm.comment+target_asm.comment+extended2str(tai_real_80bit(hp).value));
  443. { Make sure e is a extended type, bestreal could be
  444. a different type (bestreal) !! (PFV) }
  445. e:=tai_real_80bit(hp).value;
  446. AsmWrite(#9'.byte'#9);
  447. for i:=0 to 9 do
  448. begin
  449. if i<>0 then
  450. AsmWrite(',');
  451. AsmWrite(tostr(t80bitarray(e)[i]));
  452. end;
  453. AsmLn;
  454. end;
  455. {$endif cpuextended}
  456. ait_real_64bit :
  457. begin
  458. if do_line then
  459. AsmWriteLn(target_asm.comment+target_asm.comment+double2str(tai_real_64bit(hp).value));
  460. d:=tai_real_64bit(hp).value;
  461. { swap the values to correct endian if required }
  462. {$ifdef fpc}
  463. if source_info.endian <> target_info.endian then
  464. swap64bitarray(t64bitarray(d));
  465. {$endif}
  466. AsmWrite(#9'.byte'#9);
  467. for i:=0 to 7 do
  468. begin
  469. if i<>0 then
  470. AsmWrite(',');
  471. AsmWrite(tostr(t64bitarray(d)[i]));
  472. end;
  473. AsmLn;
  474. end;
  475. ait_real_32bit :
  476. begin
  477. if do_line then
  478. AsmWriteLn(target_asm.comment+target_asm.comment+single2str(tai_real_32bit(hp).value));
  479. sin:=tai_real_32bit(hp).value;
  480. {$ifdef fpc}
  481. { swap the values to correct endian if required }
  482. if source_info.endian <> target_info.endian then
  483. swap32bitarray(t32bitarray(sin));
  484. {$endif}
  485. AsmWrite(#9'.byte'#9);
  486. for i:=0 to 3 do
  487. begin
  488. if i<>0 then
  489. AsmWrite(',');
  490. AsmWrite(tostr(t32bitarray(sin)[i]));
  491. end;
  492. AsmLn;
  493. end;
  494. ait_comp_64bit :
  495. begin
  496. if do_line then
  497. AsmWriteLn(target_asm.comment+target_asm.comment+extended2str(tai_comp_64bit(hp).value));
  498. AsmWrite(#9'.byte'#9);
  499. {$ifdef FPC}
  500. co:=comp(tai_comp_64bit(hp).value);
  501. {$else}
  502. co:=tai_comp_64bit(hp).value;
  503. {$endif}
  504. {$ifdef fpc}
  505. { swap the values to correct endian if required }
  506. if source_info.endian <> target_info.endian then
  507. swap64bitarray(t64bitarray(co));
  508. {$endif}
  509. for i:=0 to 7 do
  510. begin
  511. if i<>0 then
  512. AsmWrite(',');
  513. AsmWrite(tostr(t64bitarray(co)[i]));
  514. end;
  515. AsmLn;
  516. end;
  517. ait_direct :
  518. begin
  519. AsmWritePChar(tai_direct(hp).str);
  520. AsmLn;
  521. {$IfDef GDB}
  522. if strpos(tai_direct(hp).str,'.data')<>nil then
  523. n_line:=n_dataline
  524. else if strpos(tai_direct(hp).str,'.text')<>nil then
  525. n_line:=n_textline
  526. else if strpos(tai_direct(hp).str,'.bss')<>nil then
  527. n_line:=n_bssline;
  528. {$endif GDB}
  529. end;
  530. ait_string :
  531. begin
  532. pos:=0;
  533. for i:=1 to tai_string(hp).len do
  534. begin
  535. if pos=0 then
  536. begin
  537. AsmWrite(#9'.ascii'#9'"');
  538. pos:=20;
  539. end;
  540. ch:=tai_string(hp).str[i-1];
  541. case ch of
  542. #0, {This can't be done by range, because a bug in FPC}
  543. #1..#31,
  544. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  545. '"' : s:='\"';
  546. '\' : s:='\\';
  547. else
  548. s:=ch;
  549. end;
  550. AsmWrite(s);
  551. inc(pos,length(s));
  552. if (pos>line_length) or (i=tai_string(hp).len) then
  553. begin
  554. AsmWriteLn('"');
  555. pos:=0;
  556. end;
  557. end;
  558. end;
  559. ait_label :
  560. begin
  561. if (tai_label(hp).l.is_used) then
  562. begin
  563. if tai_label(hp).l.defbind=AB_GLOBAL then
  564. begin
  565. AsmWrite('.globl'#9);
  566. AsmWriteLn(tai_label(hp).l.name);
  567. end;
  568. AsmWrite(tai_label(hp).l.name);
  569. AsmWriteLn(':');
  570. end;
  571. end;
  572. ait_symbol :
  573. begin
  574. if tai_symbol(hp).is_global then
  575. begin
  576. AsmWrite('.globl'#9);
  577. AsmWriteLn(tai_symbol(hp).sym.name);
  578. end;
  579. if target_info.system in [system_i386_linux,system_i386_beos] then
  580. begin
  581. AsmWrite(#9'.type'#9);
  582. AsmWrite(tai_symbol(hp).sym.name);
  583. if assigned(tai(hp.next)) and
  584. (tai(hp.next).typ in [ait_const_symbol,ait_const_rva,
  585. ait_const_32bit,ait_const_16bit,ait_const_8bit,ait_datablock,
  586. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit]) then
  587. AsmWriteLn(',@object')
  588. else
  589. AsmWriteLn(',@function');
  590. if tai_symbol(hp).sym.size>0 then
  591. begin
  592. AsmWrite(#9'.size'#9);
  593. AsmWrite(tai_symbol(hp).sym.name);
  594. AsmWrite(', ');
  595. AsmWriteLn(tostr(tai_symbol(hp).sym.size));
  596. end;
  597. end;
  598. AsmWrite(tai_symbol(hp).sym.name);
  599. AsmWriteLn(':');
  600. end;
  601. ait_symbol_end :
  602. begin
  603. if target_info.system in [system_i386_linux,system_i386_beos] then
  604. begin
  605. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  606. inc(symendcount);
  607. AsmWriteLn(s+':');
  608. AsmWrite(#9'.size'#9);
  609. AsmWrite(tai_symbol_end(hp).sym.name);
  610. AsmWrite(', '+s+' - ');
  611. AsmWriteLn(tai_symbol_end(hp).sym.name);
  612. end;
  613. end;
  614. ait_instruction :
  615. begin
  616. WriteInstruction(hp);
  617. end;
  618. {$ifdef GDB}
  619. ait_stabs :
  620. begin
  621. if assigned(tai_stabs(hp).str) then
  622. begin
  623. AsmWrite(#9'.stabs ');
  624. AsmWritePChar(tai_stabs(hp).str);
  625. AsmLn;
  626. end;
  627. end;
  628. ait_stabn :
  629. begin
  630. if assigned(tai_stabn(hp).str) then
  631. begin
  632. AsmWrite(#9'.stabn ');
  633. AsmWritePChar(tai_stabn(hp).str);
  634. AsmLn;
  635. end;
  636. end;
  637. ait_force_line :
  638. stabslastfileinfo.line:=0;
  639. ait_stab_function_name:
  640. funcname:=tai_stab_function_name(hp).str;
  641. {$endif GDB}
  642. ait_cut :
  643. begin
  644. if SmartAsm then
  645. begin
  646. { only reset buffer if nothing has changed }
  647. if AsmSize=AsmStartSize then
  648. AsmClear
  649. else
  650. begin
  651. AsmClose;
  652. DoAssemble;
  653. AsmCreate(tai_cut(hp).place);
  654. end;
  655. { avoid empty files }
  656. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  657. begin
  658. if tai(hp.next).typ=ait_section then
  659. lasTSec:=tai_section(hp.next).sec;
  660. hp:=tai(hp.next);
  661. end;
  662. {$ifdef GDB}
  663. { force write of filename }
  664. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  665. includecount:=0;
  666. funcname:=nil;
  667. WriteFileLineInfo(aktfilepos);
  668. {$endif GDB}
  669. if lasTSec<>sec_none then
  670. AsmWriteLn(ait_section2str(lasTSec));
  671. AsmStartSize:=AsmSize;
  672. end;
  673. end;
  674. ait_marker :
  675. if tai_marker(hp).kind=InlineStart then
  676. inc(InlineLevel)
  677. else if tai_marker(hp).kind=InlineEnd then
  678. dec(InlineLevel);
  679. else
  680. internalerror(10000);
  681. end;
  682. hp:=tai(hp.next);
  683. end;
  684. end;
  685. procedure TGNUAssembler.WriteExtraHeader;
  686. begin
  687. end;
  688. procedure TGNUAssembler.WriteAsmList;
  689. var
  690. p:dirstr;
  691. n:namestr;
  692. e:extstr;
  693. {$ifdef GDB}
  694. fileinfo : tfileposinfo;
  695. {$endif GDB}
  696. begin
  697. {$ifdef EXTDEBUG}
  698. if assigned(current_module.mainsource) then
  699. Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource^);
  700. {$endif}
  701. LasTSec:=sec_none;
  702. {$ifdef GDB}
  703. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  704. {$endif GDB}
  705. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  706. LastInfile:=nil;
  707. if assigned(current_module.mainsource) then
  708. fsplit(current_module.mainsource^,p,n,e)
  709. else
  710. begin
  711. p:=inputdir;
  712. n:=inputfile;
  713. e:=inputextension;
  714. end;
  715. { to get symify to work }
  716. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  717. WriteExtraHeader;
  718. {$ifdef GDB}
  719. n_line:=n_bssline;
  720. funcname:=nil;
  721. linecount:=1;
  722. includecount:=0;
  723. fileinfo.fileindex:=1;
  724. fileinfo.line:=1;
  725. { Write main file }
  726. WriteFileLineInfo(fileinfo);
  727. {$endif GDB}
  728. AsmStartSize:=AsmSize;
  729. symendcount:=0;
  730. If (cs_debuginfo in aktmoduleswitches) then
  731. WriteTree(debuglist);
  732. WriteTree(codesegment);
  733. WriteTree(datasegment);
  734. WriteTree(consts);
  735. WriteTree(rttilist);
  736. Writetree(resourcestringlist);
  737. WriteTree(bsssegment);
  738. Writetree(importssection);
  739. { exports are written by DLLTOOL
  740. if we use it so don't insert it twice (PM) }
  741. if not UseDeffileForExport and assigned(exportssection) then
  742. Writetree(exportssection);
  743. Writetree(resourcesection);
  744. {$ifdef GDB}
  745. WriteFileEndInfo;
  746. {$ENDIF}
  747. AsmLn;
  748. {$ifdef EXTDEBUG}
  749. if assigned(current_module.mainsource) then
  750. Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource^);
  751. {$endif EXTDEBUG}
  752. end;
  753. end.
  754. {
  755. $Log$
  756. Revision 1.36 2003-10-01 20:34:48 peter
  757. * procinfo unit contains tprocinfo
  758. * cginfo renamed to cgbase
  759. * moved cgmessage to verbose
  760. * fixed ppc and sparc compiles
  761. Revision 1.35 2003/09/23 17:56:05 peter
  762. * locals and paras are allocated in the code generation
  763. * tvarsym.localloc contains the location of para/local when
  764. generating code for the current procedure
  765. Revision 1.34 2003/09/06 16:47:24 florian
  766. + support of NaN and Inf in the compiler as values of real constants
  767. Revision 1.33 2003/09/04 00:15:29 florian
  768. * first bunch of adaptions of arm compiler for new register type
  769. Revision 1.32 2003/09/03 19:35:24 peter
  770. * powerpc compiles again
  771. Revision 1.31 2003/09/03 15:55:00 peter
  772. * NEWRA branch merged
  773. Revision 1.30 2003/09/03 11:18:36 florian
  774. * fixed arm concatcopy
  775. + arm support in the common compiler sources added
  776. * moved some generic cg code around
  777. + tfputype added
  778. * ...
  779. Revision 1.29.2.2 2003/09/01 21:02:55 peter
  780. * sparc updates for new tregister
  781. Revision 1.29.2.1 2003/08/31 15:46:26 peter
  782. * more updates for tregister
  783. Revision 1.29 2003/08/19 11:53:03 daniel
  784. * Fixed PowerPC compilation
  785. Revision 1.28 2003/08/18 11:49:47 daniel
  786. * Made ATT asm writer work with -sr
  787. Revision 1.27 2003/08/17 21:11:00 daniel
  788. * Now -sr works...
  789. Revision 1.26 2003/08/17 20:47:47 daniel
  790. * Notranslation changed into -sr functionality
  791. Revision 1.25 2003/08/17 16:59:20 jonas
  792. * fixed regvars so they work with newra (at least for ppc)
  793. * fixed some volatile register bugs
  794. + -dnotranslation option for -dnewra, which causes the registers not to
  795. be translated from virtual to normal registers. Requires support in
  796. the assembler writer as well, which is only implemented in aggas/
  797. agppcgas currently
  798. Revision 1.24 2003/04/28 21:17:53 peter
  799. * write sec_none info in extdebug
  800. Revision 1.23 2003/04/25 20:59:33 peter
  801. * removed funcretn,funcretsym, function result is now in varsym
  802. and aliases for result and function name are added using absolutesym
  803. * vs_hidden parameter for funcret passed in parameter
  804. * vs_hidden fixes
  805. * writenode changed to printnode and released from extdebug
  806. * -vp option added to generate a tree.log with the nodetree
  807. * nicer printnode for statements, callnode
  808. Revision 1.22 2003/04/24 22:29:57 florian
  809. * fixed a lot of PowerPC related stuff
  810. Revision 1.21 2003/04/22 14:33:38 peter
  811. * removed some notes/hints
  812. Revision 1.20 2003/01/09 21:52:37 peter
  813. * merged some verbosity options.
  814. * V_LineInfo is a verbosity flag to include line info
  815. Revision 1.19 2003/01/08 18:43:56 daniel
  816. * Tregister changed into a record
  817. Revision 1.18 2002/12/07 14:03:25 carl
  818. - remove some duplicates and unused vars
  819. Revision 1.17 2002/12/06 17:50:39 peter
  820. * long symbol name fix merged
  821. Revision 1.16 2002/11/17 16:31:55 carl
  822. * memory optimization (3-4%) : cleanup of tai fields,
  823. cleanup of tdef and tsym fields.
  824. * make it work for m68k
  825. Revision 1.15 2002/11/15 01:58:45 peter
  826. * merged changes from 1.0.7 up to 04-11
  827. - -V option for generating bug report tracing
  828. - more tracing for option parsing
  829. - errors for cdecl and high()
  830. - win32 import stabs
  831. - win32 records<=8 are returned in eax:edx (turned off by default)
  832. - heaptrc update
  833. - more info for temp management in .s file with EXTDEBUG
  834. Revision 1.14 2002/10/30 21:01:14 peter
  835. * always include lineno after fileswitch. valgrind requires this
  836. Revision 1.13 2002/10/05 12:43:23 carl
  837. * fixes for Delphi 6 compilation
  838. (warning : Some features do not work under Delphi)
  839. Revision 1.12 2002/08/31 16:05:17 florian
  840. * write double # before float constants when -al is turned on
  841. else some gas versions interpret it as line number
  842. Revision 1.11 2002/08/20 16:55:38 peter
  843. * don't write (stabs)line info when inlining a procedure
  844. Revision 1.10 2002/08/18 22:16:14 florian
  845. + the ppc gas assembler writer adds now registers aliases
  846. to the assembler file
  847. Revision 1.9 2002/08/18 20:06:23 peter
  848. * inlining is now also allowed in interface
  849. * renamed write/load to ppuwrite/ppuload
  850. * tnode storing in ppu
  851. * nld,ncon,nbas are already updated for storing in ppu
  852. Revision 1.8 2002/07/26 21:15:37 florian
  853. * rewrote the system handling
  854. Revision 1.7 2002/07/07 09:52:32 florian
  855. * powerpc target fixed, very simple units can be compiled
  856. * some basic stuff for better callparanode handling, far from being finished
  857. Revision 1.6 2002/07/01 18:46:20 peter
  858. * internal linker
  859. * reorganized aasm layer
  860. Revision 1.5 2002/05/18 13:34:05 peter
  861. * readded missing revisions
  862. Revision 1.4 2002/05/16 19:46:34 carl
  863. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  864. + try to fix temp allocation (still in ifdef)
  865. + generic constructor calls
  866. + start of tassembler / tmodulebase class cleanup
  867. Revision 1.2 2002/04/15 18:53:48 carl
  868. + comments in register allocator uses std_Reg2str
  869. Revision 1.1 2002/04/14 16:51:54 carl
  870. + basic GNU assembler writer class
  871. }