ag68kgas.pas 28 KB

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