ag68kgas.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. {
  2. $Id$
  3. Copyright (c) 1998 by the FPC development team
  4. This unit implements an asmoutput class for MOTOROLA syntax with
  5. Motorola 68000 (for GAS v2.52 AND HIGER)
  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. { R- Necessary for the in [] }
  20. {$ifdef TP}
  21. {$N+,E+,R-}
  22. {$endif}
  23. unit ag68kgas;
  24. interface
  25. uses cobjects,aasm,assemble;
  26. type
  27. pm68kgasasmlist=^tm68kgasasmlist;
  28. tm68kgasasmlist = object(tasmlist)
  29. procedure WriteTree(p:paasmoutput);virtual;
  30. procedure WriteAsmList;virtual;
  31. {$ifdef GDB}
  32. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  33. {$endif}
  34. end;
  35. implementation
  36. uses
  37. dos,globals,systems,m68k,
  38. strings,files,verbose
  39. {$ifdef GDB}
  40. ,gdb
  41. {$endif GDB}
  42. ;
  43. const
  44. line_length = 70;
  45. var
  46. {$ifdef GDB}
  47. n_line : byte; { different types of source lines }
  48. includecount : longint;
  49. {$endif}
  50. lastsec : tsection; { last section type written }
  51. lastsecidx,
  52. lastfileindex,
  53. lastline : longint;
  54. function double2str(d : double) : string;
  55. var
  56. hs : string;
  57. begin
  58. str(d,hs);
  59. { replace space with + }
  60. if hs[1]=' ' then
  61. hs[1]:='+';
  62. double2str:='0d'+hs
  63. end;
  64. (* TO SUPPORT SOONER OR LATER!!!
  65. function comp2str(d : bestreal) : string;
  66. type
  67. pdouble = ^double;
  68. var
  69. c : comp;
  70. dd : pdouble;
  71. begin
  72. {$ifdef TP}
  73. c:=d;
  74. {$else}
  75. c:=comp(d);
  76. {$endif}
  77. dd:=pdouble(@c); { this makes a bitwise copy of c into a double }
  78. comp2str:=double2str(dd^);
  79. end; *)
  80. function getreferencestring(const ref : treference) : string;
  81. var
  82. s : string;
  83. begin
  84. s:='';
  85. if ref.isintvalue then
  86. s:='#'+tostr(ref.offset)
  87. else
  88. with ref do
  89. begin
  90. if assigned(symbol) then
  91. s:=s+symbol^;
  92. if offset<0 then s:=s+tostr(offset)
  93. else if (offset>0) then
  94. begin
  95. if (symbol=nil) then s:=tostr(offset)
  96. else s:=s+'+'+tostr(offset);
  97. end;
  98. if (index<>R_NO) and (base=R_NO) and (direction=dir_none) then
  99. begin
  100. if (scalefactor = 1) or (scalefactor = 0) then
  101. s:=s+'(,'+gas_reg2str[index]+'.l)'
  102. else
  103. s:=s+'(,'+gas_reg2str[index]+'.l*'+tostr(scalefactor)+')'
  104. end
  105. else if (index=R_NO) and (base<>R_NO) and (direction=dir_inc) then
  106. begin
  107. if (scalefactor = 1) or (scalefactor = 0) then
  108. s:=s+'('+gas_reg2str[base]+')+'
  109. else
  110. InternalError(10002);
  111. end
  112. else if (index=R_NO) and (base<>R_NO) and (direction=dir_dec) then
  113. begin
  114. if (scalefactor = 1) or (scalefactor = 0) then
  115. s:=s+'-('+gas_reg2str[base]+')'
  116. else
  117. InternalError(10003);
  118. end
  119. else if (index=R_NO) and (base<>R_NO) and (direction=dir_none) then
  120. begin
  121. s:=s+'('+gas_reg2str[base]+')'
  122. end
  123. else if (index<>R_NO) and (base<>R_NO) and (direction=dir_none) then
  124. begin
  125. if (scalefactor = 1) or (scalefactor = 0) then
  126. s:=s+'('+gas_reg2str[base]+','+gas_reg2str[index]+'.l)'
  127. else
  128. s:=s+'('+gas_reg2str[base]+','+gas_reg2str[index]+'.l*'+tostr(scalefactor)+')';
  129. end;
  130. end; { end with }
  131. getreferencestring:=s;
  132. end;
  133. function getopstr(t : byte;o : pointer) : string;
  134. var
  135. hs : string;
  136. i: tregister;
  137. begin
  138. case t of
  139. top_reg : if target_info.target=target_m68k_PalmOS then
  140. getopstr:=gasPalmOS_reg2str[tregister(o)]
  141. else
  142. getopstr:=gas_reg2str[tregister(o)];
  143. top_ref : getopstr:=getreferencestring(preference(o)^);
  144. top_reglist : begin
  145. hs:='';
  146. for i:=R_NO to R_FPSR do
  147. begin
  148. if i in tregisterlist(o^) then
  149. hs:=hs+gas_reg2str[i]+'/';
  150. end;
  151. delete(hs,length(hs),1);
  152. getopstr := hs;
  153. end;
  154. top_const : getopstr:='#'+tostr(longint(o));
  155. top_symbol :
  156. { compare with i386, where a symbol is considered }
  157. { a constant. }
  158. begin
  159. hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
  160. move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
  161. { inc(byte(hs[0]));}
  162. if pcsymbol(o)^.offset>0 then
  163. hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
  164. else if pcsymbol(o)^.offset<0 then
  165. hs:=hs+tostr(pcsymbol(o)^.offset);
  166. getopstr:=hs;
  167. end;
  168. else internalerror(10001);
  169. end;
  170. end;
  171. function getopstr_jmp(t : byte;o : pointer) : string;
  172. var
  173. hs : string;
  174. begin
  175. case t of
  176. top_reg : getopstr_jmp:=gas_reg2str[tregister(o)];
  177. top_ref : getopstr_jmp:=getreferencestring(preference(o)^);
  178. top_const : getopstr_jmp:=tostr(longint(o));
  179. top_symbol : begin
  180. hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
  181. move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
  182. if pcsymbol(o)^.offset>0 then
  183. hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
  184. else if pcsymbol(o)^.offset<0 then
  185. hs:=hs+tostr(pcsymbol(o)^.offset);
  186. getopstr_jmp:=hs;
  187. end;
  188. else internalerror(10001);
  189. end;
  190. end;
  191. {****************************************************************************
  192. T68kGASASMOUTPUT
  193. ****************************************************************************}
  194. const
  195. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  196. (#9'.long'#9,#9'.short'#9,#9'.byte'#9);
  197. function ait_section2str(s:tsection):string;
  198. begin
  199. case s of
  200. sec_code : ait_section2str:='.text';
  201. sec_data : ait_section2str:='.data';
  202. sec_bss : ait_section2str:='.bss';
  203. else
  204. ait_section2str:='';
  205. end;
  206. LastSec:=s;
  207. end;
  208. {$ifdef GDB}
  209. var
  210. curr_n : byte;
  211. infile : pinputfile;
  212. funcname : pchar;
  213. linecount : longint;
  214. procedure tm68kgasasmlist.WriteFileLineInfo(var fileinfo : tfileposinfo);
  215. begin
  216. if not (cs_debuginfo in aktmoduleswitches) then
  217. exit;
  218. { file changed ? (must be before line info) }
  219. if lastfileindex<>fileinfo.fileindex then
  220. begin
  221. infile:=current_module^.sourcefiles^.get_file(fileinfo.fileindex);
  222. if includecount=0 then
  223. curr_n:=n_sourcefile
  224. else
  225. curr_n:=n_includefile;
  226. if (infile^.path^<>'') then
  227. begin
  228. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile^.path^)))+'",'+
  229. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  230. end;
  231. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile^.name^))+'",'+
  232. tostr(curr_n)+',0,0,'+'Ltext'+ToStr(IncludeCount));
  233. AsmWriteLn('Ltext'+ToStr(IncludeCount)+':');
  234. inc(includecount);
  235. lastfileindex:=fileinfo.fileindex;
  236. end;
  237. { line changed ? }
  238. if (fileinfo.line<>lastline) and (fileinfo.line<>0) then
  239. begin
  240. if (n_line=n_textline) and assigned(funcname) and
  241. (target_os.use_function_relative_addresses) then
  242. begin
  243. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  244. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  245. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  246. AsmWritePChar(FuncName);
  247. AsmLn;
  248. inc(linecount);
  249. end
  250. else
  251. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  252. lastline:=fileinfo.line;
  253. end;
  254. end;
  255. {$endif GDB}
  256. procedure tm68kgasasmlist.WriteTree(p:paasmoutput);
  257. type
  258. twowords=record
  259. word1,word2:word;
  260. end;
  261. textendedarray = array[0..9] of byte; { last longint will be and $ffff }
  262. var
  263. hp : pai;
  264. ch : char;
  265. consttyp : tait;
  266. s : string;
  267. pos,l,i : longint;
  268. found : boolean;
  269. begin
  270. if not assigned(p) then
  271. exit;
  272. hp:=pai(p^.first);
  273. while assigned(hp) do
  274. begin
  275. { write debugger informations }
  276. {$ifdef GDB}
  277. if cs_debuginfo in aktmoduleswitches then
  278. begin
  279. if not (hp^.typ in [ait_external,ait_stabn,ait_stabs,
  280. ait_label,ait_cut,ait_align,ait_stab_function_name]) then
  281. WriteFileLineInfo(hp^.fileinfo);
  282. end;
  283. {$endif GDB}
  284. case hp^.typ of
  285. ait_external : ; { external is ignored }
  286. ait_comment : Begin
  287. AsmWrite(target_asm.comment);
  288. AsmWritePChar(pai_asm_comment(hp)^.str);
  289. AsmLn;
  290. End;
  291. {$ifdef DREGALLOC}
  292. ait_regalloc : AsmWriteLn(target_asm.comment+'Register '+att_reg2str[pairegalloc(hp)^.reg]+' allocated');
  293. ait_regdealloc : AsmWriteLn(target_asm.comment+'Register '+att_reg2str[pairegalloc(hp)^.reg]+' released');
  294. {$endif DREGALLOC}
  295. ait_align : AsmWriteLn(#9'.align '+tostr(pai_align(hp)^.aligntype));
  296. ait_section : begin
  297. if pai_section(hp)^.sec<>sec_none then
  298. begin
  299. AsmLn;
  300. AsmWrite(ait_section2str(pai_section(hp)^.sec));
  301. if pai_section(hp)^.idataidx>0 then
  302. AsmWrite('$'+tostr(pai_section(hp)^.idataidx));
  303. AsmLn;
  304. {$ifdef GDB}
  305. case pai_section(hp)^.sec of
  306. sec_code : n_line:=n_textline;
  307. sec_data : n_line:=n_dataline;
  308. sec_bss : n_line:=n_bssline;
  309. end;
  310. {$endif GDB}
  311. end;
  312. LastSec:=pai_section(hp)^.sec;
  313. end;
  314. ait_datablock : begin
  315. { ------------------------------------------------------- }
  316. { ----------- ALIGNMENT FOR ANY NON-BYTE VALUE ---------- }
  317. { ------------- REQUIREMENT FOR 680x0 ------------------- }
  318. { ------------------------------------------------------- }
  319. if pai_datablock(hp)^.size <> 1 then
  320. begin
  321. if not(cs_littlesize in aktglobalswitches) then
  322. AsmWriteLn(#9#9'.align 4')
  323. else
  324. AsmWriteLn(#9#9'.align 2');
  325. end;
  326. if pai_datablock(hp)^.is_global then
  327. AsmWrite(#9'.comm'#9)
  328. else
  329. AsmWrite(#9'.lcomm'#9);
  330. AsmWriteLn(StrPas(pai_datablock(hp)^.name)+','+tostr(pai_datablock(hp)^.size));
  331. end;
  332. ait_const_32bit, { alignment is required for 16/32 bit data! }
  333. ait_const_16bit: begin
  334. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  335. consttyp:=hp^.typ;
  336. l:=0;
  337. repeat
  338. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  339. if found then
  340. begin
  341. hp:=Pai(hp^.next);
  342. s:=','+tostr(pai_const(hp)^.value);
  343. AsmWrite(s);
  344. inc(l,length(s));
  345. end;
  346. until (not found) or (l>line_length);
  347. AsmLn;
  348. end;
  349. ait_const_8bit : begin
  350. AsmWrite(ait_const2str[hp^.typ]+tostr(pai_const(hp)^.value));
  351. consttyp:=hp^.typ;
  352. l:=0;
  353. repeat
  354. found:=(not (Pai(hp^.next)=nil)) and (Pai(hp^.next)^.typ=consttyp);
  355. if found then
  356. begin
  357. hp:=Pai(hp^.next);
  358. s:=','+tostr(pai_const(hp)^.value);
  359. AsmWrite(s);
  360. inc(l,length(s));
  361. end;
  362. until (not found) or (l>line_length);
  363. AsmLn;
  364. end;
  365. ait_const_symbol : Begin
  366. AsmWriteLn(#9'.long'#9+StrPas(pchar(pai_const(hp)^.value)));
  367. end;
  368. ait_const_symbol_offset :
  369. Begin
  370. AsmWrite(#9'.long'#9);
  371. AsmWritePChar(pai_const_symbol_offset(hp)^.name);
  372. if pai_const_symbol_offset(hp)^.offset>0 then
  373. AsmWrite('+'+tostr(pai_const_symbol_offset(hp)^.offset))
  374. else if pai_const_symbol_offset(hp)^.offset<0 then
  375. AsmWrite(tostr(pai_const_symbol_offset(hp)^.offset));
  376. AsmLn;
  377. end;
  378. ait_real_64bit : Begin
  379. AsmWriteLn(#9'.double'#9+double2str(pai_double(hp)^.value));
  380. end;
  381. ait_real_32bit : Begin
  382. AsmWriteLn(#9'.single'#9+double2str(pai_single(hp)^.value));
  383. end;
  384. ait_real_extended : Begin
  385. AsmWriteLn(#9'.extend'#9+double2str(pai_extended(hp)^.value));
  386. { comp type is difficult to write so use double }
  387. end;
  388. { TO SUPPORT SOONER OR LATER!!!
  389. ait_comp : Begin
  390. AsmWriteLn(#9'.double'#9+comp2str(pai_extended(hp)^.value));
  391. end; }
  392. ait_direct : begin
  393. AsmWritePChar(pai_direct(hp)^.str);
  394. AsmLn;
  395. {$IfDef GDB}
  396. if strpos(pai_direct(hp)^.str,'.data')<>nil then
  397. n_line:=n_dataline
  398. else if strpos(pai_direct(hp)^.str,'.text')<>nil then
  399. n_line:=n_textline
  400. else if strpos(pai_direct(hp)^.str,'.bss')<>nil then
  401. n_line:=n_bssline;
  402. {$endif GDB}
  403. end;
  404. ait_string : begin
  405. pos:=0;
  406. for i:=1 to pai_string(hp)^.len do
  407. begin
  408. if pos=0 then
  409. begin
  410. AsmWrite(#9'.ascii'#9'"');
  411. pos:=20;
  412. end;
  413. ch:=pai_string(hp)^.str[i-1];
  414. case ch of
  415. #0, {This can't be done by range, because a bug in FPC}
  416. #1..#31,
  417. #128..#255 : s:='\'+tostr(ord(ch) shr 6)+tostr((ord(ch) and 63) shr 3)+tostr(ord(ch) and 7);
  418. '"' : s:='\"';
  419. '\' : s:='\\';
  420. else
  421. s:=ch;
  422. end;
  423. AsmWrite(s);
  424. inc(pos,length(s));
  425. if (pos>line_length) or (i=pai_string(hp)^.len) then
  426. begin
  427. AsmWriteLn('"');
  428. pos:=0;
  429. end;
  430. end;
  431. end;
  432. ait_label : begin
  433. if assigned(hp^.next) and (pai(hp^.next)^.typ in
  434. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  435. ait_const_symbol,ait_const_symbol_offset,
  436. ait_real_64bit,ait_real_32bit,ait_string]) then
  437. begin
  438. if not(cs_littlesize in aktglobalswitches) then
  439. AsmWriteLn(#9#9'.align 4')
  440. else
  441. AsmWriteLn(#9#9'.align 2');
  442. end;
  443. if (pai_label(hp)^.l^.is_used) then
  444. AsmWriteLn(lab2str(pai_label(hp)^.l)+':');
  445. end;
  446. ait_labeled_instruction : begin
  447. { labeled operand }
  448. if pai_labeled(hp)^._op1 = R_NO then
  449. AsmWriteLn(#9+mot_op2str[pai_labeled(hp)^._operator]+#9+lab2str(pai_labeled(hp)^.lab))
  450. else
  451. { labeled operand with register }
  452. AsmWriteLn(#9+mot_op2str[pai_labeled(hp)^._operator]+#9+
  453. reg2str(pai_labeled(hp)^._op1)+','+lab2str(pai_labeled(hp)^.lab))
  454. end;
  455. ait_symbol : begin
  456. { ------------------------------------------------------- }
  457. { ----------- ALIGNMENT FOR ANY NON-BYTE VALUE ---------- }
  458. { ------------- REQUIREMENT FOR 680x0 ------------------- }
  459. { ------------------------------------------------------- }
  460. if assigned(hp^.next) and (pai(hp^.next)^.typ in
  461. [ait_const_32bit,ait_const_16bit,ait_const_8bit,
  462. ait_const_symbol,ait_const_symbol_offset,
  463. ait_real_64bit,ait_real_32bit,ait_string]) then
  464. begin
  465. if not(cs_littlesize in aktglobalswitches) then
  466. AsmWriteLn(#9#9'.align 4')
  467. else
  468. AsmWriteLn(#9#9'.align 2');
  469. end;
  470. if pai_symbol(hp)^.is_global then
  471. AsmWriteLn('.globl '+StrPas(pai_symbol(hp)^.name));
  472. AsmWriteLn(StrPas(pai_symbol(hp)^.name)+':');
  473. end;
  474. ait_instruction : begin
  475. { old versions of GAS don't like PEA.L and LEA.L }
  476. if (pai68k(hp)^._operator in [
  477. A_LEA,A_PEA,A_ABCD,A_BCHG,A_BCLR,A_BSET,A_BTST,
  478. A_EXG,A_NBCD,A_SBCD,A_SWAP,A_TAS,A_SCC,A_SCS,
  479. A_SEQ,A_SGE,A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,
  480. A_SNE,A_SPL,A_ST,A_SVC,A_SVS,A_SF]) then
  481. s:=#9+mot_op2str[pai68k(hp)^._operator]
  482. else
  483. if target_info.target=target_m68k_PalmOS then
  484. s:=#9+mot_op2str[pai68k(hp)^._operator]+gas_opsize2str[pai68k(hp)^.size]
  485. else
  486. s:=#9+mot_op2str[pai68k(hp)^._operator]+mit_opsize2str[pai68k(hp)^.size];
  487. if pai68k(hp)^.op1t<>top_none then
  488. begin
  489. { call and jmp need an extra handling }
  490. { this code is only callded if jmp isn't a labeled instruction }
  491. if pai68k(hp)^._operator in [A_JSR,A_JMP] then
  492. s:=s+#9+getopstr_jmp(pai68k(hp)^.op1t,pai68k(hp)^.op1)
  493. else
  494. if pai68k(hp)^.op1t = top_reglist then
  495. s:=s+#9+getopstr(pai68k(hp)^.op1t,@(pai68k(hp)^.reglist))
  496. else
  497. s:=s+#9+getopstr(pai68k(hp)^.op1t,pai68k(hp)^.op1);
  498. if pai68k(hp)^.op2t<>top_none then
  499. begin
  500. if pai68k(hp)^.op2t = top_reglist then
  501. s:=s+','+getopstr(pai68k(hp)^.op2t,@pai68k(hp)^.reglist)
  502. else
  503. s:=s+','+getopstr(pai68k(hp)^.op2t,pai68k(hp)^.op2);
  504. { three operands }
  505. if pai68k(hp)^.op3t<>top_none then
  506. begin
  507. if (pai68k(hp)^._operator = A_DIVSL) or
  508. (pai68k(hp)^._operator = A_DIVUL) or
  509. (pai68k(hp)^._operator = A_MULU) or
  510. (pai68k(hp)^._operator = A_MULS) or
  511. (pai68k(hp)^._operator = A_DIVS) or
  512. (pai68k(hp)^._operator = A_DIVU) then
  513. s:=s+':'+getopstr(pai68k(hp)^.op3t,pai68k(hp)^.op3)
  514. else
  515. s:=s+','+getopstr(pai68k(hp)^.op3t,pai68k(hp)^.op3);
  516. end;
  517. end;
  518. end;
  519. AsmWriteLn(s);
  520. end;
  521. {$ifdef GDB}
  522. ait_stabs : begin
  523. AsmWrite(#9'.stabs ');
  524. AsmWritePChar(pai_stabs(hp)^.str);
  525. AsmLn;
  526. end;
  527. ait_stabn : begin
  528. AsmWrite(#9'.stabn ');
  529. AsmWritePChar(pai_stabn(hp)^.str);
  530. AsmLn;
  531. end;
  532. ait_stab_function_name : funcname:=pai_stab_function_name(hp)^.str;
  533. {$endif GDB}
  534. ait_cut : begin
  535. { only reset buffer if nothing has changed }
  536. if AsmSize=AsmStartSize then
  537. AsmClear
  538. else
  539. begin
  540. AsmClose;
  541. DoAssemble;
  542. AsmCreate;
  543. end;
  544. { avoid empty files }
  545. while assigned(hp^.next) and (pai(hp^.next)^.typ in [ait_cut,ait_section,ait_comment]) do
  546. begin
  547. if pai(hp^.next)^.typ=ait_section then
  548. begin
  549. lastsec:=pai_section(hp^.next)^.sec;
  550. lastsecidx:=pai_section(hp^.next)^.idataidx;
  551. {$ifdef GDB}
  552. { this is needed for line info in data }
  553. case pai_section(hp^.next)^.sec of
  554. sec_code : n_line:=n_textline;
  555. sec_data : n_line:=n_dataline;
  556. sec_bss : n_line:=n_bssline;
  557. end;
  558. {$endif GDB}
  559. end;
  560. hp:=pai(hp^.next);
  561. end;
  562. {$ifdef GDB}
  563. { force write of filename }
  564. lastfileindex:=0;
  565. includecount:=0;
  566. funcname:=nil;
  567. WriteFileLineInfo(hp^.fileinfo);
  568. {$endif GDB}
  569. if lastsec<>sec_none then
  570. AsmWriteLn(ait_section2str(lastsec));
  571. AsmStartSize:=AsmSize;
  572. end;
  573. ait_marker : ;
  574. else
  575. internalerror(10000);
  576. end;
  577. hp:=pai(hp^.next);
  578. end;
  579. end;
  580. procedure tm68kgasasmlist.WriteAsmList;
  581. var
  582. p:dirstr;
  583. n:namestr;
  584. e:extstr;
  585. {$ifdef GDB}
  586. fileinfo : tfileposinfo;
  587. {$endif GDB}
  588. begin
  589. {$ifdef EXTDEBUG}
  590. if assigned(current_module^.mainsource) then
  591. comment(v_info,'Start writing gas-styled assembler output for '+current_module^.mainsource^);
  592. {$endif}
  593. LastSec:=sec_none;
  594. if assigned(current_module^.mainsource) then
  595. fsplit(current_module^.mainsource^,p,n,e)
  596. else
  597. begin
  598. p:=inputdir;
  599. n:=inputfile;
  600. e:=inputextension;
  601. end;
  602. { to get symify to work }
  603. AsmWriteLn(#9'.file "'+FixFileName(n+e)+'"');
  604. {$ifdef GDB}
  605. includecount:=0;
  606. n_line:=n_bssline;
  607. lastline:=0;
  608. lastfileindex:=0;
  609. funcname:=nil;
  610. linecount:=1;
  611. fileinfo.fileindex:=1;
  612. fileinfo.line:=1;
  613. { Write main file }
  614. WriteFileLineInfo(fileinfo);
  615. {$endif GDB}
  616. AsmStartSize:=AsmSize;
  617. countlabelref:=false;
  618. { there should be nothing but externals so we don't need to process
  619. WriteTree(externals); }
  620. WriteTree(debuglist);
  621. WriteTree(codesegment);
  622. WriteTree(datasegment);
  623. WriteTree(consts);
  624. WriteTree(rttilist);
  625. WriteTree(bsssegment);
  626. Writetree(importssection);
  627. Writetree(exportssection);
  628. Writetree(resourcesection);
  629. countlabelref:=true;
  630. AsmLn;
  631. {$ifdef EXTDEBUG}
  632. if assigned(current_module^.mainsource) then
  633. comment(v_info,'Done writing gas-styled assembler output for '+current_module^.mainsource^);
  634. {$endif EXTDEBUG}
  635. end;
  636. end.
  637. {
  638. $Log$
  639. Revision 1.18 1998-10-14 15:56:39 pierre
  640. * all references to comp suppressed for m68k
  641. Revision 1.17 1998/10/13 13:10:08 peter
  642. * new style for m68k/i386 infos and enums
  643. Revision 1.16 1998/10/12 12:27:44 pierre
  644. * typo error for tai_const_symbol_offset corrected
  645. Revision 1.15 1998/10/12 12:20:43 pierre
  646. + added tai_const_symbol_offset
  647. for r : pointer = @var.field;
  648. * better message for different arg names on implementation
  649. of function
  650. Revision 1.14 1998/10/06 17:16:36 pierre
  651. * some memory leaks fixed (thanks to Peter for heaptrc !)
  652. Revision 1.13 1998/10/01 20:19:08 jonas
  653. + ait_marker support
  654. Revision 1.12 1998/09/28 16:57:09 pierre
  655. * changed all length(p^.value_str^) into str_length(p)
  656. to get it work with and without ansistrings
  657. * changed sourcefiles field of tmodule to a pointer
  658. Revision 1.11 1998/09/16 01:07:13 carl
  659. * alignment fix for bytes
  660. Revision 1.10 1998/09/01 09:07:08 peter
  661. * m68k fixes, splitted cg68k like cgi386
  662. Revision 1.9 1998/08/31 12:26:20 peter
  663. * m68k and palmos updates from surebugfixes
  664. Revision 1.8 1998/08/10 14:49:36 peter
  665. + localswitches, moduleswitches, globalswitches splitting
  666. Revision 1.7 1998/07/14 14:46:38 peter
  667. * released NEWINPUT
  668. Revision 1.6 1998/07/10 10:50:54 peter
  669. * m68k updates
  670. Revision 1.5 1998/06/05 17:46:04 peter
  671. * tp doesn't like comp() typecast
  672. Revision 1.4 1998/06/04 23:51:28 peter
  673. * m68k compiles
  674. + .def file creation moved to gendef.pas so it could also be used
  675. for win32
  676. }