aggas.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  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. else
  381. begin
  382. {$ifdef EXTDEBUG}
  383. AsmWrite(target_asm.comment);
  384. AsmWriteln(' sec_none');
  385. {$endif EXTDEBUG}
  386. end;
  387. end;
  388. ait_datablock :
  389. begin
  390. if tai_datablock(hp).is_global then
  391. AsmWrite(#9'.comm'#9)
  392. else
  393. AsmWrite(#9'.lcomm'#9);
  394. AsmWrite(tai_datablock(hp).sym.name);
  395. AsmWriteLn(','+tostr(tai_datablock(hp).size));
  396. end;
  397. ait_const_32bit,
  398. ait_const_16bit,
  399. ait_const_8bit :
  400. begin
  401. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  402. consttyp:=hp.typ;
  403. l:=0;
  404. repeat
  405. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  406. if found then
  407. begin
  408. hp:=tai(hp.next);
  409. s:=','+tostr(tai_const(hp).value);
  410. AsmWrite(s);
  411. inc(l,length(s));
  412. end;
  413. until (not found) or (l>line_length);
  414. AsmLn;
  415. end;
  416. ait_const_symbol :
  417. begin
  418. AsmWrite(#9'.long'#9);
  419. AsmWrite(tai_const_symbol(hp).sym.name);
  420. if tai_const_symbol(hp).offset>0 then
  421. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  422. else if tai_const_symbol(hp).offset<0 then
  423. AsmWrite(tostr(tai_const_symbol(hp).offset));
  424. AsmLn;
  425. end;
  426. ait_const_rva :
  427. begin
  428. AsmWrite(#9'.rva'#9);
  429. AsmWriteLn(tai_const_symbol(hp).sym.name);
  430. end;
  431. {$ifdef cpuextended}
  432. ait_real_80bit :
  433. begin
  434. if do_line then
  435. AsmWriteLn(target_asm.comment+target_asm.comment+extended2str(tai_real_80bit(hp).value));
  436. { Make sure e is a extended type, bestreal could be
  437. a different type (bestreal) !! (PFV) }
  438. e:=tai_real_80bit(hp).value;
  439. AsmWrite(#9'.byte'#9);
  440. for i:=0 to 9 do
  441. begin
  442. if i<>0 then
  443. AsmWrite(',');
  444. AsmWrite(tostr(t80bitarray(e)[i]));
  445. end;
  446. AsmLn;
  447. end;
  448. {$endif cpuextended}
  449. ait_real_64bit :
  450. begin
  451. if do_line then
  452. AsmWriteLn(target_asm.comment+target_asm.comment+double2str(tai_real_64bit(hp).value));
  453. d:=tai_real_64bit(hp).value;
  454. { swap the values to correct endian if required }
  455. {$ifdef fpc}
  456. if source_info.endian <> target_info.endian then
  457. swap64bitarray(t64bitarray(d));
  458. {$endif}
  459. AsmWrite(#9'.byte'#9);
  460. for i:=0 to 7 do
  461. begin
  462. if i<>0 then
  463. AsmWrite(',');
  464. AsmWrite(tostr(t64bitarray(d)[i]));
  465. end;
  466. AsmLn;
  467. end;
  468. ait_real_32bit :
  469. begin
  470. if do_line then
  471. AsmWriteLn(target_asm.comment+target_asm.comment+single2str(tai_real_32bit(hp).value));
  472. sin:=tai_real_32bit(hp).value;
  473. {$ifdef fpc}
  474. { swap the values to correct endian if required }
  475. if source_info.endian <> target_info.endian then
  476. swap32bitarray(t32bitarray(sin));
  477. {$endif}
  478. AsmWrite(#9'.byte'#9);
  479. for i:=0 to 3 do
  480. begin
  481. if i<>0 then
  482. AsmWrite(',');
  483. AsmWrite(tostr(t32bitarray(sin)[i]));
  484. end;
  485. AsmLn;
  486. end;
  487. ait_comp_64bit :
  488. begin
  489. if do_line then
  490. AsmWriteLn(target_asm.comment+target_asm.comment+extended2str(tai_comp_64bit(hp).value));
  491. AsmWrite(#9'.byte'#9);
  492. {$ifdef FPC}
  493. co:=comp(tai_comp_64bit(hp).value);
  494. {$else}
  495. co:=tai_comp_64bit(hp).value;
  496. {$endif}
  497. {$ifdef fpc}
  498. { swap the values to correct endian if required }
  499. if source_info.endian <> target_info.endian then
  500. swap64bitarray(t64bitarray(co));
  501. {$endif}
  502. for i:=0 to 7 do
  503. begin
  504. if i<>0 then
  505. AsmWrite(',');
  506. AsmWrite(tostr(t64bitarray(co)[i]));
  507. end;
  508. AsmLn;
  509. end;
  510. ait_direct :
  511. begin
  512. AsmWritePChar(tai_direct(hp).str);
  513. AsmLn;
  514. {$IfDef GDB}
  515. if strpos(tai_direct(hp).str,'.data')<>nil then
  516. n_line:=n_dataline
  517. else if strpos(tai_direct(hp).str,'.text')<>nil then
  518. n_line:=n_textline
  519. else if strpos(tai_direct(hp).str,'.bss')<>nil then
  520. n_line:=n_bssline;
  521. {$endif GDB}
  522. end;
  523. ait_string :
  524. begin
  525. pos:=0;
  526. for i:=1 to tai_string(hp).len do
  527. begin
  528. if pos=0 then
  529. begin
  530. AsmWrite(#9'.ascii'#9'"');
  531. pos:=20;
  532. end;
  533. ch:=tai_string(hp).str[i-1];
  534. case ch of
  535. #0, {This can't be done by range, because a bug in FPC}
  536. #1..#31,
  537. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  538. '"' : s:='\"';
  539. '\' : s:='\\';
  540. else
  541. s:=ch;
  542. end;
  543. AsmWrite(s);
  544. inc(pos,length(s));
  545. if (pos>line_length) or (i=tai_string(hp).len) then
  546. begin
  547. AsmWriteLn('"');
  548. pos:=0;
  549. end;
  550. end;
  551. end;
  552. ait_label :
  553. begin
  554. if (tai_label(hp).l.is_used) then
  555. begin
  556. if tai_label(hp).l.defbind=AB_GLOBAL then
  557. begin
  558. AsmWrite('.globl'#9);
  559. AsmWriteLn(tai_label(hp).l.name);
  560. end;
  561. AsmWrite(tai_label(hp).l.name);
  562. AsmWriteLn(':');
  563. end;
  564. end;
  565. ait_symbol :
  566. begin
  567. if tai_symbol(hp).is_global then
  568. begin
  569. AsmWrite('.globl'#9);
  570. AsmWriteLn(tai_symbol(hp).sym.name);
  571. end;
  572. if target_info.system in [system_i386_linux,system_i386_beos] then
  573. begin
  574. AsmWrite(#9'.type'#9);
  575. AsmWrite(tai_symbol(hp).sym.name);
  576. if assigned(tai(hp.next)) and
  577. (tai(hp.next).typ in [ait_const_symbol,ait_const_rva,
  578. ait_const_32bit,ait_const_16bit,ait_const_8bit,ait_datablock,
  579. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit]) then
  580. AsmWriteLn(',@object')
  581. else
  582. AsmWriteLn(',@function');
  583. if tai_symbol(hp).sym.size>0 then
  584. begin
  585. AsmWrite(#9'.size'#9);
  586. AsmWrite(tai_symbol(hp).sym.name);
  587. AsmWrite(', ');
  588. AsmWriteLn(tostr(tai_symbol(hp).sym.size));
  589. end;
  590. end;
  591. AsmWrite(tai_symbol(hp).sym.name);
  592. AsmWriteLn(':');
  593. end;
  594. ait_symbol_end :
  595. begin
  596. if target_info.system in [system_i386_linux,system_i386_beos] then
  597. begin
  598. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  599. inc(symendcount);
  600. AsmWriteLn(s+':');
  601. AsmWrite(#9'.size'#9);
  602. AsmWrite(tai_symbol_end(hp).sym.name);
  603. AsmWrite(', '+s+' - ');
  604. AsmWriteLn(tai_symbol_end(hp).sym.name);
  605. end;
  606. end;
  607. ait_instruction :
  608. begin
  609. WriteInstruction(hp);
  610. end;
  611. {$ifdef GDB}
  612. ait_stabs :
  613. begin
  614. AsmWrite(#9'.stabs ');
  615. AsmWritePChar(tai_stabs(hp).str);
  616. AsmLn;
  617. end;
  618. ait_stabn :
  619. begin
  620. AsmWrite(#9'.stabn ');
  621. AsmWritePChar(tai_stabn(hp).str);
  622. AsmLn;
  623. end;
  624. ait_force_line :
  625. stabslastfileinfo.line:=0;
  626. ait_stab_function_name:
  627. funcname:=tai_stab_function_name(hp).str;
  628. {$endif GDB}
  629. ait_cut :
  630. begin
  631. if SmartAsm then
  632. begin
  633. { only reset buffer if nothing has changed }
  634. if AsmSize=AsmStartSize then
  635. AsmClear
  636. else
  637. begin
  638. AsmClose;
  639. DoAssemble;
  640. AsmCreate(tai_cut(hp).place);
  641. end;
  642. { avoid empty files }
  643. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  644. begin
  645. if tai(hp.next).typ=ait_section then
  646. lasTSec:=tai_section(hp.next).sec;
  647. hp:=tai(hp.next);
  648. end;
  649. {$ifdef GDB}
  650. { force write of filename }
  651. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  652. includecount:=0;
  653. funcname:=nil;
  654. WriteFileLineInfo(aktfilepos);
  655. {$endif GDB}
  656. if lasTSec<>sec_none then
  657. AsmWriteLn(ait_section2str(lasTSec));
  658. AsmStartSize:=AsmSize;
  659. end;
  660. end;
  661. ait_marker :
  662. if tai_marker(hp).kind=InlineStart then
  663. inc(InlineLevel)
  664. else if tai_marker(hp).kind=InlineEnd then
  665. dec(InlineLevel);
  666. else
  667. internalerror(10000);
  668. end;
  669. hp:=tai(hp.next);
  670. end;
  671. end;
  672. procedure TGNUAssembler.WriteExtraHeader;
  673. begin
  674. end;
  675. procedure TGNUAssembler.WriteAsmList;
  676. var
  677. p:dirstr;
  678. n:namestr;
  679. e:extstr;
  680. {$ifdef GDB}
  681. fileinfo : tfileposinfo;
  682. {$endif GDB}
  683. begin
  684. {$ifdef EXTDEBUG}
  685. if assigned(current_module.mainsource) then
  686. Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource^);
  687. {$endif}
  688. LasTSec:=sec_none;
  689. {$ifdef GDB}
  690. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  691. {$endif GDB}
  692. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  693. LastInfile:=nil;
  694. if assigned(current_module.mainsource) then
  695. fsplit(current_module.mainsource^,p,n,e)
  696. else
  697. begin
  698. p:=inputdir;
  699. n:=inputfile;
  700. e:=inputextension;
  701. end;
  702. { to get symify to work }
  703. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  704. WriteExtraHeader;
  705. {$ifdef GDB}
  706. n_line:=n_bssline;
  707. funcname:=nil;
  708. linecount:=1;
  709. includecount:=0;
  710. fileinfo.fileindex:=1;
  711. fileinfo.line:=1;
  712. { Write main file }
  713. WriteFileLineInfo(fileinfo);
  714. {$endif GDB}
  715. AsmStartSize:=AsmSize;
  716. symendcount:=0;
  717. If (cs_debuginfo in aktmoduleswitches) then
  718. WriteTree(debuglist);
  719. WriteTree(codesegment);
  720. WriteTree(datasegment);
  721. WriteTree(consts);
  722. WriteTree(rttilist);
  723. Writetree(resourcestringlist);
  724. WriteTree(bsssegment);
  725. Writetree(importssection);
  726. { exports are written by DLLTOOL
  727. if we use it so don't insert it twice (PM) }
  728. if not UseDeffileForExport and assigned(exportssection) then
  729. Writetree(exportssection);
  730. Writetree(resourcesection);
  731. {$ifdef GDB}
  732. WriteFileEndInfo;
  733. {$ENDIF}
  734. AsmLn;
  735. {$ifdef EXTDEBUG}
  736. if assigned(current_module.mainsource) then
  737. Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource^);
  738. {$endif EXTDEBUG}
  739. end;
  740. end.
  741. {
  742. $Log$
  743. Revision 1.24 2003-04-28 21:17:53 peter
  744. * write sec_none info in extdebug
  745. Revision 1.23 2003/04/25 20:59:33 peter
  746. * removed funcretn,funcretsym, function result is now in varsym
  747. and aliases for result and function name are added using absolutesym
  748. * vs_hidden parameter for funcret passed in parameter
  749. * vs_hidden fixes
  750. * writenode changed to printnode and released from extdebug
  751. * -vp option added to generate a tree.log with the nodetree
  752. * nicer printnode for statements, callnode
  753. Revision 1.22 2003/04/24 22:29:57 florian
  754. * fixed a lot of PowerPC related stuff
  755. Revision 1.21 2003/04/22 14:33:38 peter
  756. * removed some notes/hints
  757. Revision 1.20 2003/01/09 21:52:37 peter
  758. * merged some verbosity options.
  759. * V_LineInfo is a verbosity flag to include line info
  760. Revision 1.19 2003/01/08 18:43:56 daniel
  761. * Tregister changed into a record
  762. Revision 1.18 2002/12/07 14:03:25 carl
  763. - remove some duplicates and unused vars
  764. Revision 1.17 2002/12/06 17:50:39 peter
  765. * long symbol name fix merged
  766. Revision 1.16 2002/11/17 16:31:55 carl
  767. * memory optimization (3-4%) : cleanup of tai fields,
  768. cleanup of tdef and tsym fields.
  769. * make it work for m68k
  770. Revision 1.15 2002/11/15 01:58:45 peter
  771. * merged changes from 1.0.7 up to 04-11
  772. - -V option for generating bug report tracing
  773. - more tracing for option parsing
  774. - errors for cdecl and high()
  775. - win32 import stabs
  776. - win32 records<=8 are returned in eax:edx (turned off by default)
  777. - heaptrc update
  778. - more info for temp management in .s file with EXTDEBUG
  779. Revision 1.14 2002/10/30 21:01:14 peter
  780. * always include lineno after fileswitch. valgrind requires this
  781. Revision 1.13 2002/10/05 12:43:23 carl
  782. * fixes for Delphi 6 compilation
  783. (warning : Some features do not work under Delphi)
  784. Revision 1.12 2002/08/31 16:05:17 florian
  785. * write double # before float constants when -al is turned on
  786. else some gas versions interpret it as line number
  787. Revision 1.11 2002/08/20 16:55:38 peter
  788. * don't write (stabs)line info when inlining a procedure
  789. Revision 1.10 2002/08/18 22:16:14 florian
  790. + the ppc gas assembler writer adds now registers aliases
  791. to the assembler file
  792. Revision 1.9 2002/08/18 20:06:23 peter
  793. * inlining is now also allowed in interface
  794. * renamed write/load to ppuwrite/ppuload
  795. * tnode storing in ppu
  796. * nld,ncon,nbas are already updated for storing in ppu
  797. Revision 1.8 2002/07/26 21:15:37 florian
  798. * rewrote the system handling
  799. Revision 1.7 2002/07/07 09:52:32 florian
  800. * powerpc target fixed, very simple units can be compiled
  801. * some basic stuff for better callparanode handling, far from being finished
  802. Revision 1.6 2002/07/01 18:46:20 peter
  803. * internal linker
  804. * reorganized aasm layer
  805. Revision 1.5 2002/05/18 13:34:05 peter
  806. * readded missing revisions
  807. Revision 1.4 2002/05/16 19:46:34 carl
  808. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  809. + try to fix temp allocation (still in ifdef)
  810. + generic constructor calls
  811. + start of tassembler / tmodulebase class cleanup
  812. Revision 1.2 2002/04/15 18:53:48 carl
  813. + comments in register allocator uses std_Reg2str
  814. Revision 1.1 2002/04/14 16:51:54 carl
  815. + basic GNU assembler writer class
  816. }