Sign in Join
Wiki copytemporary

FPC Internals/Parameters: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11back to contents [[FPC internals]]
22
33FPC is using the CPU target specified parameter manager to manage the location of parameters passed into and routines.
44
55CPU target should implement parameter manager in **cpupara.pas** unit.
66
77The unit should initialize the global **ParaManager** variable if an instance of the CPU specific class.
88
9-`ParaManager:=tcpuparamanager.create`
9+``` pascal
10+ParaManager:=tcpuparamanager.create
11+```
1012
1113The basic TParaManager class cannot and should not be created, as it contain the abstract methods that should be implemented by CPU target implementation class.
1214
1315## Methods to Implement
1416
1517The following methods are critical for CPU target implementation
1618
1719### push_addr_param
1820
1921Returns true if a parameter is too large to copy and only the address is pushed or if the parameter should be passed by address reference at all time.
2022
2123```delphi
2224 function push_addr_param(varspez: tvarspez; def: tdef; calloption: tproccalloption) : boolean;
2325```
2426
2527The typical approach would be first to inspect variable specifier argument **varspez**.
2628
2729Normally, vs_var, vs_out, vs_constref are always passed by reference and **push_addr_param** should return true.
2830
2931In many cases **var_const** should return true as well, however, it's driven by CPU target ABI and calling convention. (for example, if definition (**def**) is a record and it can fit CPU word, then the value of the structure can be put into memory/register. Thus the function should return false)
3032
3133If there variable specifier doesn't indicate a need to pass by address, the next step is to inspect a definition.
3234
3335The following definition types (**def.typ**) are typically passed via address (and the function should return true for those):
3436
3537- Formal (formaldef)
3638- Object instances (objectdef, but only if is_object() returns true)
3739- Strings (stringdef) for types st_shortstring or st_longstring.
3840- Arrays (arraydef) for open arrays, arrays of const.
3941
4042Depending on CPU type **calloption** should be considered, if different calling conventions apply for the CPU target.
4143
4244### create_paraloc_info
4345
4446This is used to populate the location information on all parameters for the routine as seen in either the caller or the callee. It returns the size allocated on the stack
4547
4648```delphi
4749 function create_paraloc_info(p : tabstractprocdef; side: tcallercallee):longint;
4850```
4951
5052### create_varargs_paraloc_info
5153
5254This is used to populate the location information on all parameters for the routine that are passed as varargs. It returns the size allocated on the stack (including the normal parameters)
5355
5456```delphi
5557 function create_varargs_paraloc_info(p : tabstractprocdef; side: tcallercallee; varargspara:tvarargsparalist):longint;
5658```
5759
5860### get_funcretloc
5961
6062Returns the location of the function result if p had def as function result instead of its actual result. Used if the compiler forces the function result to something different than the real result.
6163
6264```delphi
6365 function get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
6466```
6567
6668## See Also
6769
6870- [[FPC Internals]]
6971
7072---
7173*From the Free Pascal wiki, page "FPC Internals/Parameters", as it stood on 2020-12-28 after a change by E-ric, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history