123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- {
- $Id$
- Copyright (c) 2002 by Florian Klaempfl
- PowerPC specific calling conventions
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- ****************************************************************************
- }
- {# Parameter passing manager. Used to manage how
- parameters are passed to routines.
- }
- unit paramgr;
- {$i fpcdefs.inc}
- interface
- uses
- cpubase,
- symtype,symdef;
- type
- {# This class defines some methods to take care of routine
- parameters. It should be overriden for each new processor
- }
- tparamanager = class
- {# Returns true if the return value can be put in accumulator }
- function ret_in_acc(def : tdef) : boolean;virtual;
- {# Returns true if the return value is put in a register
-
- Either a floating point register, or a general purpose
- register.
- }
- function ret_in_reg(def : tdef) : boolean;virtual;
- {# Returns true if the return value is actually a parameter
- pointer.
- }
- function ret_in_param(def : tdef) : boolean;virtual;
- function push_high_param(def : tdef) : boolean;virtual;
- {# Returns true if a parameter is too large to copy and only
- the address is pushed
- }
- function push_addr_param(def : tdef) : boolean;virtual;
- {# Returns a structure giving the information on
- the storage of the parameter (which must be
- an integer parameter)
- @param(nr Parameter number of routine, starting from 1)
- }
- function getintparaloc(nr : longint) : tparalocation;virtual;abstract;
- procedure create_param_loc_info(p : tabstractprocdef);virtual;abstract;
- {#
- Returns the location where the invisible parameter for structured
- function results will be passed.
- }
- function getfuncretloc(p : tabstractprocdef) : tparalocation;virtual;abstract;
- { Returns the self pointer location for the given tabstractprocdef,
- when the stack frame is already created. This is used by the code
- generating the wrappers for implemented interfaces.
- }
- function getselflocation(p : tabstractprocdef) : tparalocation;virtual;abstract;
- {#
- Returns the location of the result if the result is in
- a register, the register(s) return depend on the type of
- the result.
-
- @param(def The definition of the result type of the function)
- }
- function getfuncresultlocreg(def : tdef): tparalocation; virtual;
- end;
- procedure setparalocs(p : tprocdef);
- var
- paralocdummy : tparalocation;
- paramanager : tparamanager;
- implementation
- uses
- cpuinfo,globals,globtype,
- symconst,symbase,symsym,
- rgobj,
- defbase,cgbase,cginfo,verbose;
- { true if the return value is in accumulator (EAX for i386), D0 for 68k }
- function tparamanager.ret_in_acc(def : tdef) : boolean;
- begin
- ret_in_acc:=(def.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
- ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_ansistring,st_widestring])) or
- ((def.deftype=procvardef) and not(po_methodpointer in tprocvardef(def).procoptions)) or
- ((def.deftype=objectdef) and not is_object(def)) or
- ((def.deftype=setdef) and (tsetdef(def).settype=smallset));
- end;
- function tparamanager.ret_in_reg(def : tdef) : boolean;
- begin
- ret_in_reg:=ret_in_acc(def) or (def.deftype=floatdef);
- end;
-
- { true if uses a parameter as return value }
- function tparamanager.ret_in_param(def : tdef) : boolean;
- begin
- ret_in_param:=(def.deftype in [arraydef,recorddef]) or
- ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_shortstring,st_longstring])) or
- ((def.deftype=procvardef) and (po_methodpointer in tprocvardef(def).procoptions)) or
- ((def.deftype=objectdef) and is_object(def)) or
- (def.deftype=variantdef) or
- ((def.deftype=setdef) and (tsetdef(def).settype<>smallset));
- end;
- function tparamanager.push_high_param(def : tdef) : boolean;
- begin
- push_high_param:=is_open_array(def) or
- is_open_string(def) or
- is_array_of_const(def);
- end;
- { true if a parameter is too large to copy and only the address is pushed }
- function tparamanager.push_addr_param(def : tdef) : boolean;
- begin
- push_addr_param:=false;
- if never_copy_const_param then
- push_addr_param:=true
- else
- begin
- case def.deftype of
- variantdef,
- formaldef :
- push_addr_param:=true;
- recorddef :
- push_addr_param:=(def.size>pointer_size);
- arraydef :
- push_addr_param:=((tarraydef(def).highrange>=tarraydef(def).lowrange) and (def.size>pointer_size)) or
- is_open_array(def) or
- is_array_of_const(def) or
- is_array_constructor(def);
- objectdef :
- push_addr_param:=is_object(def);
- stringdef :
- push_addr_param:=tstringdef(def).string_typ in [st_shortstring,st_longstring];
- procvardef :
- push_addr_param:=(po_methodpointer in tprocvardef(def).procoptions);
- setdef :
- push_addr_param:=(tsetdef(def).settype<>smallset);
- end;
- end;
- end;
-
- function tparamanager.getfuncresultlocreg(def : tdef): tparalocation;
- begin
- fillchar(result,sizeof(tparalocation),0);
- if is_void(def) then exit;
-
- result.size := def_cgsize(def);
- case aktprocdef.rettype.def.deftype of
- orddef,
- enumdef :
- begin
- result.loc := LOC_REGISTER;
- if result.size in [OS_64,OS_S64] then
- begin
- result.registerhigh:=accumulatorhigh;
- result.register:=accumulator;
- end
- else
- result.register:=accumulator;
- end;
- floatdef :
- begin
- result.loc := LOC_FPUREGISTER;
- if cs_fp_emulation in aktmoduleswitches then
- result.register := accumulator
- else
- result.register := FPU_RESULT_REG;
- end;
- else
- begin
- if ret_in_acc(def) then
- begin
- result.loc := LOC_REGISTER;
- result.register := accumulator;
- end
- else
- begin
- result.loc := LOC_REFERENCE;
- internalerror(2002081602);
- (*
- {$ifdef EXTDEBUG}
- { it is impossible to have the
- return value with an index register
- and a symbol!
- }
- if (ref.index <> R_NO) or (assigned(ref.symbol)) then
- internalerror(2002081602);
- {$endif}
- result.reference.index := ref.base;
- result.reference.offset := ref.offset;
- *)
- end;
- end;
- end;
- end;
-
- procedure setparalocs(p : tprocdef);
- var
- hp : tparaitem;
- begin
- hp:=tparaitem(p.para.first);
- while assigned(hp) do
- begin
- {$ifdef SUPPORT_MMX}
- if (hp.paraloc.loc in [LOC_REGISTER,LOC_FPUREGISTER,
- LOC_MMREGISTER]) and
- {$else}
- if (hp.paraloc.loc in [LOC_REGISTER,LOC_FPUREGISTER]) and
- {$endif}
- { if the parameter isn't regable, we've to work with the local copy }
- ((vo_regable in tvarsym(hp.parasym).varoptions) or
- (vo_fpuregable in tvarsym(hp.parasym).varoptions)) then
- begin
- case hp.paraloc.loc of
- LOC_REGISTER:
- hp.paraloc.loc := LOC_CREGISTER;
- LOC_FPUREGISTER:
- hp.paraloc.loc := LOC_CFPUREGISTER;
- {$ifdef SUPPORT_MMX}
- LOC_MMREGISTER:
- hp.paraloc.loc := LOC_CMMREGISTER;
- {$endif}
- end;
- tvarsym(hp.parasym).reg:=hp.paraloc.register;
- rg.regvar_loaded[hp.paraloc.register]:=true;
- end;
- hp:=tparaitem(hp.next);
- end;
- end;
- finalization
- paramanager.free;
- end.
- {
- $Log$
- Revision 1.12 2002-08-16 14:24:58 carl
- * issameref() to test if two references are the same (then emit no opcodes)
- + ret_in_reg to replace ret_in_acc
- (fix some register allocation bugs at the same time)
- + save_std_register now has an extra parameter which is the
- usedinproc registers
- Revision 1.11 2002/08/12 15:08:40 carl
- + stab register indexes for powerpc (moved from gdb to cpubase)
- + tprocessor enumeration moved to cpuinfo
- + linker in target_info is now a class
- * many many updates for m68k (will soon start to compile)
- - removed some ifdef or correct them for correct cpu
- Revision 1.10 2002/08/10 17:15:20 jonas
- * register parameters are now LOC_CREGISTER instead of LOC_REGISTER
- Revision 1.9 2002/08/09 07:33:02 florian
- * a couple of interface related fixes
- Revision 1.8 2002/08/06 20:55:21 florian
- * first part of ppc calling conventions fix
- Revision 1.7 2002/08/05 18:27:48 carl
- + more more more documentation
- + first version include/exclude (can't test though, not enough scratch for i386 :()...
- Revision 1.6 2002/07/30 20:50:43 florian
- * the code generator knows now if parameters are in registers
- Revision 1.5 2002/07/26 21:15:39 florian
- * rewrote the system handling
- Revision 1.4 2002/07/20 11:57:55 florian
- * types.pas renamed to defbase.pas because D6 contains a types
- unit so this would conflicts if D6 programms are compiled
- + Willamette/SSE2 instructions to assembler added
- Revision 1.3 2002/07/13 19:38:43 florian
- * some more generic calling stuff fixed
- Revision 1.2 2002/07/13 07:17:15 jonas
- * fixed memory leak reported by Sergey Korshunoff
- Revision 1.1 2002/07/11 14:41:28 florian
- * start of the new generic parameter handling
- }
|