infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
types.c File Reference

Implements the public API for creating and managing type descriptions. More...

#include "common/infix_internals.h"
#include "common/utility.h"
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for types.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define INFIX_TYPE_INIT(id, T)
 

Functions

c23_nodiscard infix_typeinfix_type_create_primitive (infix_primitive_type_id id)
 Creates an infix_type descriptor for a primitive C type.
 
c23_nodiscard infix_typeinfix_type_create_pointer (void)
 Creates an infix_type descriptor for a generic void* pointer.
 
c23_nodiscard infix_typeinfix_type_create_void (void)
 Creates an infix_type descriptor for the void type.
 
infix_struct_member infix_type_create_member (const char *name, infix_type *type, size_t offset)
 A factory function to create an infix_struct_member.
 
static infix_status _create_aggregate_setup (infix_arena_t *arena, infix_type **out_type, infix_struct_member **out_arena_members, infix_struct_member *members, size_t num_members)
 
c23_nodiscard infix_status infix_type_create_pointer_to (infix_arena_t *arena, infix_type **out_type, infix_type *pointee_type)
 Creates an infix_type for a pointer to a specific type from an arena.
 
c23_nodiscard infix_status infix_type_create_array (infix_arena_t *arena, infix_type **out_type, infix_type *element_type, size_t num_elements)
 Creates a new infix_type for a fixed-size array from an arena.
 
c23_nodiscard infix_status infix_type_create_enum (infix_arena_t *arena, infix_type **out_type, infix_type *underlying_type)
 Creates a new infix_type for an enum from an arena.
 
c23_nodiscard infix_status infix_type_create_complex (infix_arena_t *arena, infix_type **out_type, infix_type *base_type)
 Creates a new infix_type for a _Complex number from an arena.
 
c23_nodiscard infix_status infix_type_create_vector (infix_arena_t *arena, infix_type **out_type, infix_type *element_type, size_t num_elements)
 Creates a new infix_type for a SIMD vector from an arena.
 
c23_nodiscard infix_status infix_type_create_union (infix_arena_t *arena, infix_type **out_type, infix_struct_member *members, size_t num_members)
 Creates a new infix_type for a union from an arena.
 
c23_nodiscard infix_status infix_type_create_struct (infix_arena_t *arena, infix_type **out_type, infix_struct_member *members, size_t num_members)
 Creates a new infix_type for a struct from an arena.
 
c23_nodiscard infix_status infix_type_create_packed_struct (infix_arena_t *arena, infix_type **out_type, size_t total_size, size_t alignment, infix_struct_member *members, size_t num_members)
 Creates a new infix_type for a packed struct from an arena.
 
c23_nodiscard infix_status infix_type_create_named_reference (infix_arena_t *arena, infix_type **out_type, const char *name, infix_aggregate_category_t agg_cat)
 Creates a new infix_type for a named reference from an arena.
 
infix_type_copy_type_graph_to_arena (infix_arena_t *dest_arena, const infix_type *src_type)
 Performs a deep copy of a type graph from one arena to another.
 
c23_nodiscard infix_type_category infix_type_get_category (const infix_type *type)
 Retrieves the fundamental category of an infix_type.
 
c23_nodiscard size_t infix_type_get_size (const infix_type *type)
 Retrieves the size of an infix_type in bytes.
 
c23_nodiscard size_t infix_type_get_alignment (const infix_type *type)
 Retrieves the alignment requirement of an infix_type in bytes.
 
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).
 
c23_nodiscard const infix_struct_memberinfix_type_get_member (const infix_type *type, size_t index)
 Retrieves a specific member from an aggregate type by its index.
 
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.
 
c23_nodiscard const infix_typeinfix_type_get_arg_type (const infix_type *func_type, size_t index)
 Retrieves the type of a function argument by its index.
 
c23_nodiscard size_t infix_forward_get_num_args (const infix_forward_t *trampoline)
 Retrieves the number of arguments for a forward trampoline.
 
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.
 
c23_nodiscard const infix_typeinfix_forward_get_return_type (const infix_forward_t *trampoline)
 Retrieves the return type for a forward trampoline.
 
c23_nodiscard const infix_typeinfix_forward_get_arg_type (const infix_forward_t *trampoline, size_t index)
 Retrieves the type of a specific argument for a forward trampoline.
 
c23_nodiscard size_t infix_reverse_get_num_args (const infix_reverse_t *trampoline)
 Retrieves the number of arguments for a reverse trampoline.
 
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.
 
c23_nodiscard const infix_typeinfix_reverse_get_return_type (const infix_reverse_t *trampoline)
 Retrieves the return type for a reverse trampoline.
 
c23_nodiscard const infix_typeinfix_reverse_get_arg_type (const infix_reverse_t *trampoline, size_t index)
 Retrieves the type of a specific argument for a reverse trampoline.
 

Variables

