aggas.pas 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022
  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. AsmWriteLn(',@object')
  594. else
  595. AsmWriteLn(',@function');
  596. if tai_symbol(hp).sym.size>0 then
  597. begin
  598. AsmWrite(#9'.size'#9);
  599. AsmWrite(tai_symbol(hp).sym.name);
  600. AsmWrite(', ');
  601. AsmWriteLn(tostr(tai_symbol(hp).sym.size));
  602. end;
  603. end;
  604. AsmWrite(tai_symbol(hp).sym.name);
  605. AsmWriteLn(':');
  606. end;
  607. ait_symbol_end :
  608. begin
  609. if target_info.system in [system_i386_linux,system_i386_beos] then
  610. begin
  611. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  612. inc(symendcount);
  613. AsmWriteLn(s+':');
  614. AsmWrite(#9'.size'#9);
  615. AsmWrite(tai_symbol_end(hp).sym.name);
  616. AsmWrite(', '+s+' - ');
  617. AsmWriteLn(tai_symbol_end(hp).sym.name);
  618. end;
  619. end;
  620. ait_instruction :
  621. begin
  622. WriteInstruction(hp);
  623. end;
  624. {$ifdef GDB}
  625. ait_stabs :
  626. begin
  627. if assigned(tai_stabs(hp).str) then
  628. begin
  629. AsmWrite(#9'.stabs ');
  630. AsmWritePChar(tai_stabs(hp).str);
  631. AsmLn;
  632. end;
  633. end;
  634. ait_stabn :
  635. begin
  636. if assigned(tai_stabn(hp).str) then
  637. begin
  638. AsmWrite(#9'.stabn ');
  639. AsmWritePChar(tai_stabn(hp).str);
  640. AsmLn;
  641. end;
  642. end;
  643. ait_force_line :
  644. stabslastfileinfo.line:=0;
  645. ait_stab_function_name:
  646. funcname:=tai_stab_function_name(hp).str;
  647. {$endif GDB}
  648. ait_cut :
  649. begin
  650. if SmartAsm then
  651. begin
  652. { only reset buffer if nothing has changed }
  653. if AsmSize=AsmStartSize then
  654. AsmClear
  655. else
  656. begin
  657. AsmClose;
  658. DoAssemble;
  659. AsmCreate(tai_cut(hp).place);
  660. end;
  661. { avoid empty files }
  662. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  663. begin
  664. if tai(hp.next).typ=ait_section then
  665. lasTSec:=tai_section(hp.next).sec;
  666. hp:=tai(hp.next);
  667. end;
  668. {$ifdef GDB}
  669. { force write of filename }
  670. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  671. includecount:=0;
  672. funcname:=nil;
  673. WriteFileLineInfo(aktfilepos);
  674. {$endif GDB}
  675. if lasTSec<>sec_none then
  676. AsmWriteLn(ait_section2str(lasTSec));
  677. AsmStartSize:=AsmSize;
  678. end;
  679. end;
  680. ait_marker :
  681. if tai_marker(hp).kind=InlineStart then
  682. inc(InlineLevel)
  683. else if tai_marker(hp).kind=InlineEnd then
  684. dec(InlineLevel);
  685. else
  686. internalerror(10000);
  687. end;
  688. hp:=tai(hp.next);
  689. end;
  690. end;
  691. procedure TGNUAssembler.WriteExtraHeader;
  692. begin
  693. end;
  694. procedure TGNUAssembler.WriteAsmList;
  695. var
  696. p:dirstr;
  697. n:namestr;
  698. e:extstr;
  699. {$ifdef GDB}
  700. fileinfo : tfileposinfo;
  701. {$endif GDB}
  702. begin
  703. {$ifdef EXTDEBUG}
  704. if assigned(current_module.mainsource) then
  705. Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource^);
  706. {$endif}
  707. LasTSec:=sec_none;
  708. {$ifdef GDB}
  709. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  710. {$endif GDB}
  711. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  712. LastInfile:=nil;
  713. if assigned(current_module.mainsource) then
  714. fsplit(current_module.mainsource^,p,n,e)
  715. else
  716. begin
  717. p:=inputdir;
  718. n:=inputfile;
  719. e:=inputextension;
  720. end;
  721. { to get symify to work }
  722. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  723. WriteExtraHeader;
  724. {$ifdef GDB}
  725. n_line:=n_bssline;
  726. funcname:=nil;
  727. linecount:=1;
  728. includecount:=0;
  729. fileinfo.fileindex:=1;
  730. fileinfo.line:=1;
  731. { Write main file }
  732. WriteFileLineInfo(fileinfo);
  733. {$endif GDB}
  734. AsmStartSize:=AsmSize;
  735. symendcount:=0;
  736. If (cs_debuginfo in aktmoduleswitches) then
  737. WriteTree(debuglist);
  738. WriteTree(codesegment);
  739. WriteTree(datasegment);
  740. WriteTree(consts);
  741. WriteTree(rttilist);
  742. Writetree(resourcestringlist);
  743. WriteTree(bsssegment);
  744. Writetree(importssection);
  745. { exports are written by DLLTOOL
  746. if we use it so don't insert it twice (PM) }
  747. if not UseDeffileForExport and assigned(exportssection) then
  748. Writetree(exportssection);
  749. Writetree(resourcesection);
  750. {$ifdef GDB}
  751. WriteFileEndInfo;
  752. {$ENDIF}
  753. AsmLn;
  754. {$ifdef EXTDEBUG}
  755. if assigned(current_module.mainsource) then
  756. Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource^);
  757. {$endif EXTDEBUG}
  758. end;
  759. end.
  760. {
  761. $Log$
  762. Revision 1.43 2004-01-12 16:39:40 peter
  763. * sparc updates, mostly float related
  764. Revision 1.42 2004/01/07 17:40:06 jonas
  765. * darwin requires the alginment of .lcomm symbols to be specified
  766. together with the symbol itself, instead of in a .align directive
  767. Revision 1.41 2004/01/04 21:08:59 jonas
  768. * darwin only supports .align, no .balign
  769. Revision 1.40 2004/01/03 13:51:05 jonas
  770. + support exported procedures for linuxppc
  771. * refuse to compile systems/t_linux.pas if processor-specific support
  772. for exported procedures is absent
  773. + generate .type and .size info for all currently defined linux-variants
  774. in aggas.pas
  775. Revision 1.39 2003/12/14 22:42:54 peter
  776. * fixed range check error
  777. Revision 1.38 2003/12/10 17:13:22 peter
  778. * fix range error with tai_const
  779. Revision 1.37 2003/11/12 16:05:39 florian
  780. * assembler readers OOPed
  781. + typed currency constants
  782. + typed 128 bit float constants if the CPU supports it
  783. Revision 1.36 2003/10/01 20:34:48 peter
  784. * procinfo unit contains tprocinfo
  785. * cginfo renamed to cgbase
  786. * moved cgmessage to verbose
  787. * fixed ppc and sparc compiles
  788. Revision 1.35 2003/09/23 17:56:05 peter
  789. * locals and paras are allocated in the code generation
  790. * tvarsym.localloc contains the location of para/local when
  791. generating code for the current procedure
  792. Revision 1.34 2003/09/06 16:47:24 florian
  793. + support of NaN and Inf in the compiler as values of real constants
  794. Revision 1.33 2003/09/04 00:15:29 florian
  795. * first bunch of adaptions of arm compiler for new register type
  796. Revision 1.32 2003/09/03 19:35:24 peter
  797. * powerpc compiles again
  798. Revision 1.31 2003/09/03 15:55:00 peter
  799. * NEWRA branch merged
  800. Revision 1.30 2003/09/03 11:18:36 florian
  801. * fixed arm concatcopy
  802. + arm support in the common compiler sources added
  803. * moved some generic cg code around
  804. + tfputype added
  805. * ...
  806. Revision 1.29.2.2 2003/09/01 21:02:55 peter
  807. * sparc updates for new tregister
  808. Revision 1.29.2.1 2003/08/31 15:46:26 peter
  809. * more updates for tregister
  810. Revision 1.29 2003/08/19 11:53:03 daniel
  811. * Fixed PowerPC compilation
  812. Revision 1.28 2003/08/18 11:49:47 daniel
  813. * Made ATT asm writer work with -sr
  814. Revision 1.27 2003/08/17 21:11:00 daniel
  815. * Now -sr works...
  816. Revision 1.26 2003/08/17 20:47:47 daniel
  817. * Notranslation changed into -sr functionality
  818. Revision 1.25 2003/08/17 16:59:20 jonas
  819. * fixed regvars so they work with newra (at least for ppc)
  820. * fixed some volatile register bugs
  821. + -dnotranslation option for -dnewra, which causes the registers not to
  822. be translated from virtual to normal registers. Requires support in
  823. the assembler writer as well, which is only implemented in aggas/
  824. agppcgas currently
  825. Revision 1.24 2003/04/28 21:17:53 peter
  826. * write sec_none info in extdebug
  827. Revision 1.23 2003/04/25 20:59:33 peter
  828. * removed funcretn,funcretsym, function result is now in varsym
  829. and aliases for result and function name are added using absolutesym
  830. * vs_hidden parameter for funcret passed in parameter
  831. * vs_hidden fixes
  832. * writenode changed to printnode and released from extdebug
  833. * -vp option added to generate a tree.log with the nodetree
  834. * nicer printnode for statements, callnode
  835. Revision 1.22 2003/04/24 22:29:57 florian
  836. * fixed a lot of PowerPC related stuff
  837. Revision 1.21 2003/04/22 14:33:38 peter
  838. * removed some notes/hints
  839. Revision 1.20 2003/01/09 21:52:37 peter
  840. * merged some verbosity options.
  841. * V_LineInfo is a verbosity flag to include line info
  842. Revision 1.19 2003/01/08 18:43:56 daniel
  843. * Tregister changed into a record
  844. Revision 1.18 2002/12/07 14:03:25 carl
  845. - remove some duplicates and unused vars
  846. Revision 1.17 2002/12/06 17:50:39 peter
  847. * long symbol name fix merged
  848. Revision 1.16 2002/11/17 16:31:55 carl
  849. * memory optimization (3-4%) : cleanup of tai fields,
  850. cleanup of tdef and tsym fields.
  851. * make it work for m68k
  852. Revision 1.15 2002/11/15 01:58:45 peter
  853. * merged changes from 1.0.7 up to 04-11
  854. - -V option for generating bug report tracing
  855. - more tracing for option parsing
  856. - errors for cdecl and high()
  857. - win32 import stabs
  858. - win32 records<=8 are returned in eax:edx (turned off by default)
  859. - heaptrc update
  860. - more info for temp management in .s file with EXTDEBUG
  861. Revision 1.14 2002/10/30 21:01:14 peter
  862. * always include lineno after fileswitch. valgrind requires this
  863. Revision 1.13 2002/10/05 12:43:23 carl
  864. * fixes for Delphi 6 compilation
  865. (warning : Some features do not work under Delphi)
  866. Revision 1.12 2002/08/31 16:05:17 florian
  867. * write double # before float constants when -al is turned on
  868. else some gas versions interpret it as line number
  869. Revision 1.11 2002/08/20 16:55:38 peter
  870. * don't write (stabs)line info when inlining a procedure
  871. Revision 1.10 2002/08/18 22:16:14 florian
  872. + the ppc gas assembler writer adds now registers aliases
  873. to the assembler file
  874. Revision 1.9 2002/08/18 20:06:23 peter
  875. * inlining is now also allowed in interface
  876. * renamed write/load to ppuwrite/ppuload
  877. * tnode storing in ppu
  878. * nld,ncon,nbas are already updated for storing in ppu
  879. Revision 1.8 2002/07/26 21:15:37 florian
  880. * rewrote the system handling
  881. Revision 1.7 2002/07/07 09:52:32 florian
  882. * powerpc target fixed, very simple units can be compiled
  883. * some basic stuff for better callparanode handling, far from being finished
  884. Revision 1.6 2002/07/01 18:46:20 peter
  885. * internal linker
  886. * reorganized aasm layer
  887. Revision 1.5 2002/05/18 13:34:05 peter
  888. * readded missing revisions
  889. Revision 1.4 2002/05/16 19:46:34 carl
  890. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  891. + try to fix temp allocation (still in ifdef)
  892. + generic constructor calls
  893. + start of tassembler / tmodulebase class cleanup
  894. Revision 1.2 2002/04/15 18:53:48 carl
  895. + comments in register allocator uses std_Reg2str
  896. Revision 1.1 2002/04/14 16:51:54 carl
  897. + basic GNU assembler writer class
  898. }