infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
Introspection API

Functions for querying the properties of trampolines and types. More...

Collaboration diagram for Introspection API:

Type Introspection

enum  infix_print_dialect_t { INFIX_DIALECT_SIGNATURE , INFIX_DIALECT_ITANIUM_MANGLING , INFIX_DIALECT_MSVC_MANGLING }
 Specifies the output format for type-to-string serialization functions. More...
 
c23_nodiscard infix_type_category infix_type_get_category (const infix_type *)
 Retrieves the fundamental category of an infix_type.
 
c23_nodiscard size_t infix_type_get_size (const infix_type *)
 Retrieves the size of an infix_type in bytes.
 
c23_nodiscard size_t infix_type_get_alignment (const infix_type *)
 Retrieves the alignment requirement of an infix_type in bytes.
 
c23_nodiscard size_t infix_type_get_member_count (const infix_type *)
 Retrieves the number of members in an aggregate type (struct or union).
 
c23_nodiscard const infix_struct_memberinfix_type_get_member (const infix_type *, size_t)
 Retrieves a specific member from an aggregate type by its index.
 
c23_nodiscard const char * infix_type_get_arg_name (const infix_type *, size_t)
 Retrieves the name of a function argument by its index.
 
c23_nodiscard const infix_typeinfix_type_get_arg_type (const infix_type *, size_t)
 Retrieves the type of a function argument by its index.
 

Type Serialization

c23_nodiscard infix_status infix_type_print (char *, size_t, const infix_type *, infix_print_dialect_t)
 Serializes an infix_type object graph into a string representation.
 
c23_nodiscard infix_status infix_function_print (char *, size_t, const char *, const infix_type *, const infix_function_argument *, size_t, size_t, infix_print_dialect_t)
 Serializes a full function signature into a string representation.
 

Trampoline Introspection

c23_nodiscard infix_unbound_cif_func infix_forward_get_unbound_code (infix_forward_t *)
 Retrieves the executable code pointer from an unbound forward trampoline.
 
c23_nodiscard infix_cif_func infix_forward_get_code (infix_forward_t *)
 Retrieves the executable code pointer from a bound forward trampoline.
 
c23_nodiscard void * infix_reverse_get_code (const infix_reverse_t *)
 Retrieves the executable code pointer from a reverse trampoline.
 
c23_nodiscard void * infix_reverse_get_user_data (const infix_reverse_t *)
 Retrieves the user_data stored with a reverse trampoline.
 
c23_nodiscard size_t infix_forward_get_num_args (const infix_forward_t *)
 Retrieves the number of arguments for a forward trampoline.
 
c23_nodiscard size_t infix_forward_get_num_fixed_args (const infix_forward_t *)
 Retrieves the number of fixed (non-variadic) arguments for a forward trampoline.
 
c23_nodiscard const infix_typeinfix_forward_get_return_type (const infix_forward_t *)
 Retrieves the return type for a forward trampoline.
 
c23_nodiscard const infix_typeinfix_forward_get_arg_type (const infix_forward_t *, size_t)
 Retrieves the type of a specific argument for a forward trampoline.
 
c23_nodiscard size_t infix_reverse_get_num_args (const infix_reverse_t *)
 Retrieves the number of arguments for a reverse trampoline.
 
c23_nodiscard const infix_typeinfix_reverse_get_return_type (const infix_reverse_t *)
 Retrieves the return type for a reverse trampoline.
 
c23_nodiscard size_t infix_reverse_get_num_fixed_args (const infix_reverse_t *)
 Retrieves the number of fixed (non-variadic) arguments for a reverse trampoline.
 
c23_nodiscard const infix_typeinfix_reverse_get_arg_type (const infix_reverse_t *, size_t)
 Retrieves the type of a specific argument for a reverse trampoline.
 

Detailed Description

Functions for querying the properties of trampolines and types.

Enumeration Type Documentation

◆ infix_print_dialect_t

Specifies the output format for type-to-string serialization functions.

Enumerator
INFIX_DIALECT_SIGNATURE 

The standard infix signature language format.

INFIX_DIALECT_ITANIUM_MANGLING 

Itanium C++ ABI name mangling (used by GCC/Clang). (Not yet implemented)

INFIX_DIALECT_MSVC_MANGLING 

Microsoft C++ ABI name mangling. (Not yet implemented)

Function Documentation

◆ infix_forward_get_arg_type()

c23_nodiscard const infix_type * infix_forward_get_arg_type ( const infix_forward_t trampoline,
size_t  index 
)

Retrieves the type of a specific argument for a forward trampoline.

Parameters
trampolineA handle to a forward trampoline. Can be nullptr.
indexThe zero-based index of the argument to retrieve.
Returns
A constant pointer to the argument's infix_type. Returns nullptr if the handle is nullptr or the index is out of bounds.

◆ infix_forward_get_code()

