aggas.pas 32 KB

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