Interface ICallingConvention
- All Known Implementing Classes:
CallingConvention
Notes:
- support for multiple input and output entries
- entries can be registers, register pairs, or stack slots
- support for two register lists: general purpose and floating-point
- the return-address location must be single-slot entry, either register or stack
- register ids are well-defined in corresponding
IRegisterBank
implementations
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The flag indicates that all composite arguments (arrays, structures, unions) must go on the stack, regardless of registers declared to be holding storage items, if any.static final int
The first argument must be a pointer to the object.static final int
The flag indicates that all float arguments must go on the stack, regardless of registers declared to be holding storage items, if any.static final int
2+ slots (aka, multi-slot) parameters are disallowed.static final int
3+ slots parameters are disallowed.static final int
The flag indicates that the calling convention uses an implicit pointer as first parameter when the function prototype specifies that a "large" composite data type (some fundamental types, all aggregate types) is to be returned.static final int
This flag indicates that the return-address value is located after the input argument on the stack.static final int
The flag indicates that output values are located on the pre-allocated stack slots located after the input values (whose count may not be known).static final int
This flag indicates that the return values are to be pushed on the stack after return.static final int
The indices in the lists of registers used to pass integral arguments and floating-point arguments grow together, in a parallel fashion.static final int
This flag indicates that candidate input registers that were passed over in favor of stack storage because they were not suitable for an argument at position N, will not be reused for an argument at a later position (>=N+1) even if that argument would be suitable for storage in an unused input register.static final int
The flag indicates that the stack is cleaned by the callee (which is not the norm; if the flag is not set, it should be assumed the stack is cleaned by the caller). -
Method Summary
Modifier and TypeMethodDescriptionint
determineSlotcountAlignment
(int requestedSlotcount) Determine the slotcount alignment requirement of a non-composite
type.format
(int type) Get a list of alternate names for this calling convention.Get the list of compiler types this calling convention may work with.int
getFlags()
long
Get an internally-generated identifier for this calling convention object.Create a storage-location generator for the inputs provided to a routine using this calling convention.int
Return the number of slots that are reserved for parameters.Retrieve the optional calling convention, derived from this convention, used to return large composite prototypes.int
getName()
Get the common name of this calling convention.getNames()
Retrieve all names for this calling convention (principal and alternates).getNotes()
getOutput
(TypeLayoutInfo ti, int inputStackSlotCount) Convenience method to retrieve the storage location of the single return value for this calling convention.getOutputsGenerator
(int inputStackSlotCount) Create a storage-location generator for the outputs provided to a routine using this calling convention.int
Return the number of slots that are reserved for return values.Get the list of processor types this calling convention may work with.Get the list of registers that are spoiled by a callee, in the strictest sense, i.e.getReturnAddressSlot
(Integer inputStackSlotCount) Alignment specifications for non-composite
types.Get the list of all registers that may be modified and/or spoiled by a callee, in the most general sense.Get the list of subsystem types this calling convention may work with.boolean
hasFlag
(int f) boolean
isCompatibleWith
(ProcessorType wantedProcessor, SubsystemType wantedSubsystem, CompilerType wantedCompiler) Determine whether this calling convention is compatible with the provided triple (processor, subsystem, compiler).default boolean
Determine whether routine parameters pushed on stack before a routine call are cleaned by the callee.default boolean
Determine whether routine parameters pushed on stack before a routine call are cleaned by the caller.boolean
-
Field Details
-
FLAG_STACK_CLEANED_BY_CALLEE
static final int FLAG_STACK_CLEANED_BY_CALLEEThe flag indicates that the stack is cleaned by the callee (which is not the norm; if the flag is not set, it should be assumed the stack is cleaned by the caller).Note that a return-address value located on the stack is always pop'ed, regardless of the presence of this flag.
- See Also:
-
FLAG_OUTPUT_AFTER_INPUT
static final int FLAG_OUTPUT_AFTER_INPUTThe flag indicates that output values are located on the pre-allocated stack slots located after the input values (whose count may not be known).Example, when calling a function (int,int)->(int)
v ... +----------- (SP1) | ? retval1 (slot) | arg2 | arg1 v return addr +----------- <---- SP at routine entry
IfFLAG_STACK_CLEANED_BY_CALLEE
is also set, the input values as well as the output values are 'cleared', i.e. the stack pointer would be expected to have the value SP1 when execution resumes to the return address.IMPORTANT: this flag requires that all calling convention elements (inputs, outputs, return address) be located on the stack.
- See Also:
-
FLAG_FLOAT_INPUT_ON_STACK
static final int FLAG_FLOAT_INPUT_ON_STACKThe flag indicates that all float arguments must go on the stack, regardless of registers declared to be holding storage items, if any. (I.e., input registers will be used for integral types, at least, not FP types.)- See Also:
-
FLAG_LINK_AFTER_INPUT
static final int FLAG_LINK_AFTER_INPUTThis flag indicates that the return-address value is located after the input argument on the stack.Example:
| ... | return addr | argN | (...) v arg1 +----------- <---- SP at routine entry
IMPORTANT: this flag requires that all calling convention elements (inputs, outputs, return address) be located on the stack.- See Also:
-
FLAG_IPRD
static final int FLAG_IPRDThe flag indicates that the calling convention uses an implicit pointer as first parameter when the function prototype specifies that a "large" composite data type (some fundamental types, all aggregate types) is to be returned. The return value is a pointer to that data. "IPRD" means Implicit Pointer to Return Data.Example: this method, in x86:
struct S1 { int a, b, c; }; struct S1 __cdecl func(struct S1 x) { x.c += 1; return x; }
The explicit prototype and code:struct S1* __cdecl_iprd func(struct S1* prd, struct S1 x) { x.c += 1; copy(prd, &x); return prd; }
- See Also:
-
FLAG_OUTPUT_PUSHED
static final int FLAG_OUTPUT_PUSHEDThis flag indicates that the return values are to be pushed on the stack after return. If it is combined withFLAG_STACK_CLEANED_BY_CALLEE
, the input arguments are assumed to be cleaned before pushing the output.Example, when calling a function (int,int)->(int):
v ... +----------- (SP1) | retaddr | arg2 v arg1 +----------- <---- SP at routine entry
After execution:v ... +----------- (SP1) | retval +----------- <---- SP at return PC
IMPORTANT: this flag requires that all calling convention elements (inputs, outputs, return address) be located on the stack.- See Also:
-
FLAG_PARALLEL_INPUT_REGISTER_STACKS
static final int FLAG_PARALLEL_INPUT_REGISTER_STACKSThe indices in the lists of registers used to pass integral arguments and floating-point arguments grow together, in a parallel fashion.Example when calling a method:
void f(int a, float b, int c, float d)
With the standard x86_64 Windows calling convention, arguments...
- a would go in rcx - b would go in xmm1 (FP reg at index 1) - c would go in r8 (GP reg at index 2) - d would go in xmm3 (GP reg at index 3)
Here is an example of what happens when the general and FP register stacks used for arguments passing grow separately, as is the case for Linux x64, with the standard amd64 System V convention:
- a would go in rdi - b would go in xmm0 (NOT xmm1) - c would go in rsi (NOT rdx) - d would go in xmm1 (NOT xmm3)
- See Also:
-
FLAG_FIRST_ARG_IS_THIS_POINTER
static final int FLAG_FIRST_ARG_IS_THIS_POINTERThe first argument must be a pointer to the object. Typically, this flag is used by MSVC's__thiscall
convention. Generally, it enforces the fact that the first parameter of a prototype must be a single-slot element (and more specifically, apointer
-type element.- See Also:
-
FLAG_COMPOSITE_INPUT_ON_STACK
static final int FLAG_COMPOSITE_INPUT_ON_STACKThe flag indicates that all composite arguments (arrays, structures, unions) must go on the stack, regardless of registers declared to be holding storage items, if any. (I.e., input registers will be used for integral types, at least, not composite types.)- See Also:
-
FLAG_FORBID_PARAMS_2SLOTSUP
static final int FLAG_FORBID_PARAMS_2SLOTSUP2+ slots (aka, multi-slot) parameters are disallowed. All inputs must fit on a single slot. Typically, such conventions require composite types to be passed by implicit reference.- See Also:
-
FLAG_FORBID_PARAMS_3SLOTSUP
static final int FLAG_FORBID_PARAMS_3SLOTSUP3+ slots parameters are disallowed. All inputs must fit on a 1 or 2 slots. Typically, such conventions require larger composite types to be passed by implicit reference.- See Also:
-
FLAG_SKIP_PASSED_INPUT_REGISTERS
static final int FLAG_SKIP_PASSED_INPUT_REGISTERSThis flag indicates that candidate input registers that were passed over in favor of stack storage because they were not suitable for an argument at position N, will not be reused for an argument at a later position (>=N+1) even if that argument would be suitable for storage in an unused input register.An example of that is the x86
fastcall
convention on Linux. The first two small integer integer parameters go inecx
andedx
; others go on the stack. For a prototype like(int32 a, int64 b, int32 c)
,a
goes inecx
,b
on the stack, andc
on the stack as well (even though it could fit inedx
; note: x86__fastcall
on Windows does not skip over passed input registers; in this example,c
would go inedx
.}- See Also:
-
-
Method Details
-
getIdentifierKey
long getIdentifierKey()Get an internally-generated identifier for this calling convention object. The id is generated using:- the same names
- same flags
- same processor targets
- same subsystem targets
- same compiler targets
- Returns:
- the key for this calling convention
-
getNotes
String getNotes()- Returns:
-
getFlags
int getFlags()- Returns:
-
hasFlag
boolean hasFlag(int f) - Parameters:
f
-- Returns:
-
isStackCleanedByCaller
default boolean isStackCleanedByCaller()Determine whether routine parameters pushed on stack before a routine call are cleaned by the caller.- Returns:
-
isStackCleanedByCallee
default boolean isStackCleanedByCallee()Determine whether routine parameters pushed on stack before a routine call are cleaned by the callee.- Returns:
-
getName
String getName()Get the common name of this calling convention.- Returns:
-
getAlternateNames
Get a list of alternate names for this calling convention.- Returns:
-
getNames
Retrieve all names for this calling convention (principal and alternates).- Returns:
-
getProcessorTypes
List<ProcessorType> getProcessorTypes()Get the list of processor types this calling convention may work with.- Returns:
-
getSubsystemTypes
List<SubsystemType> getSubsystemTypes()Get the list of subsystem types this calling convention may work with.- Returns:
-
getCompilerTypes
List<CompilerType> getCompilerTypes()Get the list of compiler types this calling convention may work with.- Returns:
-
isCompatibleWith
boolean isCompatibleWith(ProcessorType wantedProcessor, SubsystemType wantedSubsystem, CompilerType wantedCompiler) Determine whether this calling convention is compatible with the provided triple (processor, subsystem, compiler).- Parameters:
wantedProcessor
- mandatory (pass UNKNOWN if not known)wantedSubsystem
- mandatory (pass UNKNOWN if not known)wantedCompiler
- mandatory (pass UNKNOWN if not known)- Returns:
-
getSpoiledRegisters
Collection<Long> getSpoiledRegisters()Get the list of all registers that may be modified and/or spoiled by a callee, in the most general sense. That set would include any type of return registers.- Returns:
-
getPureSpoiledRegisters
Collection<Long> getPureSpoiledRegisters()Get the list of registers that are spoiled by a callee, in the strictest sense, i.e. their value may or may not be modified, but it is meaningless and should not be interpreted by the caller upon return. That set would NOT include return registers.- Returns:
-
getReturnAddressSlot
StorageEntry getReturnAddressSlot()- Returns:
-
getReturnAddressSlot
- Parameters:
inputStackSlotCount
-- Returns:
-
getOutput
Convenience method to retrieve the storage location of the single return value for this calling convention. Most calling conventions allow the return of a single value.- Parameters:
ti
- storage typeinputStackSlotCount
- the number of stack slots used to provide input parameters (some calling conventions require that to calculate proper positioning for output values)- Returns:
-
getInputSlotCountHint
int getInputSlotCountHint()Return the number of slots that are reserved for parameters. Note that this is just a hint on how many parameters are used.- Returns:
-
getOutputSlotCountHint
int getOutputSlotCountHint()Return the number of slots that are reserved for return values. Note that this is just a hint on how many return values are defined.- Returns:
-
getSlotcountAlignmentMap
Alignment specifications for non-composite
types.- Returns:
-
determineSlotcountAlignment
int determineSlotcountAlignment(int requestedSlotcount) Determine the slotcount alignment requirement of a non-composite
type.- Parameters:
requestedSlotcount
-- Returns:
-
getIPRDMinimumSlotCount
int getIPRDMinimumSlotCount()- Returns:
-
getIPRDInputPtrEntry
StorageEntry getIPRDInputPtrEntry()- Returns:
-
getIPRDOutputPtrEntry
StorageEntry getIPRDOutputPtrEntry()- Returns:
-
getIPRDConvention
ICallingConvention getIPRDConvention()Retrieve the optional calling convention, derived from this convention, used to return large composite prototypes. This only applies if the flagFLAG_IPRD
was set.- Returns:
- a linked IPRD (Implicit Pointer to Return Data) convention, or null
-
getInputsGenerator
IStorageEntryGenerator getInputsGenerator()Create a storage-location generator for the inputs provided to a routine using this calling convention. convention.- Returns:
- a generator
-
getOutputsGenerator
Create a storage-location generator for the outputs provided to a routine using this calling convention.- Parameters:
inputStackSlotCount
- optional value indicating how many stack slots were used to provide parameters (this value is the calling convention has the flagsFLAG_OUTPUT_AFTER_INPUT
orFLAG_OUTPUT_PUSHED
)- Returns:
- a generator
-
isUnknown
boolean isUnknown()- Returns:
-
format
- Parameters:
type
- 0: short-form (i.e.,#toString()
), 1: user-friendly long-form, 2: parseable yaml form- Returns:
-