aggas.pas 30 KB

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