agppcmpw.pas 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. This unit implements an asmoutput class for PowerPC with MPW 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. {
  19. This unit implements an asmoutput class for PowerPC with MPW syntax
  20. }
  21. unit agppcmpw;
  22. {$i fpcdefs.inc}
  23. interface
  24. uses
  25. globals,aasmbase,aasmtai,aasmcpu,assemble,
  26. cpubase;
  27. const
  28. mpw_reg2str : treg2strtable = ('',
  29. 'r0','r1','r2','r3','r4','r5','r6','r7','r8','r9','r10','r11','r12','r13','r14','r15','r16',
  30. 'r17','r18','r19','r20','r21','r22','r23','r24','r25','r26','r27','r28','r29','r30','r31',
  31. 'f0','f1','f2','f3','f4','f5','f6','f7', 'f8','f9','f10','f11','f12',
  32. 'f13','f14','f15','f16','f17', 'f18','f19','f20','f21','f22', 'f23','f24',
  33. 'f25','f26','f27','f28','f29','f30','f31',
  34. 'v0','v1','v2','v3','v4','v5','v6','v7','v8','v9','v10','v11','v12',
  35. 'v13','v14','v15','v16','v17','v18','v19','v20','v21','v22', 'v23','v24',
  36. 'v25','v26','v27','v28','v29','v30','v31',
  37. 'cR','cr0','cr1','cr2','cr3','cr4','cr5','cr6','cr7',
  38. 'xer','lr','ctr','fpscr'
  39. );
  40. type
  41. TPPCMPWAssembler = class(TExternalAssembler)
  42. procedure WriteTree(p:TAAsmoutput);override;
  43. procedure WriteAsmList;override;
  44. Function DoAssemble:boolean;override;
  45. procedure WriteExternals;
  46. {$ifdef GDB}
  47. procedure WriteFileLineInfo(var fileinfo : tfileposinfo);
  48. procedure WriteFileEndInfo;
  49. {$endif}
  50. procedure WriteAsmFileHeader;
  51. private
  52. procedure GenProcedureHeader(var hp:tai);
  53. end;
  54. implementation
  55. uses
  56. {$ifdef delphi}
  57. sysutils,
  58. {$endif}
  59. cutils,globtype,systems,cclasses,
  60. verbose,finput,fmodule,script,cpuinfo
  61. ;
  62. const
  63. line_length = 70;
  64. {Whether internal procedure references should be xxx[PR]: }
  65. use_PR = false;
  66. const_storage_class = '[RW]';
  67. {$ifdef GDB}
  68. var
  69. n_line : byte; { different types of source lines }
  70. linecount,
  71. includecount : longint;
  72. funcname : pchar;
  73. stabslastfileinfo : tfileposinfo;
  74. isInFunction: Boolean;
  75. firstLineInFunction: longint;
  76. {$endif}
  77. function ReplaceForbiddenChars(var s: string):Boolean;
  78. {Returns wheater a replacement has occured.}
  79. var
  80. i:Integer;
  81. {The dollar sign is not allowed in MPW PPCAsm}
  82. begin
  83. ReplaceForbiddenChars:=false;
  84. for i:=1 to Length(s) do
  85. if s[i]='$' then
  86. begin
  87. s[i]:='s';
  88. ReplaceForbiddenChars:=true;
  89. end;
  90. end;
  91. const
  92. {*** From here is copyed from agppcgas.pp, except where marked with CHANGED.
  93. Perhaps put in a third common file. ***}
  94. op2str : array[tasmop] of string[14] = ('<none>',
  95. 'add','add.','addo','addo.','addc','addc.','addco','addco.',
  96. 'adde','adde.','addeo','addeo.','addi','addic','addic.','addis',
  97. 'addme','addme.','addmeo','addmeo.','addze','addze.','addzeo',
  98. 'addzeo.','and','and.','andc','andc.','andi.','andis.','b',
  99. 'ba','bl','bla','bc','bca','bcl','bcla','bcctr','bcctrl','bclr',
  100. 'bclrl','cmp','cmpi','cmpl','cmpli','cntlzw','cntlzw.','crand',
  101. 'crandc','creqv','crnand','crnor','cror','crorc','crxor','dcba',
  102. 'dcbf','dcbi','dcbst','dcbt','divw','divw.','divwo','divwo.',
  103. 'divwu','divwu.','divwuo','divwuo.','eciwx','ecowx','eieio','eqv',
  104. 'eqv.','extsb','extsb.','extsh','extsh.','fabs','fabs.','fadd',
  105. 'fadd.','fadds','fadds.','fcmpo','fcmpu','fctiw','fctw.','fctwz',
  106. 'fctwz.','fdiv','fdiv.','fdivs','fdivs.','fmadd','fmadd.','fmadds',
  107. 'fmadds.','fmr','fmsub','fmsub.','fmsubs','fmsubs.','fmul','fmul.',
  108. 'fmuls','fmuls.','fnabs','fnabs.','fneg','fneg.','fnmadd',
  109. 'fnmadd.','fnmadds','fnmadds.','fnmsub','fnmsub.','fnmsubs',
  110. 'fnmsubs.','fres','fres.','frsp','frsp.','frsqrte','frsqrte.',
  111. 'fsel','fsel.','fsqrt','fsqrt.','fsqrts','fsqrts.','fsub','fsub.',
  112. 'fsubs','fsubs.','icbi','isync','lbz','lbzu','lbzux','lbzx',
  113. 'lfd','lfdu','lfdux','lfdx','lfs','lfsu','lfsux','lfsx','lha',
  114. 'lhau','lhaux','lhax','hbrx','lhz','lhzu','lhzux','lhzx','lmw',
  115. 'lswi','lswx','lwarx','lwbrx','lwz','lwzu','lwzux','lwzx','mcrf',
  116. 'mcrfs','mcrxr','lcrxe','mfcr','mffs','maffs.','mfmsr','mfspr','mfsr',
  117. 'mfsrin','mftb','mtfcrf','mtfd0','mtfsb1','mtfsf','mtfsf.',
  118. 'mtfsfi','mtfsfi.','mtmsr','mtspr','mtsr','mtsrin','mulhw',
  119. 'mulhw.','mulhwu','mulhwu.','mulli','mullw','mullw.','mullwo',
  120. 'mullwo.','nand','nand.','neg','neg.','nego','nego.','nor','nor.',
  121. 'or','or.','orc','orc.','ori','oris', 'rfi', 'rlwimi', 'rlwimi.',
  122. 'rlwinm', 'rlwinm.','rlwnm','sc','slw', 'slw.', 'sraw', 'sraw.',
  123. 'srawi', 'srawi.','srw', 'srw.', 'stb', 'stbu', 'stbux','stbx','stfd',
  124. 'stfdu', 'stfdux', 'stfdx', 'stfiwx', 'stfs', 'stfsu', 'stfsux', 'stfsx',
  125. 'sth', 'sthbrx', 'sthu', 'sthux', 'sthx', 'stmw', 'stswi', 'stswx', 'stw',
  126. 'stwbrx', 'stwx.', 'stwu', 'stwux', 'stwx', 'subf', 'subf.', 'subfo',
  127. 'subfo.', 'subfc', 'subc.', 'subfco', 'subfco.', 'subfe', 'subfe.',
  128. 'subfeo', 'subfeo.', 'subfic', 'subfme', 'subfme.', 'subfmeo', 'subfmeo.',
  129. 'subfze', 'subfze.', 'subfzeo', 'subfzeo.', 'sync', 'tlbia', 'tlbie',
  130. 'tlbsync', 'tw', 'twi', 'xor', 'xor.', 'xori', 'xoris',
  131. { some simplified mnemonics }
  132. 'subi', 'subis', 'subic', 'subic.', 'sub', 'sub.', 'subo', 'subo.',
  133. 'subc', 'subc.', 'subco', 'subco.', 'cmpwi', 'cmpw', 'cmplwi', 'cmplw',
  134. 'extlwi', 'extlwi.', 'extrwi', 'extrwi.', 'inslwi', 'inslwi.', 'insrwi',
  135. 'insrwi.', 'rotlwi', 'rotlwi.', 'rotlw', 'rotlw.', 'slwi', 'slwi.',
  136. 'srwi', 'srwi.', 'clrlwi', 'clrlwi.', 'clrrwi', 'clrrwi.', 'clrslwi',
  137. 'clrslwi.', 'blr', 'bctr', 'blrl', 'bctrl', 'crset', 'crclr', 'crmove',
  138. 'crnot', 'mt', 'mf','nop', 'li', 'lis', 'la', 'mr','mr.','not', 'mtcr', 'mtlr', 'mflr',
  139. 'mtctr', 'mfctr');
  140. function getreferencestring(var ref : treference) : string;
  141. var
  142. s : string;
  143. begin
  144. with ref do
  145. begin
  146. inc(offset,offsetfixup);
  147. if (symaddr <> refs_full) then
  148. InternalError(2002110301)
  149. else if ((offset < -32768) or (offset > 32767)) then
  150. InternalError(19991);
  151. if assigned(symbol) then
  152. begin
  153. s:= symbol.name;
  154. ReplaceForbiddenChars(s);
  155. {if symbol.typ = AT_FUNCTION then
  156. ;}
  157. s:= s+'[TC]' {ref to TOC entry }
  158. end
  159. else
  160. s:= '';
  161. if offset<0 then
  162. s:=s+tostr(offset)
  163. else
  164. if (offset>0) then
  165. begin
  166. if assigned(symbol) then
  167. s:=s+'+'+tostr(offset)
  168. else
  169. s:=s+tostr(offset);
  170. end;
  171. if (index.enum=R_NO) and (base.enum<>R_NO) then
  172. begin
  173. if offset=0 then
  174. if not assigned(symbol) then
  175. s:=s+'0';
  176. s:=s+'('+mpw_reg2str[base.enum]+')'
  177. end
  178. else if (index.enum<>R_NO) and (base.enum<>R_NO) and (offset=0) then
  179. s:=s+mpw_reg2str[base.enum]+','+mpw_reg2str[index.enum]
  180. else if ((index.enum<>R_NO) or (base.enum<>R_NO)) then
  181. internalerror(19992);
  182. end;
  183. getreferencestring:=s;
  184. end;
  185. function getopstr_jmp(const o:toper) : string;
  186. var
  187. hs : string;
  188. begin
  189. case o.typ of
  190. top_reg :
  191. getopstr_jmp:=mpw_reg2str[o.reg.enum];
  192. { no top_ref jumping for powerpc }
  193. top_const :
  194. getopstr_jmp:=tostr(o.val);
  195. top_symbol :
  196. begin
  197. hs:=o.sym.name;
  198. ReplaceForbiddenChars(hs);
  199. if o.symofs>0 then
  200. hs:=hs+'+'+tostr(o.symofs)
  201. else
  202. if o.symofs<0 then
  203. hs:=hs+tostr(o.symofs);
  204. getopstr_jmp:=hs;
  205. end;
  206. top_none:
  207. getopstr_jmp:='';
  208. else
  209. {$ifndef testing}
  210. internalerror(2002070603);
  211. {$else testing}
  212. begin
  213. writeln('internalerror 10001');
  214. halt(1);
  215. end;
  216. {$endif testing}
  217. end;
  218. end;
  219. function getopstr(const o:toper) : string;
  220. var
  221. hs : string;
  222. begin
  223. case o.typ of
  224. top_reg:
  225. getopstr:=mpw_reg2str[o.reg.enum];
  226. { no top_ref jumping for powerpc }
  227. top_const:
  228. getopstr:=tostr(longint(o.val));
  229. top_ref:
  230. getopstr:=getreferencestring(o.ref^);
  231. top_symbol:
  232. begin
  233. hs:=o.sym.name;
  234. ReplaceForbiddenChars(hs);
  235. if o.symofs>0 then
  236. hs:=hs+'+'+tostr(o.symofs)
  237. else
  238. if o.symofs<0 then
  239. hs:=hs+tostr(o.symofs);
  240. getopstr:=hs;
  241. end;
  242. else
  243. {$ifndef testing}
  244. internalerror(2002070604);
  245. {$else testing}
  246. begin
  247. writeln('internalerror 10001');
  248. halt(1);
  249. end;
  250. {$endif testing}
  251. end;
  252. end;
  253. function branchmode(o: tasmop): string[4];
  254. var tempstr: string[4];
  255. begin
  256. tempstr := '';
  257. case o of
  258. A_BCCTR,A_BCCTRL: tempstr := 'ctr';
  259. A_BCLR,A_BCLRL: tempstr := 'lr';
  260. end;
  261. case o of
  262. A_BL,A_BLA,A_BCL,A_BCLA,A_BCCTRL,A_BCLRL: tempstr := tempstr+'l';
  263. end;
  264. case o of
  265. A_BA,A_BLA,A_BCA,A_BCLA: tempstr:=tempstr+'a';
  266. end;
  267. branchmode := tempstr;
  268. end;
  269. function cond2str(op: tasmop; c: tasmcond): string;
  270. { note: no checking is performed whether the given combination of }
  271. { conditions is valid }
  272. var tempstr: string;
  273. begin
  274. tempstr:=#9;
  275. case c.simple of
  276. false: cond2str := tempstr+op2str[op]+#9+tostr(c.bo)+','+
  277. tostr(c.bi);
  278. true:
  279. if (op >= A_B) and (op <= A_BCLRL) then
  280. case c.cond of
  281. { unconditional branch }
  282. C_NONE:
  283. cond2str := tempstr+op2str[op];
  284. { bdnzt etc }
  285. else
  286. begin
  287. tempstr := tempstr+'b'+asmcondflag2str[c.cond]+
  288. branchmode(op)+#9;
  289. case c.cond of
  290. C_LT..C_NU:
  291. cond2str := tempstr+mpw_reg2str[c.cr];
  292. C_T..C_DZF:
  293. cond2str := tempstr+tostr(c.crbit);
  294. end;
  295. end;
  296. end
  297. { we have a trap instruction }
  298. else
  299. begin
  300. internalerror(2002070601);
  301. { not yet implemented !!!!!!!!!!!!!!!!!!!!! }
  302. { case tempstr := 'tw';}
  303. end;
  304. end;
  305. end;
  306. Function GetInstruction(hp : tai):string; {CHANGED from method to proc}
  307. var op: TAsmOp;
  308. s: string;
  309. i: byte;
  310. sep: string[3];
  311. begin
  312. op:=taicpu(hp).opcode;
  313. if is_calljmp(op) then
  314. begin
  315. { direct BO/BI in op[0] and op[1] not supported, put them in condition! }
  316. case op of
  317. A_B,A_BA,A_BLA:
  318. s:=#9+op2str[op]+#9;
  319. A_BCTR,A_BCTRL,A_BLR,A_BLRL:
  320. s:=#9+op2str[op];
  321. A_BL:
  322. s:=#9+op2str[op]+#9'.';
  323. else
  324. s:=cond2str(op,taicpu(hp).condition)+',';
  325. end;
  326. if (taicpu(hp).oper[0].typ <> top_none) then
  327. s:=s+getopstr_jmp(taicpu(hp).oper[0]);
  328. if use_PR then
  329. if op=A_BL then
  330. s:=s+'[PR]';
  331. end
  332. else
  333. { process operands }
  334. begin
  335. case op of
  336. A_MFSPR:
  337. case taicpu(hp).oper[1].reg.enum of
  338. R_CR:
  339. begin
  340. op:=A_MFCR;
  341. taicpu(hp).ops:=1;
  342. end;
  343. R_LR:
  344. begin
  345. op:=A_MFLR;
  346. taicpu(hp).ops:=1;
  347. end;
  348. else
  349. internalerror(2002100701);
  350. end;
  351. A_MTSPR:
  352. case taicpu(hp).oper[1].reg.enum of
  353. R_CR:
  354. begin
  355. op:=A_MTCR;
  356. taicpu(hp).ops:=1;
  357. end;
  358. R_LR:
  359. begin
  360. op:=A_MTLR;
  361. taicpu(hp).ops:=1;
  362. end;
  363. else
  364. internalerror(2002100701);
  365. end;
  366. end;
  367. s:=#9+op2str[op];
  368. if taicpu(hp).ops<>0 then
  369. begin
  370. sep:=#9;
  371. for i:=0 to taicpu(hp).ops-1 do
  372. begin
  373. s:=s+sep+getopstr(taicpu(hp).oper[i]);
  374. sep:=',';
  375. end;
  376. end;
  377. end;
  378. GetInstruction:=s;
  379. end;
  380. {*** Until here is copyed from agppcgas.pp. ***}
  381. function single2str(d : single) : string;
  382. var
  383. hs : string;
  384. p : byte;
  385. begin
  386. str(d,hs);
  387. { nasm expects a lowercase e }
  388. p:=pos('E',hs);
  389. if p>0 then
  390. hs[p]:='e';
  391. p:=pos('+',hs);
  392. if p>0 then
  393. delete(hs,p,1);
  394. single2str:=lower(hs);
  395. end;
  396. function double2str(d : double) : string;
  397. var
  398. hs : string;
  399. p : byte;
  400. begin
  401. str(d,hs);
  402. { nasm expects a lowercase e }
  403. p:=pos('E',hs);
  404. if p>0 then
  405. hs[p]:='e';
  406. p:=pos('+',hs);
  407. if p>0 then
  408. delete(hs,p,1);
  409. double2str:=lower(hs);
  410. end;
  411. function fixline(s:string):string;
  412. {
  413. return s with all leading and ending spaces and tabs removed
  414. }
  415. var
  416. i,j,k : longint;
  417. begin
  418. i:=length(s);
  419. while (i>0) and (s[i] in [#9,' ']) do
  420. dec(i);
  421. j:=1;
  422. while (j<i) and (s[j] in [#9,' ']) do
  423. inc(j);
  424. for k:=j to i do
  425. if s[k] in [#0..#31,#127..#255] then
  426. s[k]:='.';
  427. fixline:=Copy(s,j,i-j+1);
  428. end;
  429. {****************************************************************************
  430. PowerPC MPW Assembler
  431. ****************************************************************************}
  432. procedure TPPCMPWAssembler.GenProcedureHeader(var hp:tai);
  433. {Returns the current hp where the caller should continue from}
  434. {For multiple entry procedures, only the last is exported as xxx[PR]
  435. (if use_PR is set) }
  436. procedure WriteExportHeader(hp:tai);
  437. var
  438. s: string;
  439. replaced: boolean;
  440. begin
  441. s:= tai_symbol(hp).sym.name;
  442. replaced:= ReplaceForbiddenChars(s);
  443. if replaced then
  444. begin
  445. if not use_PR then
  446. AsmWriteLn(#9'export'#9'.'+s+' => ''.'+tai_symbol(hp).sym.name+'''');
  447. AsmWriteLn(#9'export'#9+s+'[DS] => '''+tai_symbol(hp).sym.name+'[DS]''');
  448. end
  449. else
  450. begin
  451. if not use_PR then
  452. AsmWriteLn(#9'export'#9'.'+s);
  453. AsmWriteLn(#9'export'#9+s+'[DS]');
  454. end;
  455. {Entry in transition vector: }
  456. AsmWriteLn(#9'csect'#9+s+'[DS]');
  457. AsmWriteLn(#9'dc.l'#9'.'+s);
  458. AsmWriteln(#9'dc.l'#9'TOC[tc0]');
  459. {Entry in TOC: }
  460. AsmWriteLn(#9'toc');
  461. AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[DS]');
  462. end;
  463. function GetAdjacentTaiSymbol(var hp:tai):Boolean;
  464. begin
  465. GetAdjacentTaiSymbol:= false;
  466. while assigned(hp.next) do
  467. case tai(hp.next).typ of
  468. ait_symbol:
  469. begin
  470. hp:=tai(hp.next);
  471. GetAdjacentTaiSymbol:= true;
  472. Break;
  473. end;
  474. ait_stab_function_name:
  475. hp:=tai(hp.next);
  476. else
  477. begin
  478. //AsmWriteln(' ;#*#*# ' + tostr(Ord(tai(hp.next).typ)));
  479. Break;
  480. end;
  481. end;
  482. end;
  483. var
  484. first,last: tai;
  485. s: string;
  486. replaced: boolean;
  487. begin
  488. s:= tai_symbol(hp).sym.name;
  489. {Write all headers}
  490. first:= hp;
  491. repeat
  492. WriteExportHeader(hp);
  493. last:= hp;
  494. until not GetAdjacentTaiSymbol(hp);
  495. {Start the section of the body of the proc: }
  496. s:= tai_symbol(last).sym.name;
  497. replaced:= ReplaceForbiddenChars(s);
  498. if use_PR then
  499. if replaced then
  500. AsmWriteLn(#9'export'#9'.'+s+'[PR] => ''.'+tai_symbol(last).sym.name+'[PR]''')
  501. else
  502. AsmWriteLn(#9'export'#9'.'+s+'[PR]');
  503. AsmWriteLn(#9'csect'#9'.'+s+'[PR]'); //starts the section
  504. AsmWriteLn(#9'function'#9'.'+s+'[PR]'); //info for debugger
  505. {$ifdef GDB}
  506. if ((cs_debuginfo in aktmoduleswitches) or
  507. (cs_gdb_lineinfo in aktglobalswitches)) then
  508. begin
  509. //info for debuggers:
  510. firstLineInFunction:= stabslastfileinfo.line;
  511. AsmWriteLn(#9'beginf ' + tostr(firstLineInFunction));
  512. isInFunction:= true;
  513. end;
  514. {$endif}
  515. {Write all labels: }
  516. hp:= first;
  517. repeat
  518. s:= tai_symbol(hp).sym.name;
  519. ReplaceForbiddenChars(s);
  520. AsmWriteLn('.'+s+':');
  521. until not GetAdjacentTaiSymbol(hp);
  522. end;
  523. (*
  524. procedure TPPCMPWAssembler.GenProcedureHeader(hp:tai);
  525. var
  526. s: string;
  527. replaced: boolean;
  528. begin
  529. s:= tai_symbol(hp).sym.name;
  530. replaced:= ReplaceForbiddenChars(s);
  531. if replaced then
  532. begin
  533. AsmWriteLn(#9'export'#9'.'+s+'[PR] => ''.'+tai_symbol(hp).sym.name+'[PR]''');
  534. AsmWriteLn(#9'export'#9+s+'[DS] => '''+tai_symbol(hp).sym.name+'[DS]''');
  535. end
  536. else
  537. begin
  538. AsmWriteLn(#9'export'#9'.'+s+'[PR]');
  539. AsmWriteLn(#9'export'#9+s+'[DS]');
  540. end;
  541. {Entry in transition vector: }
  542. AsmWriteLn(#9'csect'#9+s+'[DS]');
  543. AsmWriteLn(#9'dc.l'#9'.'+s);
  544. AsmWriteln(#9'dc.l'#9'TOC[tc0]');
  545. {Entry in TOC: }
  546. AsmWriteLn(#9'toc');
  547. AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[DS]');
  548. {Start the section of the body of the proc: }
  549. AsmWriteLn(#9'csect'#9'.'+s+'[PR]');
  550. AsmWriteLn('.'+s+':');
  551. end;
  552. *)
  553. var
  554. LasTSec : TSection;
  555. lastfileinfo : tfileposinfo;
  556. infile,
  557. lastinfile : tinputfile;
  558. const
  559. ait_const2str:array[ait_const_32bit..ait_const_8bit] of string[8]=
  560. (#9'dc.l'#9,#9'dc.w'#9,#9'dc.b'#9);
  561. Function PadTabs(const p:string;addch:char):string;
  562. var
  563. s : string;
  564. i : longint;
  565. begin
  566. i:=length(p);
  567. if addch<>#0 then
  568. begin
  569. inc(i);
  570. s:=p+addch;
  571. end
  572. else
  573. s:=p;
  574. if i<8 then
  575. PadTabs:=s+#9#9
  576. else
  577. PadTabs:=s+#9;
  578. end;
  579. {$ifdef GDB}
  580. procedure TPPCMPWAssembler.WriteFileLineInfo(var fileinfo : tfileposinfo);
  581. var
  582. curr_n : byte;
  583. begin
  584. if not ((cs_debuginfo in aktmoduleswitches) or
  585. (cs_gdb_lineinfo in aktglobalswitches)) then
  586. exit;
  587. { file changed ? (must be before line info) }
  588. if (fileinfo.fileindex<>0) and
  589. (stabslastfileinfo.fileindex<>fileinfo.fileindex) then
  590. begin
  591. infile:=current_module.sourcefiles.get_file(fileinfo.fileindex);
  592. if assigned(infile) then
  593. begin
  594. (*
  595. if includecount=0 then
  596. curr_n:=n_sourcefile
  597. else
  598. curr_n:=n_includefile;
  599. if (infile.path^<>'') then
  600. begin
  601. AsmWriteLn(#9'.stabs "'+lower(BsToSlash(FixPath(infile.path^,false)))+'",'+
  602. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  603. end;
  604. AsmWriteLn(#9'.stabs "'+lower(FixFileName(infile.name^))+'",'+
  605. tostr(curr_n)+',0,0,'+target_asm.labelprefix+'text'+ToStr(IncludeCount));
  606. *)
  607. AsmWriteLn(#9'file '''+lower(FixFileName(infile.name^))+'''');
  608. (*
  609. AsmWriteLn(target_asm.labelprefix+'text'+ToStr(IncludeCount)+':');
  610. *)
  611. inc(includecount);
  612. { force new line info }
  613. stabslastfileinfo.line:=-1;
  614. end;
  615. end;
  616. { line changed ? }
  617. if (stabslastfileinfo.line<>fileinfo.line) and (fileinfo.line<>0) then
  618. begin
  619. (*
  620. if (n_line=n_textline) and assigned(funcname) and
  621. (target_info.use_function_relative_addresses) then
  622. begin
  623. AsmWriteLn(target_asm.labelprefix+'l'+tostr(linecount)+':');
  624. AsmWrite(#9'.stabn '+tostr(n_line)+',0,'+tostr(fileinfo.line)+','+
  625. target_asm.labelprefix+'l'+tostr(linecount)+' - ');
  626. AsmWritePChar(FuncName);
  627. AsmLn;
  628. inc(linecount);
  629. end
  630. else
  631. AsmWriteLn(#9'.stabd'#9+tostr(n_line)+',0,'+tostr(fileinfo.line));
  632. *)
  633. if isInFunction then
  634. AsmWriteln(#9'line '+ tostr(fileinfo.line - firstLineInFunction - 1));
  635. end;
  636. stabslastfileinfo:=fileinfo;
  637. end;
  638. procedure TPPCMPWAssembler.WriteFileEndInfo;
  639. begin
  640. if not ((cs_debuginfo in aktmoduleswitches) or
  641. (cs_gdb_lineinfo in aktglobalswitches)) then
  642. exit;
  643. AsmLn;
  644. (*
  645. AsmWriteLn(ait_section2str(sec_code));
  646. AsmWriteLn(#9'.stabs "",'+tostr(n_sourcefile)+',0,0,'+target_asm.labelprefix+'etext');
  647. AsmWriteLn(target_asm.labelprefix+'etext:');
  648. *)
  649. end;
  650. {$endif}
  651. procedure TPPCMPWAssembler.WriteTree(p:TAAsmoutput);
  652. var
  653. s,
  654. prefix,
  655. suffix : string;
  656. hp : tai;
  657. hp1 : tailineinfo;
  658. counter,
  659. lines,
  660. InlineLevel : longint;
  661. i,j,l : longint;
  662. consttyp : taitype;
  663. found,
  664. do_line,DoNotSplitLine,
  665. quoted : boolean;
  666. sep : char;
  667. replaced : boolean;
  668. begin
  669. if not assigned(p) then
  670. exit;
  671. InlineLevel:=0;
  672. { lineinfo is only needed for codesegment (PFV) }
  673. do_line:=((cs_asm_source in aktglobalswitches) or
  674. (cs_lineinfo in aktmoduleswitches))
  675. and (p=codesegment);
  676. DoNotSplitLine:=false;
  677. hp:=tai(p.first);
  678. while assigned(hp) do
  679. begin
  680. if not(hp.typ in SkipLineInfo) and
  681. not DoNotSplitLine then
  682. begin
  683. hp1 := hp as tailineinfo;
  684. {$ifdef GDB}
  685. { write debug info }
  686. if (cs_debuginfo in aktmoduleswitches) or
  687. (cs_gdb_lineinfo in aktglobalswitches) then
  688. WriteFileLineInfo(hp1.fileinfo);
  689. {$endif GDB}
  690. if do_line then
  691. begin
  692. { load infile }
  693. if lastfileinfo.fileindex<>hp1.fileinfo.fileindex then
  694. begin
  695. infile:=current_module.sourcefiles.get_file(hp1.fileinfo.fileindex);
  696. if assigned(infile) then
  697. begin
  698. { open only if needed !! }
  699. if (cs_asm_source in aktglobalswitches) then
  700. infile.open;
  701. end;
  702. { avoid unnecessary reopens of the same file !! }
  703. lastfileinfo.fileindex:=hp1.fileinfo.fileindex;
  704. { be sure to change line !! }
  705. lastfileinfo.line:=-1;
  706. end;
  707. { write source }
  708. if (cs_asm_source in aktglobalswitches) and
  709. assigned(infile) then
  710. begin
  711. if (infile<>lastinfile) then
  712. begin
  713. AsmWriteLn(target_asm.comment+'['+infile.name^+']');
  714. if assigned(lastinfile) then
  715. lastinfile.close;
  716. end;
  717. if (hp1.fileinfo.line<>lastfileinfo.line) and
  718. ((hp1.fileinfo.line<infile.maxlinebuf) or (InlineLevel>0)) then
  719. begin
  720. if (hp1.fileinfo.line<>0) and
  721. ((infile.linebuf^[hp1.fileinfo.line]>=0) or (InlineLevel>0)) then
  722. AsmWriteLn(target_asm.comment+'['+tostr(hp1.fileinfo.line)+'] '+
  723. fixline(infile.GetLineStr(hp1.fileinfo.line)));
  724. { set it to a negative value !
  725. to make that is has been read already !! PM }
  726. if (infile.linebuf^[hp1.fileinfo.line]>=0) then
  727. infile.linebuf^[hp1.fileinfo.line]:=-infile.linebuf^[hp1.fileinfo.line]-1;
  728. end;
  729. end;
  730. lastfileinfo:=hp1.fileinfo;
  731. lastinfile:=infile;
  732. end;
  733. end;
  734. DoNotSplitLine:=false;
  735. case hp.typ of
  736. ait_comment:
  737. begin
  738. AsmWrite(target_asm.comment);
  739. AsmWritePChar(tai_comment(hp).str);
  740. AsmLn;
  741. end;
  742. ait_regalloc,
  743. ait_tempalloc:
  744. ;
  745. ait_section:
  746. begin
  747. {if LasTSec<>sec_none then
  748. AsmWriteLn('_'+target_asm.secnames[LasTSec]+#9#9'ENDS');}
  749. if tai_section(hp).sec<>sec_none then
  750. begin
  751. AsmLn;
  752. AsmWriteLn(#9+target_asm.secnames[tai_section(hp).sec]);
  753. {$ifdef GDB}
  754. lastfileinfo.line:=-1;
  755. {$endif GDB}
  756. end;
  757. LasTSec:=tai_section(hp).sec;
  758. end;
  759. ait_align:
  760. begin
  761. case tai_align(hp).aligntype of
  762. 1:AsmWriteLn(#9'align 0');
  763. 2:AsmWriteLn(#9'align 1');
  764. 4:AsmWriteLn(#9'align 2');
  765. otherwise internalerror(2002110302);
  766. end;
  767. end;
  768. ait_datablock:
  769. begin
  770. s:= tai_datablock(hp).sym.name;
  771. replaced:= ReplaceForbiddenChars(s);
  772. if tai_datablock(hp).is_global then
  773. if replaced then
  774. AsmWriteLn(#9'export'#9+s+'[RW] => '''+tai_datablock(hp).sym.name+'''')
  775. else
  776. AsmWriteLn(#9'export'#9+s+'[RW]');
  777. if not macos_direct_globals then
  778. begin
  779. AsmWriteLn(#9'toc');
  780. AsmWriteLn(#9'tc'#9+s+'[TC], '+s+'[RW]');
  781. AsmWriteLn(#9'csect'#9+s+'[RW]');
  782. AsmWriteLn(#9'ds.b '+tostr(tai_datablock(hp).size));
  783. end
  784. else
  785. begin
  786. AsmWriteLn(#9'csect'#9+s+'[TC]');
  787. AsmWriteLn(PadTabs(s+':',#0)+'ds.b '+tostr(tai_datablock(hp).size));
  788. {TODO: ? PadTabs(s,#0) }
  789. end;
  790. end;
  791. ait_const_32bit,
  792. ait_const_8bit,
  793. ait_const_16bit :
  794. begin
  795. AsmWrite(ait_const2str[hp.typ]+tostr(tai_const(hp).value));
  796. consttyp:=hp.typ;
  797. l:=0;
  798. repeat
  799. found:=(not (tai(hp.next)=nil)) and (tai(hp.next).typ=consttyp);
  800. if found then
  801. begin
  802. hp:=tai(hp.next);
  803. s:=','+tostr(tai_const(hp).value);
  804. AsmWrite(s);
  805. inc(l,length(s));
  806. end;
  807. until (not found) or (l>line_length);
  808. AsmLn;
  809. end;
  810. ait_const_symbol:
  811. begin
  812. (*
  813. AsmWriteLn(#9#9'dd'#9'offset '+tai_const_symbol(hp).sym.name);
  814. if tai_const_symbol(hp).offset>0 then
  815. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  816. else if tai_const_symbol(hp).offset<0 then
  817. AsmWrite(tostr(tai_const_symbol(hp).offset));
  818. AsmLn;
  819. *)
  820. s:= tai_const_symbol(hp).sym.name;
  821. ReplaceForbiddenChars(s);
  822. if tai_const_symbol(hp).sym.typ = AT_FUNCTION then
  823. begin
  824. if use_PR then
  825. AsmWriteLn(#9'dc.l'#9'.'+ s +'[PR]')
  826. else
  827. AsmWriteLn(#9'dc.l'#9 + s + '[DS]')
  828. end
  829. else
  830. begin
  831. if macos_direct_globals then
  832. AsmWriteLn(#9'dc.l'#9+s)
  833. else
  834. AsmWriteLn(#9'dc.l'#9+s+const_storage_class);
  835. end;
  836. (* TODO: the following might need to be included. Temporaily we
  837. generate an error
  838. if tai_const_symbol(hp).offset>0 then
  839. AsmWrite('+'+tostr(tai_const_symbol(hp).offset))
  840. else if tai_const_symbol(hp).offset<0 then
  841. AsmWrite(tostr(tai_const_symbol(hp).offset));
  842. *)
  843. if tai_const_symbol(hp).offset <> 0 then
  844. InternalError(2002110101);
  845. AsmLn;
  846. end;
  847. ait_real_32bit:
  848. AsmWriteLn(#9'dc.l'#9'"'+single2str(tai_real_32bit(hp).value)+'"');
  849. ait_real_64bit:
  850. AsmWriteLn(#9'dc.d'#9'"'+double2str(tai_real_64bit(hp).value)+'"');
  851. ait_string:
  852. begin
  853. {NOTE When a single quote char is encountered, it is
  854. replaced with a numeric ascii value. It could also
  855. have been replaced with the escape seq of double quotes.}
  856. counter := 0;
  857. lines := tai_string(hp).len div line_length;
  858. { separate lines in different parts }
  859. if tai_string(hp).len > 0 then
  860. Begin
  861. for j := 0 to lines-1 do
  862. begin
  863. AsmWrite(#9'dc.b'#9);
  864. quoted:=false;
  865. for i:=counter to counter+line_length do
  866. begin
  867. { it is an ascii character. }
  868. if (ord(tai_string(hp).str[i])>31) and
  869. (ord(tai_string(hp).str[i])<128) and
  870. (tai_string(hp).str[i]<>'''') then
  871. begin
  872. if not(quoted) then
  873. begin
  874. if i>counter then
  875. AsmWrite(',');
  876. AsmWrite('''');
  877. end;
  878. AsmWrite(tai_string(hp).str[i]);
  879. quoted:=true;
  880. end { if > 31 and < 128 and ord('"') }
  881. else
  882. begin
  883. if quoted then
  884. AsmWrite('''');
  885. if i>counter then
  886. AsmWrite(',');
  887. quoted:=false;
  888. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  889. end;
  890. end; { end for i:=0 to... }
  891. if quoted then AsmWrite('''');
  892. AsmWrite(target_info.newline);
  893. counter := counter+line_length;
  894. end; { end for j:=0 ... }
  895. { do last line of lines }
  896. AsmWrite(#9'dc.b'#9);
  897. quoted:=false;
  898. for i:=counter to tai_string(hp).len-1 do
  899. begin
  900. { it is an ascii character. }
  901. if (ord(tai_string(hp).str[i])>31) and
  902. (ord(tai_string(hp).str[i])<128) and
  903. (tai_string(hp).str[i]<>'''') then
  904. begin
  905. if not(quoted) then
  906. begin
  907. if i>counter then
  908. AsmWrite(',');
  909. AsmWrite('''');
  910. end;
  911. AsmWrite(tai_string(hp).str[i]);
  912. quoted:=true;
  913. end { if > 31 and < 128 and " }
  914. else
  915. begin
  916. if quoted then
  917. AsmWrite('''');
  918. if i>counter then
  919. AsmWrite(',');
  920. quoted:=false;
  921. AsmWrite(tostr(ord(tai_string(hp).str[i])));
  922. end;
  923. end; { end for i:=0 to... }
  924. if quoted then
  925. AsmWrite('''');
  926. end;
  927. AsmLn;
  928. end;
  929. ait_label:
  930. begin
  931. if tai_label(hp).l.is_used then
  932. begin
  933. s:= tai_label(hp).l.name;
  934. ReplaceForbiddenChars(s);
  935. if s[1] = '@' then
  936. AsmWriteLn(s+':')
  937. else
  938. begin
  939. if not macos_direct_globals then
  940. begin
  941. AsmWriteLn(#9'toc');
  942. AsmWriteLn(#9'tc'#9+s+'[TC], '+s+const_storage_class);
  943. AsmWriteLn(#9'csect'#9+s+const_storage_class);
  944. end
  945. else
  946. begin
  947. AsmWriteLn(#9'csect'#9+s+'[TC]');
  948. AsmWriteLn(PadTabs(s+':',#0));
  949. end;
  950. end;
  951. end;
  952. end;
  953. ait_direct:
  954. begin
  955. AsmWritePChar(tai_direct(hp).str);
  956. AsmLn;
  957. end;
  958. ait_symbol:
  959. begin
  960. if tai_symbol(hp).sym.typ=AT_FUNCTION then
  961. GenProcedureHeader(hp)
  962. else if tai_symbol(hp).sym.typ=AT_DATA then
  963. begin
  964. s:= tai_symbol(hp).sym.name;
  965. replaced:= ReplaceForbiddenChars(s);
  966. if tai_symbol(hp).is_global then
  967. if replaced then
  968. AsmWriteLn(#9'export'#9+s+'[RW] => '''+tai_symbol(hp).sym.name+'''')
  969. else
  970. AsmWriteLn(#9'export'#9+s+'[RW]');
  971. if not macos_direct_globals then
  972. begin
  973. AsmWriteLn(#9'toc');
  974. AsmWriteLn(#9'tc'#9+s+'[TC], '+s+ const_storage_class);
  975. AsmWriteLn(#9'csect'#9+s+ const_storage_class);
  976. end
  977. else
  978. begin
  979. AsmWriteLn(#9'csect'#9+s+'[TC]');
  980. AsmWriteLn(s+':');
  981. end;
  982. end
  983. else
  984. InternalError(2003071301);
  985. end;
  986. ait_symbol_end:
  987. {$ifdef GDB}
  988. if isInFunction then
  989. if ((cs_debuginfo in aktmoduleswitches) or
  990. (cs_gdb_lineinfo in aktglobalswitches)) then
  991. begin
  992. //info for debuggers:
  993. AsmWriteLn(#9'endf ' + tostr(stabslastfileinfo.line));
  994. isInFunction:= false;
  995. end
  996. {$endif GDB}
  997. ;
  998. ait_instruction:
  999. AsmWriteLn(GetInstruction(hp));
  1000. {$ifdef GDB}
  1001. ait_stabn: ;
  1002. ait_stabs: ;
  1003. ait_force_line :
  1004. stabslastfileinfo.line:=0;
  1005. ait_stab_function_name: ;
  1006. {$endif GDB}
  1007. ait_cut :
  1008. begin
  1009. { only reset buffer if nothing has changed }
  1010. if AsmSize=AsmStartSize then
  1011. AsmClear
  1012. else
  1013. begin
  1014. {
  1015. if LasTSec<>sec_none then
  1016. AsmWriteLn('_'+target_asm.secnames[LasTSec]+#9#9'ends');
  1017. AsmLn;
  1018. }
  1019. AsmWriteLn(#9'end');
  1020. AsmClose;
  1021. DoAssemble;
  1022. AsmCreate(tai_cut(hp).place);
  1023. end;
  1024. { avoid empty files }
  1025. while assigned(hp.next) and (tai(hp.next).typ in [ait_cut,ait_section,ait_comment]) do
  1026. begin
  1027. if tai(hp.next).typ=ait_section then
  1028. begin
  1029. lasTSec:=tai_section(hp.next).sec;
  1030. end;
  1031. hp:=tai(hp.next);
  1032. end;
  1033. WriteAsmFileHeader;
  1034. if lasTSec<>sec_none then
  1035. AsmWriteLn(#9+target_asm.secnames[lasTSec]);
  1036. { AsmWriteLn('_'+target_asm.secnames[lasTSec]+#9#9+
  1037. 'SEGMENT'#9'PARA PUBLIC USE32 '''+
  1038. target_asm.secnames[lasTSec]+'''');
  1039. }
  1040. AsmStartSize:=AsmSize;
  1041. end;
  1042. ait_marker :
  1043. begin
  1044. if tai_marker(hp).kind=InlineStart then
  1045. inc(InlineLevel)
  1046. else if tai_marker(hp).kind=InlineEnd then
  1047. dec(InlineLevel);
  1048. end;
  1049. else
  1050. internalerror(2002110303);
  1051. end;
  1052. hp:=tai(hp.next);
  1053. end;
  1054. end;
  1055. var
  1056. currentasmlist : TExternalAssembler;
  1057. procedure writeexternal(p:tnamedindexitem;arg:pointer);
  1058. var
  1059. s:string;
  1060. begin
  1061. if tasmsymbol(p).defbind=AB_EXTERNAL then
  1062. begin
  1063. //Writeln('ZZZ ',p.name,' ',p.classname,' ',Ord(tasmsymbol(p).typ));
  1064. s:= p.name;
  1065. case tasmsymbol(p).typ of
  1066. AT_FUNCTION:
  1067. begin
  1068. if ReplaceForbiddenChars(s) then
  1069. begin
  1070. if not use_PR then
  1071. currentasmlist.AsmWriteLn(#9'import'#9'.'+s+' <= ''.'+p.name+'''')
  1072. else
  1073. currentasmlist.AsmWriteLn(#9'import'#9'.'+s+'[PR] <= ''.'+p.name+'[PR]''');
  1074. currentasmlist.AsmWriteLn(#9'import'#9+s+'[DS] <= '''+p.name+'[DS]''');
  1075. end
  1076. else
  1077. begin
  1078. if not use_PR then
  1079. currentasmlist.AsmWriteLn(#9'import'#9'.'+s)
  1080. else
  1081. currentasmlist.AsmWriteLn(#9'import'#9'.'+s+'[PR]');
  1082. currentasmlist.AsmWriteLn(#9'import'#9+s+'[DS]');
  1083. end;
  1084. currentasmlist.AsmWriteLn(#9'toc');
  1085. currentasmlist.AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[DS]');
  1086. end
  1087. else
  1088. begin
  1089. if ReplaceForbiddenChars(s) then
  1090. currentasmlist.AsmWriteLn(#9'import'#9+s+'[RW] <= '''+p.name+'''')
  1091. else
  1092. currentasmlist.AsmWriteLn(#9'import'#9+s+'[RW]');
  1093. currentasmlist.AsmWriteLn(#9'toc');
  1094. currentasmlist.AsmWriteLn(#9'tc'#9+s+'[TC],'+s+'[RW]');
  1095. end;
  1096. end;
  1097. end;
  1098. end;
  1099. procedure TPPCMPWAssembler.WriteExternals;
  1100. begin
  1101. currentasmlist:=self;
  1102. objectlibrary.symbolsearch.foreach_static({$ifdef fpcprocvar}@{$endif}writeexternal,nil);
  1103. end;
  1104. function TPPCMPWAssembler.DoAssemble : boolean;
  1105. var f : file;
  1106. begin
  1107. DoAssemble:=Inherited DoAssemble;
  1108. (*
  1109. { masm does not seem to recognize specific extensions and uses .obj allways PM }
  1110. if (aktoutputformat = as_i386_masm) then
  1111. begin
  1112. if not(cs_asm_extern in aktglobalswitches) then
  1113. begin
  1114. if Not FileExists(objfile) and
  1115. FileExists(ForceExtension(objfile,'.obj')) then
  1116. begin
  1117. Assign(F,ForceExtension(objfile,'.obj'));
  1118. Rename(F,objfile);
  1119. end;
  1120. end
  1121. else
  1122. AsmRes.AddAsmCommand('mv',ForceExtension(objfile,'.obj')+' '+objfile,objfile);
  1123. end;
  1124. *)
  1125. end;
  1126. procedure TPPCMPWAssembler.WriteAsmFileHeader;
  1127. begin
  1128. (*
  1129. AsmWriteLn(#9'.386p');
  1130. { masm 6.11 does not seem to like LOCALS PM }
  1131. if (aktoutputformat = as_i386_tasm) then
  1132. begin
  1133. AsmWriteLn(#9'LOCALS '+target_asm.labelprefix);
  1134. end;
  1135. AsmWriteLn('DGROUP'#9'GROUP'#9'_BSS,_DATA');
  1136. AsmWriteLn(#9'ASSUME'#9'CS:_CODE,ES:DGROUP,DS:DGROUP,SS:DGROUP');
  1137. AsmLn;
  1138. *)
  1139. AsmWriteLn(#9'string asis'); {Interpret strings just to be the content between the quotes.}
  1140. AsmWriteLn(#9'aligning off'); {We do our own aligning.}
  1141. AsmLn;
  1142. end;
  1143. procedure TPPCMPWAssembler.WriteAsmList;
  1144. {$ifdef GDB}
  1145. var
  1146. fileinfo : tfileposinfo;
  1147. {$endif GDB}
  1148. begin
  1149. {$ifdef EXTDEBUG}
  1150. if assigned(current_module.mainsource) then
  1151. comment(v_info,'Start writing MPW-styled assembler output for '+current_module.mainsource^);
  1152. {$endif}
  1153. LasTSec:=sec_none;
  1154. {$ifdef GDB}
  1155. FillChar(stabslastfileinfo,sizeof(stabslastfileinfo),0);
  1156. {$endif GDB}
  1157. {$ifdef GDB}
  1158. //n_line:=n_bssline;
  1159. funcname:=nil;
  1160. linecount:=1;
  1161. includecount:=0;
  1162. fileinfo.fileindex:=1;
  1163. fileinfo.line:=1;
  1164. isInFunction:= false;
  1165. firstLineInFunction:= 0;
  1166. { Write main file }
  1167. WriteFileLineInfo(fileinfo);
  1168. {$endif GDB}
  1169. WriteAsmFileHeader;
  1170. WriteExternals;
  1171. { PowerPC MPW ASM doesn't support stabs, as we now.
  1172. WriteTree(debuglist);}
  1173. WriteTree(codesegment);
  1174. WriteTree(datasegment);
  1175. WriteTree(consts);
  1176. WriteTree(rttilist);
  1177. WriteTree(resourcestringlist);
  1178. WriteTree(bsssegment);
  1179. {$ifdef GDB}
  1180. WriteFileEndInfo;
  1181. {$ENDIF}
  1182. AsmWriteLn(#9'end');
  1183. AsmLn;
  1184. {$ifdef EXTDEBUG}
  1185. if assigned(current_module.mainsource) then
  1186. comment(v_info,'Done writing MPW-styled assembler output for '+current_module.mainsource^);
  1187. {$endif EXTDEBUG}
  1188. end;
  1189. {*****************************************************************************
  1190. Initialize
  1191. *****************************************************************************}
  1192. const
  1193. as_powerpc_mpw_info : tasminfo =
  1194. (
  1195. id : as_powerpc_mpw;
  1196. idtxt : 'MPW';
  1197. asmbin : 'PPCAsm';
  1198. asmcmd : '';
  1199. supported_target : system_any; { what should I write here ?? }
  1200. outputbinary: false;
  1201. allowdirect : true;
  1202. needar : true;
  1203. labelprefix_only_inside_procedure : true;
  1204. labelprefix : '@';
  1205. comment : '; ';
  1206. secnames : ('',
  1207. 'csect','csect [TC]','csect [TC]', {TODO: Perhaps use other section types.}
  1208. '','','','','','',
  1209. '','','')
  1210. );
  1211. initialization
  1212. RegisterAssembler(as_powerpc_mpw_info,TPPCMPWAssembler);
  1213. end.
  1214. {
  1215. $Log$
  1216. Revision 1.21 2003-08-18 11:47:15 olle
  1217. + added asm directive ALIGNING OFF to avoid unexpected aligning by the assembler
  1218. Revision 1.20 2002/10/01 05:17:27 olle
  1219. * minor fix
  1220. Revision 1.19 2003/04/06 21:01:40 olle
  1221. + line numbers are now emitted in the assembler code
  1222. * bug in export and import directive fixed
  1223. * made code more in sync with aggas.pas
  1224. Revision 1.18 2003/01/13 17:17:50 olle
  1225. * changed global var access, TOC now contain pointers to globals
  1226. * fixed handling of function pointers
  1227. Revision 1.17 2003/01/08 18:43:57 daniel
  1228. * Tregister changed into a record
  1229. Revision 1.16 2002/11/28 10:56:07 olle
  1230. * changed proc ref from .xxx[PR] (refering to its section)
  1231. to .xxx (refering to its label) to allow for multiple ref to a proc.
  1232. Revision 1.15 2002/11/17 16:31:59 carl
  1233. * memory optimization (3-4%) : cleanup of tai fields,
  1234. cleanup of tdef and tsym fields.
  1235. * make it work for m68k
  1236. Revision 1.14 2002/11/07 15:50:23 jonas
  1237. * fixed bctr(l) problems
  1238. Revision 1.13 2002/11/04 18:24:53 olle
  1239. * globals are located in TOC and relative r2, instead of absolute
  1240. * symbols which only differs in case are treated as a single symbol
  1241. + tai_const_symbol supported
  1242. * only refs_full accepted
  1243. Revision 1.12 2002/10/23 15:31:01 olle
  1244. * branch b does not jump to dotted symbol now
  1245. Revision 1.11 2002/10/19 23:52:40 olle
  1246. * import directive changed
  1247. Revision 1.10 2002/10/10 19:39:37 florian
  1248. * changes from Olle to get simple programs compiled and assembled
  1249. Revision 1.9 2002/10/07 21:19:53 florian
  1250. * more mpw fixes
  1251. Revision 1.8 2002/10/06 22:46:20 florian
  1252. * fixed function exporting
  1253. Revision 1.7 2002/10/02 22:14:15 florian
  1254. * improve function imports
  1255. Revision 1.6 2002/09/27 21:09:49 florian
  1256. + readed because previous version was broken
  1257. Revision 1.2 2002/08/31 12:43:31 florian
  1258. * ppc compilation fixed
  1259. Revision 1.1 2002/08/20 21:40:44 florian
  1260. + target macos for ppc added
  1261. + frame work for mpw assembler output
  1262. }