aggas.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983
  1. {
  2. $Id$
  3. Copyright (c) 1998-2004 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. protected
  38. function sectionname(atype:tasmsectiontype;const aname:string):string;virtual;
  39. procedure WriteSection(atype:tasmsectiontype;const aname:string);
  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. public
  47. procedure WriteTree(p:TAAsmoutput);override;
  48. procedure WriteAsmList;override;
  49. end;
  50. const
  51. regname_count=45;
  52. regname_count_bsstart=32; { Largest power of 2 out of regname_count. }
  53. implementation
  54. uses
  55. cutils,globtype,systems,
  56. fmodule,finput,verbose,
  57. itcpugas
  58. {$ifdef GDB}
  59. {$ifdef delphi}
  60. ,sysutils
  61. {$else}
  62. ,strings
  63. {$endif}
  64. ,gdb
  65. {$endif GDB}
  66. ;
  67. const
  68. line_length = 70;
  69. var
  70. {$ifdef GDB}
  71. n_line : byte; { different types of source lines }
  72. linecount,
  73. includecount : longint;
  74. funcname : pchar;
  75. stabslastfileinfo : tfileposinfo;
  76. {$endif}
  77. lasTSecType : TAsmSectionType; { last section type written }
  78. lastfileinfo : tfileposinfo;
  79. infile,
  80. lastinfile : tinputfile;
  81. symendcount : longint;
  82. type
  83. {$ifdef cpuextended}
  84. t80bitarray = array[0..9] of byte;
  85. {$endif cpuextended}
  86. t64bitarray = array[0..7] of byte;
  87. t32bitarray = array[0..3] of byte;
  88. {****************************************************************************}
  89. { Support routines }
  90. {****************************************************************************}
  91. function fixline(s:string):string;
  92. {
  93. return s with all leading and ending spaces and tabs removed
  94. }
  95. var
  96. i,j,k : integer;
  97. begin
  98. i:=length(s);
  99. while (i>0) and (s[i] in [#9,' ']) do
  100. dec(i);
  101. j:=1;
  102. while (j<i) and (s[j] in [#9,' ']) do
  103. inc(j);
  104. for k:=j to i do
  105. if s[k] in [#0..#31,#127..#255] then
  106. s[k]:='.';
  107. fixline:=Copy(s,j,i-j+1);
  108. end;
  109. function single2str(d : single) : string;
  110. var
  111. hs : string;
  112. begin
  113. str(d,hs);
  114. { replace space with + }
  115. if hs[1]=' ' then
  116. hs[1]:='+';
  117. single2str:='0d'+hs
  118. end;
  119. function double2str(d : double) : string;
  120. var
  121. hs : string;
  122. begin
  123. str(d,hs);
  124. { replace space with + }
  125. if hs[1]=' ' then
  126. hs[1]:='+';
  127. double2str:='0d'+hs
  128. end;
  129. function extended2str(e : extended) : string;
  130. var
  131. hs : string;
  132. begin
  133. str(e,hs);
  134. { replace space with + }
  135. if hs[1]=' ' then
  136. hs[1]:='+';
  137. extended2str:='0d'+hs
  138. end;
  139. { convert floating point values }
  140. { to correct endian }
  141. procedure swap64bitarray(var t: t64bitarray);
  142. var
  143. b: byte;
  144. begin
  145. b:= t[7];
  146. t[7] := t[0];
  147. t[0] := b;
  148. b := t[6];
  149. t[6] := t[1];
  150. t[1] := b;
  151. b:= t[5];
  152. t[5] := t[2];
  153. t[2] := b;
  154. b:= t[4];
  155. t[4] := t[3];
  156. t[3] := b;
  157. end;
  158. procedure swap32bitarray(var t: t32bitarray);
  159. var
  160. b: byte;
  161. begin
  162. b:= t[1];
  163. t[1]:= t[2];
  164. t[2]:= b;
  165. b:= t[0];
  166. t[0]:= t[3];
  167. t[3]:= b;
  168. end;
  169. const
  170. ait_const2str : array[ait_const_128bit..ait_const_indirect_symbol] of string[20]=(
  171. #9'.fixme128'#9,#9'.quad'#9,#9'.long'#9,#9'.short'#9,#9'.byte'#9,
  172. #9'.sleb128'#9,#9'.uleb128'#9,
  173. #9'.rva'#9,#9'.indirect_symbol'#9
  174. );
  175. {****************************************************************************}
  176. { GNU Assembler writer }
  177. {****************************************************************************}
  178. {$ifdef GDB}
  179. procedure TGNUAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  180. var
  181. curr_n : byte;
  182. begin
  183. if not ((cs_debuginfo in aktmoduleswitches) or
  184. (cs_gdb_lineinfo in aktglobalswitches)) then
  185. exit;
  186. { file changed ? (must be before line info) }
  187. if (fileinfo.fileindex<>0) and
  188. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  189. begin
  190. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  191. if assigned(infile) then
  192. begin
  193. if includecount=0 then
  194. curr_n:=n_sourcefile
  195. else
  196. curr_n:=n_includefile;
  197. if (infile.path^<>'') then
  198. begin
  199. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  200. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  201. end;
  202. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  203. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  204. AsmWriteLn(target_asm.labelprefix+'text'+ToStr(IncludeCount)+':');
  205. inc(includecount);
  206. { force new line info }
  207. stabslastfileinfo.line:=-1;
  208. end;
  209. end;
  210. { line changed ? }
  211. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  212. begin
  213. if (n_line=n_textline) and assigned(funcname) and
  214. (target_info.use_function_relative_addresses) then
  215. begin
  216. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  217. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  218. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  219. AsmWritePChar(FuncName);
  220. AsmLn;
  221. inc(linecount);
  222. end
  223. else
  224. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  225. end;
  226. stabslastfileinfo:=fileinfo;
  227. end;
  228. procedure TGNUAssembler.WriteFileEndInfo;
  229. begin
  230. if not ((cs_debuginfo in aktmoduleswitches) or
  231. (cs_gdb_lineinfo in aktglobalswitches)) then
  232. exit;
  233. WriteSection(sec_code,'');
  234. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,'+target_asm.labelprefix+'etext');
  235. AsmWriteLn(target_asm.labelprefix+'etext:');
  236. end;
  237. {$endif GDB}
  238. function TGNUAssembler.sectionname(atype:tasmsectiontype;const aname:string):string;
  239. const
  240. secnames : array[tasmsectiontype] of string[12] = ('',
  241. {$warning TODO .rodata not yet working}
  242. '.text','.data','.data','.bss',
  243. 'common',
  244. '.note',
  245. '.stab','.stabstr',
  246. '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
  247. '.eh_frame',
  248. '.debug_frame'
  249. );
  250. begin
  251. if use_smartlink_section and
  252. (atype<>sec_bss) and
  253. (aname<>'') then
  254. result:='.gnu.linkonce'+copy(secnames[atype],1,2)+'.'+aname
  255. else
  256. result:=secnames[atype];
  257. end;
  258. procedure TGNUAssembler.WriteSection(atype:tasmsectiontype;const aname:string);
  259. var
  260. s : string;
  261. begin
  262. AsmLn;
  263. AsmWrite('.section ');
  264. s:=sectionname(atype,aname);
  265. AsmWrite(s);
  266. if copy(s,1,4)='.gnu' then
  267. begin
  268. case atype of
  269. sec_data :
  270. AsmWrite(',""');
  271. sec_code :
  272. AsmWrite(',"x"');
  273. end;
  274. end;
  275. AsmLn;
  276. {$ifdef GDB}
  277. { this is needed for line info in data }
  278. funcname:=nil;
  279. case atype of
  280. sec_code :
  281. n_line:=n_textline;
  282. sec_data :
  283. n_line:=n_dataline;
  284. sec_bss :
  285. n_line:=n_bssline;
  286. else
  287. n_line:=n_dataline;
  288. end;
  289. {$endif GDB}
  290. LasTSecType:=atype;
  291. end;
  292. procedure TGNUAssembler.WriteTree(p:TAAsmoutput);
  293. const
  294. regallocstr : array[tregalloctype] of string[10]=(' allocated',' released','resized');
  295. tempallocstr : array[boolean] of string[10]=(' released',' allocated');
  296. var
  297. ch : char;
  298. hp : tai;
  299. hp1 : tailineinfo;
  300. consttyp : taitype;
  301. s : string;
  302. i,pos,l : longint;
  303. InlineLevel : longint;
  304. last_align : longint;
  305. co : comp;
  306. sin : single;
  307. d : double;
  308. {$ifdef cpuextended}
  309. e : extended;
  310. {$endif cpuextended}
  311. do_line : boolean;
  312. begin
  313. if not assigned(p) then
  314. exit;
  315. last_align := 2;
  316. InlineLevel:=0;
  317. { lineinfo is only needed for codesegment (PFV) }
  318. do_line:=(cs_asm_source in aktglobalswitches) or
  319. ((cs_lineinfo in aktmoduleswitches)
  320. and (p=codesegment));
  321. hp:=tai(p.first);
  322. while assigned(hp) do
  323. begin
  324. if not(hp.typ in SkipLineInfo) then
  325. begin
  326. hp1 := hp as tailineinfo;
  327. aktfilepos:=hp1.fileinfo;
  328. {$ifdef GDB}
  329. { write stabs }
  330. if (cs_debuginfo in aktmoduleswitches) or
  331. (cs_gdb_lineinfo in aktglobalswitches) then
  332. WriteFileLineInfo(hp1.fileinfo);
  333. {$endif GDB}
  334. { no line info for inlined code }
  335. if do_line and (inlinelevel=0) then
  336. begin
  337. { load infile }
  338. if lastfileinfo.fileindex<>hp1.fileinfo.fileindex then
  339. begin
  340. infile:=current_module.sourcefiles.get_file(hp1.fileinfo.fileindex);
  341. if assigned(infile) then
  342. begin
  343. { open only if needed !! }
  344. if (cs_asm_source in aktglobalswitches) then
  345. infile.open;
  346. end;
  347. { avoid unnecessary reopens of the same file !! }
  348. lastfileinfo.fileindex:=hp1.fileinfo.fileindex;
  349. { be sure to change line !! }
  350. lastfileinfo.line:=-1;
  351. end;
  352. { write source }
  353. if (cs_asm_source in aktglobalswitches) and
  354. assigned(infile) then
  355. begin
  356. if (infile<>lastinfile) then
  357. begin
  358. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  359. if assigned(lastinfile) then
  360. lastinfile.close;
  361. end;
  362. if (hp1.fileinfo.line<>lastfileinfo.line) and
  363. ((hp1.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  364. begin
  365. if (hp1.fileinfo.line<>0) and
  366. ((infile.linebuf^[hp1.fileinfo.line]>=0) or (InlineLevel>0)) then
  367. AsmWriteLn(target_asm.comment+'['+tostr(hp1.fileinfo.line)+'] '+
  368. fixline(infile.GetLineStr(hp1.fileinfo.line)));
  369. { set it to a negative value !
  370. to make that is has been read already !! PM }
  371. if (infile.linebuf^[hp1.fileinfo.line]>=0) then
  372. infile.linebuf^[hp1.fileinfo.line]:=-infile.linebuf^[hp1.fileinfo.line]-1;
  373. end;
  374. end;
  375. lastfileinfo:=hp1.fileinfo;
  376. lastinfile:=infile;
  377. end;
  378. end;
  379. case hp.typ of
  380. ait_comment :
  381. Begin
  382. AsmWrite(target_asm.comment);
  383. AsmWritePChar(tai_comment(hp).str);
  384. AsmLn;
  385. End;
  386. ait_regalloc :
  387. begin
  388. if (cs_asm_regalloc in aktglobalswitches) then
  389. begin
  390. AsmWrite(#9+target_asm.comment+'Register ');
  391. repeat
  392. AsmWrite(gas_regname(Tai_regalloc(hp).reg));
  393. if (hp.next=nil) or
  394. (tai(hp.next).typ<>ait_regalloc) or
  395. (tai_regalloc(hp.next).ratype<>tai_regalloc(hp).ratype) then
  396. break;
  397. hp:=tai(hp.next);
  398. AsmWrite(',');
  399. until false;
  400. AsmWriteLn(regallocstr[tai_regalloc(hp).ratype]);
  401. end;
  402. end;
  403. ait_tempalloc :
  404. begin
  405. if (cs_asm_tempalloc in aktglobalswitches) then
  406. begin
  407. {$ifdef EXTDEBUG}
  408. if assigned(tai_tempalloc(hp).problem) then
  409. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  410. tostr(tai_tempalloc(hp).tempsize)+' '+tai_tempalloc(hp).problem^)
  411. else
  412. {$endif EXTDEBUG}
  413. AsmWriteLn(target_asm.comment+'Temp '+tostr(tai_tempalloc(hp).temppos)+','+
  414. tostr(tai_tempalloc(hp).tempsize)+tempallocstr[tai_tempalloc(hp).allocation]);
  415. end;
  416. end;
  417. ait_align :
  418. begin
  419. if tai_align(hp).aligntype>1 then
  420. begin
  421. if target_info.system <> system_powerpc_darwin then
  422. begin
  423. AsmWrite(#9'.balign '+tostr(tai_align(hp).aligntype));
  424. if tai_align(hp).use_op then
  425. AsmWrite(','+tostr(tai_align(hp).fillop))
  426. end
  427. else
  428. begin
  429. { darwin as only supports .align }
  430. if not ispowerof2(tai_align(hp).aligntype,i) then
  431. internalerror(2003010305);
  432. AsmWrite(#9'.align '+tostr(i));
  433. last_align := i;
  434. end;
  435. AsmLn;
  436. end;
  437. end;
  438. ait_section :
  439. begin
  440. if tai_section(hp).sectype<>sec_none then
  441. begin
  442. WriteSection(tai_section(hp).sectype,tai_section(hp).name^);
  443. {$ifdef GDB}
  444. lastfileinfo.line:=-1;
  445. {$endif GDB}
  446. end
  447. else
  448. begin
  449. {$ifdef EXTDEBUG}
  450. AsmWrite(target_asm.comment);
  451. AsmWriteln(' sec_none');
  452. {$endif EXTDEBUG}
  453. end;
  454. end;
  455. ait_datablock :
  456. begin
  457. if tai_datablock(hp).is_global then
  458. AsmWrite(#9'.comm'#9)
  459. else
  460. AsmWrite(#9'.lcomm'#9);
  461. AsmWrite(tai_datablock(hp).sym.name);
  462. AsmWrite(','+tostr(tai_datablock(hp).size));
  463. if (target_info.system = system_powerpc_darwin) and
  464. not(tai_datablock(hp).is_global) then
  465. AsmWrite(','+tostr(last_align));
  466. AsmWriteln('');
  467. end;
  468. {$ifndef cpu64bit}
  469. ait_const_128bit :
  470. begin
  471. internalerror(200404291);
  472. end;
  473. ait_const_64bit :
  474. begin
  475. if assigned(tai_const(hp).sym) then
  476. internalerror(200404292);
  477. AsmWrite(ait_const2str[ait_const_32bit]);
  478. if target_info.endian = endian_little then
  479. begin
  480. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  481. AsmWrite(',');
  482. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  483. end
  484. else
  485. begin
  486. AsmWrite(tostr(longint(hi(tai_const(hp).value))));
  487. AsmWrite(',');
  488. AsmWrite(tostr(longint(lo(tai_const(hp).value))));
  489. end;
  490. AsmLn;
  491. end;
  492. {$endif cpu64bit}
  493. ait_const_uleb128bit,
  494. ait_const_sleb128bit,
  495. {$ifdef cpu64bit}
  496. ait_const_128bit,
  497. ait_const_64bit,
  498. {$endif cpu64bit}
  499. ait_const_32bit,
  500. ait_const_16bit,
  501. ait_const_8bit,
  502. ait_const_rva_symbol,
  503. ait_const_indirect_symbol :
  504. begin
  505. AsmWrite(ait_const2str[hp.typ]);
  506. consttyp:=hp.typ;
  507. l:=0;
  508. repeat
  509. if assigned(tai_const(hp).sym) then
  510. begin
  511. if assigned(tai_const(hp).endsym) then
  512. s:=tai_const(hp).endsym.name+'-'+tai_const(hp).sym.name
  513. else
  514. s:=tai_const(hp).sym.name;
  515. if tai_const(hp).value<>0 then
  516. s:=s+tostr_with_plus(tai_const(hp).value);
  517. end
  518. else
  519. s:=tostr(tai_const(hp).value);
  520. AsmWrite(s);
  521. inc(l,length(s));
  522. if (LasTSecType<>sec_data) or
  523. (l>line_length) or
  524. (hp.next=nil) or
  525. (tai(hp.next).typ<>consttyp) then
  526. break;
  527. hp:=tai(hp.next);
  528. AsmWrite(',');
  529. until false;
  530. AsmLn;
  531. end;
  532. {$ifdef cpuextended}
  533. ait_real_80bit :
  534. begin
  535. if do_line then
  536. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_real_80bit(hp).value));
  537. { Make sure e is a extended type, bestreal could be
  538. a different type (bestreal) !! (PFV) }
  539. e:=tai_real_80bit(hp).value;
  540. AsmWrite(#9'.byte'#9);
  541. for i:=0 to 9 do
  542. begin
  543. if i<>0 then
  544. AsmWrite(',');
  545. AsmWrite(tostr(t80bitarray(e)[i]));
  546. end;
  547. AsmLn;
  548. end;
  549. {$endif cpuextended}
  550. ait_real_64bit :
  551. begin
  552. if do_line then
  553. AsmWriteLn(target_asm.comment+'value: '+double2str(tai_real_64bit(hp).value));
  554. d:=tai_real_64bit(hp).value;
  555. { swap the values to correct endian if required }
  556. if source_info.endian <> target_info.endian then
  557. swap64bitarray(t64bitarray(d));
  558. AsmWrite(#9'.byte'#9);
  559. {$ifdef arm}
  560. { on a real arm cpu, it's already hi/lo swapped }
  561. {$ifndef cpuarm}
  562. if tai_real_64bit(hp).formatoptions=fo_hiloswapped then
  563. begin
  564. for i:=4 to 7 do
  565. begin
  566. if i<>4 then
  567. AsmWrite(',');
  568. AsmWrite(tostr(t64bitarray(d)[i]));
  569. end;
  570. for i:=0 to 3 do
  571. begin
  572. AsmWrite(',');
  573. AsmWrite(tostr(t64bitarray(d)[i]));
  574. end;
  575. end
  576. else
  577. {$endif cpuarm}
  578. {$endif arm}
  579. begin
  580. for i:=0 to 7 do
  581. begin
  582. if i<>0 then
  583. AsmWrite(',');
  584. AsmWrite(tostr(t64bitarray(d)[i]));
  585. end;
  586. end;
  587. AsmLn;
  588. end;
  589. ait_real_32bit :
  590. begin
  591. if do_line then
  592. AsmWriteLn(target_asm.comment+'value: '+single2str(tai_real_32bit(hp).value));
  593. sin:=tai_real_32bit(hp).value;
  594. { swap the values to correct endian if required }
  595. if source_info.endian <> target_info.endian then
  596. swap32bitarray(t32bitarray(sin));
  597. AsmWrite(#9'.byte'#9);
  598. for i:=0 to 3 do
  599. begin
  600. if i<>0 then
  601. AsmWrite(',');
  602. AsmWrite(tostr(t32bitarray(sin)[i]));
  603. end;
  604. AsmLn;
  605. end;
  606. ait_comp_64bit :
  607. begin
  608. if do_line then
  609. AsmWriteLn(target_asm.comment+'value: '+extended2str(tai_comp_64bit(hp).value));
  610. AsmWrite(#9'.byte'#9);
  611. {$ifdef FPC}
  612. co:=comp(tai_comp_64bit(hp).value);
  613. {$else}
  614. co:=tai_comp_64bit(hp).value;
  615. {$endif}
  616. { swap the values to correct endian if required }
  617. if source_info.endian <> target_info.endian then
  618. swap64bitarray(t64bitarray(co));
  619. for i:=0 to 7 do
  620. begin
  621. if i<>0 then
  622. AsmWrite(',');
  623. AsmWrite(tostr(t64bitarray(co)[i]));
  624. end;
  625. AsmLn;
  626. end;
  627. ait_direct :
  628. begin
  629. AsmWritePChar(tai_direct(hp).str);
  630. AsmLn;
  631. {$IfDef GDB}
  632. if strpos(tai_direct(hp).str,'.data')<>nil then
  633. n_line:=n_dataline
  634. else if strpos(tai_direct(hp).str,'.text')<>nil then
  635. n_line:=n_textline
  636. else if strpos(tai_direct(hp).str,'.bss')<>nil then
  637. n_line:=n_bssline;
  638. {$endif GDB}
  639. end;
  640. ait_string :
  641. begin
  642. pos:=0;
  643. for i:=1 to tai_string(hp).len do
  644. begin
  645. if pos=0 then
  646. begin
  647. AsmWrite(#9'.ascii'#9'"');
  648. pos:=20;
  649. end;
  650. ch:=tai_string(hp).str[i-1];
  651. case ch of
  652. #0, {This can't be done by range, because a bug in FPC}
  653. #1..#31,
  654. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  655. '"' : s:='\"';
  656. '\' : s:='\\';
  657. else
  658. s:=ch;
  659. end;
  660. AsmWrite(s);
  661. inc(pos,length(s));
  662. if (pos>line_length) or (i=tai_string(hp).len) then
  663. begin
  664. AsmWriteLn('"');
  665. pos:=0;
  666. end;
  667. end;
  668. end;
  669. ait_label :
  670. begin
  671. if (tai_label(hp).l.is_used) then
  672. begin
  673. if tai_label(hp).l.defbind=AB_GLOBAL then
  674. begin
  675. AsmWrite('.globl'#9);
  676. AsmWriteLn(tai_label(hp).l.name);
  677. end;
  678. AsmWrite(tai_label(hp).l.name);
  679. AsmWriteLn(':');
  680. end;
  681. end;
  682. ait_symbol :
  683. begin
  684. if tai_symbol(hp).is_global then
  685. begin
  686. AsmWrite('.globl'#9);
  687. AsmWriteLn(tai_symbol(hp).sym.name);
  688. end;
  689. if target_info.system in [system_i386_linux,system_i386_beos,
  690. system_powerpc_linux,system_m68k_linux,
  691. system_sparc_linux,system_alpha_linux,
  692. system_x86_64_linux,system_arm_linux] then
  693. begin
  694. AsmWrite(#9'.type'#9);
  695. AsmWrite(tai_symbol(hp).sym.name);
  696. if assigned(tai(hp.next)) and
  697. (tai(hp.next).typ in [ait_const_rva_symbol,
  698. ait_const_32bit,ait_const_16bit,ait_const_8bit,ait_datablock,
  699. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit]) then
  700. begin
  701. if target_info.system = system_arm_linux then
  702. AsmWriteLn(',#object')
  703. else
  704. AsmWriteLn(',@object')
  705. end
  706. else
  707. begin
  708. if target_info.system = system_arm_linux then
  709. AsmWriteLn(',#function')
  710. else
  711. AsmWriteLn(',@function');
  712. end;
  713. if tai_symbol(hp).sym.size>0 then
  714. begin
  715. AsmWrite(#9'.size'#9);
  716. AsmWrite(tai_symbol(hp).sym.name);
  717. AsmWrite(', ');
  718. AsmWriteLn(tostr(tai_symbol(hp).sym.size));
  719. end;
  720. end;
  721. AsmWrite(tai_symbol(hp).sym.name);
  722. AsmWriteLn(':');
  723. end;
  724. ait_symbol_end :
  725. begin
  726. if tf_needs_symbol_size in target_info.flags then
  727. begin
  728. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  729. inc(symendcount);
  730. AsmWriteLn(s+':');
  731. AsmWrite(#9'.size'#9);
  732. AsmWrite(tai_symbol_end(hp).sym.name);
  733. AsmWrite(', '+s+' - ');
  734. AsmWriteLn(tai_symbol_end(hp).sym.name);
  735. end;
  736. end;
  737. ait_instruction :
  738. begin
  739. WriteInstruction(hp);
  740. end;
  741. {$ifdef GDB}
  742. ait_stabs :
  743. begin
  744. if assigned(tai_stabs(hp).str) then
  745. begin
  746. AsmWrite(#9'.stabs ');
  747. AsmWritePChar(tai_stabs(hp).str);
  748. AsmLn;
  749. end;
  750. end;
  751. ait_stabn :
  752. begin
  753. if assigned(tai_stabn(hp).str) then
  754. begin
  755. AsmWrite(#9'.stabn ');
  756. AsmWritePChar(tai_stabn(hp).str);
  757. AsmLn;
  758. end;
  759. end;
  760. ait_force_line :
  761. stabslastfileinfo.line:=0;
  762. ait_stab_function_name:
  763. funcname:=tai_stab_function_name(hp).str;
  764. {$endif GDB}
  765. ait_cutobject :
  766. begin
  767. if SmartAsm then
  768. begin
  769. { only reset buffer if nothing has changed }
  770. if AsmSize=AsmStartSize then
  771. AsmClear
  772. else
  773. begin
  774. AsmClose;
  775. DoAssemble;
  776. AsmCreate(tai_cutobject(hp).place);
  777. end;
  778. { avoid empty files }
  779. while assigned(hp.next) and (tai(hp.next).typ in [ait_cutobject,ait_section,ait_comment]) do
  780. begin
  781. if tai(hp.next).typ=ait_section then
  782. lasTSectype:=tai_section(hp.next).sectype;
  783. hp:=tai(hp.next);
  784. end;
  785. {$ifdef GDB}
  786. { force write of filename }
  787. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  788. includecount:=0;
  789. funcname:=nil;
  790. WriteFileLineInfo(aktfilepos);
  791. {$endif GDB}
  792. if lasTSectype<>sec_none then
  793. WriteSection(lasTSectype,'');
  794. AsmStartSize:=AsmSize;
  795. end;
  796. end;
  797. ait_marker :
  798. if tai_marker(hp).kind=InlineStart then
  799. inc(InlineLevel)
  800. else if tai_marker(hp).kind=InlineEnd then
  801. dec(InlineLevel);
  802. ait_non_lazy_symbol_pointer:
  803. AsmWriteLn('.non_lazy_symbol_pointer');
  804. else
  805. internalerror(10000);
  806. end;
  807. hp:=tai(hp.next);
  808. end;
  809. end;
  810. procedure TGNUAssembler.WriteExtraHeader;
  811. begin
  812. end;
  813. procedure TGNUAssembler.WriteAsmList;
  814. var
  815. p:dirstr;
  816. n:namestr;
  817. e:extstr;
  818. {$ifdef GDB}
  819. fileinfo : tfileposinfo;
  820. {$endif GDB}
  821. begin
  822. {$ifdef EXTDEBUG}
  823. if assigned(current_module.mainsource) then
  824. Comment(V_Debug,'Start writing gas-styled assembler output for '+current_module.mainsource^);
  825. {$endif}
  826. LasTSectype:=sec_none;
  827. {$ifdef GDB}
  828. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  829. {$endif GDB}
  830. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  831. LastInfile:=nil;
  832. if assigned(current_module.mainsource) then
  833. fsplit(current_module.mainsource^,p,n,e)
  834. else
  835. begin
  836. p:=inputdir;
  837. n:=inputfile;
  838. e:=inputextension;
  839. end;
  840. { to get symify to work }
  841. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  842. WriteExtraHeader;
  843. {$ifdef GDB}
  844. n_line:=n_bssline;
  845. funcname:=nil;
  846. linecount:=1;
  847. includecount:=0;
  848. fileinfo.fileindex:=1;
  849. fileinfo.line:=1;
  850. { Write main file }
  851. WriteFileLineInfo(fileinfo);
  852. {$endif GDB}
  853. AsmStartSize:=AsmSize;
  854. symendcount:=0;
  855. If (cs_debuginfo in aktmoduleswitches) then
  856. WriteTree(debuglist);
  857. WriteTree(codesegment);
  858. WriteTree(datasegment);
  859. WriteTree(consts);
  860. WriteTree(rttilist);
  861. WriteTree(picdata);
  862. Writetree(resourcestringlist);
  863. WriteTree(bsssegment);
  864. Writetree(importssection);
  865. { exports are written by DLLTOOL
  866. if we use it so don't insert it twice (PM) }
  867. if not UseDeffileForExports and assigned(exportssection) then
  868. Writetree(exportssection);
  869. Writetree(resourcesection);
  870. Writetree(dwarflist);
  871. {$ifdef GDB}
  872. WriteFileEndInfo;
  873. {$ENDIF}
  874. AsmLn;
  875. {$ifdef EXTDEBUG}
  876. if assigned(current_module.mainsource) then
  877. Comment(V_Debug,'Done writing gas-styled assembler output for '+current_module.mainsource^);
  878. {$endif EXTDEBUG}
  879. end;
  880. end.
  881. {
  882. $Log$
  883. Revision 1.55 2004-06-20 08:55:28 florian
  884. * logs truncated
  885. Revision 1.54 2004/06/16 20:07:06 florian
  886. * dwarf branch merged
  887. Revision 1.53 2004/05/28 21:13:08 peter
  888. * fix wrong regalloc comments
  889. Revision 1.52 2004/05/22 23:34:27 peter
  890. tai_regalloc.allocation changed to ratype to notify rgobj of register size changes
  891. Revision 1.51 2004/04/27 13:38:24 florian
  892. * fixed wrong commit from yesterday
  893. Revision 1.50 2004/04/25 21:26:16 florian
  894. * some m68k stuff fixed
  895. }