c23_nodiscard infix_cif_func infix_forward_get_code ( infix_forward_t trampoline)

Retrieves the executable code pointer from a bound forward trampoline.

Parameters
trampolineA handle to a previously created bound forward trampoline.
Returns
A callable function pointer of type infix_cif_func. Returns nullptr if the handle is invalid or if it points to an unbound trampoline.

◆ infix_forward_get_num_args()

c23_nodiscard size_t infix_forward_get_num_args ( const infix_forward_t trampoline)

Retrieves the number of arguments for a forward trampoline.

Parameters
trampolineA handle to a forward trampoline. Can be nullptr.
Returns
The total number of arguments. Returns 0 if the handle is nullptr.

◆ infix_forward_get_num_fixed_args()

c23_nodiscard size_t infix_forward_get_num_fixed_args ( const infix_forward_t trampoline)

Retrieves the number of fixed (non-variadic) arguments for a forward trampoline.

Parameters
trampolineA handle to a forward trampoline. Can be nullptr.
Returns
The number of fixed arguments. Returns 0 if the handle is nullptr.

◆ infix_forward_get_return_type()

c23_nodiscard const infix_type * infix_forward_get_return_type ( const infix_forward_t trampoline)

Retrieves the return type for a forward trampoline.

Parameters
trampolineA handle to a forward trampoline. Can be nullptr.
Returns
A constant pointer to the return infix_type. Returns nullptr if the handle is nullptr.

◆ infix_forward_get_unbound_code()

c23_nodiscard infix_unbound_cif_func infix_forward_get_unbound_code ( infix_forward_t trampoline)

Retrieves the executable code pointer from an unbound forward trampoline.

Parameters
trampolineA handle to a previously created unbound forward trampoline.
Returns
A callable function pointer of type infix_unbound_cif_func. Returns nullptr if the handle is invalid or if it points to a bound trampoline.

◆ infix_function_print()

c23_nodiscard infix_status infix_function_print ( char *  buffer,
size_t  buffer_size,
const char *  function_name,
const infix_type ret_type,
const infix_function_argument args,
size_t  num_args,
size_t  num_fixed_args,
infix_print_dialect_t  dialect 
)

Serializes a full function signature into a string representation.

This is a convenience wrapper around infix_type_print for serializing function types, with future support for including a function name for C++ name mangling.

Parameters
[out]bufferThe character buffer to write the string into.
[in]buffer_sizeThe total size of the buffer.
[in]function_nameThe name of the function (optional, for mangling). Can be nullptr.
[in]ret_typeThe return type of the function.
[in]argsAn array of infix_function_argument.
[in]num_argsThe total number of arguments.
[in]num_fixed_argsThe number of non-variadic arguments.
[in]dialectThe output format to use.
Returns
INFIX_SUCCESS on success.

Serializes a full function signature into a string representation.

◆ infix_reverse_get_arg_type()

c23_nodiscard const infix_type * infix_reverse_get_arg_type ( const infix_reverse_t trampoline,
size_t  index 
)

Retrieves the type of a specific argument for a reverse trampoline.

Parameters
trampolineA handle to a reverse trampoline. Can be nullptr.
indexThe zero-based index of the argument to retrieve.
Returns
A constant pointer to the argument's infix_type. Returns nullptr if the handle is nullptr or the index is out of bounds.

◆ infix_reverse_get_code()

c23_nodiscard void * infix_reverse_get_code ( const infix_reverse_t reverse_trampoline)

Retrieves the executable code pointer from a reverse trampoline.

Parameters
reverse_trampolineA handle to a previously created reverse trampoline.
Returns
A callable function pointer. Returns nullptr if the handle is invalid.

◆ infix_reverse_get_num_args()

c23_nodiscard size_t infix_reverse_get_num_args ( const infix_reverse_t trampoline)

Retrieves the number of arguments for a reverse trampoline.

Parameters
trampolineA handle to a reverse trampoline. Can be nullptr.
Returns
The total number of arguments. Returns 0 if the handle is nullptr.

◆ infix_reverse_get_num_fixed_args()

c23_nodiscard size_t infix_reverse_get_num_fixed_args ( const infix_reverse_t trampoline)

Retrieves the number of fixed (non-variadic) arguments for a reverse trampoline.

Parameters
trampolineA handle to a reverse trampoline. Can be nullptr.
Returns
The number of fixed arguments. Returns 0 if the handle is nullptr.

◆ infix_reverse_get_return_type()

c23_nodiscard const infix_type * infix_reverse_get_return_type ( const infix_reverse_t trampoline)

Retrieves the return type for a reverse trampoline.

Parameters
trampolineA handle to a reverse trampoline. Can be nullptr.
Returns
A constant pointer to the return infix_type. Returns nullptr if the handle is nullptr.

◆ infix_reverse_get_user_data()

