aggas.pas 28 KB

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