static infix_type _infix_type_void
 
static infix_type _infix_type_pointer
 
static infix_type _infix_type_bool = INFIX_TYPE_INIT(INFIX_PRIMITIVE_BOOL, bool)
 
static infix_type _infix_type_uint8 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT8, uint8_t)
 
static infix_type _infix_type_sint8 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT8, int8_t)
 
static infix_type _infix_type_uint16 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT16, uint16_t)
 
static infix_type _infix_type_sint16 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT16, int16_t)
 
static infix_type _infix_type_uint32 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT32, uint32_t)
 
static infix_type _infix_type_sint32 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT32, int32_t)
 
static infix_type _infix_type_uint64 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT64, uint64_t)
 
static infix_type _infix_type_sint64 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT64, int64_t)
 
static infix_type _infix_type_uint128 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT128, __uint128_t)
 
static infix_type _infix_type_sint128 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT128, __int128_t)
 
static infix_type _infix_type_float = INFIX_TYPE_INIT(INFIX_PRIMITIVE_FLOAT, float)
 
static infix_type _infix_type_double = INFIX_TYPE_INIT(INFIX_PRIMITIVE_DOUBLE, double)
 
static infix_type _infix_type_long_double = INFIX_TYPE_INIT(INFIX_PRIMITIVE_LONG_DOUBLE, long double)
 

Detailed Description

Implements the public API for creating and managing type descriptions.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

Macro Definition Documentation

◆ INFIX_TYPE_INIT

#define INFIX_TYPE_INIT (   id,
 
)
Value:
{.category = INFIX_TYPE_PRIMITIVE, \
.size = sizeof(T), \
.alignment = _Alignof(T), \
.is_arena_allocated = false, \
.meta.primitive_id = id}
@ INFIX_TYPE_PRIMITIVE
A built-in type like int, float, double.
Definition infix.h:115

Function Documentation

◆ _copy_type_graph_to_arena()

infix_type * _copy_type_graph_to_arena ( infix_arena_t dest_arena,
const infix_type src_type 
)

Performs a deep copy of a type graph from one arena to another.

◆ _create_aggregate_setup()

static infix_status _create_aggregate_setup ( infix_arena_t arena,
infix_type **  out_type,
infix_struct_member **  out_arena_members,
infix_struct_member members,
size_t  num_members 
)
static

Variable Documentation

◆ _infix_type_bool

infix_type _infix_type_bool = INFIX_TYPE_INIT(INFIX_PRIMITIVE_BOOL, bool)
static

◆ _infix_type_double

infix_type _infix_type_double = INFIX_TYPE_INIT(INFIX_PRIMITIVE_DOUBLE, double)
static

◆ _infix_type_float

infix_type _infix_type_float = INFIX_TYPE_INIT(INFIX_PRIMITIVE_FLOAT, float)
static

◆ _infix_type_long_double

infix_type _infix_type_long_double = INFIX_TYPE_INIT(INFIX_PRIMITIVE_LONG_DOUBLE, long double)
static

◆ _infix_type_pointer

infix_type _infix_type_pointer
static
Initial value:
= {.category = INFIX_TYPE_POINTER,
.size = sizeof(void *),
.alignment = _Alignof(void *),
.is_arena_allocated = false,
.meta.pointer_info = {.pointee_type = &_infix_type_void}}
@ INFIX_TYPE_POINTER
A generic void* pointer type.
Definition infix.h:116
static infix_type _infix_type_void
Definition types.c:57

◆ _infix_type_sint128

infix_type _infix_type_sint128 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT128, __int128_t)
static

◆ _infix_type_sint16

infix_type _infix_type_sint16 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT16, int16_t)
static

◆ _infix_type_sint32

infix_type _infix_type_sint32 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT32, int32_t)
static

◆ _infix_type_sint64

infix_type _infix_type_sint64 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT64, int64_t)
static

◆ _infix_type_sint8

infix_type _infix_type_sint8 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_SINT8, int8_t)
static

◆ _infix_type_uint128

infix_type _infix_type_uint128 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT128, __uint128_t)
static

◆ _infix_type_uint16

infix_type _infix_type_uint16 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT16, uint16_t)
static

◆ _infix_type_uint32

infix_type _infix_type_uint32 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT32, uint32_t)
static

◆ _infix_type_uint64

infix_type _infix_type_uint64 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT64, uint64_t)
static

◆ _infix_type_uint8

infix_type _infix_type_uint8 = INFIX_TYPE_INIT(INFIX_PRIMITIVE_UINT8, uint8_t)
static

◆ _infix_type_void

infix_type _infix_type_void
static
Initial value:
= {
.category = INFIX_TYPE_VOID, .size = 0, .alignment = 0, .is_arena_allocated = false, .meta = {0}}
@ INFIX_TYPE_VOID
The void type, used for function returns with no value.
Definition infix.h:125