aggas.pas 34 KB

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