packages /

llvm 0.1.0

Bindings to LLVM's C API (LLVM 23), for the Auk compiler's back end: build IR, verify and print it, optimize it, emit object files and bitcode, link modules,...

files / src/ir.auk 6.8 kB · 201 lines

// Generated by packages/llvm/gen/gen.py from gen/bind.txt and the LLVM 23.1.4 C headers; don't edit.

/// Contexts, modules, types, attributes, module flags, verification and printing.

pub extern fn add_function(
  m: llvm.Module,
  name: str,
  function_ty: llvm.Type,
): llvm.Value = "LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name, LLVMTypeRef FunctionTy)"

extern fn c_add_module_flag(
  m: llvm.Module,
  behavior: int,
  key: str,
  key_len: int,
  val: llvm.Metadata,
) = "void LLVMAddModuleFlag(LLVMModuleRef M, int Behavior, const char *Key, size_t KeyLen, LLVMMetadataRef Val)"

pub fn add_module_flag(m: llvm.Module, behavior: int, key: str, val: llvm.Metadata) uses ffi =
  c_add_module_flag(m, behavior, key, key.byte_len(), val)

pub extern fn array_type2(
  element_type: llvm.Type,
  element_count: int,
): llvm.Type = "LLVMTypeRef LLVMArrayType2(LLVMTypeRef ElementType, uint64_t ElementCount)"

pub extern fn context_create(): llvm.Context = "LLVMContextRef LLVMContextCreate(void)"
pub extern fn context_dispose(c: llvm.Context) = "void LLVMContextDispose(LLVMContextRef C)"

pub extern fn count_param_types(
  function_ty: llvm.Type,
): int = "unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy)"

pub extern fn create_enum_attribute(
  c: llvm.Context,
  kind_id: int,
  val: int,
): llvm.Attribute = "LLVMAttributeRef LLVMCreateEnumAttribute(LLVMContextRef C, unsigned KindID, uint64_t Val)"

extern fn c_create_string_attribute(
  c: llvm.Context,
  k: str,
  klength: int,
  v: str,
  vlength: int,
): llvm.Attribute = "LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C, const char *K, unsigned KLength, const char *V, unsigned VLength)"

pub fn create_string_attribute(c: llvm.Context, k: str, v: str): llvm.Attribute uses ffi =
  c_create_string_attribute(c, k, k.byte_len(), v, v.byte_len())

pub extern fn create_type_attribute(
  c: llvm.Context,
  kind_id: int,
  type_ref: llvm.Type,
): llvm.Attribute = "LLVMAttributeRef LLVMCreateTypeAttribute(LLVMContextRef C, unsigned KindID, LLVMTypeRef type_ref)"

pub extern fn dispose_message(message: ffi.Ptr) = "void LLVMDisposeMessage(char *Message)"
pub extern fn dispose_module(m: llvm.Module) = "void LLVMDisposeModule(LLVMModuleRef M)"

pub extern fn double_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C)"

pub extern fn float_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C)"

extern fn c_function_type(
  return_type: llvm.Type,
  param_types: [llvm.Type],
  param_count: int,
  is_var_arg: int,
): llvm.Type = "LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType, LLVMTypeRef *ParamTypes, unsigned ParamCount, int IsVarArg)"

pub fn function_type(
  return_type: llvm.Type,
  param_types: [llvm.Type],
  is_var_arg: int,
): llvm.Type uses ffi = c_function_type(return_type, param_types, param_types.len(), is_var_arg)

pub extern fn get_data_layout_str(
  m: llvm.Module,
): str = "const char *LLVMGetDataLayoutStr(LLVMModuleRef M)"

extern fn c_get_enum_attribute_kind_for_name(
  name: str,
  slen: int,
): int = "unsigned LLVMGetEnumAttributeKindForName(const char *Name, size_t SLen)"

pub fn get_enum_attribute_kind_for_name(name: str): int uses ffi =
  c_get_enum_attribute_kind_for_name(name, name.byte_len())

pub extern fn get_first_function(
  m: llvm.Module,
): llvm.Value? = "LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M)"

pub extern fn get_int_type_width(
  integer_ty: llvm.Type,
): int = "unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy)"

pub extern fn get_module_identifier(
  m: llvm.Module,
  len: var int,
): str = "const char *LLVMGetModuleIdentifier(LLVMModuleRef M, size_t *Len)"

pub extern fn get_named_function(
  m: llvm.Module,
  name: str,
): llvm.Value? = "LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name)"

pub extern fn get_next_function(
  func: llvm.Value,
): llvm.Value? = "LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn)"

pub extern fn get_return_type(
  function_ty: llvm.Type,
): llvm.Type = "LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy)"

pub extern fn get_target(m: llvm.Module): str = "const char *LLVMGetTarget(LLVMModuleRef M)"
pub extern fn get_type_kind(ty: llvm.Type): int = "int LLVMGetTypeKind(LLVMTypeRef Ty)"

pub extern fn int16_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C)"

pub extern fn int1_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C)"

pub extern fn int32_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C)"

pub extern fn int64_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C)"

pub extern fn int8_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C)"

pub extern fn int_type_in_context(
  c: llvm.Context,
  num_bits: int,
): llvm.Type = "LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits)"

pub extern fn module_create_with_name_in_context(
  module_id: str,
  c: llvm.Context,
): llvm.Module = "LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, LLVMContextRef C)"

pub extern fn pointer_type_in_context(
  c: llvm.Context,
  address_space: int,
): llvm.Type = "LLVMTypeRef LLVMPointerTypeInContext(LLVMContextRef C, unsigned AddressSpace)"

pub extern fn print_module_to_string(
  m: llvm.Module,
): str = "char *LLVMPrintModuleToString(LLVMModuleRef M) +free(LLVMDisposeMessage)"

pub extern fn print_type_to_string(
  val: llvm.Type,
): str = "char *LLVMPrintTypeToString(LLVMTypeRef Val) +free(LLVMDisposeMessage)"

pub extern fn set_data_layout(
  m: llvm.Module,
  data_layout_str: str,
) = "void LLVMSetDataLayout(LLVMModuleRef M, const char *DataLayoutStr)"

pub extern fn set_target(
  m: llvm.Module,
  triple: str,
) = "void LLVMSetTarget(LLVMModuleRef M, const char *Triple)"

extern fn c_struct_type_in_context(
  c: llvm.Context,
  element_types: [llvm.Type],
  element_count: int,
  packed: int,
): llvm.Type = "LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes, unsigned ElementCount, int Packed)"

pub fn struct_type_in_context(
  c: llvm.Context,
  element_types: [llvm.Type],
  packed: int,
): llvm.Type uses ffi = c_struct_type_in_context(c, element_types, element_types.len(), packed)

pub extern fn verify_function(
  func: llvm.Value,
  action: int,
): int = "int LLVMVerifyFunction(LLVMValueRef Fn, int Action)"

pub extern fn verify_module(
  m: llvm.Module,
  action: int,
  out_message: var str?,
): int = "int LLVMVerifyModule(LLVMModuleRef M, int Action, char **OutMessage) +free(LLVMDisposeMessage)"

pub extern fn void_type_in_context(
  c: llvm.Context,
): llvm.Type = "LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C)"