aggas.pas 28 KB

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