aggas.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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. dos,
  25. cclasses,
  26. globals,
  27. aasmbase,aasmtai,aasmcpu,
  28. assemble;
  29. type
  30. {# This is a derived class which is used to write
  31. GAS styled assembler.
  32. The WriteInstruction() method must be overriden
  33. to write a single instruction to the assembler
  34. file.
  35. }
  36. TGNUAssembler=class(texternalassembler)
  37. public
  38. procedure WriteTree(p:TAAsmoutput);override;
  39. procedure WriteAsmList;override;
  40. procedure WriteExtraHeader;virtual;
  41. {$ifdef GDB}
  42. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  43. procedure WriteFileEndInfo;
  44. {$endif}
  45. procedure WriteInstruction(hp: tai); virtual; abstract;
  46. end;
  47. const
  48. regname_count=45;
  49. regname_count_bsstart=32; { Largest power of 2 out of regname_count. }
  50. implementation
  51. uses
  52. cutils,globtype,systems,
  53. fmodule,finput,verbose,cpubase,
  54. itcpugas
  55. {$ifdef GDB}
  56. {$ifdef delphi}
  57. ,sysutils
  58. {$else}
  59. ,strings
  60. {$endif}
  61. ,gdb
  62. {$endif GDB}
  63. ;
  64. const
  65. line_length = 70;
  66. var
  67. {$ifdef GDB}
  68. n_line : byte; { different types of source lines }
  69. linecount,
  70. includecount : longint;
  71. funcname : pchar;
  72. stabslastfileinfo : tfileposinfo;
  73. {$endif}
  74. lasTSec : TSection; { last section type written }
  75. lastfileinfo : tfileposinfo;
  76. infile,
  77. lastinfile : tinputfile;
  78. symendcount : longint;
  79. type
  80. t80bitarray = array[0..9] of byte;
  81. t64bitarray = array[0..7] of byte;
  82. t32bitarray = array[0..3] of byte;
  83. {****************************************************************************}
  84. { Support routines }
  85. {****************************************************************************}
  86. function fixline(s:string):string;
  87. {
  88. return s with all leading and ending spaces and tabs removed
  89. }
  90. var
  91. i,j,k : integer;
  92. begin
  93. i:=length(s);
  94. while (i>0) and (s[i] in [#9,' ']) do
  95. dec(i);
  96. j:=1;
  97. while (j<i) and (s[j] in [#9,' ']) do
  98. inc(j);
  99. for k:=j to i do
  100. if s[k] in [#0..#31,#127..#255] then
  101. s[k]:='.';
  102. fixline:=Copy(s,j,i-j+1);
  103. end;
  104. function single2str(d : single) : string;
  105. var
  106. hs : string;
  107. begin
  108. str(d,hs);
  109. { replace space with + }
  110. if hs[1]=' ' then
  111. hs[1]:='+';
  112. single2str:='0d'+hs
  113. end;
  114. function double2str(d : double) : string;
  115. var
  116. hs : string;
  117. begin
  118. str(d,hs);
  119. { replace space with + }
  120. if hs[1]=' ' then
  121. hs[1]:='+';
  122. double2str:='0d'+hs
  123. end;
  124. function extended2str(e : extended) : string;
  125. var
  126. hs : string;
  127. begin
  128. str(e,hs);
  129. { replace space with + }
  130. if hs[1]=' ' then
  131. hs[1]:='+';
  132. extended2str:='0d'+hs
  133. end;
  134. { convert floating point values }
  135. { to correct endian }
  136. procedure swap64bitarray(var t: t64bitarray);
  137. var
  138. b: byte;
  139. begin
  140. b:= t[7];
  141. t[7] := t[0];
  142. t[0] := b;
  143. b := t[6];
  144. t[6] := t[1];
  145. t[1] := b;
  146. b:= t[5];
  147. t[5] := t[2];
  148. t[2] := b;
  149. b:= t[4];
  150. t[4] := t[3];
  151. t[3] := b;
  152. end;
  153. procedure swap32bitarray(var t: t32bitarray);
  154. var
  155. b: byte;
  156. begin
  157. b:= t[1];
  158. t[1]:= t[2];
  159. t[2]:= b;
  160. b:= t[0];
  161. t[0]:= t[3];
  162. t[3]:= b;
  163. end;
  164. const
  165. ait_const2str : array[ait_const_64bit..ait_const_8bit] of string[8]=
  166. (#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  167. function ait_section2str(s:TSection):string;
  168. begin
  169. ait_section2str:=target_asm.secnames[s];
  170. {$ifdef GDB}
  171. { this is needed for line info in data }
  172. funcname:=nil;
  173. case s of
  174. sec_code : n_line:=n_textline;
  175. sec_data : n_line:=n_dataline;
  176. sec_bss : n_line:=n_bssline;
  177. else n_line:=n_dataline;
  178. end;
  179. {$endif GDB}
  180. LasTSec:=s;
  181. end;
  182. {****************************************************************************}
  183. { GNU Assembler writer }
  184. {****************************************************************************}
  185. {$ifdef GDB}
  186. procedure TGNUAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  187. var
  188. curr_n : byte;
  189. begin
  190. if not ((cs_debuginfo in aktmoduleswitches) or
  191. (cs_gdb_lineinfo in aktglobalswitches)) then
  192. exit;
  193. { file changed ? (must be before line info) }
  194. if (fileinfo.fileindex<>0) and
  195. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  196. begin
  197. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  198. if assigned(infile) then
  199. begin
  200. if includecount=0 then
  201. curr_n:=n_sourcefile
  202. else
  203. curr_n:=n_includefile;
  204. if (infile.path^<>'') then
  205. begin
  206. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  207. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  208. end;
  209. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  210. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  211. AsmWriteLn(target_asm.labelprefix+'text'+ToStr(IncludeCount)+':');
  212. inc(includecount);
  213. { force new line info }
  214. stabslastfileinfo.line:=-1;
  215. end;
  216. end;
  217. { line changed ? }
  218. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  219. begin
  220. if (n_line=n_textline) and assigned(funcname) and
  221. (target_info.use_function_relative_addresses) then
  222. begin
  223. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  224. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  225. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  226. AsmWritePChar(FuncName);
  227. AsmLn;
  228. inc(linecount);
  229. end
  230. else
  231. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  232. end;
  233. stabslastfileinfo:=fileinfo;
  234. end;
  235. procedure TGNUAssembler.WriteFileEndInfo;
  236. begin
  237. if not ((cs_debuginfo in aktmoduleswitches) or
  238. (cs_gdb_lineinfo in aktglobalswitches)) then
  239. exit;
  240. AsmLn;
  241. AsmWriteLn(ait_section2str(sec_code));
  242. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,'+target_asm.labelprefix+'etext');
  243. AsmWriteLn(target_asm.labelprefix+'etext:');
  244. end;
  245. {$endif GDB}
  246. procedure TGNUAssembler.WriteTree(p:TAAsmoutput);
  247. const
  248. allocstr : array[boolean] of string[10]=(' released',' allocated');
  249. var
  250. ch : char;
  251. hp : tai;
  252. hp1 : tailineinfo;
  253. consttyp : taitype;
  254. s : string;
  255. found : boolean;
  256. i,pos,l : longint;
  257. InlineLevel : longint;
  258. last_align : longint;
  259. co : comp;
  260. sin : single;
  261. d : double;
  262. {$ifdef cpuextended}
  263. e : extended;
  264. {$endif cpuextended}
  265. do_line : boolean;
  266. begin
  267. if not assigned(p) then
  268. exit;
  269. last_align := 2;
  270. InlineLevel:=0;
  271. { lineinfo is only needed for codesegment (PFV) }
  272. do_line:=(cs_asm_source in aktglobalswitches) or
  273. ((cs_lineinfo in aktmoduleswitches)
  274. and (p=codesegment));
  275. hp:=tai(p.first);
  276. while assigned(hp) do
  277. begin
  278. if not(hp.typ in SkipLineInfo) then
  279. begin
  280. hp1 := hp as tailineinfo;
  281. aktfilepos:=hp1.fileinfo;
  282. {$ifdef GDB}
  283. { write stabs }
  284. if (cs_debuginfo in aktmoduleswitches) or
  285. (cs_gdb_lineinfo in aktglobalswitches) then
  286. WriteFileLineInfo(hp1.fileinfo);
  287. {$endif GDB}
  288. { no line info for inlined code }
  289. if do_line and (inlinelevel=0) then
  290. begin
  291. { load infile }
  292. if lastfileinfo.fileindex<>hp1.fileinfo.fileindex then
  293. begin
  294. infile:=current_module.sourcefiles.get_file(hp1.fileinfo.fileindex);
  295. if assigned(infile) then
  296. begin
  297. { open only if needed !! }
  298. if (cs_asm_source in aktglobalswitches) then
  299. infile.open;
  300. end;
  301. { avoid unnecessary reopens of the same file !! }
  302. lastfileinfo.fileindex:=hp1.fileinfo.fileindex;
  303. { be sure to change line !! }
  304. lastfileinfo.line:=-1;
  305. end;
  306. { write source }
  307. if (cs_asm_source in aktglobalswitches) and
  308. assigned(infile) then
  309. begin
  310. if (infile<>lastinfile) then
  311. begin
  312. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  313. if assigned(lastinfile) then
  314. lastinfile.close;
  315. end;
  316. if (hp1.fileinfo.line<>lastfileinfo.line) and
  317. ((hp1.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  318. begin
  319. if (hp1.fileinfo.line<>0) and
  320. ((infile.linebuf^[hp1.fileinfo.line]>=0) or (InlineLevel>0)) then
  321. AsmWriteLn(target_asm.comment+'['+tostr(hp1.fileinfo.line)+'] '+
  322. fixline(infile.GetLineStr(hp1.fileinfo.line)));
  323. { set it to a negative value !
  324. to make that is has been read already !! PM }
  325. if (infile.linebuf^[hp1.fileinfo.line]>=0) then
  326. infile.linebuf^[hp1.fileinfo.line]:=-infile.linebuf^[hp1.fileinfo.line]-1;
  327. end;
  328. end;
  329. lastfileinfo:=hp1.fileinfo;
  330. lastinfile:=infile;
  331. end;
  332. end;
  333. case hp.typ of
  334. ait_comment :
  335. Begin
  336. AsmWrite(target_asm.comment);
  337. AsmWritePChar(tai_comment(hp).str);
  338. AsmLn;
  339. End;
  340. ait_regalloc :
  341. begin
  342. if (cs_asm_regalloc in aktglobalswitches) then
  343. AsmWriteLn(#9+target_asm.comment+'Register '+gas_regname(Tai_regalloc(hp).reg)+
  344. allocstr[tai_regalloc(hp).allocation]);
  345. end;
  346. ait_tempalloc :
  347. begin
  348. if (cs_asm_tempalloc in aktglobalswitches) then
  349. begin
  350. {$ifdef EXTDEBUG}
  351. if assigned(tai_tempalloc(hp).problem) then
  352. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  353. tostr(tai_tempalloc(hp).tempsize)+' '+tai_tempalloc(hp).problem^)
  354. else
  355. {$endif EXTDEBUG}
  356. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  357. tostr(tai_tempalloc(hp).tempsize)+allocstr[tai_tempalloc(hp).allocation]);
  358. end;
  359. end;
  360. ait_align :
  361. begin
  362. if target_info.system <> system_powerpc_darwin then
  363. begin
  364. AsmWrite(#9'.balign '+tostr(tai_align(hp).aligntype));
  365. if tai_align(hp).use_op then
  366. AsmWrite(','+tostr(tai_align(hp).fillop))
  367. end
  368. else
  369. begin
  370. { darwin as only supports .align }
  371. if not ispowerof2(tai_align(hp).aligntype,i) then
  372. internalerror(2003010305);
  373. AsmWrite(#9'.align '+tostr(i));
  374. last_align := i;
  375. end;
  376. AsmLn;
  377. end;
  378. ait_section :
  379. begin
  380. if tai_section(hp).sec<>sec_none then
  381. begin
  382. AsmLn;
  383. AsmWriteLn(ait_section2str(tai_section(hp).sec));
  384. {$ifdef GDB}
  385. lastfileinfo.line:=-1;
  386. {$endif GDB}
  387. end
  388. else
  389. begin
  390. {$ifdef EXTDEBUG}
  391. AsmWrite(target_asm.comment);
  392. AsmWriteln(' sec_none');
  393. {$endif EXTDEBUG}
  394. end;
  395. end;
  396. ait_datablock :
  397. begin
  398. if tai_datablock(hp).is_global then
  399. AsmWrite(#9'.comm'#9)
  400. else
  401. AsmWrite(#9'.lcomm'#9);
  402. AsmWrite(tai_datablock(hp).sym.name);
  403. AsmWrite(','+tostr(tai_datablock(hp).size));
  404. if (target_info.system = system_powerpc_darwin) and
  405. not(tai_datablock(hp).is_global) then
  406. AsmWrite(','+tostr(last_align));
  407. AsmWriteln('');
  408. end;
  409. ait_const_64bit,
  410. ait_const_32bit,
  411. ait_const_16bit,
  412. ait_const_8bit :
  413. begin
  414. AsmWrite(ait_const2str[hp.typ]+tostru(tai_const(hp).value));
  415. consttyp:=hp.typ;
  416. l:=0;
  417. repeat
  418. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  419. if found then
  420. begin
  421. hp:=tai(hp.next);
  422. s:=','+tostru(tai_const(hp).value);
  423. AsmWrite(s);
  424. inc(l,length(s));
  425. end;
  426. until (not found) or (l>line_length);
  427. AsmLn;
  428. end;
  429. ait_const_symbol :
  430. begin
  431. AsmWrite(#9'.long'#9);
  432. AsmWrite(tai_const_symbol(hp).sym.name);
  433. if tai_const_symbol(hp).offset>0 then
  434. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  435. else if tai_const_symbol(hp).offset<0 then
  436. AsmWrite(tostr(tai_const_symbol(hp).offset));
  437. AsmLn;
  438. end;
  439. ait_indirect_symbol :
  440. begin
  441. AsmWrite(#9'.indirect_symbol'#9);
  442. AsmWrite(tai_const_symbol(hp).sym.name);
  443. AsmLn;
  444. end;
  445. ait_const_rva :
  446. begin
  447. AsmWrite(#9'.rva'#9);
  448. AsmWriteLn(tai_const_symbol(hp).sym.name);
  449. end;
  450. {$ifdef cpuextended}
  451. ait_real_80bit :
  452. begin
  453. if do_line then
  454. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_real_80bit(hp).value));
  455. { Make sure e is a extended type, bestreal could be
  456. a different type (bestreal) !! (PFV) }
  457. e:=tai_real_80bit(hp).value;
  458. AsmWrite(#9'.byte'#9);
  459. for i:=0 to 9 do
  460. begin
  461. if i<>0 then
  462. AsmWrite(',');
  463. AsmWrite(tostr(t80bitarray(e)[i]));
  464. end;
  465. AsmLn;
  466. end;
  467. {$endif cpuextended}
  468. ait_real_64bit :
  469. begin
  470. if do_line then
  471. AsmWriteLn(target_asm.comment+'value: '+double2str(tai_real_64bit(hp).value));
  472. d:=tai_real_64bit(hp).value;
  473. { swap the values to correct endian if required }
  474. if source_info.endian <> target_info.endian then
  475. swap64bitarray(t64bitarray(d));
  476. AsmWrite(#9'.byte'#9);
  477. {$ifdef arm}
  478. { on a real arm cpu, it's already hi/lo swapped }
  479. {$ifndef cpuarm}
  480. if tai_real_64bit(hp).formatoptions=fo_hiloswapped then
  481. begin
  482. for i:=4 to 7 do
  483. begin
  484. if i<>4 then
  485. AsmWrite(',');
  486. AsmWrite(tostr(t64bitarray(d)[i]));
  487. end;
  488. for i:=0 to 3 do
  489. begin
  490. AsmWrite(',');
  491. AsmWrite(tostr(t64bitarray(d)[i]));
  492. end;
  493. end
  494. else
  495. {$endif cpuarm}
  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.51 2004-04-27 13:38:24 florian
  801. * fixed wrong commit from yesterday
  802. Revision 1.50 2004/04/25 21:26:16 florian
  803. * some m68k stuff fixed
  804. Revision 1.49 2004/04/12 18:59:32 florian
  805. * small x86_64 fixes
  806. Revision 1.48 2004/03/17 22:27:41 florian
  807. * fixed handling of doubles in a native arm compiler
  808. * fixed handling of typed double constants on arm
  809. Revision 1.47 2004/03/02 17:32:12 florian
  810. * make cycle fixed
  811. + pic support for darwin
  812. + support of importing vars from shared libs on darwin implemented
  813. Revision 1.46 2004/02/22 16:51:50 peter
  814. * tf_need_symbol_size added
  815. Revision 1.45 2004/01/24 18:12:40 florian
  816. * fixed several arm floating point issues
  817. Revision 1.44 2004/01/20 21:02:54 florian
  818. * fixed symbol type writing for arm-linux
  819. * fixed assembler generation for abs
  820. Revision 1.43 2004/01/12 16:39:40 peter
  821. * sparc updates, mostly float related
  822. Revision 1.42 2004/01/07 17:40:06 jonas
  823. * darwin requires the alginment of .lcomm symbols to be specified
  824. together with the symbol itself, instead of in a .align directive
  825. Revision 1.41 2004/01/04 21:08:59 jonas
  826. * darwin only supports .align, no .balign
  827. Revision 1.40 2004/01/03 13:51:05 jonas
  828. + support exported procedures for linuxppc
  829. * refuse to compile systems/t_linux.pas if processor-specific support
  830. for exported procedures is absent
  831. + generate .type and .size info for all currently defined linux-variants
  832. in aggas.pas
  833. Revision 1.39 2003/12/14 22:42:54 peter
  834. * fixed range check error
  835. Revision 1.38 2003/12/10 17:13:22 peter
  836. * fix range error with tai_const
  837. Revision 1.37 2003/11/12 16:05:39 florian
  838. * assembler readers OOPed
  839. + typed currency constants
  840. + typed 128 bit float constants if the CPU supports it
  841. Revision 1.36 2003/10/01 20:34:48 peter
  842. * procinfo unit contains tprocinfo
  843. * cginfo renamed to cgbase
  844. * moved cgmessage to verbose
  845. * fixed ppc and sparc compiles
  846. Revision 1.35 2003/09/23 17:56:05 peter
  847. * locals and paras are allocated in the code generation
  848. * tvarsym.localloc contains the location of para/local when
  849. generating code for the current procedure
  850. Revision 1.34 2003/09/06 16:47:24 florian
  851. + support of NaN and Inf in the compiler as values of real constants
  852. Revision 1.33 2003/09/04 00:15:29 florian
  853. * first bunch of adaptions of arm compiler for new register type
  854. Revision 1.32 2003/09/03 19:35:24 peter
  855. * powerpc compiles again
  856. Revision 1.31 2003/09/03 15:55:00 peter
  857. * NEWRA branch merged
  858. Revision 1.30 2003/09/03 11:18:36 florian
  859. * fixed arm concatcopy
  860. + arm support in the common compiler sources added
  861. * moved some generic cg code around
  862. + tfputype added
  863. * ...
  864. Revision 1.29.2.2 2003/09/01 21:02:55 peter
  865. * sparc updates for new tregister
  866. Revision 1.29.2.1 2003/08/31 15:46:26 peter
  867. * more updates for tregister
  868. Revision 1.29 2003/08/19 11:53:03 daniel
  869. * Fixed PowerPC compilation
  870. Revision 1.28 2003/08/18 11:49:47 daniel
  871. * Made ATT asm writer work with -sr
  872. Revision 1.27 2003/08/17 21:11:00 daniel
  873. * Now -sr works...
  874. Revision 1.26 2003/08/17 20:47:47 daniel
  875. * Notranslation changed into -sr functionality
  876. Revision 1.25 2003/08/17 16:59:20 jonas
  877. * fixed regvars so they work with newra (at least for ppc)
  878. * fixed some volatile register bugs
  879. + -dnotranslation option for -dnewra, which causes the registers not to
  880. be translated from virtual to normal registers. Requires support in
  881. the assembler writer as well, which is only implemented in aggas/
  882. agppcgas currently
  883. Revision 1.24 2003/04/28 21:17:53 peter
  884. * write sec_none info in extdebug
  885. Revision 1.23 2003/04/25 20:59:33 peter
  886. * removed funcretn,funcretsym, function result is now in varsym
  887. and aliases for result and function name are added using absolutesym
  888. * vs_hidden parameter for funcret passed in parameter
  889. * vs_hidden fixes
  890. * writenode changed to printnode and released from extdebug
  891. * -vp option added to generate a tree.log with the nodetree
  892. * nicer printnode for statements, callnode
  893. Revision 1.22 2003/04/24 22:29:57 florian
  894. * fixed a lot of PowerPC related stuff
  895. Revision 1.21 2003/04/22 14:33:38 peter
  896. * removed some notes/hints
  897. Revision 1.20 2003/01/09 21:52:37 peter
  898. * merged some verbosity options.
  899. * V_LineInfo is a verbosity flag to include line info
  900. Revision 1.19 2003/01/08 18:43:56 daniel
  901. * Tregister changed into a record
  902. Revision 1.18 2002/12/07 14:03:25 carl
  903. - remove some duplicates and unused vars
  904. Revision 1.17 2002/12/06 17:50:39 peter
  905. * long symbol name fix merged
  906. Revision 1.16 2002/11/17 16:31:55 carl
  907. * memory optimization (3-4%) : cleanup of tai fields,
  908. cleanup of tdef and tsym fields.
  909. * make it work for m68k
  910. Revision 1.15 2002/11/15 01:58:45 peter
  911. * merged changes from 1.0.7 up to 04-11
  912. - -V option for generating bug report tracing
  913. - more tracing for option parsing
  914. - errors for cdecl and high()
  915. - win32 import stabs
  916. - win32 records<=8 are returned in eax:edx (turned off by default)
  917. - heaptrc update
  918. - more info for temp management in .s file with EXTDEBUG
  919. Revision 1.14 2002/10/30 21:01:14 peter
  920. * always include lineno after fileswitch. valgrind requires this
  921. Revision 1.13 2002/10/05 12:43:23 carl
  922. * fixes for Delphi 6 compilation
  923. (warning : Some features do not work under Delphi)
  924. Revision 1.12 2002/08/31 16:05:17 florian
  925. * write double # before float constants when -al is turned on
  926. else some gas versions interpret it as line number
  927. Revision 1.11 2002/08/20 16:55:38 peter
  928. * don't write (stabs)line info when inlining a procedure
  929. Revision 1.10 2002/08/18 22:16:14 florian
  930. + the ppc gas assembler writer adds now registers aliases
  931. to the assembler file
  932. Revision 1.9 2002/08/18 20:06:23 peter
  933. * inlining is now also allowed in interface
  934. * renamed write/load to ppuwrite/ppuload
  935. * tnode storing in ppu
  936. * nld,ncon,nbas are already updated for storing in ppu
  937. Revision 1.8 2002/07/26 21:15:37 florian
  938. * rewrote the system handling
  939. Revision 1.7 2002/07/07 09:52:32 florian
  940. * powerpc target fixed, very simple units can be compiled
  941. * some basic stuff for better callparanode handling, far from being finished
  942. Revision 1.6 2002/07/01 18:46:20 peter
  943. * internal linker
  944. * reorganized aasm layer
  945. Revision 1.5 2002/05/18 13:34:05 peter
  946. * readded missing revisions
  947. Revision 1.4 2002/05/16 19:46:34 carl
  948. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  949. + try to fix temp allocation (still in ifdef)
  950. + generic constructor calls
  951. + start of tassembler / tmodulebase class cleanup
  952. Revision 1.2 2002/04/15 18:53:48 carl
  953. + comments in register allocator uses std_Reg2str
  954. Revision 1.1 2002/04/14 16:51:54 carl
  955. + basic GNU assembler writer class
  956. }