aggas.pas 34 KB

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