aggas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  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. aasm,assemble;
  27. type
  28. {# This is a derived class which is used to write
  29. GAS styled assembler.
  30. The WriteInstruction() method must be overriden
  31. to write a single instruction to the assembler
  32. file.
  33. }
  34. TGNUAssembler=class(texternalassembler)
  35. public
  36. procedure WriteTree(p:TAAsmoutput);override;
  37. procedure WriteAsmList;override;
  38. {$ifdef GDB}
  39. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  40. procedure WriteFileEndInfo;
  41. {$endif}
  42. procedure WriteInstruction(hp: tai); virtual; abstract;
  43. end;
  44. implementation
  45. uses
  46. {$ifdef Delphi}
  47. dmisc,
  48. {$else Delphi}
  49. dos,
  50. {$endif Delphi}
  51. cutils,globtype,systems,
  52. fmodule,finput,verbose,cpubase,cpuasm, tainst
  53. {$ifdef GDB}
  54. {$ifdef delphi}
  55. ,sysutils
  56. {$else}
  57. ,strings
  58. {$endif}
  59. ,gdb
  60. {$endif GDB}
  61. ;
  62. const
  63. line_length = 70;
  64. var
  65. {$ifdef GDB}
  66. n_line : byte; { different types of source lines }
  67. linecount,
  68. includecount : longint;
  69. funcname : pchar;
  70. stabslastfileinfo : tfileposinfo;
  71. {$endif}
  72. lastsec : tsection; { last section type written }
  73. lastfileinfo : tfileposinfo;
  74. infile,
  75. lastinfile : tinputfile;
  76. symendcount : longint;
  77. type
  78. t80bitarray = array[0..9] of byte;
  79. t64bitarray = array[0..7] of byte;
  80. t32bitarray = array[0..3] of byte;
  81. {****************************************************************************}
  82. { Support routines }
  83. {****************************************************************************}
  84. function fixline(s:string):string;
  85. {
  86. return s with all leading and ending spaces and tabs removed
  87. }
  88. var
  89. i,j,k : integer;
  90. begin
  91. i:=length(s);
  92. while (i>0) and (s[i] in [#9,' ']) do
  93. dec(i);
  94. j:=1;
  95. while (j<i) and (s[j] in [#9,' ']) do
  96. inc(j);
  97. for k:=j to i do
  98. if s[k] in [#0..#31,#127..#255] then
  99. s[k]:='.';
  100. fixline:=Copy(s,j,i-j+1);
  101. end;
  102. function single2str(d : single) : string;
  103. var
  104. hs : string;
  105. begin
  106. str(d,hs);
  107. { replace space with + }
  108. if hs[1]=' ' then
  109. hs[1]:='+';
  110. single2str:='0d'+hs
  111. end;
  112. function double2str(d : double) : string;
  113. var
  114. hs : string;
  115. begin
  116. str(d,hs);
  117. { replace space with + }
  118. if hs[1]=' ' then
  119. hs[1]:='+';
  120. double2str:='0d'+hs
  121. end;
  122. function extended2str(e : extended) : string;
  123. var
  124. hs : string;
  125. begin
  126. str(e,hs);
  127. { replace space with + }
  128. if hs[1]=' ' then
  129. hs[1]:='+';
  130. extended2str:='0d'+hs
  131. end;
  132. { convert floating point values }
  133. { to correct endian }
  134. procedure swap64bitarray(var t: t64bitarray);
  135. var
  136. b: byte;
  137. begin
  138. b:= t[7];
  139. t[7] := t[0];
  140. t[0] := b;
  141. b := t[6];
  142. t[6] := t[1];
  143. t[1] := b;
  144. b:= t[5];
  145. t[5] := t[2];
  146. t[2] := b;
  147. b:= t[4];
  148. t[4] := t[3];
  149. t[3] := b;
  150. end;
  151. procedure swap32bitarray(var t: t32bitarray);
  152. var
  153. b: byte;
  154. begin
  155. b:= t[1];
  156. t[1]:= t[2];
  157. t[2]:= b;
  158. b:= t[0];
  159. t[0]:= t[3];
  160. t[3]:= b;
  161. end;
  162. procedure swap80bitarray(var t: t80bitarray);
  163. begin
  164. {!!!!!!!!!!!!}
  165. end;
  166. const
  167. ait_const2str : array[ait_const_32bit..ait_const_8bit] of string[8]=
  168. (#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  169. function ait_section2str(s:tsection):string;
  170. begin
  171. ait_section2str:=target_asm.secnames[s];
  172. {$ifdef GDB}
  173. { this is needed for line info in data }
  174. funcname:=nil;
  175. case s of
  176. sec_code : n_line:=n_textline;
  177. sec_data : n_line:=n_dataline;
  178. sec_bss : n_line:=n_bssline;
  179. else n_line:=n_dataline;
  180. end;
  181. {$endif GDB}
  182. LastSec:=s;
  183. end;
  184. {****************************************************************************}
  185. { GNU Assembler writer }
  186. {****************************************************************************}
  187. {$ifdef GDB}
  188. procedure TGNUAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  189. var
  190. curr_n : byte;
  191. begin
  192. if not ((cs_debuginfo in aktmoduleswitches) or
  193. (cs_gdb_lineinfo in aktglobalswitches)) then
  194. exit;
  195. { file changed ? (must be before line info) }
  196. if (fileinfo.fileindex<>0) and
  197. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  198. begin
  199. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  200. if assigned(infile) then
  201. begin
  202. if includecount=0 then
  203. curr_n:=n_sourcefile
  204. else
  205. curr_n:=n_includefile;
  206. if (infile.path^<>'') then
  207. begin
  208. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  209. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  210. end;
  211. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  212. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  213. AsmWriteLn('Ltext'+ToStr(IncludeCount)+':');
  214. inc(includecount);
  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,Letext');
  243. AsmWriteLn('Letext:');
  244. end;
  245. {$endif GDB}
  246. procedure TGNUAssembler.WriteTree(p:TAAsmoutput);
  247. const
  248. allocstr : array[boolean] of string[10]=(' released',' allocated');
  249. nolinetai =[ait_label,
  250. ait_regalloc,ait_tempalloc,
  251. ait_stabn,ait_stabs,ait_section,
  252. ait_cut,ait_marker,ait_align,ait_stab_function_name];
  253. type
  254. t80bitarray = array[0..9] of byte;
  255. t64bitarray = array[0..7] of byte;
  256. t32bitarray = array[0..3] of byte;
  257. var
  258. ch : char;
  259. hp : tai;
  260. consttyp : tait;
  261. s : string;
  262. found : boolean;
  263. i,pos,l : longint;
  264. InlineLevel : longint;
  265. co : comp;
  266. sin : single;
  267. d : double;
  268. e : extended;
  269. do_line : boolean;
  270. sep : char;
  271. begin
  272. if not assigned(p) then
  273. exit;
  274. InlineLevel:=0;
  275. { lineinfo is only needed for codesegment (PFV) }
  276. do_line:=(cs_asm_source in aktglobalswitches) or
  277. ((cs_lineinfo in aktmoduleswitches)
  278. and (p=codesegment));
  279. hp:=tai(p.first);
  280. while assigned(hp) do
  281. begin
  282. aktfilepos:=hp.fileinfo;
  283. if not(hp.typ in nolinetai) then
  284. begin
  285. {$ifdef GDB}
  286. { write stabs }
  287. if (cs_debuginfo in aktmoduleswitches) or
  288. (cs_gdb_lineinfo in aktglobalswitches) then
  289. WriteFileLineInfo(hp.fileinfo);
  290. {$endif GDB}
  291. if do_line then
  292. begin
  293. { load infile }
  294. if lastfileinfo.fileindex<>hp.fileinfo.fileindex then
  295. begin
  296. infile:=current_module.sourcefiles.get_file(hp.fileinfo.fileindex);
  297. if assigned(infile) then
  298. begin
  299. { open only if needed !! }
  300. if (cs_asm_source in aktglobalswitches) then
  301. infile.open;
  302. end;
  303. { avoid unnecessary reopens of the same file !! }
  304. lastfileinfo.fileindex:=hp.fileinfo.fileindex;
  305. { be sure to change line !! }
  306. lastfileinfo.line:=-1;
  307. end;
  308. { write source }
  309. if (cs_asm_source in aktglobalswitches) and
  310. assigned(infile) then
  311. begin
  312. if (infile<>lastinfile) then
  313. begin
  314. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  315. if assigned(lastinfile) then
  316. lastinfile.close;
  317. end;
  318. if (hp.fileinfo.line<>lastfileinfo.line) and
  319. ((hp.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  320. begin
  321. if (hp.fileinfo.line<>0) and
  322. ((infile.linebuf^[hp.fileinfo.line]>=0) or (InlineLevel>0)) then
  323. AsmWriteLn(target_asm.comment+'['+tostr(hp.fileinfo.line)+'] '+
  324. fixline(infile.GetLineStr(hp.fileinfo.line)));
  325. { set it to a negative value !
  326. to make that is has been read already !! PM }
  327. if (infile.linebuf^[hp.fileinfo.line]>=0) then
  328. infile.linebuf^[hp.fileinfo.line]:=-infile.linebuf^[hp.fileinfo.line]-1;
  329. end;
  330. end;
  331. lastfileinfo:=hp.fileinfo;
  332. lastinfile:=infile;
  333. end;
  334. end;
  335. case hp.typ of
  336. ait_comment :
  337. Begin
  338. AsmWrite(target_asm.comment);
  339. AsmWritePChar(tai_asm_comment(hp).str);
  340. AsmLn;
  341. End;
  342. ait_regalloc :
  343. begin
  344. if (cs_asm_regalloc in aktglobalswitches) then
  345. AsmWriteLn(target_asm.comment+'Register '+std_reg2str[tairegalloc(hp).reg]+
  346. allocstr[tairegalloc(hp).allocation]);
  347. end;
  348. ait_tempalloc :
  349. begin
  350. if (cs_asm_tempalloc in aktglobalswitches) then
  351. AsmWriteLn(target_asm.comment+'Temp '+tostr(taitempalloc(hp).temppos)+','+
  352. tostr(taitempalloc(hp).tempsize)+allocstr[taitempalloc(hp).allocation]);
  353. end;
  354. ait_align :
  355. begin
  356. AsmWrite(#9'.balign '+tostr(tai_align(hp).aligntype));
  357. if tai_align(hp).use_op then
  358. AsmWrite(','+tostr(tai_align(hp).fillop));
  359. AsmLn;
  360. end;
  361. ait_section :
  362. begin
  363. if tai_section(hp).sec<>sec_none then
  364. begin
  365. AsmLn;
  366. AsmWriteLn(ait_section2str(tai_section(hp).sec));
  367. {$ifdef GDB}
  368. lastfileinfo.line:=-1;
  369. {$endif GDB}
  370. end;
  371. end;
  372. ait_datablock :
  373. begin
  374. if tai_datablock(hp).is_global then
  375. AsmWrite(#9'.comm'#9)
  376. else
  377. AsmWrite(#9'.lcomm'#9);
  378. AsmWrite(tai_datablock(hp).sym.name);
  379. AsmWriteLn(','+tostr(tai_datablock(hp).size));
  380. end;
  381. ait_const_32bit,
  382. ait_const_16bit,
  383. ait_const_8bit :
  384. begin
  385. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  386. consttyp:=hp.typ;
  387. l:=0;
  388. repeat
  389. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  390. if found then
  391. begin
  392. hp:=tai(hp.next);
  393. s:=','+tostr(tai_const(hp).value);
  394. AsmWrite(s);
  395. inc(l,length(s));
  396. end;
  397. until (not found) or (l>line_length);
  398. AsmLn;
  399. end;
  400. ait_const_symbol :
  401. begin
  402. AsmWrite(#9'.long'#9+tai_const_symbol(hp).sym.name);
  403. if tai_const_symbol(hp).offset>0 then
  404. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  405. else if tai_const_symbol(hp).offset<0 then
  406. AsmWrite(tostr(tai_const_symbol(hp).offset));
  407. AsmLn;
  408. end;
  409. ait_const_rva :
  410. AsmWriteLn(#9'.rva'#9+tai_const_symbol(hp).sym.name);
  411. ait_real_80bit :
  412. begin
  413. if do_line then
  414. AsmWriteLn(target_asm.comment+extended2str(tai_real_80bit(hp).value));
  415. { Make sure e is a extended type, bestreal could be
  416. a different type (bestreal) !! (PFV) }
  417. e:=tai_real_80bit(hp).value;
  418. AsmWrite(#9'.byte'#9);
  419. for i:=0 to 9 do
  420. begin
  421. if i<>0 then
  422. AsmWrite(',');
  423. AsmWrite(tostr(t80bitarray(e)[i]));
  424. end;
  425. AsmLn;
  426. end;
  427. ait_real_64bit :
  428. begin
  429. if do_line then
  430. AsmWriteLn(target_asm.comment+double2str(tai_real_64bit(hp).value));
  431. d:=tai_real_64bit(hp).value;
  432. { swap the values to correct endian if required }
  433. if source_info.endian <> target_info.endian then
  434. swap64bitarray(t64bitarray(d));
  435. AsmWrite(#9'.byte'#9);
  436. for i:=0 to 7 do
  437. begin
  438. if i<>0 then
  439. AsmWrite(',');
  440. AsmWrite(tostr(t64bitarray(d)[i]));
  441. end;
  442. AsmLn;
  443. end;
  444. ait_real_32bit :
  445. begin
  446. if do_line then
  447. AsmWriteLn(target_asm.comment+single2str(tai_real_32bit(hp).value));
  448. sin:=tai_real_32bit(hp).value;
  449. { swap the values to correct endian if required }
  450. if source_info.endian <> target_info.endian then
  451. swap32bitarray(t32bitarray(sin));
  452. AsmWrite(#9'.byte'#9);
  453. for i:=0 to 3 do
  454. begin
  455. if i<>0 then
  456. AsmWrite(',');
  457. AsmWrite(tostr(t32bitarray(sin)[i]));
  458. end;
  459. AsmLn;
  460. end;
  461. ait_comp_64bit :
  462. begin
  463. if do_line then
  464. AsmWriteLn(target_asm.comment+extended2str(tai_comp_64bit(hp).value));
  465. AsmWrite(#9'.byte'#9);
  466. {$ifdef FPC}
  467. co:=comp(tai_comp_64bit(hp).value);
  468. {$else}
  469. co:=tai_comp_64bit(hp).value;
  470. {$endif}
  471. { swap the values to correct endian if required }
  472. if source_info.endian <> target_info.endian then
  473. swap64bitarray(t64bitarray(co));
  474. for i:=0 to 7 do
  475. begin
  476. if i<>0 then
  477. AsmWrite(',');
  478. AsmWrite(tostr(t64bitarray(co)[i]));
  479. end;
  480. AsmLn;
  481. end;
  482. ait_direct :
  483. begin
  484. AsmWritePChar(tai_direct(hp).str);
  485. AsmLn;
  486. {$IfDef GDB}
  487. if strpos(tai_direct(hp).str,'.data')<>nil then
  488. n_line:=n_dataline
  489. else if strpos(tai_direct(hp).str,'.text')<>nil then
  490. n_line:=n_textline
  491. else if strpos(tai_direct(hp).str,'.bss')<>nil then
  492. n_line:=n_bssline;
  493. {$endif GDB}
  494. end;
  495. ait_string :
  496. begin
  497. pos:=0;
  498. for i:=1 to tai_string(hp).len do
  499. begin
  500. if pos=0 then
  501. begin
  502. AsmWrite(#9'.ascii'#9'"');
  503. pos:=20;
  504. end;
  505. ch:=tai_string(hp).str[i-1];
  506. case ch of
  507. #0, {This can't be done by range, because a bug in FPC}
  508. #1..#31,
  509. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  510. '"' : s:='\"';
  511. '\' : s:='\\';
  512. else
  513. s:=ch;
  514. end;
  515. AsmWrite(s);
  516. inc(pos,length(s));
  517. if (pos>line_length) or (i=tai_string(hp).len) then
  518. begin
  519. AsmWriteLn('"');
  520. pos:=0;
  521. end;
  522. end;
  523. end;
  524. ait_label :
  525. begin
  526. if (tai_label(hp).l.is_used) then
  527. begin
  528. if tai_label(hp).l.defbind=AB_GLOBAL then
  529. begin
  530. AsmWrite('.globl'#9);
  531. AsmWriteLn(tai_label(hp).l.name);
  532. end;
  533. AsmWrite(tai_label(hp).l.name);
  534. AsmWriteLn(':');
  535. end;
  536. end;
  537. ait_symbol :
  538. begin
  539. if tai_symbol(hp).is_global then
  540. begin
  541. AsmWrite('.globl'#9);
  542. AsmWriteLn(tai_symbol(hp).sym.name);
  543. end;
  544. if target_info.target in [target_i386_linux,target_i386_beos] then
  545. begin
  546. AsmWrite(#9'.type'#9);
  547. AsmWrite(tai_symbol(hp).sym.name);
  548. if assigned(tai(hp.next)) and
  549. (tai(hp.next).typ in [ait_const_symbol,ait_const_rva,
  550. ait_const_32bit,ait_const_16bit,ait_const_8bit,ait_datablock,
  551. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit]) then
  552. AsmWriteLn(',@object')
  553. else
  554. AsmWriteLn(',@function');
  555. if tai_symbol(hp).sym.size>0 then
  556. begin
  557. AsmWrite(#9'.size'#9);
  558. AsmWrite(tai_symbol(hp).sym.name);
  559. AsmWrite(', ');
  560. AsmWriteLn(tostr(tai_symbol(hp).sym.size));
  561. end;
  562. end;
  563. AsmWrite(tai_symbol(hp).sym.name);
  564. AsmWriteLn(':');
  565. end;
  566. ait_symbol_end :
  567. begin
  568. if target_info.target in [target_i386_linux,target_i386_beos] then
  569. begin
  570. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  571. inc(symendcount);
  572. AsmWriteLn(s+':');
  573. AsmWrite(#9'.size'#9);
  574. AsmWrite(tai_symbol_end(hp).sym.name);
  575. AsmWrite(', '+s+' - ');
  576. AsmWriteLn(tai_symbol_end(hp).sym.name);
  577. end;
  578. end;
  579. ait_instruction :
  580. begin
  581. WriteInstruction(hp);
  582. end;
  583. {$ifdef GDB}
  584. ait_stabs :
  585. begin
  586. AsmWrite(#9'.stabs ');
  587. AsmWritePChar(tai_stabs(hp).str);
  588. AsmLn;
  589. end;
  590. ait_stabn :
  591. begin
  592. AsmWrite(#9'.stabn ');
  593. AsmWritePChar(tai_stabn(hp).str);
  594. AsmLn;
  595. end;
  596. ait_force_line :
  597. stabslastfileinfo.line:=0;
  598. ait_stab_function_name:
  599. funcname:=tai_stab_function_name(hp).str;
  600. {$endif GDB}
  601. ait_cut :
  602. begin
  603. if SmartAsm then
  604. begin
  605. { only reset buffer if nothing has changed }
  606. if AsmSize=AsmStartSize then
  607. AsmClear
  608. else
  609. begin
  610. AsmClose;
  611. DoAssemble;
  612. AsmCreate(tai_cut(hp).place);
  613. end;
  614. { avoid empty files }
  615. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  616. begin
  617. if tai(hp.next).typ=ait_section then
  618. lastsec:=tai_section(hp.next).sec;
  619. hp:=tai(hp.next);
  620. end;
  621. {$ifdef GDB}
  622. { force write of filename }
  623. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  624. includecount:=0;
  625. funcname:=nil;
  626. WriteFileLineInfo(hp.fileinfo);
  627. {$endif GDB}
  628. if lastsec<>sec_none then
  629. AsmWriteLn(ait_section2str(lastsec));
  630. AsmStartSize:=AsmSize;
  631. end;
  632. end;
  633. ait_marker :
  634. if tai_marker(hp).kind=InlineStart then
  635. inc(InlineLevel)
  636. else if tai_marker(hp).kind=InlineEnd then
  637. dec(InlineLevel);
  638. else
  639. internalerror(10000);
  640. end;
  641. hp:=tai(hp.next);
  642. end;
  643. end;
  644. procedure TGNUAssembler.WriteAsmList;
  645. var
  646. p:dirstr;
  647. n:namestr;
  648. e:extstr;
  649. {$ifdef GDB}
  650. fileinfo : tfileposinfo;
  651. {$endif GDB}
  652. begin
  653. {$ifdef EXTDEBUG}
  654. if assigned(current_module.mainsource) then
  655. Comment(v_info,'Start writing gas-styled assembler output for '+current_module.mainsource^);
  656. {$endif}
  657. LastSec:=sec_none;
  658. {$ifdef GDB}
  659. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  660. {$endif GDB}
  661. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  662. LastInfile:=nil;
  663. if assigned(current_module.mainsource) then
  664. fsplit(current_module.mainsource^,p,n,e)
  665. else
  666. begin
  667. p:=inputdir;
  668. n:=inputfile;
  669. e:=inputextension;
  670. end;
  671. { to get symify to work }
  672. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  673. {$ifdef GDB}
  674. n_line:=n_bssline;
  675. funcname:=nil;
  676. linecount:=1;
  677. includecount:=0;
  678. fileinfo.fileindex:=1;
  679. fileinfo.line:=1;
  680. { Write main file }
  681. WriteFileLineInfo(fileinfo);
  682. {$endif GDB}
  683. AsmStartSize:=AsmSize;
  684. symendcount:=0;
  685. countlabelref:=false;
  686. If (cs_debuginfo in aktmoduleswitches) then
  687. WriteTree(debuglist);
  688. WriteTree(codesegment);
  689. WriteTree(datasegment);
  690. WriteTree(consts);
  691. WriteTree(rttilist);
  692. Writetree(resourcestringlist);
  693. WriteTree(bsssegment);
  694. Writetree(importssection);
  695. { exports are written by DLLTOOL
  696. if we use it so don't insert it twice (PM) }
  697. if not UseDeffileForExport and assigned(exportssection) then
  698. Writetree(exportssection);
  699. Writetree(resourcesection);
  700. {$ifdef GDB}
  701. WriteFileEndInfo;
  702. {$ENDIF}
  703. countlabelref:=true;
  704. AsmLn;
  705. {$ifdef EXTDEBUG}
  706. if assigned(current_module.mainsource) then
  707. comment(v_info,'Done writing gas-styled assembler output for '+current_module.mainsource^);
  708. {$endif EXTDEBUG}
  709. end;
  710. end.
  711. {
  712. $Log$
  713. Revision 1.4 2002-05-16 19:46:34 carl
  714. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  715. + try to fix temp allocation (still in ifdef)
  716. + generic constructor calls
  717. + start of tassembler / tmodulebase class cleanup
  718. Revision 1.2 2002/04/15 18:53:48 carl
  719. + comments in register allocator uses std_Reg2str
  720. Revision 1.1 2002/04/14 16:51:54 carl
  721. + basic GNU assembler writer class
  722. }