aggas.pas 34 KB

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