ag386att.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements an asmoutput class for i386 AT&T syntax
  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. unit ag386att;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. cobjects,
  23. globals,
  24. aasm,assemble;
  25. type
  26. pi386attasmlist=^ti386attasmlist;
  27. ti386attasmlist=object(tasmlist)
  28. procedure WriteTree(p:TAAsmoutput);virtual;
  29. procedure WriteAsmList;virtual;
  30. {$ifdef GDB}
  31. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  32. procedure WriteFileEndInfo;
  33. {$endif}
  34. end;
  35. implementation
  36. uses
  37. {$ifdef Delphi}
  38. sysutils,
  39. dmisc,
  40. {$else Delphi}
  41. strings,
  42. dos,
  43. {$endif Delphi}
  44. cutils,globtype,systems,
  45. fmodule,finput,verbose,cpubase,cpuasm
  46. {$ifdef GDB}
  47. ,gdb
  48. {$endif GDB}
  49. ;
  50. const
  51. line_length = 70;
  52. var
  53. {$ifdef GDB}
  54. n_line : byte; { different types of source lines }
  55. linecount,
  56. includecount : longint;
  57. funcname : pchar;
  58. stabslastfileinfo : tfileposinfo;
  59. {$endif}
  60. lastsec : tsection; { last section type written }
  61. lastfileinfo : tfileposinfo;
  62. infile,
  63. lastinfile : tinputfile;
  64. symendcount : longint;
  65. function fixline(s:string):string;
  66. {
  67. return s with all leading and ending spaces and tabs removed
  68. }
  69. var
  70. i,j,k : longint;
  71. begin
  72. i:=length(s);
  73. while (i>0) and (s[i] in [#9,' ']) do
  74. dec(i);
  75. j:=1;
  76. while (j<i) and (s[j] in [#9,' ']) do
  77. inc(j);
  78. for k:=j to i do
  79. if s[k] in [#0..#31,#127..#255] then
  80. s[k]:='.';
  81. fixline:=Copy(s,j,i-j+1);
  82. end;
  83. function single2str(d : single) : string;
  84. var
  85. hs : string;
  86. begin
  87. str(d,hs);
  88. { replace space with + }
  89. if hs[1]=' ' then
  90. hs[1]:='+';
  91. single2str:='0d'+hs
  92. end;
  93. function double2str(d : double) : string;
  94. var
  95. hs : string;
  96. begin
  97. str(d,hs);
  98. { replace space with + }
  99. if hs[1]=' ' then
  100. hs[1]:='+';
  101. double2str:='0d'+hs
  102. end;
  103. function extended2str(e : extended) : string;
  104. var
  105. hs : string;
  106. begin
  107. str(e,hs);
  108. { replace space with + }
  109. if hs[1]=' ' then
  110. hs[1]:='+';
  111. extended2str:='0d'+hs
  112. end;
  113. type
  114. pdouble = ^double;
  115. function comp2str(d : bestreal) : string;
  116. var
  117. c : comp;
  118. dd : pdouble;
  119. begin
  120. {$ifdef FPC}
  121. c:=comp(d);
  122. {$else}
  123. c:=d;
  124. {$endif}
  125. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  126. comp2str:=double2str(dd^);
  127. end;
  128. function getreferencestring(var ref : treference) : string;
  129. var
  130. s : string;
  131. begin
  132. if ref.is_immediate then
  133. begin
  134. internalerror(1000101);
  135. exit;
  136. end
  137. else
  138. begin
  139. with ref do
  140. begin
  141. inc(offset,offsetfixup);
  142. offsetfixup:=0;
  143. { have we a segment prefix ? }
  144. { These are probably not correctly handled under GAS }
  145. { should be replaced by coding the segment override }
  146. { directly! - DJGPP FAQ }
  147. if segment<>R_NO then
  148. s:=att_reg2str[segment]+':'
  149. else
  150. s:='';
  151. if assigned(symbol) then
  152. s:=s+symbol^.name;
  153. if offset<0 then
  154. s:=s+tostr(offset)
  155. else
  156. if (offset>0) then
  157. begin
  158. if assigned(symbol) then
  159. s:=s+'+'+tostr(offset)
  160. else
  161. s:=s+tostr(offset);
  162. end;
  163. if (index<>R_NO) and (base=R_NO) then
  164. Begin
  165. s:=s+'(,'+att_reg2str[index];
  166. if scalefactor<>0 then
  167. s:=s+','+tostr(scalefactor)+')'
  168. else
  169. s:=s+')';
  170. end
  171. else
  172. if (index=R_NO) and (base<>R_NO) then
  173. s:=s+'('+att_reg2str[base]+')'
  174. else
  175. if (index<>R_NO) and (base<>R_NO) then
  176. Begin
  177. s:=s+'('+att_reg2str[base]+','+att_reg2str[index];
  178. if scalefactor<>0 then
  179. s:=s+','+tostr(scalefactor)+')'
  180. else
  181. s := s+')';
  182. end;
  183. end;
  184. end;
  185. getreferencestring:=s;
  186. end;
  187. function getopstr(const o:toper) : string;
  188. var
  189. hs : string;
  190. begin
  191. case o.typ of
  192. top_reg :
  193. getopstr:=att_reg2str[o.reg];
  194. top_ref :
  195. getopstr:=getreferencestring(o.ref^);
  196. top_const :
  197. getopstr:='$'+tostr(o.val);
  198. top_symbol :
  199. begin
  200. if assigned(o.sym) then
  201. hs:='$'+o.sym^.name
  202. else
  203. hs:='$';
  204. if o.symofs>0 then
  205. hs:=hs+'+'+tostr(o.symofs)
  206. else
  207. if o.symofs<0 then
  208. hs:=hs+tostr(o.symofs)
  209. else
  210. if not(assigned(o.sym)) then
  211. hs:=hs+'0';
  212. getopstr:=hs;
  213. end;
  214. else
  215. internalerror(10001);
  216. end;
  217. end;
  218. function getopstr_jmp(const o:toper) : string;
  219. var
  220. hs : string;
  221. begin
  222. case o.typ of
  223. top_reg :
  224. getopstr_jmp:='*'+att_reg2str[o.reg];
  225. top_ref :
  226. getopstr_jmp:='*'+getreferencestring(o.ref^);
  227. top_const :
  228. getopstr_jmp:=tostr(o.val);
  229. top_symbol :
  230. begin
  231. hs:=o.sym^.name;
  232. if o.symofs>0 then
  233. hs:=hs+'+'+tostr(o.symofs)
  234. else
  235. if o.symofs<0 then
  236. hs:=hs+tostr(o.symofs);
  237. getopstr_jmp:=hs;
  238. end;
  239. else
  240. internalerror(10001);
  241. end;
  242. end;
  243. {****************************************************************************
  244. TI386ATTASMOUTPUT
  245. ****************************************************************************}
  246. const
  247. ait_const2str : array[ait_const_32bit..ait_const_8bit] of string[8]=
  248. (#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  249. function ait_section2str(s:tsection):string;
  250. begin
  251. ait_section2str:=target_asm.secnames[s];
  252. {$ifdef GDB}
  253. { this is needed for line info in data }
  254. funcname:=nil;
  255. case s of
  256. sec_code : n_line:=n_textline;
  257. sec_data : n_line:=n_dataline;
  258. sec_bss : n_line:=n_bssline;
  259. else n_line:=n_dataline;
  260. end;
  261. {$endif GDB}
  262. LastSec:=s;
  263. end;
  264. {$ifdef GDB}
  265. procedure ti386attasmlist.WriteFileLineInfo(var fileinfo : tfileposinfo);
  266. var
  267. curr_n : byte;
  268. begin
  269. if not ((cs_debuginfo in aktmoduleswitches) or
  270. (cs_gdb_lineinfo in aktglobalswitches)) then
  271. exit;
  272. { file changed ? (must be before line info) }
  273. if (fileinfo.fileindex<>0) and
  274. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  275. begin
  276. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  277. if assigned(infile) then
  278. begin
  279. if includecount=0 then
  280. curr_n:=n_sourcefile
  281. else
  282. curr_n:=n_includefile;
  283. if (infile.path^<>'') then
  284. begin
  285. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  286. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  287. end;
  288. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  289. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  290. AsmWriteLn('Ltext'+ToStr(IncludeCount)+':');
  291. inc(includecount);
  292. end;
  293. end;
  294. { line changed ? }
  295. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  296. begin
  297. if (n_line=n_textline) and assigned(funcname) and
  298. (target_os.use_function_relative_addresses) then
  299. begin
  300. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  301. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  302. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  303. AsmWritePChar(FuncName);
  304. AsmLn;
  305. inc(linecount);
  306. end
  307. else
  308. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  309. end;
  310. stabslastfileinfo:=fileinfo;
  311. end;
  312. procedure ti386attasmlist.WriteFileEndInfo;
  313. begin
  314. if not ((cs_debuginfo in aktmoduleswitches) or
  315. (cs_gdb_lineinfo in aktglobalswitches)) then
  316. exit;
  317. AsmLn;
  318. AsmWriteLn(ait_section2str(sec_code));
  319. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,Letext');
  320. AsmWriteLn('Letext:');
  321. end;
  322. {$endif GDB}
  323. procedure ti386attasmlist.WriteTree(p:TAAsmoutput);
  324. const
  325. allocstr : array[boolean] of string[10]=(' released',' allocated');
  326. nolinetai =[ait_label,
  327. ait_regalloc,ait_tempalloc,
  328. ait_stabn,ait_stabs,ait_section,
  329. ait_cut,ait_marker,ait_align,ait_stab_function_name];
  330. type
  331. t80bitarray = array[0..9] of byte;
  332. t64bitarray = array[0..7] of byte;
  333. t32bitarray = array[0..3] of byte;
  334. var
  335. ch : char;
  336. hp : tai;
  337. consttyp : tait;
  338. s : string;
  339. found : boolean;
  340. i,pos,l : longint;
  341. InlineLevel : longint;
  342. co : comp;
  343. sin : single;
  344. d : double;
  345. e : extended;
  346. op : tasmop;
  347. calljmp,
  348. do_line : boolean;
  349. sep : char;
  350. begin
  351. if not assigned(p) then
  352. exit;
  353. InlineLevel:=0;
  354. { lineinfo is only needed for codesegment (PFV) }
  355. do_line:=(cs_asm_source in aktglobalswitches) or
  356. ((cs_lineinfo in aktmoduleswitches)
  357. and (p=codesegment));
  358. hp:=tai(p.first);
  359. while assigned(hp) do
  360. begin
  361. aktfilepos:=hp.fileinfo;
  362. if not(hp.typ in nolinetai) then
  363. begin
  364. {$ifdef GDB}
  365. { write stabs }
  366. if (cs_debuginfo in aktmoduleswitches) or
  367. (cs_gdb_lineinfo in aktglobalswitches) then
  368. WriteFileLineInfo(hp.fileinfo);
  369. {$endif GDB}
  370. if do_line then
  371. begin
  372. { load infile }
  373. if lastfileinfo.fileindex<>hp.fileinfo.fileindex then
  374. begin
  375. infile:=current_module.sourcefiles.get_file(hp.fileinfo.fileindex);
  376. if assigned(infile) then
  377. begin
  378. { open only if needed !! }
  379. if (cs_asm_source in aktglobalswitches) then
  380. infile.open;
  381. end;
  382. { avoid unnecessary reopens of the same file !! }
  383. lastfileinfo.fileindex:=hp.fileinfo.fileindex;
  384. { be sure to change line !! }
  385. lastfileinfo.line:=-1;
  386. end;
  387. { write source }
  388. if (cs_asm_source in aktglobalswitches) and
  389. assigned(infile) then
  390. begin
  391. if (infile<>lastinfile) then
  392. begin
  393. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  394. if assigned(lastinfile) then
  395. lastinfile.close;
  396. end;
  397. if (hp.fileinfo.line<>lastfileinfo.line) and
  398. ((hp.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  399. begin
  400. if (hp.fileinfo.line<>0) and
  401. ((infile.linebuf^[hp.fileinfo.line]>=0) or (InlineLevel>0)) then
  402. AsmWriteLn(target_asm.comment+'['+tostr(hp.fileinfo.line)+'] '+
  403. fixline(infile.GetLineStr(hp.fileinfo.line)));
  404. { set it to a negative value !
  405. to make that is has been read already !! PM }
  406. if (infile.linebuf^[hp.fileinfo.line]>=0) then
  407. infile.linebuf^[hp.fileinfo.line]:=-infile.linebuf^[hp.fileinfo.line]-1;
  408. end;
  409. end;
  410. lastfileinfo:=hp.fileinfo;
  411. lastinfile:=infile;
  412. end;
  413. end;
  414. case hp.typ of
  415. ait_comment :
  416. Begin
  417. AsmWrite(target_asm.comment);
  418. AsmWritePChar(tai_asm_comment(hp).str);
  419. AsmLn;
  420. End;
  421. ait_regalloc :
  422. begin
  423. if (cs_asm_regalloc in aktglobalswitches) then
  424. AsmWriteLn(target_asm.comment+'Register '+att_reg2str[tairegalloc(hp).reg]+
  425. allocstr[tairegalloc(hp).allocation]);
  426. end;
  427. ait_tempalloc :
  428. begin
  429. if (cs_asm_tempalloc in aktglobalswitches) then
  430. AsmWriteLn(target_asm.comment+'Temp '+tostr(taitempalloc(hp).temppos)+','+
  431. tostr(taitempalloc(hp).tempsize)+allocstr[taitempalloc(hp).allocation]);
  432. end;
  433. ait_align :
  434. begin
  435. AsmWrite(#9'.balign '+tostr(tai_align(hp).aligntype));
  436. if tai_align(hp).use_op then
  437. AsmWrite(','+tostr(tai_align(hp).fillop));
  438. AsmLn;
  439. end;
  440. ait_section :
  441. begin
  442. if tai_section(hp).sec<>sec_none then
  443. begin
  444. AsmLn;
  445. AsmWriteLn(ait_section2str(tai_section(hp).sec));
  446. {$ifdef GDB}
  447. lastfileinfo.line:=-1;
  448. {$endif GDB}
  449. end;
  450. end;
  451. ait_datablock :
  452. begin
  453. if tai_datablock(hp).is_global then
  454. AsmWrite(#9'.comm'#9)
  455. else
  456. AsmWrite(#9'.lcomm'#9);
  457. AsmWrite(tai_datablock(hp).sym^.name);
  458. AsmWriteLn(','+tostr(tai_datablock(hp).size));
  459. end;
  460. ait_const_32bit,
  461. ait_const_16bit,
  462. ait_const_8bit :
  463. begin
  464. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  465. consttyp:=hp.typ;
  466. l:=0;
  467. repeat
  468. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  469. if found then
  470. begin
  471. hp:=tai(hp.next);
  472. s:=','+tostr(tai_const(hp).value);
  473. AsmWrite(s);
  474. inc(l,length(s));
  475. end;
  476. until (not found) or (l>line_length);
  477. AsmLn;
  478. end;
  479. ait_const_symbol :
  480. begin
  481. AsmWrite(#9'.long'#9+tai_const_symbol(hp).sym^.name);
  482. if tai_const_symbol(hp).offset>0 then
  483. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  484. else if tai_const_symbol(hp).offset<0 then
  485. AsmWrite(tostr(tai_const_symbol(hp).offset));
  486. AsmLn;
  487. end;
  488. ait_const_rva :
  489. AsmWriteLn(#9'.rva'#9+tai_const_symbol(hp).sym^.name);
  490. ait_real_80bit :
  491. begin
  492. if do_line then
  493. AsmWriteLn(target_asm.comment+extended2str(tai_real_80bit(hp).value));
  494. { Make sure e is a extended type, bestreal could be
  495. a different type (bestreal) !! (PFV) }
  496. e:=tai_real_80bit(hp).value;
  497. AsmWrite(#9'.byte'#9);
  498. for i:=0 to 9 do
  499. begin
  500. if i<>0 then
  501. AsmWrite(',');
  502. AsmWrite(tostr(t80bitarray(e)[i]));
  503. end;
  504. AsmLn;
  505. end;
  506. ait_real_64bit :
  507. begin
  508. if do_line then
  509. AsmWriteLn(target_asm.comment+double2str(tai_real_64bit(hp).value));
  510. d:=tai_real_64bit(hp).value;
  511. AsmWrite(#9'.byte'#9);
  512. for i:=0 to 7 do
  513. begin
  514. if i<>0 then
  515. AsmWrite(',');
  516. AsmWrite(tostr(t64bitarray(d)[i]));
  517. end;
  518. AsmLn;
  519. end;
  520. ait_real_32bit :
  521. begin
  522. if do_line then
  523. AsmWriteLn(target_asm.comment+single2str(tai_real_32bit(hp).value));
  524. sin:=tai_real_32bit(hp).value;
  525. AsmWrite(#9'.byte'#9);
  526. for i:=0 to 3 do
  527. begin
  528. if i<>0 then
  529. AsmWrite(',');
  530. AsmWrite(tostr(t32bitarray(sin)[i]));
  531. end;
  532. AsmLn;
  533. end;
  534. ait_comp_64bit :
  535. begin
  536. if do_line then
  537. AsmWriteLn(target_asm.comment+comp2str(tai_comp_64bit(hp).value));
  538. AsmWrite(#9'.byte'#9);
  539. {$ifdef FPC}
  540. co:=comp(tai_comp_64bit(hp).value);
  541. {$else}
  542. co:=tai_comp_64bit(hp).value;
  543. {$endif}
  544. for i:=0 to 7 do
  545. begin
  546. if i<>0 then
  547. AsmWrite(',');
  548. AsmWrite(tostr(t64bitarray(co)[i]));
  549. end;
  550. AsmLn;
  551. end;
  552. ait_direct :
  553. begin
  554. AsmWritePChar(tai_direct(hp).str);
  555. AsmLn;
  556. {$IfDef GDB}
  557. if strpos(tai_direct(hp).str,'.data')<>nil then
  558. n_line:=n_dataline
  559. else if strpos(tai_direct(hp).str,'.text')<>nil then
  560. n_line:=n_textline
  561. else if strpos(tai_direct(hp).str,'.bss')<>nil then
  562. n_line:=n_bssline;
  563. {$endif GDB}
  564. end;
  565. ait_string :
  566. begin
  567. pos:=0;
  568. for i:=1 to tai_string(hp).len do
  569. begin
  570. if pos=0 then
  571. begin
  572. AsmWrite(#9'.ascii'#9'"');
  573. pos:=20;
  574. end;
  575. ch:=tai_string(hp).str[i-1];
  576. case ch of
  577. #0, {This can't be done by range, because a bug in FPC}
  578. #1..#31,
  579. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  580. '"' : s:='\"';
  581. '\' : s:='\\';
  582. else
  583. s:=ch;
  584. end;
  585. AsmWrite(s);
  586. inc(pos,length(s));
  587. if (pos>line_length) or (i=tai_string(hp).len) then
  588. begin
  589. AsmWriteLn('"');
  590. pos:=0;
  591. end;
  592. end;
  593. end;
  594. ait_label :
  595. begin
  596. if (tai_label(hp).l^.is_used) then
  597. begin
  598. if tai_label(hp).l^.defbind=AB_GLOBAL then
  599. begin
  600. AsmWrite('.globl'#9);
  601. AsmWriteLn(tai_label(hp).l^.name);
  602. end;
  603. AsmWrite(tai_label(hp).l^.name);
  604. AsmWriteLn(':');
  605. end;
  606. end;
  607. ait_symbol :
  608. begin
  609. if tai_symbol(hp).is_global then
  610. begin
  611. AsmWrite('.globl'#9);
  612. AsmWriteLn(tai_symbol(hp).sym^.name);
  613. end;
  614. if target_info.target=target_i386_linux then
  615. begin
  616. AsmWrite(#9'.type'#9);
  617. AsmWrite(tai_symbol(hp).sym^.name);
  618. if assigned(tai(hp.next)) and
  619. (tai(hp.next).typ in [ait_const_symbol,ait_const_rva,
  620. ait_const_32bit,ait_const_16bit,ait_const_8bit,ait_datablock,
  621. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit]) then
  622. AsmWriteLn(',@object')
  623. else
  624. AsmWriteLn(',@function');
  625. if tai_symbol(hp).sym^.size>0 then
  626. begin
  627. AsmWrite(#9'.size'#9);
  628. AsmWrite(tai_symbol(hp).sym^.name);
  629. AsmWrite(', ');
  630. AsmWriteLn(tostr(tai_symbol(hp).sym^.size));
  631. end;
  632. end;
  633. AsmWrite(tai_symbol(hp).sym^.name);
  634. AsmWriteLn(':');
  635. end;
  636. ait_symbol_end :
  637. begin
  638. if target_info.target=target_i386_linux then
  639. begin
  640. s:=target_asm.labelprefix+'e'+tostr(symendcount);
  641. inc(symendcount);
  642. AsmWriteLn(s+':');
  643. AsmWrite(#9'.size'#9);
  644. AsmWrite(tai_symbol(hp).sym^.name);
  645. AsmWrite(', '+s+' - ');
  646. AsmWriteLn(tai_symbol(hp).sym^.name);
  647. end;
  648. end;
  649. ait_instruction :
  650. begin
  651. op:=taicpu(hp).opcode;
  652. calljmp:=is_calljmp(op);
  653. { call maybe not translated to call }
  654. s:=#9+att_op2str[op]+cond2str[taicpu(hp).condition];
  655. { suffix needed ? fnstsw,fldcw don't support suffixes
  656. with binutils 2.9.5 under linux }
  657. if (not calljmp) and
  658. (att_needsuffix[op]<>AttSufNONE) and
  659. (op<>A_FNSTSW) and (op<>A_FSTSW) and
  660. (op<>A_FNSTCW) and (op<>A_FSTCW) and
  661. (op<>A_FLDCW) and
  662. not(
  663. (taicpu(hp).oper[0].typ=top_reg) and
  664. (taicpu(hp).oper[0].reg in [R_ST..R_ST7])
  665. ) then
  666. s:=s+att_opsize2str[taicpu(hp).opsize];
  667. { process operands }
  668. if taicpu(hp).ops<>0 then
  669. begin
  670. { call and jmp need an extra handling }
  671. { this code is only called if jmp isn't a labeled instruction }
  672. { quick hack to overcome a problem with manglednames=255 chars }
  673. if calljmp then
  674. begin
  675. AsmWrite(s+#9);
  676. s:=getopstr_jmp(taicpu(hp).oper[0]);
  677. end
  678. else
  679. begin
  680. for i:=0 to taicpu(hp).ops-1 do
  681. begin
  682. if i=0 then
  683. sep:=#9
  684. else
  685. sep:=',';
  686. s:=s+sep+getopstr(taicpu(hp).oper[i])
  687. end;
  688. end;
  689. end;
  690. AsmWriteLn(s);
  691. end;
  692. {$ifdef GDB}
  693. ait_stabs :
  694. begin
  695. AsmWrite(#9'.stabs ');
  696. AsmWritePChar(tai_stabs(hp).str);
  697. AsmLn;
  698. end;
  699. ait_stabn :
  700. begin
  701. AsmWrite(#9'.stabn ');
  702. AsmWritePChar(tai_stabn(hp).str);
  703. AsmLn;
  704. end;
  705. ait_force_line :
  706. stabslastfileinfo.line:=0;
  707. ait_stab_function_name:
  708. funcname:=tai_stab_function_name(hp).str;
  709. {$endif GDB}
  710. ait_cut :
  711. begin
  712. if SmartAsm then
  713. begin
  714. { only reset buffer if nothing has changed }
  715. if AsmSize=AsmStartSize then
  716. AsmClear
  717. else
  718. begin
  719. AsmClose;
  720. DoAssemble;
  721. AsmCreate(tai_cut(hp).place);
  722. end;
  723. { avoid empty files }
  724. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  725. begin
  726. if tai(hp.next).typ=ait_section then
  727. lastsec:=tai_section(hp.next).sec;
  728. hp:=tai(hp.next);
  729. end;
  730. {$ifdef GDB}
  731. { force write of filename }
  732. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  733. includecount:=0;
  734. funcname:=nil;
  735. WriteFileLineInfo(hp.fileinfo);
  736. {$endif GDB}
  737. if lastsec<>sec_none then
  738. AsmWriteLn(ait_section2str(lastsec));
  739. AsmStartSize:=AsmSize;
  740. end;
  741. end;
  742. ait_marker :
  743. if tai_marker(hp).kind=InlineStart then
  744. inc(InlineLevel)
  745. else if tai_marker(hp).kind=InlineEnd then
  746. dec(InlineLevel);
  747. else
  748. internalerror(10000);
  749. end;
  750. hp:=tai(hp.next);
  751. end;
  752. end;
  753. procedure ti386attasmlist.WriteAsmList;
  754. var
  755. p:dirstr;
  756. n:namestr;
  757. e:extstr;
  758. {$ifdef GDB}
  759. fileinfo : tfileposinfo;
  760. {$endif GDB}
  761. begin
  762. {$ifdef EXTDEBUG}
  763. if assigned(current_module.mainsource) then
  764. Comment(v_info,'Start writing att-styled assembler output for '+current_module.mainsource^);
  765. {$endif}
  766. LastSec:=sec_none;
  767. {$ifdef GDB}
  768. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  769. {$endif GDB}
  770. FillChar(lastfileinfo,sizeof(lastfileinfo),0);
  771. LastInfile:=nil;
  772. if assigned(current_module.mainsource) then
  773. fsplit(current_module.mainsource^,p,n,e)
  774. else
  775. begin
  776. p:=inputdir;
  777. n:=inputfile;
  778. e:=inputextension;
  779. end;
  780. { to get symify to work }
  781. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  782. {$ifdef GDB}
  783. n_line:=n_bssline;
  784. funcname:=nil;
  785. linecount:=1;
  786. includecount:=0;
  787. fileinfo.fileindex:=1;
  788. fileinfo.line:=1;
  789. { Write main file }
  790. WriteFileLineInfo(fileinfo);
  791. {$endif GDB}
  792. AsmStartSize:=AsmSize;
  793. symendcount:=0;
  794. countlabelref:=false;
  795. If (cs_debuginfo in aktmoduleswitches) then
  796. WriteTree(debuglist);
  797. WriteTree(codesegment);
  798. WriteTree(datasegment);
  799. WriteTree(consts);
  800. WriteTree(rttilist);
  801. Writetree(resourcestringlist);
  802. WriteTree(bsssegment);
  803. Writetree(importssection);
  804. { exports are written by DLLTOOL
  805. if we use it so don't insert it twice (PM) }
  806. if not UseDeffileForExport and assigned(exportssection) then
  807. Writetree(exportssection);
  808. Writetree(resourcesection);
  809. {$ifdef GDB}
  810. WriteFileEndInfo;
  811. {$ENDIF}
  812. countlabelref:=true;
  813. AsmLn;
  814. {$ifdef EXTDEBUG}
  815. if assigned(current_module.mainsource) then
  816. comment(v_info,'Done writing att-styled assembler output for '+current_module.mainsource^);
  817. {$endif EXTDEBUG}
  818. end;
  819. end.
  820. {
  821. $Log$
  822. Revision 1.2 2000-12-25 00:07:31 peter
  823. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  824. tlinkedlist objects)
  825. Revision 1.1 2000/11/30 22:18:48 florian
  826. * moved to i386
  827. Revision 1.6 2000/09/24 15:06:10 peter
  828. * use defines.inc
  829. Revision 1.5 2000/08/27 16:11:49 peter
  830. * moved some util functions from globals,cobjects to cutils
  831. * splitted files into finput,fmodule
  832. Revision 1.4 2000/08/20 17:38:21 peter
  833. * smartlinking fixed for linux (merged)
  834. Revision 1.3 2000/07/13 12:08:24 michael
  835. + patched to 1.1.0 with former 1.09patch from peter
  836. Revision 1.2 2000/07/13 11:32:28 michael
  837. + removed logs
  838. }