ag386nsm.pas 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. This unit implements an asmoutput class for the Nasm assembler with
  5. Intel syntax for the i386+
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit ag386nsm;
  20. {$i defines.inc}
  21. interface
  22. uses aasm,assemble;
  23. type
  24. pi386nasmasmlist=^ti386nasmasmlist;
  25. ti386nasmasmlist = object(tasmlist)
  26. procedure WriteTree(p:paasmoutput);virtual;
  27. procedure WriteAsmList;virtual;
  28. procedure WriteExternals;
  29. end;
  30. implementation
  31. uses
  32. {$ifdef delphi}
  33. sysutils,
  34. {$else}
  35. strings,
  36. {$endif}
  37. cutils,globtype,globals,systems,cobjects,
  38. fmodule,finput,verbose,cpubase,cpuasm
  39. {$ifdef GDB}
  40. ,gdb
  41. {$endif GDB}
  42. ;
  43. const
  44. line_length = 64;
  45. var
  46. lastfileinfo : tfileposinfo;
  47. infile,
  48. lastinfile : pinputfile;
  49. function fixline(s:string):string;
  50. {
  51. return s with all leading and ending spaces and tabs removed
  52. }
  53. var
  54. i,j,k : longint;
  55. begin
  56. i:=length(s);
  57. while (i>0) and (s[i] in [#9,' ']) do
  58. dec(i);
  59. j:=1;
  60. while (j<i) and (s[j] in [#9,' ']) do
  61. inc(j);
  62. for k:=j to i do
  63. if s[k] in [#0..#31,#127..#255] then
  64. s[k]:='.';
  65. fixline:=Copy(s,j,i-j+1);
  66. end;
  67. function single2str(d : single) : string;
  68. var
  69. hs : string;
  70. p : byte;
  71. begin
  72. str(d,hs);
  73. { nasm expects a lowercase e }
  74. p:=pos('E',hs);
  75. if p>0 then
  76. hs[p]:='e';
  77. p:=pos('+',hs);
  78. if p>0 then
  79. delete(hs,p,1);
  80. single2str:=lower(hs);
  81. end;
  82. function double2str(d : double) : string;
  83. var
  84. hs : string;
  85. p : byte;
  86. begin
  87. str(d,hs);
  88. { nasm expects a lowercase e }
  89. p:=pos('E',hs);
  90. if p>0 then
  91. hs[p]:='e';
  92. p:=pos('+',hs);
  93. if p>0 then
  94. delete(hs,p,1);
  95. double2str:=lower(hs);
  96. end;
  97. function extended2str(e : extended) : string;
  98. var
  99. hs : string;
  100. p : byte;
  101. begin
  102. str(e,hs);
  103. { nasm expects a lowercase e }
  104. p:=pos('E',hs);
  105. if p>0 then
  106. hs[p]:='e';
  107. p:=pos('+',hs);
  108. if p>0 then
  109. delete(hs,p,1);
  110. extended2str:=lower(hs);
  111. end;
  112. function comp2str(d : bestreal) : string;
  113. type
  114. pdouble = ^double;
  115. var
  116. c : comp;
  117. dd : pdouble;
  118. begin
  119. {$ifdef FPC}
  120. c:=comp(d);
  121. {$else}
  122. c:=d;
  123. {$endif}
  124. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  125. comp2str:=double2str(dd^);
  126. end;
  127. function getreferencestring(var ref : treference) : string;
  128. var
  129. s : string;
  130. first : boolean;
  131. begin
  132. if ref.is_immediate then
  133. begin
  134. getreferencestring:=tostr(ref.offset);
  135. exit;
  136. end
  137. else
  138. with ref do
  139. begin
  140. first:=true;
  141. inc(offset,offsetfixup);
  142. offsetfixup:=0;
  143. if ref.segment<>R_NO then
  144. s:='['+int_reg2str[segment]+':'
  145. else
  146. s:='[';
  147. if assigned(symbol) then
  148. begin
  149. s:=s+symbol^.name;
  150. first:=false;
  151. end;
  152. if (base<>R_NO) then
  153. begin
  154. if not(first) then
  155. s:=s+'+'
  156. else
  157. first:=false;
  158. s:=s+int_reg2str[base];
  159. end;
  160. if (index<>R_NO) then
  161. begin
  162. if not(first) then
  163. s:=s+'+'
  164. else
  165. first:=false;
  166. s:=s+int_reg2str[index];
  167. if scalefactor<>0 then
  168. s:=s+'*'+tostr(scalefactor);
  169. end;
  170. if offset<0 then
  171. s:=s+tostr(offset)
  172. else if (offset>0) then
  173. s:=s+'+'+tostr(offset);
  174. s:=s+']';
  175. end;
  176. getreferencestring:=s;
  177. end;
  178. function sizestr(s:topsize;dest:boolean):string;
  179. begin
  180. case s of
  181. S_B : sizestr:='byte ';
  182. S_W : sizestr:='word ';
  183. S_L : sizestr:='dword ';
  184. S_IS : sizestr:='word ';
  185. S_IL : sizestr:='dword ';
  186. S_IQ : sizestr:='qword ';
  187. S_FS : sizestr:='dword ';
  188. S_FL : sizestr:='qword ';
  189. S_FX : sizestr:='tword ';
  190. S_BW : if dest then
  191. sizestr:='word '
  192. else
  193. sizestr:='byte ';
  194. S_BL : if dest then
  195. sizestr:='dword '
  196. else
  197. sizestr:='byte ';
  198. S_WL : if dest then
  199. sizestr:='dword '
  200. else
  201. sizestr:='word ';
  202. else { S_NO }
  203. sizestr:='';
  204. end;
  205. end;
  206. function getopstr(const o:toper;s : topsize; opcode: tasmop;ops:longint;dest : boolean) : string;
  207. var
  208. hs : string;
  209. begin
  210. case o.typ of
  211. top_reg :
  212. getopstr:=int_nasmreg2str[o.reg];
  213. top_const :
  214. begin
  215. if (ops=1) and (opcode<>A_RET) then
  216. getopstr:=sizestr(s,dest)+tostr(o.val)
  217. else
  218. getopstr:=tostr(o.val);
  219. end;
  220. top_symbol :
  221. begin
  222. if assigned(o.sym) then
  223. hs:='dword '+o.sym^.name
  224. else
  225. hs:='dword ';
  226. if o.symofs>0 then
  227. hs:=hs+'+'+tostr(o.symofs)
  228. else
  229. if o.symofs<0 then
  230. hs:=hs+tostr(o.symofs)
  231. else
  232. if not(assigned(o.sym)) then
  233. hs:=hs+'0';
  234. getopstr:=hs;
  235. end;
  236. top_ref :
  237. begin
  238. hs:=getreferencestring(o.ref^);
  239. if not ((opcode = A_LEA) or (opcode = A_LGS) or
  240. (opcode = A_LSS) or (opcode = A_LFS) or
  241. (opcode = A_LES) or (opcode = A_LDS) or
  242. (opcode = A_SHR) or (opcode = A_SHL) or
  243. (opcode = A_SAR) or (opcode = A_SAL) or
  244. (opcode = A_OUT) or (opcode = A_IN)) then
  245. begin
  246. hs:=sizestr(s,dest)+hs;
  247. end;
  248. getopstr:=hs;
  249. end;
  250. else
  251. internalerror(10001);
  252. end;
  253. end;
  254. function getopstr_jmp(const o:toper; op : tasmop) : string;
  255. var
  256. hs : string;
  257. begin
  258. case o.typ of
  259. top_reg :
  260. getopstr_jmp:=int_nasmreg2str[o.reg];
  261. top_ref :
  262. getopstr_jmp:=getreferencestring(o.ref^);
  263. top_const :
  264. getopstr_jmp:=tostr(o.val);
  265. top_symbol :
  266. begin
  267. hs:=o.sym^.name;
  268. if o.symofs>0 then
  269. hs:=hs+'+'+tostr(o.symofs)
  270. else
  271. if o.symofs<0 then
  272. hs:=hs+tostr(o.symofs);
  273. if (op=A_JCXZ) or (op=A_JECXZ) or
  274. (op=A_LOOP) or (op=A_LOOPE) or
  275. (op=A_LOOPNE) or (op=A_LOOPNZ) or
  276. (op=A_LOOPZ) then
  277. getopstr_jmp:=hs
  278. else
  279. getopstr_jmp:='NEAR '+hs;
  280. end;
  281. else
  282. internalerror(10001);
  283. end;
  284. end;
  285. {****************************************************************************
  286. Ti386nasmasmlist
  287. ****************************************************************************}
  288. var
  289. LastSec : tsection;
  290. const
  291. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  292. (#9'DD'#9,#9'DW'#9,#9'DB'#9);
  293. Function PadTabs(const p:string;addch:char):string;
  294. var
  295. s : string;
  296. i : longint;
  297. begin
  298. i:=length(p);
  299. if addch<>#0 then
  300. begin
  301. inc(i);
  302. s:=p+addch;
  303. end
  304. else
  305. s:=p;
  306. if i<8 then
  307. PadTabs:=s+#9#9
  308. else
  309. PadTabs:=s+#9;
  310. end;
  311. procedure ti386nasmasmlist.WriteTree(p:paasmoutput);
  312. const
  313. allocstr : array[boolean] of string[10]=(' released',' allocated');
  314. nolinetai =[ait_label,
  315. ait_regalloc,ait_tempalloc,
  316. ait_stabn,ait_stabs,ait_section,
  317. ait_cut,ait_marker,ait_align,ait_stab_function_name];
  318. var
  319. s : string;
  320. {prefix,
  321. suffix : string; no need here }
  322. hp : pai;
  323. counter,
  324. lines,
  325. i,j,l : longint;
  326. InlineLevel : longint;
  327. consttyp : tait;
  328. found,
  329. do_line,
  330. quoted : boolean;
  331. sep : char;
  332. begin
  333. if not assigned(p) then
  334. exit;
  335. InlineLevel:=0;
  336. { lineinfo is only needed for codesegment (PFV) }
  337. do_line:=(cs_asm_source in aktglobalswitches) or
  338. ((cs_lineinfo in aktmoduleswitches)
  339. and (p=codesegment));
  340. hp:=pai(p^.first);
  341. while assigned(hp) do
  342. begin
  343. aktfilepos:=hp^.fileinfo;
  344. if not(hp^.typ in nolinetai) then
  345. begin
  346. if do_line then
  347. begin
  348. { load infile }
  349. if lastfileinfo.fileindex<>hp^.fileinfo.fileindex then
  350. begin
  351. infile:=current_module^.sourcefiles^.get_file(hp^.fileinfo.fileindex);
  352. if assigned(infile) then
  353. begin
  354. { open only if needed !! }
  355. if (cs_asm_source in aktglobalswitches) then
  356. infile^.open;
  357. end;
  358. { avoid unnecessary reopens of the same file !! }
  359. lastfileinfo.fileindex:=hp^.fileinfo.fileindex;
  360. { be sure to change line !! }
  361. lastfileinfo.line:=-1;
  362. end;
  363. { write source }
  364. if (cs_asm_source in aktglobalswitches) and
  365. assigned(infile) then
  366. begin
  367. if (infile<>lastinfile) then
  368. begin
  369. AsmWriteLn(target_asm.comment+'['+infile^.name^+']');
  370. if assigned(lastinfile) then
  371. lastinfile^.close;
  372. end;
  373. if (hp^.fileinfo.line<>lastfileinfo.line) and
  374. ((hp^.fileinfo.line<infile^.maxlinebuf) or (InlineLevel>0)) then
  375. begin
  376. if (hp^.fileinfo.line<>0) and
  377. ((infile^.linebuf^[hp^.fileinfo.line]>=0) or (InlineLevel>0)) then
  378. AsmWriteLn(target_asm.comment+'['+tostr(hp^.fileinfo.line)+'] '+
  379. fixline(infile^.GetLineStr(hp^.fileinfo.line)));
  380. { set it to a negative value !
  381. to make that is has been read already !! PM }
  382. if (infile^.linebuf^[hp^.fileinfo.line]>=0) then
  383. infile^.linebuf^[hp^.fileinfo.line]:=-infile^.linebuf^[hp^.fileinfo.line]-1;
  384. end;
  385. end;
  386. lastfileinfo:=hp^.fileinfo;
  387. lastinfile:=infile;
  388. end;
  389. end;
  390. case hp^.typ of
  391. ait_comment :
  392. Begin
  393. AsmWrite(target_asm.comment);
  394. AsmWritePChar(pai_asm_comment(hp)^.str);
  395. AsmLn;
  396. End;
  397. ait_regalloc :
  398. begin
  399. if (cs_asm_regalloc in aktglobalswitches) then
  400. AsmWriteLn(target_asm.comment+'Register '+att_reg2str[pairegalloc(hp)^.reg]+
  401. allocstr[pairegalloc(hp)^.allocation]);
  402. end;
  403. ait_tempalloc :
  404. begin
  405. if (cs_asm_tempalloc in aktglobalswitches) then
  406. AsmWriteLn(target_asm.comment+'Temp '+tostr(paitempalloc(hp)^.temppos)+','+
  407. tostr(paitempalloc(hp)^.tempsize)+allocstr[paitempalloc(hp)^.allocation]);
  408. end;
  409. ait_section :
  410. begin
  411. if pai_section(hp)^.sec<>sec_none then
  412. begin
  413. AsmLn;
  414. AsmWriteLn('SECTION '+target_asm.secnames[pai_section(hp)^.sec]);
  415. end;
  416. LastSec:=pai_section(hp)^.sec;
  417. end;
  418. ait_align :
  419. AsmWriteLn(#9'ALIGN '+tostr(pai_align(hp)^.aligntype));
  420. ait_datablock :
  421. begin
  422. if pai_datablock(hp)^.is_global then
  423. begin
  424. AsmWrite(#9'GLOBAL ');
  425. AsmWriteLn(pai_datablock(hp)^.sym^.name);
  426. end;
  427. AsmWrite(PadTabs(pai_datablock(hp)^.sym^.name,':'));
  428. AsmWriteLn('RESB'#9+tostr(pai_datablock(hp)^.size));
  429. end;
  430. ait_const_32bit,
  431. ait_const_16bit,
  432. ait_const_8bit :
  433. begin
  434. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  435. consttyp:=hp^.typ;
  436. l:=0;
  437. repeat
  438. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  439. if found then
  440. begin
  441. hp:=Pai(hp^.next);
  442. s:=','+tostr(pai_const(hp)^.value);
  443. AsmWrite(s);
  444. inc(l,length(s));
  445. end;
  446. until (not found) or (l>line_length);
  447. AsmLn;
  448. end;
  449. ait_const_symbol :
  450. begin
  451. AsmWrite(#9#9'DD'#9);
  452. AsmWrite(pai_const_symbol(hp)^.sym^.name);
  453. if pai_const_symbol(hp)^.offset>0 then
  454. AsmWrite('+'+tostr(pai_const_symbol(hp)^.offset))
  455. else if pai_const_symbol(hp)^.offset<0 then
  456. AsmWrite(tostr(pai_const_symbol(hp)^.offset));
  457. AsmLn;
  458. end;
  459. ait_const_rva :
  460. begin
  461. AsmWrite(#9#9'RVA'#9);
  462. AsmWriteLn(pai_const_symbol(hp)^.sym^.name);
  463. end;
  464. ait_real_32bit :
  465. AsmWriteLn(#9#9'DD'#9+single2str(pai_real_32bit(hp)^.value));
  466. ait_real_64bit :
  467. AsmWriteLn(#9#9'DQ'#9+double2str(pai_real_64bit(hp)^.value));
  468. ait_real_80bit :
  469. AsmWriteLn(#9#9'DT'#9+extended2str(pai_real_80bit(hp)^.value));
  470. ait_comp_64bit :
  471. AsmWriteLn(#9#9'DQ'#9+comp2str(pai_real_80bit(hp)^.value));
  472. ait_string :
  473. begin
  474. counter := 0;
  475. lines := pai_string(hp)^.len div line_length;
  476. { separate lines in different parts }
  477. if pai_string(hp)^.len > 0 then
  478. Begin
  479. for j := 0 to lines-1 do
  480. begin
  481. AsmWrite(#9#9'DB'#9);
  482. quoted:=false;
  483. for i:=counter to counter+line_length-1 do
  484. begin
  485. { it is an ascii character. }
  486. if (ord(pai_string(hp)^.str[i])>31) and
  487. (ord(pai_string(hp)^.str[i])<128) and
  488. (pai_string(hp)^.str[i]<>'"') then
  489. begin
  490. if not(quoted) then
  491. begin
  492. if i>counter then
  493. AsmWrite(',');
  494. AsmWrite('"');
  495. end;
  496. AsmWrite(pai_string(hp)^.str[i]);
  497. quoted:=true;
  498. end { if > 31 and < 128 and ord('"') }
  499. else
  500. begin
  501. if quoted then
  502. AsmWrite('"');
  503. if i>counter then
  504. AsmWrite(',');
  505. quoted:=false;
  506. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  507. end;
  508. end; { end for i:=0 to... }
  509. if quoted then AsmWrite('"');
  510. AsmWrite(target_os.newline);
  511. inc(counter,line_length);
  512. end; { end for j:=0 ... }
  513. { do last line of lines }
  514. if counter<pai_string(hp)^.len then
  515. AsmWrite(#9#9'DB'#9);
  516. quoted:=false;
  517. for i:=counter to pai_string(hp)^.len-1 do
  518. begin
  519. { it is an ascii character. }
  520. if (ord(pai_string(hp)^.str[i])>31) and
  521. (ord(pai_string(hp)^.str[i])<128) and
  522. (pai_string(hp)^.str[i]<>'"') then
  523. begin
  524. if not(quoted) then
  525. begin
  526. if i>counter then
  527. AsmWrite(',');
  528. AsmWrite('"');
  529. end;
  530. AsmWrite(pai_string(hp)^.str[i]);
  531. quoted:=true;
  532. end { if > 31 and < 128 and " }
  533. else
  534. begin
  535. if quoted then
  536. AsmWrite('"');
  537. if i>counter then
  538. AsmWrite(',');
  539. quoted:=false;
  540. AsmWrite(tostr(ord(pai_string(hp)^.str[i])));
  541. end;
  542. end; { end for i:=0 to... }
  543. if quoted then
  544. AsmWrite('"');
  545. end;
  546. AsmLn;
  547. end;
  548. ait_label :
  549. begin
  550. if pai_label(hp)^.l^.is_used then
  551. AsmWriteLn(pai_label(hp)^.l^.name+':');
  552. end;
  553. ait_direct :
  554. begin
  555. AsmWritePChar(pai_direct(hp)^.str);
  556. AsmLn;
  557. end;
  558. ait_symbol :
  559. begin
  560. if pai_symbol(hp)^.is_global then
  561. begin
  562. AsmWrite(#9'GLOBAL ');
  563. AsmWriteLn(pai_symbol(hp)^.sym^.name);
  564. end;
  565. AsmWrite(pai_symbol(hp)^.sym^.name);
  566. if assigned(hp^.next) and not(pai(hp^.next)^.typ in
  567. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  568. ait_const_symbol,ait_const_rva,
  569. ait_real_32bit,ait_real_64bit,ait_real_80bit,ait_comp_64bit,ait_string]) then
  570. AsmWriteLn(':')
  571. end;
  572. ait_symbol_end :
  573. begin
  574. end;
  575. ait_instruction :
  576. begin
  577. { Must be done with args in ATT order }
  578. paicpu(hp)^.CheckNonCommutativeOpcodes;
  579. { We need intel order, no At&t }
  580. paicpu(hp)^.SwapOperands;
  581. { Reset
  582. suffix:='';
  583. prefix:='';}
  584. s:='';
  585. if (paicpu(hp)^.opcode=A_FADDP) and (paicpu(hp)^.ops=0) then
  586. begin
  587. paicpu(hp)^.ops:=2;
  588. paicpu(hp)^.oper[0].typ:=top_reg;
  589. paicpu(hp)^.oper[0].reg:=R_ST1;
  590. paicpu(hp)^.oper[1].typ:=top_reg;
  591. paicpu(hp)^.oper[1].reg:=R_ST;
  592. end;
  593. if paicpu(hp)^.ops<>0 then
  594. begin
  595. if is_calljmp(paicpu(hp)^.opcode) then
  596. s:=#9+getopstr_jmp(paicpu(hp)^.oper[0],paicpu(hp)^.opcode)
  597. else
  598. begin
  599. { We need to explicitely set
  600. word prefix to get selectors
  601. to be pushed in 2 bytes PM }
  602. if (paicpu(hp)^.opsize=S_W) and
  603. ((paicpu(hp)^.opcode=A_PUSH) or
  604. (paicpu(hp)^.opcode=A_POP)) and
  605. (paicpu(hp)^.oper[0].typ=top_reg) and
  606. ((paicpu(hp)^.oper[0].reg>=firstsreg) and
  607. (paicpu(hp)^.oper[0].reg<=lastsreg)) then
  608. AsmWriteln(#9#9'DB'#9'066h');
  609. for i:=0 to paicpu(hp)^.ops-1 do
  610. begin
  611. if i=0 then
  612. sep:=#9
  613. else
  614. sep:=',';
  615. s:=s+sep+getopstr(paicpu(hp)^.oper[i],paicpu(hp)^.opsize,paicpu(hp)^.opcode,
  616. paicpu(hp)^.ops,(i=2));
  617. end;
  618. end;
  619. end;
  620. if paicpu(hp)^.opcode=A_FWAIT then
  621. AsmWriteln(#9#9'DB'#9'09bh')
  622. else
  623. AsmWriteLn(#9#9+{prefix+}int_op2str[paicpu(hp)^.opcode]+
  624. cond2str[paicpu(hp)^.condition]+{suffix+}s);
  625. end;
  626. {$ifdef GDB}
  627. ait_stabn,
  628. ait_stabs,
  629. ait_force_line,
  630. ait_stab_function_name : ;
  631. {$endif GDB}
  632. ait_cut :
  633. begin
  634. { only reset buffer if nothing has changed }
  635. if AsmSize=AsmStartSize then
  636. AsmClear
  637. else
  638. begin
  639. AsmClose;
  640. DoAssemble;
  641. AsmCreate(pai_cut(hp)^.place);
  642. end;
  643. { avoid empty files }
  644. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  645. begin
  646. if pai(hp^.next)^.typ=ait_section then
  647. lastsec:=pai_section(hp^.next)^.sec;
  648. hp:=pai(hp^.next);
  649. end;
  650. if lastsec<>sec_none then
  651. AsmWriteLn('SECTION '+target_asm.secnames[lastsec]);
  652. AsmStartSize:=AsmSize;
  653. end;
  654. ait_marker :
  655. if pai_marker(hp)^.kind=InlineStart then
  656. inc(InlineLevel)
  657. else if pai_marker(hp)^.kind=InlineEnd then
  658. dec(InlineLevel);
  659. else
  660. internalerror(10000);
  661. end;
  662. hp:=pai(hp^.next);
  663. end;
  664. end;
  665. var
  666. currentasmlist : PAsmList;
  667. procedure writeexternal(p:pnamedindexobject);
  668. begin
  669. if pasmsymbol(p)^.defbind=AB_EXTERNAL then
  670. currentasmlist^.AsmWriteln('EXTERN'#9+p^.name);
  671. end;
  672. procedure ti386nasmasmlist.WriteExternals;
  673. begin
  674. currentasmlist:=@self;
  675. AsmSymbolList^.foreach({$ifdef fpcprocvar}@{$endif}writeexternal);
  676. end;
  677. procedure ti386nasmasmlist.WriteAsmList;
  678. begin
  679. {$ifdef EXTDEBUG}
  680. if assigned(current_module^.mainsource) then
  681. comment(v_info,'Start writing nasm-styled assembler output for '+current_module^.mainsource^);
  682. {$endif}
  683. LastSec:=sec_none;
  684. AsmWriteLn('BITS 32');
  685. AsmLn;
  686. countlabelref:=false;
  687. lastfileinfo.line:=-1;
  688. lastfileinfo.fileindex:=0;
  689. lastinfile:=nil;
  690. WriteExternals;
  691. { Nasm doesn't support stabs
  692. WriteTree(debuglist);}
  693. WriteTree(codesegment);
  694. WriteTree(datasegment);
  695. WriteTree(consts);
  696. WriteTree(rttilist);
  697. WriteTree(resourcestringlist);
  698. WriteTree(bsssegment);
  699. countlabelref:=true;
  700. AsmLn;
  701. {$ifdef EXTDEBUG}
  702. if assigned(current_module^.mainsource) then
  703. comment(v_info,'Done writing nasm-styled assembler output for '+current_module^.mainsource^);
  704. {$endif EXTDEBUG}
  705. end;
  706. end.
  707. {
  708. $Log$
  709. Revision 1.6 2000-09-24 15:06:11 peter
  710. * use defines.inc
  711. Revision 1.5 2000/08/27 16:11:49 peter
  712. * moved some util functions from globals,cobjects to cutils
  713. * splitted files into finput,fmodule
  714. Revision 1.4 2000/08/20 17:38:21 peter
  715. * smartlinking fixed for linux (merged)
  716. Revision 1.3 2000/07/13 12:08:24 michael
  717. + patched to 1.1.0 with former 1.09patch from peter
  718. Revision 1.2 2000/07/13 11:32:30 michael
  719. + removed logs
  720. }