aggas.pas 35 KB

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