aggas.pas 34 KB

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