aggas.pas 33 KB

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