cga68k.pas 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl, Carl Eric Codere
  4. This unit generates 68000 (or better) assembler from the parse tree
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit cga68k;
  19. interface
  20. uses
  21. cobjects,tree,m68k,aasm,symtable;
  22. procedure emitl(op : tasmop;var l : plabel);
  23. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  24. procedure emitcall(const routine:string;add_to_externals : boolean);
  25. procedure emitloadord2reg(location:Tlocation;orddef:Porddef;
  26. destreg:Tregister;delloc:boolean);
  27. { produces jumps to true respectively false labels using boolean expressions }
  28. procedure maketojumpbool(p : ptree);
  29. procedure emitoverflowcheck(p: ptree);
  30. procedure push_int(l : longint);
  31. function maybe_push(needed : byte;p : ptree) : boolean;
  32. procedure restore(p : ptree);
  33. procedure emit_push_mem(const ref : treference);
  34. procedure emitpushreferenceaddr(const ref : treference);
  35. procedure copystring(const dref,sref : treference;len : byte);
  36. procedure concatcopy(source,dest : treference;size : longint;delsource : boolean);
  37. { see implementation }
  38. procedure maybe_loada5;
  39. procedure emit_bounds_check(hp: treference; index: tregister);
  40. procedure loadstring(p:ptree);
  41. procedure floatload(t : tfloattype;const ref : treference; var location:tlocation);
  42. { return a float op_size from a floatb type }
  43. { also does some error checking for problems }
  44. function getfloatsize(t: tfloattype): topsize;
  45. procedure floatstore(t : tfloattype;var location:tlocation; const ref:treference);
  46. { procedure floatloadops(t : tfloattype;var op : tasmop;var s : topsize);
  47. procedure floatstoreops(t : tfloattype;var op : tasmop;var s : topsize); }
  48. procedure firstcomplex(p : ptree);
  49. procedure secondfuncret(var p : ptree);
  50. { generate stackframe for interrupt procedures }
  51. procedure generate_interrupt_stackframe_entry;
  52. procedure generate_interrupt_stackframe_exit;
  53. { generate entry code for a procedure.}
  54. procedure genentrycode(const proc_names:Tstringcontainer;make_global:boolean;
  55. stackframe:longint;
  56. var parasize:longint;var nostackframe:boolean);
  57. { generate the exit code for a procedure. }
  58. procedure genexitcode(parasize:longint;nostackframe:boolean);
  59. implementation
  60. uses
  61. systems,globals,verbose,files,types,pbase,
  62. tgenm68k,hcodegen
  63. {$ifdef GDB}
  64. ,gdb
  65. {$endif}
  66. ;
  67. {
  68. procedure genconstadd(size : topsize;l : longint;const str : string);
  69. begin
  70. if l=0 then
  71. else if l=1 then
  72. exprasmlist^.concat(new(pai68k,op_A_INC,size,str)
  73. else if l=-1 then
  74. exprasmlist^.concat(new(pai68k,op_A_INC,size,str)
  75. else
  76. exprasmlist^.concat(new(pai68k,op_ADD,size,'$'+tostr(l)+','+str);
  77. end;
  78. }
  79. procedure copystring(const dref,sref : treference;len : byte);
  80. var
  81. pushed : tpushed;
  82. begin
  83. pushusedregisters(pushed,$ffff);
  84. emitpushreferenceaddr(dref);
  85. emitpushreferenceaddr(sref);
  86. push_int(len);
  87. emitcall('STRCOPY',true);
  88. maybe_loada5;
  89. popusedregisters(pushed);
  90. end;
  91. procedure loadstring(p:ptree);
  92. begin
  93. case p^.right^.resulttype^.deftype of
  94. stringdef : begin
  95. { load a string ... }
  96. { here two possible choices: }
  97. { if it is a char, then simply }
  98. { load 0 length string }
  99. if (p^.right^.treetype=stringconstn) and
  100. (p^.right^.values^='') then
  101. exprasmlist^.concat(new(pai68k,op_const_ref(
  102. A_MOVE,S_B,0,newreference(p^.left^.location.reference))))
  103. else
  104. copystring(p^.left^.location.reference,p^.right^.location.reference,
  105. min(pstringdef(p^.right^.resulttype)^.len,pstringdef(p^.left^.resulttype)^.len));
  106. end;
  107. orddef : begin
  108. if p^.right^.treetype=ordconstn then
  109. begin
  110. exprasmlist^.concat(new(pai68k,op_const_ref(A_MOVE,S_W,p^.right^.value*256+1,
  111. newreference(p^.left^.location.reference))))
  112. end
  113. else
  114. begin
  115. { not so elegant (goes better with extra register }
  116. if (p^.right^.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  117. begin
  118. exprasmlist^.concat(new(pai68k,op_reg_reg(
  119. A_MOVE,S_L,p^.right^.location.register,R_D0)));
  120. ungetregister32(p^.right^.location.register);
  121. end
  122. else
  123. begin
  124. exprasmlist^.concat(new(pai68k,op_ref_reg(
  125. A_MOVE,S_L,newreference(p^.right^.location.reference),R_D0)));
  126. del_reference(p^.right^.location.reference);
  127. end;
  128. if (opt_processors = MC68020) then
  129. { alignment is not a problem on the 68020 and higher processors }
  130. Begin
  131. { add length of string to word }
  132. exprasmlist^.concat(new(pai68k,op_const_reg(A_OR,S_W,$0100,R_D0)));
  133. { put back into mem ... }
  134. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_W,R_D0,
  135. newreference(p^.left^.location.reference))));
  136. end
  137. else
  138. Begin
  139. { alignment can cause problems }
  140. { add length of string to ref }
  141. exprasmlist^.concat(new(pai68k,op_const_ref(A_MOVE,S_B,1,
  142. newreference(p^.left^.location.reference))));
  143. if abs(p^.left^.location.reference.offset) >= 1 then
  144. Begin
  145. { temporarily decrease offset }
  146. Inc(p^.left^.location.reference.offset);
  147. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_B,R_D0,
  148. newreference(p^.left^.location.reference))));
  149. Dec(p^.left^.location.reference.offset);
  150. { restore offset }
  151. end
  152. else
  153. Begin
  154. Comment(V_Debug,'SecondChar2String() internal error.');
  155. internalerror(34);
  156. end;
  157. end;
  158. end;
  159. end;
  160. else
  161. Message(sym_e_type_mismatch);
  162. end;
  163. end;
  164. procedure restore(p : ptree);
  165. var
  166. hregister : tregister;
  167. begin
  168. hregister:=getregister32;
  169. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_SPPULL,hregister)));
  170. if (p^.location.loc=LOC_REGISTER) or (p^.location.loc=LOC_CREGISTER) then
  171. begin
  172. p^.location.register:=hregister;
  173. end
  174. else
  175. begin
  176. reset_reference(p^.location.reference);
  177. p^.location.reference.index:=hregister;
  178. set_location(p^.left^.location,p^.location);
  179. end;
  180. end;
  181. function maybe_push(needed : byte;p : ptree) : boolean;
  182. var
  183. pushed : boolean;
  184. {hregister : tregister; }
  185. reg: tregister;
  186. begin
  187. if needed>usablereg32 then
  188. begin
  189. if (p^.location.loc=LOC_REGISTER) or
  190. (p^.location.loc=LOC_CREGISTER) then
  191. begin
  192. pushed:=true;
  193. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,p^.location.register,R_SPPUSH)));
  194. ungetregister32(p^.location.register);
  195. end
  196. else if ((p^.location.loc=LOC_MEM) or
  197. (p^.location.loc=LOC_REFERENCE)
  198. ) and
  199. ((p^.location.reference.base<>R_NO) or
  200. (p^.location.reference.index<>R_NO)
  201. ) then
  202. begin
  203. del_reference(p^.location.reference);
  204. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(p^.location.reference),
  205. R_A0)));
  206. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A0,R_SPPUSH)));
  207. pushed:=true;
  208. end
  209. else pushed:=false;
  210. end
  211. else pushed:=false;
  212. maybe_push:=pushed;
  213. end;
  214. { emit out of range check for arrays and sets}
  215. procedure emit_bounds_check(hp: treference; index: tregister);
  216. { index = index of array to check }
  217. { memory of range check information for array }
  218. var
  219. hl : plabel;
  220. begin
  221. if (opt_processors = MC68020) then
  222. begin
  223. exprasmlist^.concat(new(pai68k, op_ref_reg(A_CMP2,S_L,newreference(hp),index)));
  224. getlabel(hl);
  225. emitl(A_BCC, hl);
  226. exprasmlist^.concat(new(pai68k, op_const_reg(A_MOVE,S_L,201,R_D0)));
  227. emitcall('HALT_ERROR',true);
  228. emitl(A_LABEL, hl);
  229. end
  230. else
  231. begin
  232. exprasmlist^.concat(new(pai68k, op_ref_reg(A_LEA,S_L,newreference(hp), R_A1)));
  233. exprasmlist^.concat(new(pai68k, op_reg_reg(A_MOVE, S_L, index, R_D0)));
  234. emitcall('RE_BOUNDS_CHECK',true);
  235. end;
  236. end;
  237. function getfloatsize(t: tfloattype): topsize;
  238. begin
  239. case t of
  240. s32real: getfloatsize := S_FS;
  241. s64real: getfloatsize := S_FL;
  242. s80real: getfloatsize := S_FX;
  243. {$ifdef extdebug}
  244. else {else case }
  245. begin
  246. Comment(V_Debug,' getfloatsize() trying to get unknown size.');
  247. internalerror(12);
  248. end;
  249. {$endif}
  250. end;
  251. end;
  252. procedure emitl(op : tasmop;var l : plabel);
  253. begin
  254. if op=A_LABEL then
  255. exprasmlist^.concat(new(pai_label,init(l)))
  256. else
  257. exprasmlist^.concat(new(pai_labeled,init(op,l)))
  258. end;
  259. procedure emit_reg_reg(i : tasmop;s : topsize;reg1,reg2 : tregister);
  260. begin
  261. if (reg1 <> reg2) or (i <> A_MOVE) then
  262. exprasmlist^.concat(new(pai68k,op_reg_reg(i,s,reg1,reg2)));
  263. end;
  264. procedure emitcall(const routine:string;add_to_externals : boolean);
  265. begin
  266. exprasmlist^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,newcsymbol(routine,0))));
  267. if assem_need_external_list and add_to_externals and
  268. not (cs_compilesystem in aktswitches) then
  269. concat_external(routine,EXT_NEAR);
  270. end;
  271. procedure maketojumpbool(p : ptree);
  272. begin
  273. if p^.error then
  274. exit;
  275. if (p^.resulttype^.deftype=orddef) and
  276. (porddef(p^.resulttype)^.typ=bool8bit) then
  277. begin
  278. if is_constboolnode(p) then
  279. begin
  280. if p^.value<>0 then
  281. emitl(A_JMP,truelabel)
  282. else emitl(A_JMP,falselabel);
  283. end
  284. else
  285. begin
  286. case p^.location.loc of
  287. LOC_CREGISTER,LOC_REGISTER : begin
  288. exprasmlist^.concat(new(pai68k,op_reg(A_TST,S_B,p^.location.register)));
  289. ungetregister32(p^.location.register);
  290. emitl(A_BNE,truelabel);
  291. emitl(A_JMP,falselabel);
  292. end;
  293. LOC_MEM,LOC_REFERENCE : begin
  294. exprasmlist^.concat(new(pai68k,op_ref(
  295. A_TST,S_B,newreference(p^.location.reference))));
  296. del_reference(p^.location.reference);
  297. emitl(A_BNE,truelabel);
  298. emitl(A_JMP,falselabel);
  299. end;
  300. LOC_FLAGS : begin
  301. emitl(flag_2_jmp[p^.location.resflags],truelabel);
  302. emitl(A_JMP,falselabel);
  303. end;
  304. end;
  305. end;
  306. end
  307. else
  308. Message(sym_e_type_mismatch);
  309. end;
  310. procedure emitoverflowcheck(p: ptree);
  311. var
  312. hl : plabel;
  313. begin
  314. if cs_check_overflow in aktswitches then
  315. begin
  316. getlabel(hl);
  317. if not ((p^.resulttype^.deftype=pointerdef) or
  318. ((p^.resulttype^.deftype=orddef) and
  319. (porddef(p^.resulttype)^.typ in [u16bit,u32bit,u8bit,uchar,bool8bit]))) then
  320. emitl(A_BVC,hl)
  321. else
  322. emitl(A_BCC,hl);
  323. emitcall('RE_OVERFLOW',true);
  324. emitl(A_LABEL,hl);
  325. end;
  326. end;
  327. procedure push_int(l : longint);
  328. begin
  329. if (l = 0) and (opt_processors = MC68020) then
  330. begin
  331. exprasmlist^.concat(new(pai68k,op_reg(A_CLR,S_L,R_D6)));
  332. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,
  333. R_D6, R_SPPUSH)));
  334. end
  335. else
  336. if not(cs_littlesize in aktswitches) and (l >= -128) and (l <= 127) then
  337. begin
  338. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVEQ,S_L,l,R_D6)));
  339. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_D6,R_SPPUSH)));
  340. end
  341. else
  342. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,l,R_SPPUSH)));
  343. end;
  344. procedure emit_push_mem(const ref : treference);
  345. begin
  346. if ref.isintvalue then
  347. push_int(ref.offset)
  348. else
  349. exprasmlist^.concat(new(pai68k,op_ref(A_PEA,S_L,newreference(ref))));
  350. end;
  351. { USES REGISTER R_A1 }
  352. procedure emitpushreferenceaddr(const ref : treference);
  353. begin
  354. if ref.isintvalue then
  355. push_int(ref.offset)
  356. else
  357. begin
  358. if (ref.base=R_NO) and (ref.index=R_NO) then
  359. exprasmlist^.concat(new(pai68k,op_ref(A_PEA,S_L,
  360. newreference(ref))))
  361. else if (ref.base=R_NO) and (ref.index<>R_NO) and
  362. (ref.offset=0) and (ref.scalefactor=0) and (ref.symbol=nil) then
  363. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,
  364. ref.index,R_SPPUSH)))
  365. else if (ref.base<>R_NO) and (ref.index=R_NO) and
  366. (ref.offset=0) and (ref.symbol=nil) then
  367. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,ref.base,R_SPPUSH)))
  368. else
  369. begin
  370. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(ref),R_A1)));
  371. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A1,R_SPPUSH)));
  372. end;
  373. end;
  374. end;
  375. procedure generate_interrupt_stackframe_entry;
  376. begin
  377. { save the registers of an interrupt procedure }
  378. { .... also the segment registers }
  379. end;
  380. procedure generate_interrupt_stackframe_exit;
  381. begin
  382. { restore the registers of an interrupt procedure }
  383. end;
  384. procedure genentrycode(const proc_names:Tstringcontainer;make_global:boolean;
  385. stackframe:longint;
  386. var parasize:longint;var nostackframe:boolean);
  387. {Generates the entry code for a procedure.}
  388. var hs:string;
  389. hp:Pused_unit;
  390. unitinits:taasmoutput;
  391. {$ifdef GDB}
  392. oldaktprocname : string;
  393. stab_function_name:Pai_stab_function_name;
  394. {$endif GDB}
  395. begin
  396. if (aktprocsym^.definition^.options and poproginit<>0) then
  397. begin
  398. {Init the stack checking.}
  399. if (cs_check_stack in aktswitches) and
  400. (target_info.target=target_linux) then
  401. begin
  402. procinfo.aktentrycode^.insert(new(pai68k,
  403. op_csymbol(A_JSR,S_NO,newcsymbol('INIT_STACK_CHECK',0))));
  404. end;
  405. unitinits.init;
  406. {Call the unit init procedures.}
  407. hp:=pused_unit(usedunits.first);
  408. while assigned(hp) do
  409. begin
  410. { call the unit init code and make it external }
  411. if (hp^.u^.flags and uf_init)<>0 then
  412. begin
  413. unitinits.concat(new(pai68k,op_csymbol(A_JSR,S_NO,newcsymbol('INIT$$'+hp^.u^.unitname^,0))));
  414. externals^.concat(new(pai_external,init('INIT$$'+hp^.u^.unitname^,EXT_NEAR)));
  415. end;
  416. hp:=pused_unit(hp^.next);
  417. end;
  418. procinfo.aktentrycode^.insertlist(@unitinits);
  419. unitinits.done;
  420. end;
  421. { a constructor needs a help procedure }
  422. if (aktprocsym^.definition^.options and poconstructor)<>0 then
  423. begin
  424. if procinfo._class^.isclass then
  425. begin
  426. procinfo.aktentrycode^.insert(new(pai_labeled,init(A_BEQ,quickexitlabel)));
  427. procinfo.aktentrycode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  428. newcsymbol('NEW_CLASS',0))));
  429. concat_external('NEW_CLASS',EXT_NEAR);
  430. end
  431. else
  432. begin
  433. procinfo.aktentrycode^.insert(new(pai_labeled,init(A_BEQ,quickexitlabel)));
  434. procinfo.aktentrycode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  435. newcsymbol('HELP_CONSTRUCTOR',0))));
  436. concat_external('HELP_CONSTRUCTOR',EXT_NEAR);
  437. end;
  438. end;
  439. { don't load ESI, does the caller }
  440. { omit stack frame ? }
  441. if procinfo.framepointer=stack_pointer then
  442. begin
  443. Message(cg_d_stackframe_omited);
  444. nostackframe:=true;
  445. if (aktprocsym^.definition^.options and (pounitinit or poproginit)<>0) then
  446. parasize:=0
  447. else
  448. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo.call_offset;
  449. end
  450. else
  451. begin
  452. if (aktprocsym^.definition^.options and (pounitinit or poproginit)<>0) then
  453. parasize:=0
  454. else
  455. parasize:=aktprocsym^.definition^.parast^.datasize+procinfo.call_offset-8;
  456. nostackframe:=false;
  457. if stackframe<>0 then
  458. begin
  459. if cs_littlesize in aktswitches then
  460. begin
  461. if (cs_check_stack in aktswitches) and
  462. (target_info.target<>target_linux) then
  463. begin
  464. procinfo.aktentrycode^.insert(new(pai68k,
  465. op_csymbol(A_JSR,S_NO,newcsymbol('STACKCHECK',0))));
  466. procinfo.aktentrycode^.insert(new(pai68k,op_const_reg(A_MOVE,S_L,stackframe,R_SPPUSH)));
  467. end;
  468. { to allocate stack space }
  469. { here we allocate space using link signed 16-bit version }
  470. { -ve offset to allocate stack space! }
  471. if (stackframe > -32767) and (stackframe < 32769) then
  472. procinfo.aktentrycode^.insert(new(pai68k,op_reg_const(A_LINK,S_W,R_A6,-stackframe)))
  473. else
  474. Message(cg_e_stacklimit_in_local_routine);
  475. end
  476. else
  477. begin
  478. { Not to complicate the code generator too much, and since some }
  479. { of the systems only support this format, the stackframe cannot }
  480. { exceed 32K in size. }
  481. if (stackframe > -32767) and (stackframe < 32769) then
  482. begin
  483. procinfo.aktentrycode^.insert(new(pai68k,op_const_reg(A_SUB,S_L,stackframe,R_SP)));
  484. if (cs_check_stack in aktswitches) then
  485. begin
  486. procinfo.aktentrycode^.insert(new(pai68k,
  487. op_csymbol(A_JSR,S_NO,newcsymbol('STACKCHECK',0))));
  488. procinfo.aktentrycode^.insert(new(pai68k,op_const_reg(A_MOVE,S_L,
  489. stackframe,R_SPPUSH)));
  490. concat_external('STACKCHECK',EXT_NEAR);
  491. end;
  492. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_SP,R_A6)));
  493. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A6,R_SPPUSH)));
  494. end
  495. else
  496. Message(cg_e_stacklimit_in_local_routine);
  497. end;
  498. end {endif stackframe<>0 }
  499. else
  500. begin
  501. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_SP,R_A6)));
  502. procinfo.aktentrycode^.insert(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A6,R_SPPUSH)));
  503. end;
  504. end;
  505. if (aktprocsym^.definition^.options and pointerrupt)<>0 then
  506. generate_interrupt_stackframe_entry;
  507. {proc_names.insert(aktprocsym^.definition^.mangledname);}
  508. if (aktprocsym^.definition^.owner^.symtabletype=globalsymtable) or
  509. ((procinfo._class<>nil) and (procinfo._class^.owner^.
  510. symtabletype=globalsymtable)) then
  511. make_global:=true;
  512. hs:=proc_names.get;
  513. {$IfDef GDB}
  514. if (cs_debuginfo in aktswitches) and
  515. target_info.use_function_relative_addresses then
  516. stab_function_name := new(pai_stab_function_name,init(strpnew(hs)));
  517. oldaktprocname:=aktprocsym^.name;
  518. {$EndIf GDB}
  519. while hs<>'' do
  520. begin
  521. if make_global then
  522. procinfo.aktentrycode^.insert(new(pai_symbol,init_global(hs)))
  523. else
  524. procinfo.aktentrycode^.insert(new(pai_symbol,init(hs)));
  525. {$ifdef GDB}
  526. if (cs_debuginfo in aktswitches) and
  527. target_info.use_function_relative_addresses then
  528. begin
  529. procinfo.aktentrycode^.insert(new(pai_stab_function_name,init(strpnew(hs))));
  530. { This is not a nice solution to save the name, change it and restore when done }
  531. aktprocsym^.setname(hs);
  532. procinfo.aktentrycode^.insert(new(pai_stabs,init(aktprocsym^.stabstring)));
  533. end;
  534. {$endif GDB}
  535. hs:=proc_names.get;
  536. end;
  537. {$ifdef GDB}
  538. aktprocsym^.setname(oldaktprocname);
  539. if (cs_debuginfo in aktswitches) then
  540. begin
  541. if target_info.use_function_relative_addresses then
  542. procinfo.aktentrycode^.insert(stab_function_name);
  543. if make_global or ((procinfo.flags and pi_is_global) <> 0) then
  544. aktprocsym^.is_global := True;
  545. {This is dead code! Because lexlevel is increased at the
  546. start of compile_proc_body it can never be zero.}
  547. { if (lexlevel > 0) and (oldprocsym^.definition^.localst^.name = nil) then
  548. if oldprocsym^.owner^.symtabletype = objectsymtable then
  549. oldprocsym^.definition^.localst^.name := stringdup(oldprocsym^.owner^.name^+'_'+oldprocsym^.name)
  550. else
  551. oldprocsym^.definition^.localst^.name := stringdup(oldprocsym^.name);}
  552. aktprocsym^.isstabwritten:=true;
  553. end;
  554. {$endif GDB}
  555. { Alignment required for Motorola }
  556. procinfo.aktentrycode^.insert(new(pai_align,init(2)));
  557. end;
  558. {Generate the exit code for a procedure.}
  559. procedure genexitcode(parasize:longint;nostackframe:boolean);
  560. var hr:Preference; {This is for function results.}
  561. op:Tasmop;
  562. s:Topsize;
  563. begin
  564. { !!!! insert there automatic destructors }
  565. procinfo.aktexitcode^.insert(new(pai_label,init(aktexitlabel)));
  566. { call the destructor help procedure }
  567. if (aktprocsym^.definition^.options and podestructor)<>0 then
  568. begin
  569. if procinfo._class^.isclass then
  570. begin
  571. procinfo.aktexitcode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  572. newcsymbol('DISPOSE_CLASS',0))));
  573. concat_external('DISPOSE_CLASS',EXT_NEAR);
  574. end
  575. else
  576. begin
  577. procinfo.aktexitcode^.insert(new(pai68k,op_csymbol(A_JSR,S_NO,
  578. newcsymbol('HELP_DESTRUCTOR',0))));
  579. concat_external('HELP_DESTRUCTOR',EXT_NEAR);
  580. end;
  581. end;
  582. { call __EXIT for main program }
  583. { ????????? }
  584. if (aktprocsym^.definition^.options and poproginit)<>0 then
  585. begin
  586. procinfo.aktexitcode^.concat(new(pai68k,op_csymbol(A_JSR,S_NO,newcsymbol('__EXIT',0))));
  587. externals^.concat(new(pai_external,init('__EXIT',EXT_NEAR)));
  588. end;
  589. { handle return value }
  590. if (aktprocsym^.definition^.options and poassembler)=0 then
  591. if (aktprocsym^.definition^.options and poconstructor)=0 then
  592. begin
  593. if procinfo.retdef<>pdef(voiddef) then
  594. begin
  595. if not procinfo.funcret_is_valid then
  596. Message(sym_w_function_result_not_set);
  597. new(hr);
  598. reset_reference(hr^);
  599. hr^.offset:=procinfo.retoffset;
  600. hr^.base:=procinfo.framepointer;
  601. if (procinfo.retdef^.deftype=orddef) then
  602. begin
  603. case porddef(procinfo.retdef)^.typ of
  604. s32bit,u32bit :
  605. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hr,R_D0)));
  606. u8bit,s8bit,uchar,bool8bit :
  607. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,hr,R_D0)));
  608. s16bit,u16bit :
  609. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,hr,R_D0)));
  610. end;
  611. end
  612. else
  613. if (procinfo.retdef^.deftype in [pointerdef,enumdef,procvardef]) or
  614. ((procinfo.retdef^.deftype=setdef) and
  615. (psetdef(procinfo.retdef)^.settype=smallset)) then
  616. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hr,R_D0)))
  617. else
  618. if (procinfo.retdef^.deftype=floatdef) then
  619. begin
  620. if pfloatdef(procinfo.retdef)^.typ=f32bit then
  621. begin
  622. { Isnt this missing ? }
  623. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hr,R_D0)));
  624. end
  625. else
  626. begin
  627. { how the return value is handled }
  628. { if in FPU mode, return in FP0 }
  629. if (pfloatdef(procinfo.retdef)^.typ = s32real)
  630. and (cs_fp_emulation in aktswitches) then
  631. begin
  632. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,
  633. S_L,hr,R_D0)))
  634. end
  635. else
  636. begin
  637. if cs_fp_emulation in aktswitches then
  638. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_MOVE,
  639. S_L,hr,R_D0)))
  640. else
  641. procinfo.aktexitcode^.concat(new(pai68k,op_ref_reg(A_FMOVE,
  642. getfloatsize(pfloatdef(procinfo.retdef)^.typ),hr,R_FP0)));
  643. end;
  644. end;
  645. end
  646. else
  647. dispose(hr);
  648. end
  649. end
  650. else
  651. begin
  652. { successful constructor deletes the zero flag }
  653. { and returns self in accumulator }
  654. procinfo.aktexitcode^.concat(new(pai_label,init(quickexitlabel)));
  655. { eax must be set to zero if the allocation failed !!! }
  656. procinfo.aktexitcode^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,R_A5,R_D0)));
  657. { faster then OR on mc68000/mc68020 }
  658. procinfo.aktexitcode^.concat(new(pai68k,op_reg(A_TST,S_L,R_D0)));
  659. end;
  660. procinfo.aktexitcode^.concat(new(pai_label,init(aktexit2label)));
  661. if not(nostackframe) then
  662. procinfo.aktexitcode^.concat(new(pai68k,op_reg(A_UNLK,S_NO,R_A6)));
  663. { at last, the return is generated }
  664. if (aktprocsym^.definition^.options and pointerrupt)<>0 then
  665. generate_interrupt_stackframe_exit
  666. else
  667. if (parasize=0) or ((aktprocsym^.definition^.options and poclearstack)<>0)
  668. then
  669. {Routines with the poclearstack flag set use only a ret.}
  670. { also routines with parasize=0 }
  671. procinfo.aktexitcode^.concat(new(pai68k,op_none(A_RTS,S_NO)))
  672. else
  673. { return with immediate size possible here }
  674. { signed! }
  675. if (opt_processors = MC68020) and (parasize < $7FFF) then
  676. procinfo.aktexitcode^.concat(new(pai68k,op_const(
  677. A_RTD,S_NO,parasize)))
  678. { manually restore the stack }
  679. else
  680. begin
  681. { We must pull the PC Counter from the stack, before }
  682. { restoring the stack pointer, otherwise the PC would }
  683. { point to nowhere! }
  684. { save the PC counter (pop it from the stack) }
  685. procinfo.aktexitcode^.concat(new(pai68k,op_reg_reg(
  686. A_MOVE,S_L,R_SPPULL,R_A0)));
  687. { can we do a quick addition ... }
  688. if (parasize > 0) and (parasize < 9) then
  689. procinfo.aktexitcode^.concat(new(pai68k,op_const_reg(
  690. A_ADD,S_L,parasize,R_SP)))
  691. else { nope ... }
  692. procinfo.aktexitcode^.concat(new(pai68k,op_const_reg(
  693. A_ADD,S_L,parasize,R_SP)));
  694. { endif }
  695. { restore the PC counter (push it on the stack) }
  696. procinfo.aktexitcode^.concat(new(pai68k,op_reg_reg(
  697. A_MOVE,S_L,R_A0,R_SPPUSH)));
  698. procinfo.aktexitcode^.concat(new(pai68k,op_none(
  699. A_RTS,S_NO)))
  700. end;
  701. {$ifdef GDB}
  702. if cs_debuginfo in aktswitches then
  703. begin
  704. aktprocsym^.concatstabto(procinfo.aktexitcode);
  705. if assigned(procinfo._class) then
  706. procinfo.aktexitcode^.concat(new(pai_stabs,init(strpnew(
  707. '"$t:v'+procinfo._class^.numberstring+'",'+
  708. tostr(N_PSYM)+',0,0,'+tostr(procinfo.esi_offset)))));
  709. if (porddef(aktprocsym^.definition^.retdef) <> voiddef) then
  710. procinfo.aktexitcode^.concat(new(pai_stabs,init(strpnew(
  711. '"'+aktprocsym^.name+':X'+aktprocsym^.definition^.retdef^.numberstring+'",'+
  712. tostr(N_PSYM)+',0,0,'+tostr(procinfo.retoffset)))));
  713. procinfo.aktexitcode^.concat(new(pai_stabn,init(strpnew('192,0,0,'
  714. +aktprocsym^.definition^.mangledname))));
  715. procinfo.aktexitcode^.concat(new(pai_stabn,init(strpnew('224,0,0,'
  716. +lab2str(aktexit2label)))));
  717. end;
  718. {$endif * GDB *}
  719. end;
  720. { USES REGISTERS R_A0 AND R_A1 }
  721. procedure concatcopy(source,dest : treference;size : longint;delsource : boolean);
  722. var
  723. ecxpushed : boolean;
  724. helpsize : longint;
  725. i : byte;
  726. reg8,reg32 : tregister;
  727. swap : boolean;
  728. hregister : tregister;
  729. iregister : tregister;
  730. jregister : tregister;
  731. hp1 : treference;
  732. hp2 : treference;
  733. hl : plabel;
  734. begin
  735. hregister := getregister32;
  736. if delsource then
  737. del_reference(source);
  738. { from 12 bytes movs is being used }
  739. if (size<=8) or (not(cs_littlesize in aktswitches) and (size<=12)) then
  740. begin
  741. helpsize:=size div 4;
  742. { move a dword x times }
  743. for i:=1 to helpsize do
  744. begin
  745. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(source),hregister)));
  746. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_L,hregister,newreference(dest))));
  747. inc(source.offset,4);
  748. inc(dest.offset,4);
  749. dec(size,4);
  750. end;
  751. { move a word }
  752. if size>1 then
  753. begin
  754. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,newreference(source),hregister)));
  755. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_W,hregister,newreference(dest))));
  756. inc(source.offset,2);
  757. inc(dest.offset,2);
  758. dec(size,2);
  759. end;
  760. { move a single byte }
  761. if size>0 then
  762. begin
  763. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,newreference(source),hregister)));
  764. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_B,hregister,newreference(dest))));
  765. end
  766. end
  767. else
  768. begin
  769. if (usableaddress > 1) then
  770. begin
  771. iregister := getaddressreg;
  772. jregister := getaddressreg;
  773. end
  774. else
  775. if (usableaddress = 1) then
  776. begin
  777. iregister := getaddressreg;
  778. jregister := R_A1;
  779. end
  780. else
  781. begin
  782. iregister := R_A0;
  783. jregister := R_A1;
  784. end;
  785. { reference for move (An)+,(An)+ }
  786. reset_reference(hp1);
  787. hp1.base := iregister; { source register }
  788. hp1.direction := dir_inc;
  789. reset_reference(hp2);
  790. hp2.base := jregister;
  791. hp1.direction := dir_inc;
  792. { iregister = source }
  793. { jregister = destination }
  794. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(source),iregister)));
  795. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(dest),jregister)));
  796. { double word move }
  797. helpsize := size - size mod 4;
  798. size := size mod 4;
  799. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,helpsize div 4,hregister)));
  800. getlabel(hl);
  801. emitl(A_LABEL,hl);
  802. exprasmlist^.concat(new(pai68k,op_ref_ref(A_MOVE,S_L,newreference(hp1),newreference(hp2))));
  803. exprasmlist^.concat(new(pai68k,op_const_reg(A_SUBQ,S_L,4,hregister)));
  804. emitl(A_BNE,hl);
  805. if size > 1 then
  806. begin
  807. dec(size,2);
  808. exprasmlist^.concat(new(pai68k,op_ref_ref(A_MOVE,S_W,newreference(hp1), newreference(hp2))));
  809. end;
  810. if size = 1 then
  811. exprasmlist^.concat(new(pai68k,op_ref_ref(A_MOVE,S_B,newreference(hp1), newreference(hp2))));
  812. { restore the registers that we have just used olny if they are used! }
  813. if jregister = R_A1 then
  814. hp2.base := R_NO;
  815. if iregister = R_A0 then
  816. hp1.base := R_NO;
  817. del_reference(hp1);
  818. del_reference(hp2);
  819. end;
  820. { loading SELF-reference again }
  821. maybe_loada5;
  822. if delsource then
  823. ungetiftemp(source);
  824. ungetregister32(hregister);
  825. end;
  826. procedure emitloadord2reg(location:Tlocation;orddef:Porddef;
  827. destreg:Tregister;delloc:boolean);
  828. {A lot smaller and less bug sensitive than the original unfolded loads.}
  829. var tai:pai68k;
  830. r:Preference;
  831. begin
  832. case location.loc of
  833. LOC_REGISTER,LOC_CREGISTER:
  834. begin
  835. case orddef^.typ of
  836. u8bit: begin
  837. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,location.register,destreg)));
  838. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$FF,destreg)));
  839. end;
  840. s8bit: begin
  841. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_B,location.register,destreg)));
  842. if (opt_processors <> MC68020) then
  843. begin
  844. { byte to word }
  845. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_W,destreg)));
  846. { word to long }
  847. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  848. end
  849. else { 68020+ and later only }
  850. exprasmlist^.concat(new(pai68k,op_reg(A_EXTB,S_L,destreg)));
  851. end;
  852. u16bit: begin
  853. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_W,location.register,destreg)));
  854. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$FFFF,destreg)));
  855. end;
  856. s16bit: begin
  857. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_W,location.register,destreg)));
  858. { word to long }
  859. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  860. end;
  861. u32bit:
  862. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,location.register,destreg)));
  863. s32bit:
  864. exprasmlist^.concat(new(pai68k,op_reg_reg(A_MOVE,S_L,location.register,destreg)));
  865. end;
  866. if delloc then
  867. ungetregister(location.register);
  868. end;
  869. LOC_REFERENCE:
  870. begin
  871. r:=newreference(location.reference);
  872. case orddef^.typ of
  873. u8bit: begin
  874. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,destreg)));
  875. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$FF,destreg)));
  876. end;
  877. s8bit: begin
  878. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_B,r,destreg)));
  879. if (opt_processors <> MC68020) then
  880. begin
  881. { byte to word }
  882. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_W,destreg)));
  883. { word to long }
  884. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  885. end
  886. else { 68020+ and later only }
  887. exprasmlist^.concat(new(pai68k,op_reg(A_EXTB,S_L,destreg)));
  888. end;
  889. u16bit: begin
  890. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,r,destreg)));
  891. exprasmlist^.concat(new(pai68k,op_const_reg(A_ANDI,S_L,$ffff,destreg)));
  892. end;
  893. s16bit: begin
  894. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,r,destreg)));
  895. { word to long }
  896. exprasmlist^.concat(new(pai68k,op_reg(A_EXT,S_L,destreg)));
  897. end;
  898. u32bit:
  899. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,destreg)));
  900. s32bit:
  901. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,destreg)));
  902. end;
  903. if delloc then
  904. del_reference(location.reference);
  905. end
  906. else
  907. internalerror(6);
  908. end;
  909. end;
  910. { if necessary A5 is reloaded after a call}
  911. procedure maybe_loada5;
  912. var
  913. hp : preference;
  914. p : pprocinfo;
  915. i : longint;
  916. begin
  917. if assigned(procinfo._class) then
  918. begin
  919. if lexlevel>2 then
  920. begin
  921. new(hp);
  922. reset_reference(hp^);
  923. hp^.offset:=procinfo.framepointer_offset;
  924. hp^.base:=procinfo.framepointer;
  925. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  926. p:=procinfo.parent;
  927. for i:=3 to lexlevel-1 do
  928. begin
  929. new(hp);
  930. reset_reference(hp^);
  931. hp^.offset:=p^.framepointer_offset;
  932. hp^.base:=R_A5;
  933. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  934. p:=p^.parent;
  935. end;
  936. new(hp);
  937. reset_reference(hp^);
  938. hp^.offset:=p^.ESI_offset;
  939. hp^.base:=R_A5;
  940. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  941. end
  942. else
  943. begin
  944. new(hp);
  945. reset_reference(hp^);
  946. hp^.offset:=procinfo.ESI_offset;
  947. hp^.base:=procinfo.framepointer;
  948. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,hp,R_A5)));
  949. end;
  950. end;
  951. end;
  952. (***********************************************************************)
  953. (* PROCEDURE FLOATLOAD *)
  954. (* Description: This routine is to be called each time a location *)
  955. (* must be set to LOC_FPU and a value loaded into a FPU register. *)
  956. (* *)
  957. (* Remark: The routine sets up the register field of LOC_FPU correctly*)
  958. (***********************************************************************)
  959. procedure floatload(t : tfloattype;const ref : treference; var location:tlocation);
  960. var
  961. op : tasmop;
  962. s : topsize;
  963. begin
  964. { no emulation }
  965. case t of
  966. s32real : s := S_FS;
  967. s64real : s := S_FL;
  968. s80real : s := S_FX;
  969. else
  970. begin
  971. Message(cg_f_unknown_float_type);
  972. end;
  973. end; { end case }
  974. location.loc := LOC_FPU;
  975. if not ((cs_fp_emulation) in aktswitches) then
  976. begin
  977. location.fpureg := getfloatreg;
  978. exprasmlist^.concat(new(pai68k,op_ref_reg(A_FMOVE,s,newreference(ref),location.fpureg)))
  979. end
  980. else
  981. { handle emulation }
  982. begin
  983. if t = s32real then
  984. begin
  985. location.fpureg := getregister32;
  986. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,newreference(ref),location.fpureg)))
  987. end
  988. else
  989. { other floating types are not supported in emulation mode }
  990. Message(sym_e_type_id_not_defined);
  991. end;
  992. end;
  993. { procedure floatstoreops(t : tfloattype;var op : tasmop;var s : topsize);
  994. begin
  995. case t of
  996. s32real : begin
  997. op:=A_FSTP;
  998. s:=S_FS;
  999. end;
  1000. s64real : begin
  1001. op:=A_FSTP;
  1002. s:=S_FL;
  1003. end;
  1004. s80real : begin
  1005. op:=A_FSTP;
  1006. s:=S_FX;
  1007. end;
  1008. s64bit : begin
  1009. op:=A_FISTP;
  1010. s:=S_IQ;
  1011. end;
  1012. else internalerror(17);
  1013. end;
  1014. end; }
  1015. { stores an FPU value to memory }
  1016. { location:tlocation used to free up FPU register }
  1017. { ref: destination of storage }
  1018. procedure floatstore(t : tfloattype;var location:tlocation; const ref:treference);
  1019. var
  1020. op : tasmop;
  1021. s : topsize;
  1022. begin
  1023. if location.loc <> LOC_FPU then
  1024. InternalError(34);
  1025. { no emulation }
  1026. case t of
  1027. s32real : s := S_FS;
  1028. s64real : s := S_FL;
  1029. s80real : s := S_FX;
  1030. else
  1031. begin
  1032. Message(cg_f_unknown_float_type);
  1033. end;
  1034. end; { end case }
  1035. if not ((cs_fp_emulation) in aktswitches) then
  1036. begin
  1037. exprasmlist^.concat(new(pai68k,op_reg_ref(A_FMOVE,s,location.fpureg,newreference(ref))));
  1038. ungetregister(location.fpureg);
  1039. end
  1040. else
  1041. { handle emulation }
  1042. begin
  1043. if t = s32real then
  1044. begin
  1045. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_L,location.fpureg,newreference(ref))));
  1046. ungetregister32(location.fpureg);
  1047. end
  1048. else
  1049. { other floating types are not supported in emulation mode }
  1050. Message(sym_e_type_id_not_defined);
  1051. end;
  1052. location.fpureg:=R_NO; { no register in LOC_FPU now }
  1053. end;
  1054. procedure firstcomplex(p : ptree);
  1055. var
  1056. hp : ptree;
  1057. begin
  1058. { always calculate boolean AND and OR from left to right }
  1059. if ((p^.treetype=orn) or (p^.treetype=andn)) and
  1060. (p^.left^.resulttype^.deftype=orddef) and
  1061. (porddef(p^.left^.resulttype)^.typ=bool8bit) then
  1062. p^.swaped:=false
  1063. else if (p^.left^.registers32<p^.right^.registers32)
  1064. { the following check is appropriate, because all }
  1065. { 4 registers are rarely used and it is thereby }
  1066. { achieved that the extra code is being dropped }
  1067. { by exchanging not commutative operators }
  1068. and (p^.right^.registers32<=4) then
  1069. begin
  1070. hp:=p^.left;
  1071. p^.left:=p^.right;
  1072. p^.right:=hp;
  1073. p^.swaped:=true;
  1074. end
  1075. else p^.swaped:=false;
  1076. end;
  1077. procedure secondfuncret(var p : ptree);
  1078. var
  1079. hregister : tregister;
  1080. begin
  1081. clear_reference(p^.location.reference);
  1082. p^.location.reference.base:=procinfo.framepointer;
  1083. p^.location.reference.offset:=procinfo.retoffset;
  1084. if ret_in_param(procinfo.retdef) then
  1085. begin
  1086. hregister:=getaddressreg;
  1087. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVEA,S_L,newreference(p^.location.reference),hregister)));
  1088. p^.location.reference.base:=hregister;
  1089. p^.location.reference.offset:=0;
  1090. end;
  1091. end;
  1092. end.
  1093. {
  1094. $Log$
  1095. Revision 1.4 1998-05-07 00:17:00 peter
  1096. * smartlinking for sets
  1097. + consts labels are now concated/generated in hcodegen
  1098. * moved some cpu code to cga and some none cpu depended code from cga
  1099. to tree and hcodegen and cleanup of hcodegen
  1100. * assembling .. output reduced for smartlinking ;)
  1101. Revision 1.3 1998/04/29 10:33:46 pierre
  1102. + added some code for ansistring (not complete nor working yet)
  1103. * corrected operator overloading
  1104. * corrected nasm output
  1105. + started inline procedures
  1106. + added starstarn : use ** for exponentiation (^ gave problems)
  1107. + started UseTokenInfo cond to get accurate positions
  1108. }