aggas.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. procedure swap80bitarray(var t: t80bitarray);
  165. begin
  166. {!!!!!!!!!!!!}
  167. end;
  168. const
  169. ait_const2str : array[ait_const_32bit..ait_const_8bit] of string[8]=
  170. (#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  171. function ait_section2str(s:TSection):string;
  172. begin
  173. ait_section2str:=target_asm.secnames[s];
  174. {$ifdef GDB}
  175. { this is needed for line info in data }
  176. funcname:=nil;
  177. case s of
  178. sec_code : n_line:=n_textline;
  179. sec_data : n_line:=n_dataline;
  180. sec_bss : n_line:=n_bssline;
  181. else n_line:=n_dataline;
  182. end;
  183. {$endif GDB}
  184. LasTSec:=s;
  185. end;
  186. {****************************************************************************}
  187. { GNU Assembler writer }
  188. {****************************************************************************}
  189. {$ifdef GDB}
  190. procedure TGNUAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  191. var
  192. curr_n : byte;
  193. begin
  194. if not ((cs_debuginfo in aktmoduleswitches) or
  195. (cs_gdb_lineinfo in aktglobalswitches)) then
  196. exit;
  197. { file changed ? (must be before line info) }
  198. if (fileinfo.fileindex<>0) and
  199. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  200. begin
  201. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  202. if assigned(infile) then
  203. begin
  204. if includecount=0 then
  205. curr_n:=n_sourcefile
  206. else
  207. curr_n:=n_includefile;
  208. if (infile.path^<>'') then
  209. begin
  210. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  211. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  212. end;
  213. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  214. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  215. AsmWriteLn('Ltext'+ToStr(IncludeCount)+':');
  216. inc(includecount);
  217. end;
  218. end;
  219. { line changed ? }
  220. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  221. begin
  222. if (n_line=n_textline) and assigned(funcname) and
  223. (target_info.use_function_relative_addresses) then
  224. begin
  225. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  226. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  227. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  228. AsmWritePChar(FuncName);
  229. AsmLn;
  230. inc(linecount);
  231. end
  232. else
  233. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  234. end;
  235. stabslastfileinfo:=fileinfo;
  236. end;
  237. procedure TGNUAssembler.WriteFileEndInfo;
  238. begin
  239. if not ((cs_debuginfo in aktmoduleswitches) or
  240. (cs_gdb_lineinfo in aktglobalswitches)) then
  241. exit;
  242. AsmLn;
  243. AsmWriteLn(ait_section2str(sec_code));
  244. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,Letext');
  245. AsmWriteLn('Letext:');
  246. end;
  247. {$endif GDB}
  248. procedure TGNUAssembler.WriteTree(p:TAAsmoutput);
  249. const
  250. allocstr : array[boolean] of string[10]=(' released',' allocated');
  251. nolinetai =[ait_label,
  252. ait_regalloc,ait_tempalloc,
  253. {$ifdef GDB}
  254. ait_stabn,ait_stabs,ait_stab_function_name,
  255. {$endif GDB}
  256. ait_cut,ait_marker,ait_align,ait_section];
  257. type
  258. t80bitarray = array[0..9] of byte;
  259. t64bitarray = array[0..7] of byte;
  260. t32bitarray = array[0..3] of byte;
  261. var
  262. ch : char;
  263. hp : tai;
  264. consttyp : taitype;
  265. s : string;
  266. found : boolean;
  267. i,pos,l : longint;
  268. InlineLevel : longint;
  269. co : comp;
  270. sin : single;
  271. d : double;
  272. e : extended;
  273. do_line : boolean;
  274. sep : char;
  275. begin
  276. if not assigned(p) then
  277. exit;
  278. InlineLevel:=0;
  279. { lineinfo is only needed for codesegment (PFV) }
  280. do_line:=(cs_asm_source in aktglobalswitches) or
  281. ((cs_lineinfo in aktmoduleswitches)
  282. and (p=codesegment));
  283. hp:=tai(p.first);
  284. while assigned(hp) do
  285. begin
  286. aktfilepos:=hp.fileinfo;
  287. if not(hp.typ in nolinetai) then
  288. begin
  289. {$ifdef GDB}
  290. { write stabs }
  291. if (cs_debuginfo in aktmoduleswitches) or
  292. (cs_gdb_lineinfo in aktglobalswitches) then
  293. WriteFileLineInfo(hp.fileinfo);
  294. {$endif GDB}
  295. if do_line then
  296. begin
  297. { load infile }
  298. if lastfileinfo.fileindex<>hp.fileinfo.fileindex then
  299. begin
  300. infile:=current_module.sourcefiles.get_file(hp.fileinfo.fileindex);
  301. if assigned(infile) then
  302. begin
  303. { open only if needed !! }
  304. if (cs_asm_source in aktglobalswitches) then
  305. infile.open;
  306. end;
  307. { avoid unnecessary reopens of the same file !! }
  308. lastfileinfo.fileindex:=hp.fileinfo.fileindex;
  309. { be sure to change line !! }
  310. lastfileinfo.line:=-1;
  311. end;
  312. { write source }
  313. if (cs_asm_source in aktglobalswitches) and
  314. assigned(infile) then
  315. begin
  316. if (infile<>lastinfile) then
  317. begin
  318. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  319. if assigned(lastinfile) then
  320. lastinfile.close;
  321. end;
  322. if (hp.fileinfo.line<>lastfileinfo.line) and
  323. ((hp.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  324. begin
  325. if (hp.fileinfo.line<>0) and
  326. ((infile.linebuf^[hp.fileinfo.line]>=0) or (InlineLevel>0)) then
  327. AsmWriteLn(target_asm.comment+'['+tostr(hp.fileinfo.line)+'] '+
  328. fixline(infile.GetLineStr(hp.fileinfo.line)));
  329. { set it to a negative value !
  330. to make that is has been read already !! PM }
  331. if (infile.linebuf^[hp.fileinfo.line]>=0) then
  332. infile.linebuf^[hp.fileinfo.line]:=-infile.linebuf^[hp.fileinfo.line]-1;
  333. end;
  334. end;
  335. lastfileinfo:=hp.fileinfo;
  336. lastinfile:=infile;
  337. end;
  338. end;
  339. case hp.typ of
  340. ait_comment :
  341. Begin
  342. AsmWrite(target_asm.comment);
  343. AsmWritePChar(tai_comment(hp).str);
  344. AsmLn;
  345. End;
  346. ait_regalloc :
  347. begin
  348. if (cs_asm_regalloc in aktglobalswitches) then
  349. AsmWriteLn(target_asm.comment+'Register '+std_reg2str[tai_regalloc(hp).reg]+
  350. allocstr[tai_regalloc(hp).allocation]);
  351. end;
  352. ait_tempalloc :
  353. begin
  354. if (cs_asm_tempalloc in aktglobalswitches) then
  355. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  356. tostr(tai_tempalloc(hp).tempsize)+allocstr[tai_tempalloc(hp).allocation]);
  357. end;
  358. ait_align :
  359. begin
  360. AsmWrite(#9'.balign '+tostr(tai_align(hp).aligntype));
  361. if tai_align(hp).use_op then
  362. AsmWrite(','+tostr(tai_align(hp).fillop));
  363. AsmLn;
  364. end;
  365. ait_section :
  366. begin
  367. if tai_section(hp).sec<>sec_none then
  368. begin
  369. AsmLn;
  370. AsmWriteLn(ait_section2str(tai_section(hp).sec));
  371. {$ifdef GDB}
  372. lastfileinfo.line:=-1;
  373. {$endif GDB}
  374. end;
  375. end;
  376. ait_datablock :
  377. begin
  378. if tai_datablock(hp).is_global then
  379. AsmWrite(#9'.comm'#9)
  380. else
  381. AsmWrite(#9'.lcomm'#9);
  382. AsmWrite(tai_datablock(hp).sym.name);
  383. AsmWriteLn(','+tostr(tai_datablock(hp).size));
  384. end;
  385. ait_const_32bit,
  386. ait_const_16bit,
  387. ait_const_8bit :
  388. begin
  389. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  390. consttyp:=hp.typ;
  391. l:=0;
  392. repeat
  393. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  394. if found then
  395. begin
  396. hp:=tai(hp.next);
  397. s:=','+tostr(tai_const(hp).value);
  398. AsmWrite(s);
  399. inc(l,length(s));
  400. end;
  401. until (not found) or (l>line_length);
  402. AsmLn;
  403. end;
  404. ait_const_symbol :
  405. begin
  406. AsmWrite(#9'.long'#9+tai_const_symbol(hp).sym.name);
  407. if tai_const_symbol(hp).offset>0 then
  408. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  409. else if tai_const_symbol(hp).offset<0 then
  410. AsmWrite(tostr(tai_const_symbol(hp).offset));
  411. AsmLn;
  412. end;
  413. ait_const_rva :
  414. AsmWriteLn(#9'.rva'#9+tai_const_symbol(hp).sym.name);
  415. ait_real_80bit :
  416. begin
  417. if do_line then
  418. AsmWriteLn(target_asm.comment+extended2str(tai_real_80bit(hp).value));
  419. { Make sure e is a extended type, bestreal could be
  420. a different type (bestreal) !! (PFV) }
  421. e:=tai_real_80bit(hp).value;
  422. AsmWrite(#9'.byte'#9);
  423. for i:=0 to 9 do
  424. begin
  425. if i<>0 then
  426. AsmWrite(',');
  427. AsmWrite(tostr(t80bitarray(e)[i]));
  428. end;
  429. AsmLn;
  430. end;
  431. ait_real_64bit :
  432. begin
  433. if do_line then
  434. AsmWriteLn(target_asm.comment+double2str(tai_real_64bit(hp).value));
  435. d:=tai_real_64bit(hp).value;
  436. { swap the values to correct endian if required }
  437. if source_info.endian <> target_info.endian then
  438. swap64bitarray(t64bitarray(d));
  439. AsmWrite(#9'.byte'#9);
  440. for i:=0 to 7 do
  441. begin
  442. if i<>0 then
  443. AsmWrite(',');
  444. AsmWrite(tostr(t64bitarray(d)[i]));
  445. end;
  446. AsmLn;
  447. end;
  448. ait_real_32bit :
  449. begin
  450. if do_line then
  451. AsmWriteLn(target_asm.comment+single2str(tai_real_32bit(hp).value));
  452. sin:=tai_real_32bit(hp).value;
  453. { swap the values to correct endian if required }
  454. if source_info.endian <> target_info.endian then
  455. swap32bitarray(t32bitarray(sin));
  456. AsmWrite(#9'.byte'#9);
  457. for i:=0 to 3 do
  458. begin
  459. if i<>0 then
  460. AsmWrite(',');
  461. AsmWrite(tostr(t32bitarray(sin)[i]));
  462. end;
  463. AsmLn;
  464. end;
  465. ait_comp_64bit :
  466. begin
  467. if do_line then
  468. AsmWriteLn(target_asm.comment+extended2str(tai_comp_64bit(hp).value));
  469. AsmWrite(#9'.byte'#9);
  470. {$ifdef FPC}
  471. co:=comp(tai_comp_64bit(hp).value);
  472. {$else}
  473. co:=tai_comp_64bit(hp).value;
  474. {$endif}
  475. { swap the values to correct endian if required }
  476. if source_info.endian <> target_info.endian then
  477. swap64bitarray(t64bitarray(co));
  478. for i:=0 to 7 do
  479. begin
  480. if i<>0 then
  481. AsmWrite(',');
  482. AsmWrite(tostr(t64bitarray(co)[i]));
  483. end;
  484. AsmLn;
  485. end;
  486. ait_direct :
  487. begin
  488. AsmWritePChar(tai_direct(hp).str);
  489. AsmLn;
  490. {$IfDef GDB}
  491. if strpos(tai_direct(hp).str,'.data')<>nil then
  492. n_line:=n_dataline
  493. else if strpos(tai_direct(hp).str,'.text')<>nil then
  494. n_line:=n_textline
  495. else if strpos(tai_direct(hp).str,'.bss')<>nil then
  496. n_line:=n_bssline;
  497. {$endif GDB}
  498. end;
  499. ait_string :
  500. begin
  501. pos:=0;
  502. for i:=1 to tai_string(hp).len do
  503. begin
  504. if pos=0 then
  505. begin
  506. AsmWrite(#9'.ascii'#9'"');
  507. pos:=20;
  508. end;
  509. ch:=tai_string(hp).str[i-1];
  510. case ch of
  511. #0, {This can't be done by range, because a bug in FPC}
  512. #1..#31,
  513. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  514. '"' : s:='\"';
  515. '\' : s:='\\';
  516. else
  517. s:=ch;
  518. end;
  519. AsmWrite(s);
  520. inc(pos,length(s));
  521. if (pos>line_length) or (i=tai_string(hp).len) then
  522. begin
  523. AsmWriteLn('"');
  524. pos:=0;
  525. end;
  526. end;
  527. end;
  528. ait_label :
  529. begin
  530. if (tai_label(hp).l.is_used) then
  531. begin
  532. if tai_label(hp).l.defbind=AB_GLOBAL then
  533. begin
  534. AsmWrite('.globl'#9);
  535. AsmWriteLn(tai_label(hp).l.name);
  536. end;
  537. AsmWrite(tai_label(hp).l.name);
  538. AsmWriteLn(':');
  539. end;
  540. end;
  541. ait_symbol :
  542. begin
  543. if tai_symbol(hp).is_global then
  544. begin
  545. AsmWrite('.globl'#9);
  546. AsmWriteLn(tai_symbol(hp).sym.name);
  547. end;
  548. if target_info.system in [system_i386_linux,system_i386_beos] then
  549. begin
  550. AsmWrite(#9'.type'#9);
  551. AsmWrite(tai_symbol(hp).sym.name);
  552. if assigned(tai(hp.next)) and
  553. (tai(hp.next).typ in [ait_const_symbol,ait_const_rva,
  554. ait_const_32bit,ait_const_16bit,ait_const_8bit,ait_datablock,
  555. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit]) then
  556. AsmWriteLn(',@object')
  557. else
  558. AsmWriteLn(',@function');
  559. if tai_symbol(hp).sym.size>0 then
  560. begin
  561. AsmWrite(#9'.size'#9);
  562. AsmWrite(tai_symbol(hp).sym.name);
  563. AsmWrite(', ');
  564. AsmWriteLn(tostr(tai_symbol(hp).sym.size));
  565. end;
  566. end;
  567. AsmWrite(tai_symbol(hp).sym.name);
  568. AsmWriteLn(':');
  569. end;
  570. ait_symbol_end :
  571. begin
  572. if target_info.system in [system_i386_linux,system_i386_beos] then
  573. begin
  574. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  575. inc(symendcount);
  576. AsmWriteLn(s+':');
  577. AsmWrite(#9'.size'#9);
  578. AsmWrite(tai_symbol_end(hp).sym.name);
  579. AsmWrite(', '+s+' - ');
  580. AsmWriteLn(tai_symbol_end(hp).sym.name);
  581. end;
  582. end;
  583. ait_instruction :
  584. begin
  585. WriteInstruction(hp);
  586. end;
  587. {$ifdef GDB}
  588. ait_stabs :
  589. begin
  590. AsmWrite(#9'.stabs ');
  591. AsmWritePChar(tai_stabs(hp).str);
  592. AsmLn;
  593. end;
  594. ait_stabn :
  595. begin
  596. AsmWrite(#9'.stabn ');
  597. AsmWritePChar(tai_stabn(hp).str);
  598. AsmLn;
  599. end;
  600. ait_force_line :
  601. stabslastfileinfo.line:=0;
  602. ait_stab_function_name:
  603. funcname:=tai_stab_function_name(hp).str;
  604. {$endif GDB}
  605. ait_cut :
  606. begin
  607. if SmartAsm then
  608. begin
  609. { only reset buffer if nothing has changed }
  610. if AsmSize=AsmStartSize then
  611. AsmClear
  612. else
  613. begin
  614. AsmClose;
  615. DoAssemble;
  616. AsmCreate(tai_cut(hp).place);
  617. end;
  618. { avoid empty files }
  619. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  620. begin
  621. if tai(hp.next).typ=ait_section then
  622. lasTSec:=tai_section(hp.next).sec;
  623. hp:=tai(hp.next);
  624. end;
  625. {$ifdef GDB}
  626. { force write of filename }
  627. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  628. includecount:=0;
  629. funcname:=nil;
  630. WriteFileLineInfo(hp.fileinfo);
  631. {$endif GDB}
  632. if lasTSec<>sec_none then
  633. AsmWriteLn(ait_section2str(lasTSec));
  634. AsmStartSize:=AsmSize;
  635. end;
  636. end;
  637. ait_marker :
  638. if tai_marker(hp).kind=InlineStart then
  639. inc(InlineLevel)
  640. else if tai_marker(hp).kind=InlineEnd then
  641. dec(InlineLevel);
  642. else
  643. internalerror(10000);
  644. end;
  645. hp:=tai(hp.next);
  646. end;
  647. end;
  648. procedure TGNUAssembler.WriteExtraHeader;
  649. begin
  650. end;
  651. procedure TGNUAssembler.WriteAsmList;
  652. var
  653. p:dirstr;
  654. n:namestr;
  655. e:extstr;
  656. {$ifdef GDB}
  657. fileinfo : tfileposinfo;
  658. {$endif GDB}
  659. begin
  660. {$ifdef EXTDEBUG}
  661. if assigned(current_module.mainsource) then
  662. Comment(v_info,'Start writing gas-styled assembler output for '+current_module.mainsource^);
  663. {$endif}
  664. LasTSec:=sec_none;
  665. {$ifdef GDB}
  666. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  667. {$endif GDB}
  668. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  669. LastInfile:=nil;
  670. if assigned(current_module.mainsource) then
  671. fsplit(current_module.mainsource^,p,n,e)
  672. else
  673. begin
  674. p:=inputdir;
  675. n:=inputfile;
  676. e:=inputextension;
  677. end;
  678. { to get symify to work }
  679. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  680. WriteExtraHeader;
  681. {$ifdef GDB}
  682. n_line:=n_bssline;
  683. funcname:=nil;
  684. linecount:=1;
  685. includecount:=0;
  686. fileinfo.fileindex:=1;
  687. fileinfo.line:=1;
  688. { Write main file }
  689. WriteFileLineInfo(fileinfo);
  690. {$endif GDB}
  691. AsmStartSize:=AsmSize;
  692. symendcount:=0;
  693. If (cs_debuginfo in aktmoduleswitches) then
  694. WriteTree(debuglist);
  695. WriteTree(codesegment);
  696. WriteTree(datasegment);
  697. WriteTree(consts);
  698. WriteTree(rttilist);
  699. Writetree(resourcestringlist);
  700. WriteTree(bsssegment);
  701. Writetree(importssection);
  702. { exports are written by DLLTOOL
  703. if we use it so don't insert it twice (PM) }
  704. if not UseDeffileForExport and assigned(exportssection) then
  705. Writetree(exportssection);
  706. Writetree(resourcesection);
  707. {$ifdef GDB}
  708. WriteFileEndInfo;
  709. {$ENDIF}
  710. AsmLn;
  711. {$ifdef EXTDEBUG}
  712. if assigned(current_module.mainsource) then
  713. comment(v_info,'Done writing gas-styled assembler output for '+current_module.mainsource^);
  714. {$endif EXTDEBUG}
  715. end;
  716. end.
  717. {
  718. $Log$
  719. Revision 1.10 2002-08-18 22:16:14 florian
  720. + the ppc gas assembler writer adds now registers aliases
  721. to the assembler file
  722. Revision 1.9 2002/08/18 20:06:23 peter
  723. * inlining is now also allowed in interface
  724. * renamed write/load to ppuwrite/ppuload
  725. * tnode storing in ppu
  726. * nld,ncon,nbas are already updated for storing in ppu
  727. Revision 1.8 2002/07/26 21:15:37 florian
  728. * rewrote the system handling
  729. Revision 1.7 2002/07/07 09:52:32 florian
  730. * powerpc target fixed, very simple units can be compiled
  731. * some basic stuff for better callparanode handling, far from being finished
  732. Revision 1.6 2002/07/01 18:46:20 peter
  733. * internal linker
  734. * reorganized aasm layer
  735. Revision 1.5 2002/05/18 13:34:05 peter
  736. * readded missing revisions
  737. Revision 1.4 2002/05/16 19:46:34 carl
  738. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  739. + try to fix temp allocation (still in ifdef)
  740. + generic constructor calls
  741. + start of tassembler / tmodulebase class cleanup
  742. Revision 1.2 2002/04/15 18:53:48 carl
  743. + comments in register allocator uses std_Reg2str
  744. Revision 1.1 2002/04/14 16:51:54 carl
  745. + basic GNU assembler writer class
  746. }