aggas.pas 32 KB

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