aggas.pas 29 KB

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