c23_nodiscard void * infix_reverse_get_user_data ( const infix_reverse_t reverse_trampoline)

Retrieves the user_data stored with a reverse trampoline.

Parameters
reverse_trampolineA handle to a reverse trampoline context.
Returns
The opaque user_data pointer. Returns nullptr if the handle is invalid.

◆ infix_type_get_alignment()

c23_nodiscard size_t infix_type_get_alignment ( const infix_type type)

Retrieves the alignment requirement of an infix_type in bytes.

Parameters
typeA pointer to the infix_type to inspect. Can be nullptr.
Returns
The alignment of the type. Returns 0 if the type is nullptr.

◆ infix_type_get_arg_name()

c23_nodiscard const char * infix_type_get_arg_name ( const infix_type func_type,
size_t  index 
)

Retrieves the name of a function argument by its index.

Parameters
func_typeA pointer to an infix_type of category INFIX_TYPE_REVERSE_TRAMPOLINE.
indexThe zero-based index of the argument to retrieve.
Returns
A constant string for the argument's name, or nullptr.

◆ infix_type_get_arg_type()

c23_nodiscard const infix_type * infix_type_get_arg_type ( const infix_type func_type,
size_t  index 
)

Retrieves the type of a function argument by its index.

Parameters
func_typeA pointer to an infix_type of category INFIX_TYPE_REVERSE_TRAMPOLINE.
indexThe zero-based index of the argument to retrieve.
Returns
A constant pointer to the argument's infix_type. Returns nullptr if invalid.

◆ infix_type_get_category()

c23_nodiscard infix_type_category infix_type_get_category ( const infix_type type)

Retrieves the fundamental category of an infix_type.

Parameters
typeA pointer to the infix_type to inspect. Can be nullptr.
Returns
The infix_type_category enum for the type.

◆ infix_type_get_member()

c23_nodiscard const infix_struct_member * infix_type_get_member ( const infix_type type,
size_t  index 
)

Retrieves a specific member from an aggregate type by its index.

Parameters
typeA pointer to an infix_type. Can be nullptr.
indexThe zero-based index of the member to retrieve.
Returns
A constant pointer to the infix_struct_member on success. Returns nullptr if type is not a struct/union or the index is out of bounds.

◆ infix_type_get_member_count()

c23_nodiscard size_t infix_type_get_member_count ( const infix_type type)

Retrieves the number of members in an aggregate type (struct or union).

Parameters
typeA pointer to an infix_type. Can be nullptr.
Returns
The number of members if the type is a struct or union; 0 otherwise.

◆ infix_type_get_size()

c23_nodiscard size_t infix_type_get_size ( const infix_type type)

Retrieves the size of an infix_type in bytes.

Parameters
typeA pointer to the infix_type to inspect. Can be nullptr.
Returns
The size of the type. Returns 0 if the type is nullptr.

◆ infix_type_print()

c23_nodiscard infix_status infix_type_print ( char *  buffer,
size_t  buffer_size,
const infix_type type,
infix_print_dialect_t  dialect 
)

Serializes an infix_type object graph into a string representation.

This function recursively walks an infix_type graph and writes its string representation into the provided buffer. This is useful for debugging, logging, or generating code.

Parameters
[out]bufferThe character buffer to write the string into.
[in]buffer_sizeThe total size of the buffer.
[in]typeThe infix_type to serialize.
[in]dialectThe output format to use (e.g., INFIX_DIALECT_SIGNATURE).
Returns
INFIX_SUCCESS on success. Returns INFIX_ERROR_INVALID_ARGUMENT if the buffer is too small to hold the entire string.
infix_type* type = NULL;
infix_type_from_signature(&type, &arena, "{int, *void}", nullptr);
char buffer[128];
if (infix_type_print(buffer, sizeof(buffer), type, INFIX_DIALECT_SIGNATURE) == INFIX_SUCCESS) {
printf("Serialized type: %s\n", buffer); // Output: {int,*void}
}
infix_arena_t * arena
Definition 005_layouts.c:57
c23_nodiscard infix_status infix_type_from_signature(infix_type **, infix_arena_t **, const char *, infix_registry_t *)
Parses a signature string representing a single data type.
Definition signature.c:1090
c23_nodiscard infix_status infix_type_print(char *, size_t, const infix_type *, infix_print_dialect_t)
Serializes an infix_type object graph into a string representation.
Definition signature.c:1370
@ INFIX_DIALECT_SIGNATURE
The standard infix signature language format.
Definition infix.h:815
void infix_arena_destroy(infix_arena_t *)
Frees an entire memory arena and all objects allocated within it.
Definition arena.c:68
@ INFIX_SUCCESS
The operation completed successfully.
Definition infix.h:352
Definition infix_internals.h:130
The central structure for describing any data type in the FFI system.
Definition infix.h:161

Serializes an infix_type object graph into a string representation.