Compare commits

...

18 Commits

Author SHA1 Message Date
David Gonzalez Martin
3994767e8d wip4 2024-05-16 12:48:17 -06:00
David Gonzalez Martin
d3af927719 wip3 2024-05-15 21:00:52 -06:00
David Gonzalez Martin
ebac108da4 wip2 2024-05-15 00:31:13 -06:00
David Gonzalez Martin
b5e762c2b9 metadata kind block 2024-05-14 17:14:24 -06:00
David Gonzalez Martin
586900dde5 constant block 2024-05-14 13:55:24 -06:00
David Gonzalez Martin
95c3570871 module info block 2024-05-14 00:25:08 -06:00
David Gonzalez Martin
d366a911a1 attribute group table 2024-05-13 20:47:57 -06:00
David Gonzalez Martin
871e8f13ef wip 2024-05-13 16:35:19 -06:00
David Gonzalez Martin
2f6ba47ac5 Type table 2024-05-13 16:32:24 -06:00
David Gonzalez Martin
b9fdc72ed6 more progress 2 2024-05-13 15:28:11 -06:00
David Gonzalez Martin
b9df85f55a more progress 2024-05-12 13:34:31 -06:00
David Gonzalez Martin
3a7ee24509 (wip) module version + block info 2024-05-11 21:56:04 -06:00
David Gonzalez Martin
b9ba5eee11 identification block 2024-05-11 19:53:55 -06:00
David Gonzalez Martin
aade460a50 bitcode split 2024-05-11 11:53:32 -06:00
David Gonzalez Martin
1f945a8877 bitcode try 2024-05-11 00:19:36 -06:00
David Gonzalez Martin
7094d59372 parse bitcode 2024-05-10 15:13:14 -06:00
David Gonzalez Martin
a379ba9cf1 disable LLVM API calls 2024-05-10 12:12:28 -06:00
David Gonzalez Martin
3ce2a607ad new parser wip 2024-05-10 10:14:00 -06:00
10 changed files with 8149 additions and 250 deletions

View File

@ -18,6 +18,8 @@ const starts_with_slice = library.starts_with_slice;
const PinnedArray = library.PinnedArray; const PinnedArray = library.PinnedArray;
const PinnedArrayAdvanced = library.PinnedArrayAdvanced; const PinnedArrayAdvanced = library.PinnedArrayAdvanced;
const PinnedHashMap = library.PinnedHashMap; const PinnedHashMap = library.PinnedHashMap;
const realpath = library.realpath;
const self_exe_path = library.self_exe_path;
const span = library.span; const span = library.span;
const format_int = library.format_int; const format_int = library.format_int;
const my_hash = library.my_hash; const my_hash = library.my_hash;
@ -3087,19 +3089,6 @@ fn createUnit(context: *const Context, arguments: struct {
return unit; return unit;
} }
pub fn self_exe_path(arena: *Arena) ![]const u8 {
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
return try arena.duplicate_bytes(try std.fs.selfExePath(&buffer));
}
pub fn realpath(arena: *Arena, dir: std.fs.Dir, relative_path: []const u8) ![]const u8 {
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const stack_realpath = try dir.realpath(relative_path, &buffer);
const heap_realpath = try arena.new_array(u8, stack_realpath.len);
@memcpy(heap_realpath, stack_realpath);
return heap_realpath;
}
pub const ContainerType = enum { pub const ContainerType = enum {
@"struct", @"struct",
@"enum", @"enum",

View File

@ -1,71 +1,72 @@
const llvm = @import("llvm.zig"); const compiler = @import("../compiler.zig");
const LLVM = llvm.LLVM; const LLVM = compiler.LLVM;
pub extern fn NativityLLVMCreateContext() ?*LLVM.Context;
pub extern fn NativityLLVMCreateModule(module_name_ptr: [*:0]const u8, module_name_len: usize, context: *LLVM.Context) ?*LLVM.Module; pub extern fn NativityLLVMCreateContext() *LLVM.Context;
pub extern fn NativityLLVMCreateBuilder(context: *LLVM.Context) ?*LLVM.Builder; pub extern fn NativityLLVMCreateModule(module_name_ptr: [*]const u8, module_name_len: usize, context: *LLVM.Context) *LLVM.Module;
pub extern fn NativityLLVMGetFunctionType(return_type: *LLVM.Type, argument_type_ptr: [*]const *LLVM.Type, argument_type_len: usize, is_var_args: bool) ?*LLVM.Type.Function; pub extern fn NativityLLVMCreateBuilder(context: *LLVM.Context) *LLVM.Builder;
pub extern fn NativityLLVMGetFunctionType(return_type: *LLVM.Type, argument_type_ptr: [*]const *LLVM.Type, argument_type_len: usize, is_var_args: bool) *LLVM.Type.Function;
pub extern fn NativityLLVMFunctionTypeGetArgumentType(function_type: *LLVM.Type.Function, argument_index: c_uint) *LLVM.Type; pub extern fn NativityLLVMFunctionTypeGetArgumentType(function_type: *LLVM.Type.Function, argument_index: c_uint) *LLVM.Type;
pub extern fn NativityLLVMGetIntegerType(context: *LLVM.Context, bit_count: u32) ?*LLVM.Type.Integer; pub extern fn NativityLLVMGetIntegerType(context: *LLVM.Context, bit_count: u32) *LLVM.Type.Integer;
pub extern fn NativityLLVMGetPointerType(context: *LLVM.Context, address_space: u32) ?*LLVM.Type.Pointer; pub extern fn NativityLLVMGetPointerType(context: *LLVM.Context, address_space: u32) *LLVM.Type.Pointer;
pub extern fn NativityLLVMPointerTypeGetNull(pointer_type: *LLVM.Type.Pointer) *LLVM.Value.Constant.PointerNull; pub extern fn NativityLLVMPointerTypeGetNull(pointer_type: *LLVM.Type.Pointer) *LLVM.Value.Constant.PointerNull;
pub extern fn NativityLLVMGetArrayType(element_type: *LLVM.Type, element_count: u64) ?*LLVM.Type.Array; pub extern fn NativityLLVMGetArrayType(element_type: *LLVM.Type, element_count: u64) *LLVM.Type.Array;
pub extern fn NativityLLVMGetStructType(context: *LLVM.Context, type_ptr: [*]const *LLVM.Type, type_count: usize, is_packed: bool) ?*LLVM.Type.Struct; pub extern fn NativityLLVMGetStructType(context: *LLVM.Context, type_ptr: [*]const *LLVM.Type, type_count: usize, is_packed: bool) *LLVM.Type.Struct;
pub extern fn NativityLLVMConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_count: usize) ?*LLVM.Value.Constant; pub extern fn NativityLLVMConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_count: usize) *LLVM.Value.Constant;
pub extern fn NativityLLVMModuleGetFunction(module: *LLVM.Module, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function; pub extern fn NativityLLVMModuleGetFunction(module: *LLVM.Module, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function;
pub extern fn NativityLLVModuleCreateFunction(module: *LLVM.Module, function_type: *LLVM.Type.Function, linkage: LLVM.Linkage, address_space: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Constant.Function; pub extern fn NativityLLVModuleCreateFunction(module: *LLVM.Module, function_type: *LLVM.Type.Function, linkage: LLVM.Linkage, address_space: c_uint, name_ptr: [*]const u8, name_len: usize) *LLVM.Value.Constant.Function;
pub extern fn NativityLLVMModuleCreateDebugInfoBuilder(module: *LLVM.Module) ?*LLVM.DebugInfo.Builder; pub extern fn NativityLLVMModuleCreateDebugInfoBuilder(module: *LLVM.Module) *LLVM.DebugInfo.Builder;
pub extern fn NativityLLVMDebugInfoBuilderCreateFile(builder: *LLVM.DebugInfo.Builder, filename_ptr: [*]const u8, filename_len: usize, directory_ptr: [*]const u8, directory_len: usize) ?*LLVM.DebugInfo.File; pub extern fn NativityLLVMDebugInfoBuilderCreateFile(builder: *LLVM.DebugInfo.Builder, filename_ptr: [*]const u8, filename_len: usize, directory_ptr: [*]const u8, directory_len: usize) *LLVM.DebugInfo.File;
pub extern fn NativityLLVMDebugInfoBuilderCreateCompileUnit(builder: *LLVM.DebugInfo.Builder, language: LLVM.DebugInfo.Language, file: *LLVM.DebugInfo.File, producer_ptr: [*]const u8, producer_len: usize, is_optimized: bool, flags_ptr: [*]const u8, flags_len: usize, runtime_version: c_uint, split_name_ptr: [*]const u8, split_name_len: usize, debug_info_emission_kind: LLVM.DebugInfo.CompileUnit.EmissionKind, DWOId: u64, split_debug_inlining: bool, debug_info_for_profiling: bool, debug_info_name_table_kind: LLVM.DebugInfo.CompileUnit.NameTableKind, ranges_base_address: bool, sysroot_ptr: [*]const u8, sysroot_len: usize, sdk_ptr: [*]const u8, sdk_len: usize) ?*LLVM.DebugInfo.CompileUnit; pub extern fn NativityLLVMDebugInfoBuilderCreateCompileUnit(builder: *LLVM.DebugInfo.Builder, language: LLVM.DebugInfo.Language, file: *LLVM.DebugInfo.File, producer_ptr: [*]const u8, producer_len: usize, is_optimized: bool, flags_ptr: [*]const u8, flags_len: usize, runtime_version: c_uint, split_name_ptr: [*]const u8, split_name_len: usize, debug_info_emission_kind: LLVM.DebugInfo.CompileUnit.EmissionKind, DWOId: u64, split_debug_inlining: bool, debug_info_for_profiling: bool, debug_info_name_table_kind: LLVM.DebugInfo.CompileUnit.NameTableKind, ranges_base_address: bool, sysroot_ptr: [*]const u8, sysroot_len: usize, sdk_ptr: [*]const u8, sdk_len: usize) *LLVM.DebugInfo.CompileUnit;
pub extern fn NativityLLVMDebugInfoBuilderCreateFunction(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type.Subroutine, scope_line: c_uint, flags: LLVM.DebugInfo.Node.Flags, subprogram_flags: LLVM.DebugInfo.Subprogram.Flags, declaration: ?*LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.Subprogram; pub extern fn NativityLLVMDebugInfoBuilderCreateFunction(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type.Subroutine, scope_line: c_uint, flags: LLVM.DebugInfo.Node.Flags, subprogram_flags: LLVM.DebugInfo.Subprogram.Flags, declaration: ?*LLVM.DebugInfo.Subprogram) *LLVM.DebugInfo.Subprogram;
pub extern fn NativityLLVMDebugInfoBuilderCreateSubroutineType(builder: *LLVM.DebugInfo.Builder, parameter_types_ptr: [*]const *LLVM.DebugInfo.Type, parameter_type_count: usize, flags: LLVM.DebugInfo.Node.Flags, calling_convention: LLVM.DebugInfo.CallingConvention) ?*LLVM.DebugInfo.Type.Subroutine; pub extern fn NativityLLVMDebugInfoBuilderCreateSubroutineType(builder: *LLVM.DebugInfo.Builder, parameter_types_ptr: [*]const *LLVM.DebugInfo.Type, parameter_type_count: usize, flags: LLVM.DebugInfo.Node.Flags, calling_convention: LLVM.DebugInfo.CallingConvention) *LLVM.DebugInfo.Type.Subroutine;
pub extern fn NativityLLVMDebugInfoBuilderCreateLexicalBlock(builder: *LLVM.DebugInfo.Builder, parent_scope: *LLVM.DebugInfo.Scope, parent_file: *LLVM.DebugInfo.File, line: c_uint, column: c_uint) ?*LLVM.DebugInfo.LexicalBlock; pub extern fn NativityLLVMDebugInfoBuilderCreateLexicalBlock(builder: *LLVM.DebugInfo.Builder, parent_scope: *LLVM.DebugInfo.Scope, parent_file: *LLVM.DebugInfo.File, line: c_uint, column: c_uint) *LLVM.DebugInfo.LexicalBlock;
pub extern fn NativityLLVMDebugInfoBuilderCreateExpression(builder: *LLVM.DebugInfo.Builder, address: [*]const u64, length: usize) *LLVM.DebugInfo.Expression; pub extern fn NativityLLVMDebugInfoBuilderCreateExpression(builder: *LLVM.DebugInfo.Builder, address: [*]const u64, length: usize) *LLVM.DebugInfo.Expression;
pub extern fn NativityLLVMDebugInfoBuilderCreateGlobalVariableExpression(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, is_local_to_unit: bool, is_defined: bool, expression: ?*LLVM.DebugInfo.Expression, declaration: ?*LLVM.Metadata.Node, template_parameters: ?*LLVM.Metadata.Tuple, alignment: u32) ?*LLVM.DebugInfo.GlobalVariableExpression; pub extern fn NativityLLVMDebugInfoBuilderCreateGlobalVariableExpression(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, linkage_name_ptr: [*]const u8, linkage_name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, is_local_to_unit: bool, is_defined: bool, expression: ?*LLVM.DebugInfo.Expression, declaration: ?*LLVM.Metadata.Node, template_parameters: ?*LLVM.Metadata.Tuple, alignment: u32) *LLVM.DebugInfo.GlobalVariableExpression;
pub extern fn NativityLLVMDebugInfoBuilderCreateParameterVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, argument_index: c_uint, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags) ?*LLVM.DebugInfo.LocalVariable; pub extern fn NativityLLVMDebugInfoBuilderCreateParameterVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, argument_index: c_uint, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags) *LLVM.DebugInfo.LocalVariable;
pub extern fn NativityLLVMDebugInfoBuilderCreateAutoVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags, alignment: u32) ?*LLVM.DebugInfo.LocalVariable; // 0 means 1 << 0 (alignment of 1) pub extern fn NativityLLVMDebugInfoBuilderCreateAutoVariable(builder: *LLVM.DebugInfo.Builder, scope: *LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line_number: c_uint, type: *LLVM.DebugInfo.Type, always_preserve: bool, flags: LLVM.DebugInfo.Node.Flags, alignment: u32) *LLVM.DebugInfo.LocalVariable; // 0 means 1 << 0 (alignment of 1)
pub extern fn NativityLLVMDebugInfoBuilderInsertDeclare(builder: *LLVM.DebugInfo.Builder, pointer: *LLVM.Value, local_variable: *LLVM.DebugInfo.LocalVariable, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, basic_block: *LLVM.Value.BasicBlock) ?*LLVM.Value.Instruction; pub extern fn NativityLLVMDebugInfoBuilderInsertDeclare(builder: *LLVM.DebugInfo.Builder, pointer: *LLVM.Value, local_variable: *LLVM.DebugInfo.LocalVariable, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, basic_block: *LLVM.Value.BasicBlock) *LLVM.Value.Instruction;
pub extern fn NativityLLVMDebugInfoBuilderCreateBasicType(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, bit_count: u64, dwarf_encoding: LLVM.DebugInfo.AttributeType, flags: LLVM.DebugInfo.Node.Flags) ?*LLVM.DebugInfo.Type; pub extern fn NativityLLVMDebugInfoBuilderCreateBasicType(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, bit_count: u64, dwarf_encoding: LLVM.DebugInfo.AttributeType, flags: LLVM.DebugInfo.Node.Flags) *LLVM.DebugInfo.Type;
pub extern fn NativityLLVMDebugInfoBuilderCreatePointerType(builder: *LLVM.DebugInfo.Builder, element_type: *LLVM.DebugInfo.Type, pointer_bit_count: u64, alignment: u32, name_ptr: [*]const u8, name_len: usize) ?*LLVM.DebugInfo.Type.Derived; pub extern fn NativityLLVMDebugInfoBuilderCreatePointerType(builder: *LLVM.DebugInfo.Builder, element_type: *LLVM.DebugInfo.Type, pointer_bit_count: u64, alignment: u32, name_ptr: [*]const u8, name_len: usize) *LLVM.DebugInfo.Type.Derived;
pub extern fn NativityLLVMDebugInfoBuilderCreateStructType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_count: u64, alignment: u32, flags: LLVM.DebugInfo.Node.Flags, derived_from: ?*LLVM.DebugInfo.Type, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize, forward_declaration: ?*LLVM.DebugInfo.Type.Composite) ?*LLVM.DebugInfo.Type.Composite; pub extern fn NativityLLVMDebugInfoBuilderCreateStructType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_count: u64, alignment: u32, flags: LLVM.DebugInfo.Node.Flags, derived_from: ?*LLVM.DebugInfo.Type, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize, forward_declaration: ?*LLVM.DebugInfo.Type.Composite) *LLVM.DebugInfo.Type.Composite;
pub extern fn NativityLLVMDebugInfoBuilderCreateArrayType(builder: *LLVM.DebugInfo.Builder, bit_size: u64, alignment: u32, type: *LLVM.DebugInfo.Type, element_count: usize) ?*LLVM.DebugInfo.Type.Composite; pub extern fn NativityLLVMDebugInfoBuilderCreateArrayType(builder: *LLVM.DebugInfo.Builder, bit_size: u64, alignment: u32, type: *LLVM.DebugInfo.Type, element_count: usize) *LLVM.DebugInfo.Type.Composite;
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line: c_uint, bit_size: u64, alignment: u32, enumerator_ptr: [*]const *LLVM.DebugInfo.Type.Enumerator, enumerator_count: usize, underlying_type: *LLVM.DebugInfo.Type) ?*LLVM.DebugInfo.Type.Composite; pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerationType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: *LLVM.DebugInfo.File, line: c_uint, bit_size: u64, alignment: u32, enumerator_ptr: [*]const *LLVM.DebugInfo.Type.Enumerator, enumerator_count: usize, underlying_type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Composite;
pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerator(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, value: u64, is_unsigned: bool) ?*LLVM.DebugInfo.Type.Enumerator; pub extern fn NativityLLVMDebugInfoBuilderCreateEnumerator(builder: *LLVM.DebugInfo.Builder, name_ptr: [*]const u8, name_len: usize, value: u64, is_unsigned: bool) *LLVM.DebugInfo.Type.Enumerator;
pub extern fn NativityLLVMDebugInfoBuilderCreateReplaceableCompositeType(builder: *LLVM.DebugInfo.Builder, tag: c_uint, name_ptr: [*]const u8, name_len: usize, scope: ?*LLVM.DebugInfo.Scope, file: ?*LLVM.DebugInfo.File, line: c_uint) ?*LLVM.DebugInfo.Type.Composite; pub extern fn NativityLLVMDebugInfoBuilderCreateReplaceableCompositeType(builder: *LLVM.DebugInfo.Builder, tag: c_uint, name_ptr: [*]const u8, name_len: usize, scope: ?*LLVM.DebugInfo.Scope, file: ?*LLVM.DebugInfo.File, line: c_uint) *LLVM.DebugInfo.Type.Composite;
pub extern fn NativityLLVMDebugInfoBuilderCreateMemberType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, alignment: u32, bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived; pub extern fn NativityLLVMDebugInfoBuilderCreateMemberType(builder: *LLVM.DebugInfo.Builder, scope: ?*LLVM.DebugInfo.Scope, name_ptr: [*]const u8, name_len: usize, file: ?*LLVM.DebugInfo.File, line_number: c_uint, bit_size: u64, alignment: u32, bit_offset: u64, flags: LLVM.DebugInfo.Node.Flags, type: *LLVM.DebugInfo.Type) *LLVM.DebugInfo.Type.Derived;
pub extern fn NativityLLVMDebugInfoBuilderCompositeTypeReplaceTypes(builder: *LLVM.DebugInfo.Builder, type: *LLVM.DebugInfo.Type.Composite, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize) void; pub extern fn NativityLLVMDebugInfoBuilderCompositeTypeReplaceTypes(builder: *LLVM.DebugInfo.Builder, type: *LLVM.DebugInfo.Type.Composite, element_type_ptr: [*]const *LLVM.DebugInfo.Type, element_type_count: usize) void;
pub extern fn NativityLLLVMDITypeIsResolved(type: *LLVM.DebugInfo.Type) bool; pub extern fn NativityLLLVMDITypeIsResolved(type: *LLVM.DebugInfo.Type) bool;
pub extern fn NativityLLVMDebugInfoBuilderFinalizeSubprogram(builder: *LLVM.DebugInfo.Builder, subprogram: *LLVM.DebugInfo.Subprogram, function: *LLVM.Value.Constant.Function) void; pub extern fn NativityLLVMDebugInfoBuilderFinalizeSubprogram(builder: *LLVM.DebugInfo.Builder, subprogram: *LLVM.DebugInfo.Subprogram, function: *LLVM.Value.Constant.Function) void;
pub extern fn NativityLLVMDebugInfoBuilderFinalize(builder: *LLVM.DebugInfo.Builder) void; pub extern fn NativityLLVMDebugInfoBuilderFinalize(builder: *LLVM.DebugInfo.Builder) void;
pub extern fn NativityLLVMDebugInfoSubprogramGetFile(subprogram: *LLVM.DebugInfo.Subprogram) ?*LLVM.DebugInfo.File; pub extern fn NativityLLVMDebugInfoSubprogramGetFile(subprogram: *LLVM.DebugInfo.Subprogram) *LLVM.DebugInfo.File;
pub extern fn NativityLLVMDebugInfoSubprogramGetArgumentType(subprogram: *LLVM.DebugInfo.Subprogram, argument_index: usize) ?*LLVM.DebugInfo.Type; pub extern fn NativityLLVMDebugInfoSubprogramGetArgumentType(subprogram: *LLVM.DebugInfo.Subprogram, argument_index: usize) *LLVM.DebugInfo.Type;
pub extern fn NativityLLVMDebugInfoScopeToSubprogram(scope: *LLVM.DebugInfo.Scope) ?*LLVM.DebugInfo.Subprogram; pub extern fn NativityLLVMDebugInfoScopeToSubprogram(scope: *LLVM.DebugInfo.Scope) ?*LLVM.DebugInfo.Subprogram;
pub extern fn NativityLLVMCreateBasicBlock(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, parent_function: ?*LLVM.Value.Constant.Function, insert_before: ?*LLVM.Value.BasicBlock) ?*LLVM.Value.BasicBlock; pub extern fn NativityLLVMCreateBasicBlock(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, parent_function: ?*LLVM.Value.Constant.Function, insert_before: ?*LLVM.Value.BasicBlock) *LLVM.Value.BasicBlock;
pub extern fn NativityLLVMBasicBlockRemoveFromParent(basic_block: *LLVM.Value.BasicBlock) void; pub extern fn NativityLLVMBasicBlockRemoveFromParent(basic_block: *LLVM.Value.BasicBlock) void;
pub extern fn NativityLLVMBuilderSetInsertPoint(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) void; pub extern fn NativityLLVMBuilderSetInsertPoint(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) void;
pub extern fn NativityLLVMBuilderGetInsertBlock(builder: *LLVM.Builder) ?*LLVM.Value.BasicBlock; pub extern fn NativityLLVMBuilderGetInsertBlock(builder: *LLVM.Builder) *LLVM.Value.BasicBlock;
pub extern fn NativityLLVMBuilderSetCurrentDebugLocation(builder: *LLVM.Builder, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, function: *LLVM.Value.Constant.Function) void; pub extern fn NativityLLVMBuilderSetCurrentDebugLocation(builder: *LLVM.Builder, context: *LLVM.Context, line: c_uint, column: c_uint, scope: *LLVM.DebugInfo.Scope, function: *LLVM.Value.Constant.Function) void;
pub extern fn NativityLLVMValueSetName(value: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) void; pub extern fn NativityLLVMValueSetName(value: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) void;
pub extern fn NativityLLVMValueGetType(value: *LLVM.Value) *LLVM.Type; pub extern fn NativityLLVMValueGetType(value: *LLVM.Value) *LLVM.Type;
pub extern fn NativityLLVMArgumentGetIndex(argument: *LLVM.Value.Argument) c_uint; pub extern fn NativityLLVMArgumentGetIndex(argument: *LLVM.Value.Argument) c_uint;
pub extern fn NativityLLVMFunctionGetArguments(function: *LLVM.Value.Constant.Function, argument_ptr: [*]*LLVM.Value.Argument, argument_len: *usize) void; pub extern fn NativityLLVMFunctionGetArguments(function: *LLVM.Value.Constant.Function, argument_ptr: [*]*LLVM.Value.Argument, argument_len: *usize) void;
pub extern fn NativityLLVMFunctionGetArgument(function: *LLVM.Value.Constant.Function, index: c_uint) ?*LLVM.Value.Argument; pub extern fn NativityLLVMFunctionGetArgument(function: *LLVM.Value.Constant.Function, index: c_uint) *LLVM.Value.Argument;
pub extern fn NativityLLVMFunctionGetType(function: *LLVM.Value.Constant.Function) *LLVM.Type.Function; pub extern fn NativityLLVMFunctionGetType(function: *LLVM.Value.Constant.Function) *LLVM.Type.Function;
pub extern fn NativityLLVMFunctionTypeGetReturnType(function_type: *LLVM.Type.Function) *LLVM.Type; pub extern fn NativityLLVMFunctionTypeGetReturnType(function_type: *LLVM.Type.Function) *LLVM.Type;
pub extern fn NativityLLVMTypeIsVoid(type: *LLVM.Type) bool; pub extern fn NativityLLVMTypeIsVoid(type: *LLVM.Type) bool;
pub extern fn NativityLLVMBuilderCreateAlloca(builder: *LLVM.Builder, type: *LLVM.Type, address_space: c_uint, array_size: ?*LLVM.Value, name_ptr: [*]const u8, name_len: usize, alignment: u32) ?*LLVM.Value.Instruction.Alloca; pub extern fn NativityLLVMBuilderCreateAlloca(builder: *LLVM.Builder, type: *LLVM.Type, address_space: c_uint, array_size: ?*LLVM.Value, name_ptr: [*]const u8, name_len: usize, alignment: u32) *LLVM.Value.Instruction.Alloca;
pub extern fn NativityLLVMBuilderCreateStore(builder: *LLVM.Builder, value: *LLVM.Value, pointer: *LLVM.Value, is_volatile: bool, alignment: u32) ?*LLVM.Value.Instruction.Store; pub extern fn NativityLLVMBuilderCreateStore(builder: *LLVM.Builder, value: *LLVM.Value, pointer: *LLVM.Value, is_volatile: bool, alignment: u32) *LLVM.Value.Instruction.Store;
pub extern fn NativityLLVMBuilderCreateMemcpy(builder: *LLVM.Builder, destination: *LLVM.Value, destination_alignment: u32, source: *LLVM.Value, source_alignment: u32, size: u64, is_volatile: bool) *LLVM.Value.Instruction.Call; pub extern fn NativityLLVMBuilderCreateMemcpy(builder: *LLVM.Builder, destination: *LLVM.Value, destination_alignment: u32, source: *LLVM.Value, source_alignment: u32, size: u64, is_volatile: bool) *LLVM.Value.Instruction.Call;
pub extern fn NativityLLVMContextGetConstantInt(context: *LLVM.Context, bit_count: c_uint, value: u64, is_signed: bool) ?*LLVM.Value.Constant.Int; pub extern fn NativityLLVMContextGetConstantInt(context: *LLVM.Context, bit_count: c_uint, value: u64, is_signed: bool) *LLVM.Value.Constant.Int;
pub extern fn NativityLLVMContextGetConstantString(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, null_terminate: bool) ?*LLVM.Value.Constant; pub extern fn NativityLLVMContextGetConstantString(context: *LLVM.Context, name_ptr: [*]const u8, name_len: usize, null_terminate: bool) *LLVM.Value.Constant;
pub extern fn NativityLLVMGetConstantArray(array_type: *LLVM.Type.Array, value_ptr: [*]const *LLVM.Value.Constant, value_count: usize) ?*LLVM.Value.Constant; pub extern fn NativityLLVMGetConstantArray(array_type: *LLVM.Type.Array, value_ptr: [*]const *LLVM.Value.Constant, value_count: usize) *LLVM.Value.Constant;
pub extern fn NativityLLVMGetConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) ?*LLVM.Value.Constant; pub extern fn NativityLLVMGetConstantStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) *LLVM.Value.Constant;
pub extern fn NativityLLVMConstantToInt(constant: *LLVM.Value.Constant) ?*LLVM.Value.Constant.Int; pub extern fn NativityLLVMConstantToInt(constant: *LLVM.Value.Constant) ?*LLVM.Value.Constant.Int;
pub extern fn NativityLLVMBuilderCreateICmp(builder: *LLVM.Builder, integer_comparison: LLVM.Value.Instruction.ICmp.Kind, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateICmp(builder: *LLVM.Builder, integer_comparison: LLVM.Value.Instruction.ICmp.Kind, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateLoad(builder: *LLVM.Builder, type: *LLVM.Type, value: *LLVM.Value, is_volatile: bool, name_ptr: [*]const u8, name_len: usize, alignment: u32) ?*LLVM.Value.Instruction.Load; pub extern fn NativityLLVMBuilderCreateLoad(builder: *LLVM.Builder, type: *LLVM.Type, value: *LLVM.Value, is_volatile: bool, name_ptr: [*]const u8, name_len: usize, alignment: u32) *LLVM.Value.Instruction.Load;
pub extern fn NativityLLVMBuilderCreateRet(builder: *LLVM.Builder, value: ?*LLVM.Value) ?*LLVM.Value.Instruction.Ret; pub extern fn NativityLLVMBuilderCreateRet(builder: *LLVM.Builder, value: ?*LLVM.Value) *LLVM.Value.Instruction.Ret;
pub extern fn NativityLLVMBuilderCreateCast(builder: *LLVM.Builder, cast_type: LLVM.Value.Instruction.Cast.Type, value: *LLVM.Value, type: *LLVM.Type, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateCast(builder: *LLVM.Builder, cast_type: LLVM.Value.Instruction.Cast.Type, value: *LLVM.Value, type: *LLVM.Type, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMContextGetAttributeFromEnum(context: *LLVM.Context, attribute_key: LLVM.Attribute.Id, attribute_value: u64) *LLVM.Attribute; pub extern fn NativityLLVMContextGetAttributeFromEnum(context: *LLVM.Context, attribute_key: LLVM.Attribute.Id, attribute_value: u64) *LLVM.Attribute;
pub extern fn NativityLLVMContextGetAttributeFromString(context: *LLVM.Context, key_ptr: [*]const u8, key_len: usize, value_ptr: [*]const u8, value_len: usize) *LLVM.Attribute; pub extern fn NativityLLVMContextGetAttributeFromString(context: *LLVM.Context, key_ptr: [*]const u8, key_len: usize, value_ptr: [*]const u8, value_len: usize) *LLVM.Attribute;
pub extern fn NativityLLVMContextGetAttributeFromType(context: *LLVM.Context, attribute_key: LLVM.Attribute.Id, type: *LLVM.Type) *LLVM.Attribute; pub extern fn NativityLLVMContextGetAttributeFromType(context: *LLVM.Context, attribute_key: LLVM.Attribute.Id, type: *LLVM.Type) *LLVM.Attribute;
@ -73,50 +74,51 @@ pub extern fn NativityLLVMContextGetAttributeSet(context: *LLVM.Context, attribu
pub extern fn NativityLLVMFunctionSetAttributes(function: *LLVM.Value.Constant.Function, context: *LLVM.Context, function_attributes: *const LLVM.Attribute.Set, return_attributes: *const LLVM.Attribute.Set, parameter_attribute_set_ptr: [*]const *const LLVM.Attribute.Set, parameter_attribute_set_count: usize) void; pub extern fn NativityLLVMFunctionSetAttributes(function: *LLVM.Value.Constant.Function, context: *LLVM.Context, function_attributes: *const LLVM.Attribute.Set, return_attributes: *const LLVM.Attribute.Set, parameter_attribute_set_ptr: [*]const *const LLVM.Attribute.Set, parameter_attribute_set_count: usize) void;
pub extern fn NativityLLVMCallSetAttributes(call: *LLVM.Value.Instruction.Call, context: *LLVM.Context, function_attributes: *const LLVM.Attribute.Set, return_attributes: *const LLVM.Attribute.Set, parameter_attribute_set_ptr: [*]const *const LLVM.Attribute.Set, parameter_attribute_set_count: usize) void; pub extern fn NativityLLVMCallSetAttributes(call: *LLVM.Value.Instruction.Call, context: *LLVM.Context, function_attributes: *const LLVM.Attribute.Set, return_attributes: *const LLVM.Attribute.Set, parameter_attribute_set_ptr: [*]const *const LLVM.Attribute.Set, parameter_attribute_set_count: usize) void;
// pub extern fn NativityLLVMFunctionAddAttributeKey(builder: *LLVM.Value.Constant.Function, attribute_key: LLVM.Attribute) void; // pub extern fn NativityLLVMFunctionAddAttributeKey(builder: *LLVM.Value.Constant.Function, attribute_key: LLVM.Attribute) void;
pub extern fn NativityLLVMGetVoidType(context: *LLVM.Context) ?*LLVM.Type; pub extern fn NativityLLVMGetVoidType(context: *LLVM.Context) *LLVM.Type;
pub extern fn NativityLLVMGetInlineAssembly(function_type: *LLVM.Type.Function, assembly_ptr: [*]const u8, assembly_len: usize, constraints_ptr: [*]const u8, constrains_len: usize, has_side_effects: bool, is_align_stack: bool, dialect: LLVM.Value.InlineAssembly.Dialect, can_throw: bool) ?*LLVM.Value.InlineAssembly; pub extern fn NativityLLVMGetInlineAssembly(function_type: *LLVM.Type.Function, assembly_ptr: [*]const u8, assembly_len: usize, constraints_ptr: [*]const u8, constrains_len: usize, has_side_effects: bool, is_align_stack: bool, dialect: LLVM.Value.InlineAssembly.Dialect, can_throw: bool) *LLVM.Value.InlineAssembly;
pub extern fn NativityLLVMBuilderCreateCall(builder: *LLVM.Builder, function_type: *LLVM.Type.Function, callee: *LLVM.Value, argument_ptr: [*]const *LLVM.Value, argument_count: usize, name_ptr: [*]const u8, name_len: usize, fp_math_tag: ?*LLVM.Metadata.Node) ?*LLVM.Value.Instruction.Call; pub extern fn NativityLLVMBuilderCreateCall(builder: *LLVM.Builder, function_type: *LLVM.Type.Function, callee: *LLVM.Value, argument_ptr: [*]const *LLVM.Value, argument_count: usize, name_ptr: [*]const u8, name_len: usize, fp_math_tag: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Call;
pub extern fn NativityLLVMBuilderCreateUnreachable(builder: *LLVM.Builder) ?*LLVM.Value.Instruction.Unreachable; pub extern fn NativityLLVMBuilderCreateUnreachable(builder: *LLVM.Builder) *LLVM.Value.Instruction.Unreachable;
pub extern fn NativityLLVMModuleAddGlobalVariable(module: *LLVM.Module, type: *LLVM.Type, is_constant: bool, linkage: LLVM.Linkage, initializer: ?*LLVM.Value.Constant, name_ptr: [*]const u8, name_len: usize, insert_before: ?*LLVM.Value.Constant.GlobalVariable, thread_local_mode: LLVM.ThreadLocalMode, address_space: c_uint, externally_initialized: bool) ?*LLVM.Value.Constant.GlobalVariable; pub extern fn NativityLLVMModuleAddGlobalVariable(module: *LLVM.Module, type: *LLVM.Type, is_constant: bool, linkage: LLVM.Linkage, initializer: ?*LLVM.Value.Constant, name_ptr: [*]const u8, name_len: usize, insert_before: ?*LLVM.Value.Constant.GlobalVariable, thread_local_mode: LLVM.ThreadLocalMode, address_space: c_uint, externally_initialized: bool) *LLVM.Value.Constant.GlobalVariable;
pub extern fn NativityLLVMBuilderCreateAdd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateAdd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateSub(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateSub(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateMultiply(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateMultiply(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateShiftLeft(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateShiftLeft(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, no_unsigned_wrapping: bool, no_signed_wrapping: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateUDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateUDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateSDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateSDiv(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateURem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateURem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateSRem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateSRem(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateLogicalShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateLogicalShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateArithmeticShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateArithmeticShiftRight(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize, is_exact: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateXor(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateXor(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateAnd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateAnd(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateOr(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateOr(builder: *LLVM.Builder, left: *LLVM.Value, right: *LLVM.Value, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index_ptr: [*]const *LLVM.Value, index_count: usize, name_ptr: [*]const u8, name_len: usize, in_bounds: bool) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index_ptr: [*]const *LLVM.Value, index_count: usize, name_ptr: [*]const u8, name_len: usize, in_bounds: bool) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateStructGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateStructGEP(builder: *LLVM.Builder, type: *LLVM.Type, pointer: *LLVM.Value, index: c_uint, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateBranch(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) ?*LLVM.Value.Instruction.Branch; pub extern fn NativityLLVMBuilderCreateBranch(builder: *LLVM.Builder, basic_block: *LLVM.Value.BasicBlock) *LLVM.Value.Instruction.Branch;
pub extern fn NativityLLVMBuilderCreateConditionalBranch(builder: *LLVM.Builder, condition: *LLVM.Value, true_block: *LLVM.Value.BasicBlock, false_block: *LLVM.Value.BasicBlock, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) ?*LLVM.Value.Instruction.Branch; pub extern fn NativityLLVMBuilderCreateConditionalBranch(builder: *LLVM.Builder, condition: *LLVM.Value, true_block: *LLVM.Value.BasicBlock, false_block: *LLVM.Value.BasicBlock, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Branch;
pub extern fn NativityLLVMBuilderCreateSwitch(builder: *LLVM.Builder, condition: *LLVM.Value, default_block: ?*LLVM.Value.BasicBlock, case_ptr: [*]const *LLVM.Value.Constant.Int, case_block_ptr: [*]const *LLVM.Value.BasicBlock, case_count: c_uint, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Switch; pub extern fn NativityLLVMBuilderCreateSwitch(builder: *LLVM.Builder, condition: *LLVM.Value, default_block: ?*LLVM.Value.BasicBlock, case_ptr: [*]const *LLVM.Value.Constant.Int, case_block_ptr: [*]const *LLVM.Value.BasicBlock, case_count: c_uint, branch_weights: ?*LLVM.Metadata.Node, unpredictable: ?*LLVM.Metadata.Node) *LLVM.Value.Instruction.Switch;
pub extern fn NativityLLVMVerifyFunction(function: *LLVM.Value.Constant.Function, message_ptr: *[*]const u8, message_len: *usize) bool; pub extern fn NativityLLVMVerifyFunction(function: *LLVM.Value.Constant.Function, message_ptr: *[*]const u8, message_len: *usize) bool;
pub extern fn NativityLLVMVerifyModule(module: *LLVM.Module, message_ptr: *[*]const u8, message_len: *usize) bool; pub extern fn NativityLLVMVerifyModule(module: *LLVM.Module, message_ptr: *[*]const u8, message_len: *usize) bool;
pub extern fn NativityLLVMModuleToString(module: *LLVM.Module, message_len: *usize) [*]const u8; pub extern fn NativityLLVMModuleToString(module: *LLVM.Module, message_pointer: *[*]const u8, message_len: *usize) void;
pub extern fn NativityLLVMFunctionToString(function: *LLVM.Value.Constant.Function, message_len: *usize) [*]const u8; pub extern fn NativityLLVMFunctionToString(function: *LLVM.Value.Constant.Function, message_pointer: *[*]const u8, message_len: *usize) void;
pub extern fn NativityLLVMValueToString(value: *LLVM.Value, message_len: *usize) [*]const u8; pub extern fn NativityLLVMValueToString(value: *LLVM.Value, message_pointer: *[*]const u8, message_len: *usize) void;
pub extern fn NativityLLVMBuilderIsCurrentBlockTerminated(builder: *LLVM.Builder) bool; pub extern fn NativityLLVMBuilderIsCurrentBlockTerminated(builder: *LLVM.Builder) bool;
pub extern fn NativityLLVMGetUndefined(type: *LLVM.Type) ?*LLVM.Value.Constant.Undefined; pub extern fn NativityLLVMGetUndefined(type: *LLVM.Type) *LLVM.Value.Constant.Undefined;
pub extern fn NativityLLVMGetPoisonValue(type: *LLVM.Type) ?*LLVM.Value.Constant.Poison; pub extern fn NativityLLVMGetPoisonValue(type: *LLVM.Type) *LLVM.Value.Constant.Poison;
pub extern fn NativityLLVMTypeGetContext(type: *LLVM.Type) *LLVM.Context;
pub extern fn NativityLLVMFunctionSetCallingConvention(function: *LLVM.Value.Constant.Function, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void; pub extern fn NativityLLVMFunctionSetCallingConvention(function: *LLVM.Value.Constant.Function, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void;
pub extern fn NativityLLVMFunctionGetCallingConvention(function: *LLVM.Value.Constant.Function) LLVM.Value.Constant.Function.CallingConvention; pub extern fn NativityLLVMFunctionGetCallingConvention(function: *LLVM.Value.Constant.Function) LLVM.Value.Constant.Function.CallingConvention;
pub extern fn NativityLLVMFunctionSetSubprogram(function: *LLVM.Value.Constant.Function, subprogram: *LLVM.DebugInfo.Subprogram) void; pub extern fn NativityLLVMFunctionSetSubprogram(function: *LLVM.Value.Constant.Function, subprogram: *LLVM.DebugInfo.Subprogram) void;
pub extern fn NativityLLVMFunctionGetSubprogram(function: *LLVM.Value.Constant.Function) ?*LLVM.DebugInfo.Subprogram; pub extern fn NativityLLVMFunctionGetSubprogram(function: *LLVM.Value.Constant.Function) *LLVM.DebugInfo.Subprogram;
pub extern fn NativityLLVMCallSetCallingConvention(instruction: *LLVM.Value.Instruction.Call, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void; pub extern fn NativityLLVMCallSetCallingConvention(instruction: *LLVM.Value.Instruction.Call, calling_convention: LLVM.Value.Constant.Function.CallingConvention) void;
pub extern fn NativityLLVMGetStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) ?*LLVM.Value.Constant; pub extern fn NativityLLVMGetStruct(struct_type: *LLVM.Type.Struct, constant_ptr: [*]const *LLVM.Value.Constant, constant_len: usize) *LLVM.Value.Constant;
pub extern fn NativityLLVMValueToConstant(value: *LLVM.Value) ?*LLVM.Value.Constant; pub extern fn NativityLLVMValueToConstant(value: *LLVM.Value) ?*LLVM.Value.Constant;
pub extern fn NativityLLVMValueToFunction(value: *LLVM.Value) ?*LLVM.Value.Constant.Function; pub extern fn NativityLLVMValueToFunction(value: *LLVM.Value) ?*LLVM.Value.Constant.Function;
@ -129,31 +131,35 @@ pub extern fn NativityLLVMTypeToFunction(type: *LLVM.Type) ?*LLVM.Type.Function;
pub extern fn NativityLLVMTypeToArray(type: *LLVM.Type) ?*LLVM.Type.Array; pub extern fn NativityLLVMTypeToArray(type: *LLVM.Type) ?*LLVM.Type.Array;
pub extern fn NativityLLVMTypeToPointer(Type: *LLVM.Type) ?*LLVM.Type.Pointer; pub extern fn NativityLLVMTypeToPointer(Type: *LLVM.Type) ?*LLVM.Type.Pointer;
pub extern fn NativityLLVMArrayTypeGetElementType(array_type: *LLVM.Type.Array) ?*LLVM.Type; pub extern fn NativityLLVMArrayTypeGetElementType(array_type: *LLVM.Type.Array) *LLVM.Type;
pub extern fn NativityLLVMLookupIntrinsic(name_ptr: [*]const u8, name_len: usize) LLVM.Value.IntrinsicID; pub extern fn NativityLLVMLookupIntrinsic(name_ptr: [*]const u8, name_len: usize) LLVM.Value.IntrinsicID;
pub extern fn NativityLLVMModuleGetIntrinsicDeclaration(module: *LLVM.Module, intrinsic_id: LLVM.Value.IntrinsicID, parameter_types_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Value.Constant.Function; pub extern fn NativityLLVMModuleGetIntrinsicDeclaration(module: *LLVM.Module, intrinsic_id: LLVM.Value.IntrinsicID, parameter_types_ptr: [*]const *LLVM.Type, parameter_type_count: usize) *LLVM.Value.Constant.Function;
pub extern fn NativityLLVMContextGetIntrinsicType(context: *LLVM.Context, intrinsic_id: LLVM.Value.IntrinsicID, parameter_type_ptr: [*]const *LLVM.Type, parameter_type_count: usize) ?*LLVM.Type.Function; pub extern fn NativityLLVMContextGetIntrinsicType(context: *LLVM.Context, intrinsic_id: LLVM.Value.IntrinsicID, parameter_type_ptr: [*]const *LLVM.Type, parameter_type_count: usize) *LLVM.Type.Function;
pub extern fn NativityLLVMBuilderCreateExtractValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateExtractValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateInsertValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, value: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value; pub extern fn NativityLLVMBuilderCreateInsertValue(builder: *LLVM.Builder, aggregate: *LLVM.Value, value: *LLVM.Value, indices_ptr: [*]const c_uint, indices_len: usize, name_ptr: [*]const u8, name_len: usize) *LLVM.Value;
pub extern fn NativityLLVMBuilderCreateGlobalString(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) ?*LLVM.Value.Constant.GlobalVariable; pub extern fn NativityLLVMBuilderCreateGlobalString(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) *LLVM.Value.Constant.GlobalVariable;
pub extern fn NativityLLVMBuilderCreateGlobalStringPointer(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) ?*LLVM.Value.Constant; pub extern fn NativityLLVMBuilderCreateGlobalStringPointer(builder: *LLVM.Builder, string_ptr: [*]const u8, string_len: usize, name_ptr: [*]const u8, name_len: usize, address_space: c_uint, module: *LLVM.Module) *LLVM.Value.Constant;
pub extern fn NativityLLVMCompareTypes(a: *LLVM.Type, b: *LLVM.Type) bool; pub extern fn NativityLLVMCompareTypes(a: *LLVM.Type, b: *LLVM.Type) bool;
pub extern fn NativityLLVMBuilderCreatePhi(builder: *LLVM.Builder, type: *LLVM.Type, reserved_value_count: c_uint, name_ptr: [*]const u8, name_len: usize) ?*LLVM.Value.Instruction.PhiNode; pub extern fn NativityLLVMBuilderCreatePhi(builder: *LLVM.Builder, type: *LLVM.Type, reserved_value_count: c_uint, name_ptr: [*]const u8, name_len: usize) *LLVM.Value.Instruction.PhiNode;
pub extern fn NativityLLVMPhiAddIncoming(phi: *LLVM.Value.Instruction.PhiNode, value: *LLVM.Value, basic_block: *LLVM.Value.BasicBlock) void; pub extern fn NativityLLVMPhiAddIncoming(phi: *LLVM.Value.Instruction.PhiNode, value: *LLVM.Value, basic_block: *LLVM.Value.BasicBlock) void;
pub extern fn NativityLLVMAllocatGetAllocatedType(alloca: *LLVM.Value.Instruction.Alloca) *LLVM.Type; pub extern fn NativityLLVMAllocatGetAllocatedType(alloca: *LLVM.Value.Instruction.Alloca) *LLVM.Type;
pub extern fn NativityLLVMValueToAlloca(value: *LLVM.Value) ?*LLVM.Value.Instruction.Alloca; pub extern fn NativityLLVMValueToAlloca(value: *LLVM.Value) ?*LLVM.Value.Instruction.Alloca;
pub extern fn NativityLLVMGlobalVariableSetInitializer(global_variable: *LLVM.Value.Constant.GlobalVariable, constant_initializer: *LLVM.Value.Constant) void; pub extern fn NativityLLVMGlobalVariableSetInitializer(global_variable: *LLVM.Value.Constant.GlobalVariable, constant_initializer: *LLVM.Value.Constant) void;
pub extern fn NativityLLVMInitializeCodeGeneration() void; pub extern fn NativityLLVMLinkModules(destination: *LLVM.Module, source: *LLVM.Module, flags: LLVM.LinkFlags) bool;
pub extern fn NativityLLVMGetTarget(target_triple_ptr: [*]const u8, target_triple_len: usize, message_ptr: *[*]const u8, message_len: *usize) ?*LLVM.Target; pub extern fn NativityLLVMGetTarget(target_triple_ptr: [*]const u8, target_triple_len: usize, message_ptr: *[*]const u8, message_len: *usize) ?*LLVM.Target;
pub extern fn NativityLLVMTargetCreateTargetMachine(target: *LLVM.Target, target_triple_ptr: [*]const u8, target_triple_len: usize, cpu_ptr: [*]const u8, cpu_len: usize, features_ptr: [*]const u8, features_len: usize, relocation_model: LLVM.RelocationModel, maybe_code_model: LLVM.CodeModel, is_code_model_present: bool, optimization_level: LLVM.CodegenOptimizationLevel, jit: bool) ?*LLVM.Target.Machine; pub extern fn NativityLLVMTargetCreateTargetMachine(target: *LLVM.Target, target_triple_ptr: [*]const u8, target_triple_len: usize, cpu_ptr: [*]const u8, cpu_len: usize, features_ptr: [*]const u8, features_len: usize, relocation_model: LLVM.RelocationModel, maybe_code_model: LLVM.CodeModel, is_code_model_present: bool, optimization_level: LLVM.CodegenOptimizationLevel, jit: bool) *LLVM.Target.Machine;
pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module, target_machine: *LLVM.Target.Machine) void;
pub extern fn NativityLLVMModuleSetTargetTriple(module: *LLVM.Module, target_triple_ptr: [*]const u8, target_triple_len: usize) void;
pub extern fn NativityLLVMRunOptimizationPipeline(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, optimization_level: LLVM.OptimizationLevel) void; pub extern fn NativityLLVMRunOptimizationPipeline(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, optimization_level: LLVM.OptimizationLevel) void;
pub extern fn NativityLLVMModuleAddPassesToEmitFile(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, object_file_path_ptr: [*]const u8, object_file_path_len: usize, codegen_file_type: LLVM.CodeGenFileType, disable_verify: bool) bool; pub extern fn NativityLLVMModuleAddPassesToEmitFile(module: *LLVM.Module, target_machine: *LLVM.Target.Machine, object_file_path_ptr: [*]const u8, object_file_path_len: usize, codegen_file_type: LLVM.CodeGenFileType, disable_verify: bool) bool;
pub extern fn NativityLLVMModuleSetTargetMachineDataLayout(module: *LLVM.Module, target_machine: *LLVM.Target.Machine) void;
pub extern fn NativityLLVMModuleSetTargetTriple(module: *LLVM.Module, target_triple_ptr: [*]const u8, target_triple_len: usize) void;
pub extern fn NativityLLVMTypeAssertEqual(a: *LLVM.Type, b: *LLVM.Type) void; pub extern fn NativityLLVMTypeAssertEqual(a: *LLVM.Type, b: *LLVM.Type) void;
pub extern fn LLVMCreateMemoryBufferWithMemoryRange(InputData: [*]const u8, InputDataLength: usize, BufferName: ?[*:0]const u8, RequiresNullTerminator: c_int) *LLVM.MemoryBuffer;
pub extern fn LLVMParseBitcodeInContext2(context: *LLVM.Context, memory_buffer: *LLVM.MemoryBuffer, out_module: **LLVM.Module) c_int;
pub extern fn LLVMInitializeAArch64TargetInfo() void; pub extern fn LLVMInitializeAArch64TargetInfo() void;
pub extern fn LLVMInitializeAMDGPUTargetInfo() void; pub extern fn LLVMInitializeAMDGPUTargetInfo() void;
pub extern fn LLVMInitializeARMTargetInfo() void; pub extern fn LLVMInitializeARMTargetInfo() void;

7806
bootstrap/compiler.zig Normal file

File diff suppressed because it is too large Load Diff

View File

@ -153,19 +153,20 @@ pub fn DynamicBoundedArray(comptime T: type) type {
const pinned_array_page_size = 2 * 1024 * 1024; const pinned_array_page_size = 2 * 1024 * 1024;
const pinned_array_max_size = std.math.maxInt(u32) - pinned_array_page_size; const pinned_array_max_size = std.math.maxInt(u32) - pinned_array_page_size;
const pinned_array_default_granularity = pinned_array_page_size;
const small_granularity = std.mem.page_size;
const large_granularity = 2 * 1024 * 1024;
// This must be used with big arrays, which are not resizeable (can't be cleared) // This must be used with big arrays, which are not resizeable (can't be cleared)
pub fn PinnedArray(comptime T: type) type { pub fn PinnedArray(comptime T: type) type {
return PinnedArrayAdvanced(T, null); return PinnedArrayAdvanced(T, null, small_granularity);
} }
// This must be used with big arrays, which are not resizeable (can't be cleared) // This must be used with big arrays, which are not resizeable (can't be cleared)
pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type { pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type, comptime granularity: comptime_int) type {
return struct { return struct {
pointer: [*]T = @constCast((&[_]T{}).ptr), pointer: [*]T = undefined,
length: u32 = 0, length: u32 = 0,
granularity: u32 = 0, committed: u32 = 0,
pub const Index = if (MaybeIndex) |I| getIndexForType(T, I) else enum(u32) { pub const Index = if (MaybeIndex) |I| getIndexForType(T, I) else enum(u32) {
null = 0xffff_ffff, null = 0xffff_ffff,
@ -174,6 +175,10 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
const Array = @This(); const Array = @This();
pub fn clear(array: *Array) void {
array.length = 0;
}
pub fn const_slice(array: *const Array) []const T { pub fn const_slice(array: *const Array) []const T {
return array.pointer[0..array.length]; return array.pointer[0..array.length];
} }
@ -193,38 +198,36 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
return array.get_unchecked(i); return array.get_unchecked(i);
} }
pub fn get_index(array: *Array, item: *T) Index { pub fn get_index(array: *Array, item: *T) u32 {
const many_item: [*]T = @ptrCast(item); const many_item: [*]T = @ptrCast(item);
const result = @intFromPtr(many_item) - @intFromPtr(array.pointer); const result: u32 = @intCast(@intFromPtr(many_item) - @intFromPtr(array.pointer));
assert(result < pinned_array_max_size); assert(result < pinned_array_max_size);
return @enumFromInt(@divExact(result, @sizeOf(T))); return @divExact(result, @sizeOf(T));
} }
pub fn init(granularity: u32) !Array { pub fn get_typed_index(array: *Array, item: *T) Index {
assert(granularity & 0xfff == 0); return @enumFromInt(array.get_index(item));
const raw_ptr = try reserve(pinned_array_max_size);
try commit(raw_ptr, granularity);
return Array{
.pointer = @alignCast(@ptrCast(raw_ptr)),
.length = 0,
.granularity = granularity,
};
}
pub fn init_with_default_granularity() !Array {
return try Array.init(pinned_array_default_granularity);
} }
pub fn ensure_capacity(array: *Array, additional: u32) void { pub fn ensure_capacity(array: *Array, additional: u32) void {
if (array.committed == 0) {
assert(array.length == 0);
array.pointer = @alignCast(@ptrCast(reserve(pinned_array_max_size) catch unreachable));
}
const length = array.length; const length = array.length;
const size = length * @sizeOf(T); const size = length * @sizeOf(T);
const granularity_aligned_size = align_forward(size, array.granularity); const granularity_aligned_size = array.committed * granularity;
const new_size = size + additional * @sizeOf(T); const new_size = size + additional * @sizeOf(T);
if (granularity_aligned_size < new_size) { if (granularity_aligned_size < new_size) {
assert((length + additional) * @sizeOf(T) <= pinned_array_max_size); assert((length + additional) * @sizeOf(T) <= pinned_array_max_size);
const new_granularity_aligned_size = align_forward(new_size, array.granularity); const new_granularity_aligned_size = align_forward(new_size, granularity);
const ptr: [*]u8 = @ptrCast(array.pointer); const pointer: [*]u8 = @ptrCast(array.pointer);
commit(ptr + granularity_aligned_size, new_granularity_aligned_size - granularity_aligned_size) catch unreachable; const commit_pointer = pointer + granularity_aligned_size;
const commit_size = new_granularity_aligned_size - granularity_aligned_size;
commit(commit_pointer, commit_size) catch unreachable;
array.committed += @intCast(@divExact(commit_size, granularity));
} }
} }
@ -233,31 +236,47 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
return array.append_with_capacity(item); return array.append_with_capacity(item);
} }
pub fn append_index(array: *Array, item: T) Index { pub fn append_index(array: *Array, item: T) u32 {
return array.get_index(array.append(item)); return array.get_index(array.append(item));
} }
pub fn append_typed_index(array: *Array, item: T) Index {
return array.get_typed_index(array.append(item));
}
pub fn append_slice(array: *Array, items: []const T) void { pub fn append_slice(array: *Array, items: []const T) void {
array.ensure_capacity(@intCast(items.len)); array.ensure_capacity(@intCast(items.len));
array.append_slice_with_capacity(items); array.append_slice_with_capacity(items);
} }
pub fn append_with_capacity(array: *Array, item: T) *T { pub fn add_one_with_capacity(array: *Array) *T {
const index = array.length; const index = array.length;
assert(index * @sizeOf(T) < pinned_array_max_size); assert(index * @sizeOf(T) < pinned_array_max_size);
array.length += 1; array.length += 1;
const ptr = &array.pointer[index]; const ptr = &array.pointer[index];
return ptr;
}
pub fn add_one(array: *Array) *T {
array.ensure_capacity(1);
return array.add_one_with_capacity();
}
pub fn append_with_capacity(array: *Array, item: T) *T {
const ptr = array.add_one_with_capacity();
ptr.* = item; ptr.* = item;
return ptr; return ptr;
} }
pub fn append_slice_with_capacity(array: *Array, items: []const T) void { pub fn append_slice_with_capacity(array: *Array, items: []const T) void {
if (items.len > 0) {
const index = array.length; const index = array.length;
const count: u32 = @intCast(items.len); const count: u32 = @intCast(items.len);
assert((index + count - 1) * @sizeOf(T) < pinned_array_max_size); assert((index + count - 1) * @sizeOf(T) < pinned_array_max_size);
array.length += count; array.length += count;
@memcpy(array.pointer[index..][0..count], items); @memcpy(array.pointer[index..][0..count], items);
} }
}
pub fn insert(array: *@This(), index: u32, item: T) void { pub fn insert(array: *@This(), index: u32, item: T) void {
assert(index < array.length); assert(index < array.length);
@ -268,6 +287,14 @@ pub fn PinnedArrayAdvanced(comptime T: type, comptime MaybeIndex: ?type) type {
copy_backwards(T, dst, src); copy_backwards(T, dst, src);
array.slice()[index] = item; array.slice()[index] = item;
} }
pub fn in_range(array: *@This(), item: *T) bool {
if (array.committed == 0) return false;
if (@intFromPtr(item) < @intFromPtr(array.pointer)) return false;
const top = @intFromPtr(array.pointer) + array.committed * granularity;
if (@intFromPtr(item) >= top) return false;
return true;
}
}; };
} }
@ -385,31 +412,19 @@ const pinned_hash_map_max_size = std.math.maxInt(u32) - pinned_hash_map_page_siz
const pinned_hash_map_default_granularity = pinned_hash_map_page_size; const pinned_hash_map_default_granularity = pinned_hash_map_page_size;
pub fn PinnedHashMap(comptime K: type, comptime V: type) type { pub fn PinnedHashMap(comptime K: type, comptime V: type) type {
return PinnedHashMapAdvanced(K, V, small_granularity);
}
pub fn PinnedHashMapAdvanced(comptime K: type, comptime V: type, comptime granularity: comptime_int) type {
return struct { return struct {
key_pointer: [*]K, key_pointer: [*]K = undefined,
value_pointer: [*]V, value_pointer: [*]V = undefined,
length: u32, length: u64 = 0,
granularity: u32, committed_key: u32 = 0,
committed: u32, committed_value: u32 = 0,
const Map = @This(); const Map = @This();
pub fn init(granularity: u32) !Map {
assert(granularity & 0xfff == 0);
const key_raw_pointer = try reserve(pinned_hash_map_max_size);
try commit(key_raw_pointer, granularity);
const value_raw_pointer = try reserve(pinned_hash_map_max_size);
try commit(value_raw_pointer, granularity);
return Map{
.key_pointer = @alignCast(@ptrCast(key_raw_pointer)),
.value_pointer = @alignCast(@ptrCast(value_raw_pointer)),
.length = 0,
.granularity = granularity,
.committed = 1,
};
}
pub fn get_pointer(map: *Map, key: K) ?*V { pub fn get_pointer(map: *Map, key: K) ?*V {
for (map.keys(), 0..) |k, i| { for (map.keys(), 0..) |k, i| {
const is_equal = switch (@typeInfo(K)) { const is_equal = switch (@typeInfo(K)) {
@ -437,7 +452,7 @@ pub fn PinnedHashMap(comptime K: type, comptime V: type) type {
} }
} }
pub fn put(map: *@This(), key: K, value: V) !void { pub fn put(map: *@This(), key: K, value: V) void {
if (map.get_pointer(key)) |value_pointer| { if (map.get_pointer(key)) |value_pointer| {
value_pointer.* = value; value_pointer.* = value;
} else { } else {
@ -447,45 +462,57 @@ pub fn PinnedHashMap(comptime K: type, comptime V: type) type {
} }
} }
pub fn put_no_clobber(map: *@This(), key: K, value: V) !void { pub fn put_no_clobber(map: *@This(), key: K, value: V) void {
assert(map.get_pointer(key) == null); assert(map.get_pointer(key) == null);
const len = map.length; const len = map.length;
map.ensure_capacity(len + 1); map.ensure_capacity(len + 1);
map.put_at_with_capacity(len, key, value); map.put_at_with_capacity(len, key, value);
} }
fn put_at_with_capacity(map: *@This(), index: u32, key: K, value: V) void { fn put_at_with_capacity(map: *@This(), index: u64, key: K, value: V) void {
map.length += 1; map.length += 1;
assert(index < map.length); assert(index < map.length);
map.key_pointer[index] = key; map.key_pointer[index] = key;
map.value_pointer[index] = value; map.value_pointer[index] = value;
} }
fn ensure_capacity(map: *Map, additional: u32) void { fn ensure_capacity(map: *Map, additional: u64) void {
if (map.committed_key == 0) {
map.key_pointer = @alignCast(@ptrCast(reserve(pinned_hash_map_max_size) catch unreachable));
map.value_pointer = @alignCast(@ptrCast(reserve(pinned_hash_map_max_size) catch unreachable));
}
const length = map.length; const length = map.length;
assert((length + additional) * @sizeOf(K) <= pinned_array_max_size); assert((length + additional) * @sizeOf(K) <= pinned_array_max_size);
{ {
const key_size = length * @sizeOf(K); const key_size = length * @sizeOf(K);
const key_granularity_aligned_size = align_forward(key_size, map.granularity); const key_granularity_aligned_size = map.committed_key * granularity;
const key_new_size = key_size + additional * @sizeOf(K); const key_new_size = key_size + additional * @sizeOf(K);
if (key_granularity_aligned_size < key_new_size) { if (key_granularity_aligned_size < key_new_size) {
const new_key_granularity_aligned_size = align_forward(key_new_size, map.granularity); const new_key_granularity_aligned_size = align_forward(key_new_size, granularity);
const key_pointer: [*]u8 = @ptrCast(map.key_pointer); const key_pointer: [*]u8 = @ptrCast(map.key_pointer);
commit(key_pointer + key_granularity_aligned_size, new_key_granularity_aligned_size - key_granularity_aligned_size) catch unreachable; const commit_pointer = key_pointer + key_granularity_aligned_size;
const commit_size = new_key_granularity_aligned_size - key_granularity_aligned_size;
commit(commit_pointer, commit_size) catch unreachable;
map.committed_key += @intCast(@divExact(commit_size, granularity));
} }
} }
{ {
const value_size = length * @sizeOf(V); const value_size = length * @sizeOf(V);
const value_granularity_aligned_size = align_forward(value_size, map.granularity); const value_granularity_aligned_size = map.committed_value * granularity;
const value_new_size = value_size + additional * @sizeOf(K); const value_new_size = value_size + additional * @sizeOf(K);
if (value_granularity_aligned_size < value_new_size) { if (value_granularity_aligned_size < value_new_size) {
const new_value_granularity_aligned_size = align_forward(value_new_size, map.granularity); const new_value_granularity_aligned_size = align_forward(value_new_size, granularity);
const value_pointer: [*]u8 = @ptrCast(map.value_pointer); const value_pointer: [*]u8 = @ptrCast(map.value_pointer);
commit(value_pointer + value_granularity_aligned_size, new_value_granularity_aligned_size - value_granularity_aligned_size) catch unreachable; commit(value_pointer + value_granularity_aligned_size, new_value_granularity_aligned_size - value_granularity_aligned_size) catch unreachable;
const commit_pointer = value_pointer + value_granularity_aligned_size;
const commit_size = new_value_granularity_aligned_size - value_granularity_aligned_size;
commit(commit_pointer, commit_size) catch unreachable;
map.committed_value += @intCast(@divExact(commit_size, granularity));
} }
} }
} }
@ -737,3 +764,39 @@ pub fn exit_with_error() noreturn {
@breakpoint(); @breakpoint();
std.posix.exit(1); std.posix.exit(1);
} }
pub fn read_file(arena: *Arena, directory: std.fs.Dir, file_relative_path: []const u8) []const u8 {
const source_file = directory.openFile(file_relative_path, .{}) catch |err| {
const stdout = std.io.getStdOut();
stdout.writeAll("Can't find file ") catch {};
stdout.writeAll(file_relative_path) catch {};
// stdout.writeAll(" in directory ") catch {};
// stdout.writeAll(file.package.directory.path) catch {};
stdout.writeAll(" for error ") catch {};
stdout.writeAll(@errorName(err)) catch {};
@panic("Unrecoverable error");
};
const file_size = source_file.getEndPos() catch unreachable;
var file_buffer = arena.new_array(u8, file_size) catch unreachable;
const read_byte_count = source_file.readAll(file_buffer) catch unreachable;
assert(read_byte_count == file_size);
source_file.close();
//TODO: adjust file maximum size
return file_buffer[0..read_byte_count];
}
pub fn self_exe_path(arena: *Arena) ![]const u8 {
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
return try arena.duplicate_bytes(try std.fs.selfExePath(&buffer));
}
pub fn realpath(arena: *Arena, dir: std.fs.Dir, relative_path: []const u8) ![]const u8 {
var buffer: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const stack_realpath = try dir.realpath(relative_path, &buffer);
const heap_realpath = try arena.new_array(u8, stack_realpath.len);
@memcpy(heap_realpath, stack_realpath);
return heap_realpath;
}

View File

@ -9,6 +9,7 @@ const byte_equal = library.byte_equal;
const configuration = @import("configuration"); const configuration = @import("configuration");
const editor = @import("editor.zig"); const editor = @import("editor.zig");
const compiler = @import("compiler.zig");
const env_detecting_libc_paths = "NATIVITY_IS_DETECTING_LIBC_PATHS"; const env_detecting_libc_paths = "NATIVITY_IS_DETECTING_LIBC_PATHS";
@ -25,49 +26,50 @@ pub fn main() !void {
if (configuration.editor) { if (configuration.editor) {
editor.main(); editor.main();
} else { } else {
var arg_iterator = std.process.ArgIterator.init(); compiler.make();
var buffer = library.BoundedArray([]const u8, 512){}; // var arg_iterator = std.process.ArgIterator.init();
while (arg_iterator.next()) |argument| { // var buffer = library.BoundedArray([]const u8, 512){};
buffer.appendAssumeCapacity(argument); // while (arg_iterator.next()) |argument| {
} // buffer.appendAssumeCapacity(argument);
const arguments = buffer.slice(); // }
const context = try Compilation.createContext(); // const arguments = buffer.slice();
// const context = try Compilation.createContext();
if (arguments.len <= 1) { //
return error.InvalidInput; // if (arguments.len <= 1) {
} // return error.InvalidInput;
// }
if (std.process.can_execv and std.posix.getenvZ(env_detecting_libc_paths) != null) { //
todo(); // if (std.process.can_execv and std.posix.getenvZ(env_detecting_libc_paths) != null) {
} // todo();
// }
const command = arguments[1]; //
const command_arguments = arguments[2..]; // const command = arguments[1];
// const command_arguments = arguments[2..];
if (byte_equal(command, "build")) { //
try Compilation.compileBuildExecutable(context, command_arguments); // if (byte_equal(command, "build")) {
} else if (byte_equal(command, "clang") or byte_equal(command, "-cc1") or byte_equal(command, "-cc1as")) { // try Compilation.compileBuildExecutable(context, command_arguments);
const exit_code = try Compilation.clangMain(context.arena, arguments); // } else if (byte_equal(command, "clang") or byte_equal(command, "-cc1") or byte_equal(command, "-cc1as")) {
std.process.exit(exit_code); // const exit_code = try Compilation.clangMain(context.arena, arguments);
} else if (byte_equal(command, "cc")) { // std.process.exit(exit_code);
try Compilation.compileCSourceFile(context, command_arguments, .c); // } else if (byte_equal(command, "cc")) {
} else if (byte_equal(command, "c++")) { // try Compilation.compileCSourceFile(context, command_arguments, .c);
try Compilation.compileCSourceFile(context, command_arguments, .cpp); // } else if (byte_equal(command, "c++")) {
} else if (byte_equal(command, "exe")) { // try Compilation.compileCSourceFile(context, command_arguments, .cpp);
try Compilation.buildExecutable(context, command_arguments, .{ // } else if (byte_equal(command, "exe")) {
.is_test = false, // try Compilation.buildExecutable(context, command_arguments, .{
}); // .is_test = false,
} else if (byte_equal(command, "lib")) { // });
todo(); // } else if (byte_equal(command, "lib")) {
} else if (byte_equal(command, "obj")) { // todo();
todo(); // } else if (byte_equal(command, "obj")) {
} else if (byte_equal(command, "test")) { // todo();
try Compilation.buildExecutable(context, command_arguments, .{ // } else if (byte_equal(command, "test")) {
.is_test = true, // try Compilation.buildExecutable(context, command_arguments, .{
}); // .is_test = true,
} else { // });
todo(); // } else {
} // todo();
// }
} }
} }

View File

@ -26,10 +26,11 @@ pub fn build(b: *std.Build) !void {
const print_stack_trace = b.option(bool, "print_stack_trace", "This option enables printing stack traces inside the compiler") orelse is_ci; const print_stack_trace = b.option(bool, "print_stack_trace", "This option enables printing stack traces inside the compiler") orelse is_ci;
const native_target = b.resolveTargetQuery(.{}); const native_target = b.resolveTargetQuery(.{});
const optimization = b.standardOptimizeOption(.{}); const optimization = b.standardOptimizeOption(.{});
const use_editor = b.option(bool, "editor", "Use the GUI editor to play around the programming language") orelse !is_ci; const enable_editor = false;
const use_editor = b.option(bool, "editor", "Use the GUI editor to play around the programming language") orelse (!is_ci and enable_editor);
const use_debug = b.option(bool, "use_debug", "This option enables the LLVM debug build in the development PC") orelse false; const use_debug = b.option(bool, "use_debug", "This option enables the LLVM debug build in the development PC") orelse false;
const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) { const static = b.option(bool, "static", "This option enables the compiler to be built statically") orelse switch (@import("builtin").os.tag) {
else => use_debug, else => false,
.windows => true, .windows => true,
// .macos => true, // .macos => true,
}; };
@ -40,7 +41,7 @@ pub fn build(b: *std.Build) !void {
const fetcher = b.addExecutable(.{ const fetcher = b.addExecutable(.{
.name = "llvm_fetcher", .name = "llvm_fetcher",
.root_source_file = .{ .path = "build/fetcher.zig" }, .root_source_file = b.path("build/fetcher.zig"),
.target = native_target, .target = native_target,
.optimize = .Debug, .optimize = .Debug,
.single_threaded = true, .single_threaded = true,
@ -82,18 +83,18 @@ pub fn build(b: *std.Build) !void {
const compiler = b.addExecutable(.{ const compiler = b.addExecutable(.{
.name = "nat", .name = "nat",
.root_source_file = .{ .path = "bootstrap/main.zig" }, .root_source_file = b.path("bootstrap/main.zig"),
.target = target, .target = target,
.optimize = optimization, .optimize = optimization,
}); });
const cpp_files = .{ const cpp_files = .{
"src/llvm/llvm.cpp", "src/llvm/llvm.cpp",
"src/llvm/lld.cpp", // "src/llvm/lld.cpp",
"src/llvm/clang_main.cpp", // "src/llvm/clang_main.cpp",
"src/llvm/clang_cc1.cpp", // "src/llvm/clang_cc1.cpp",
"src/llvm/clang_cc1as.cpp", // "src/llvm/clang_cc1as.cpp",
"src/llvm/ar.cpp", // "src/llvm/ar.cpp",
}; };
compiler.addCSourceFiles(.{ compiler.addCSourceFiles(.{
@ -408,8 +409,8 @@ pub fn build(b: *std.Build) !void {
break :blk llvm_directory.items; break :blk llvm_directory.items;
} else { } else {
break :blk switch (use_debug) { break :blk switch (use_debug) {
true => "../llvm-17-static-debug", true => "../zig-bootstrap/out/x86_64-linux-musl-native-debug-static",
false => "../llvm-17-static-release", false => "../zig-bootstrap/out/x86_64-linux-musl-native-release-static",
}; };
} }
}; };
@ -422,16 +423,16 @@ pub fn build(b: *std.Build) !void {
compiler.addObjectFile(std.Build.path(b, try std.mem.concat(b.allocator, u8, &.{ llvm_lib_dir, "/", llvm_library }))); compiler.addObjectFile(std.Build.path(b, try std.mem.concat(b.allocator, u8, &.{ llvm_lib_dir, "/", llvm_library })));
} }
} else { } else {
compiler.linkSystemLibrary("LLVM-17"); compiler.linkSystemLibrary("LLVM");
compiler.linkSystemLibrary("clang-cpp"); // compiler.linkSystemLibrary("clang-cpp");
compiler.linkSystemLibrary("lldCommon"); // compiler.linkSystemLibrary("lldCommon");
compiler.linkSystemLibrary("lldCOFF"); // compiler.linkSystemLibrary("lldCOFF");
compiler.linkSystemLibrary("lldELF"); // compiler.linkSystemLibrary("lldELF");
compiler.linkSystemLibrary("lldMachO"); // compiler.linkSystemLibrary("lldMachO");
compiler.linkSystemLibrary("lldWasm"); // compiler.linkSystemLibrary("lldWasm");
compiler.linkSystemLibrary("unwind"); // compiler.linkSystemLibrary("unwind");
compiler.linkSystemLibrary(if (is_ci) "z" else "zlib"); // compiler.linkSystemLibrary(if (is_ci) "z" else "zlib");
compiler.linkSystemLibrary("zstd"); // compiler.linkSystemLibrary("zstd");
switch (target.result.os.tag) { switch (target.result.os.tag) {
.linux => { .linux => {
@ -475,11 +476,19 @@ pub fn build(b: *std.Build) !void {
const cxx_include_base = try std.mem.concat(b.allocator, u8, &.{ "/usr/include/c++/", cxx_version }); const cxx_include_base = try std.mem.concat(b.allocator, u8, &.{ "/usr/include/c++/", cxx_version });
const cxx_include_arch = try std.mem.concat(b.allocator, u8, &.{ cxx_include_base, "/" ++ @tagName(@import("builtin").cpu.arch) ++ "-pc-linux-gnu" }); const cxx_include_arch = try std.mem.concat(b.allocator, u8, &.{ cxx_include_base, "/" ++ @tagName(@import("builtin").cpu.arch) ++ "-pc-linux-gnu" });
compiler.addObjectFile(.{ .cwd_relative = "/usr/lib64/libstdc++.so.6" }); compiler.addObjectFile(.{ .cwd_relative = "/usr/lib64/libstdc++.so.6" });
compiler.addIncludePath(.{ .cwd_relative = "/usr/lib64/llvm17/include/" }); if (use_debug) {
compiler.addIncludePath(.{ .cwd_relative = "../../local/llvm18-debug/include" });
} else {
compiler.addIncludePath(.{ .cwd_relative = "../../local/llvm18-release/include" });
}
compiler.addIncludePath(.{ .cwd_relative = "/usr/include" }); compiler.addIncludePath(.{ .cwd_relative = "/usr/include" });
compiler.addIncludePath(.{ .cwd_relative = cxx_include_base }); compiler.addIncludePath(.{ .cwd_relative = cxx_include_base });
compiler.addIncludePath(.{ .cwd_relative = cxx_include_arch }); compiler.addIncludePath(.{ .cwd_relative = cxx_include_arch });
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64/llvm17/lib" }); if (use_debug) {
compiler.addLibraryPath(.{ .cwd_relative = "../../local/llvm18-debug/lib" });
} else {
compiler.addLibraryPath(.{ .cwd_relative = "../../local/llvm18-release/lib" });
}
compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64" }); compiler.addLibraryPath(.{ .cwd_relative = "/usr/lib64" });
} }
}, },
@ -557,6 +566,7 @@ pub fn build(b: *std.Build) !void {
const debug_command = switch (os) { const debug_command = switch (os) {
.linux => blk: { .linux => blk: {
const result = b.addSystemCommand(&.{"gf2"}); const result = b.addSystemCommand(&.{"gf2"});
result.addArgs(&.{ "-ex", "set debuginfod enabled off" });
result.addArgs(&.{ "-ex", "set disassembly-flavor intel" }); result.addArgs(&.{ "-ex", "set disassembly-flavor intel" });
result.addArg("-ex=r"); result.addArg("-ex=r");
result.addArgs(&.{ "-ex", "up" }); result.addArgs(&.{ "-ex", "up" });
@ -581,7 +591,7 @@ pub fn build(b: *std.Build) !void {
const test_runner = b.addExecutable(.{ const test_runner = b.addExecutable(.{
.name = "test_runner", .name = "test_runner",
.root_source_file = .{ .path = "build/test_runner.zig" }, .root_source_file = b.path("build/test_runner.zig"),
.target = native_target, .target = native_target,
.optimize = optimization, .optimize = optimization,
.single_threaded = true, .single_threaded = true,

4
newlib/std/std.nat Normal file
View File

@ -0,0 +1,4 @@
fn[extern] exit(exit_code: s32) noreturn;
fn my_exit(exit_code: s32) noreturn {
exit(exit_code);
}

View File

@ -0,0 +1,4 @@
fn foo() s32
{
return 0;
}

View File

@ -0,0 +1,4 @@
fn [cc(.c)] main [export]() s32
{
return 0;
}

View File

@ -1,10 +1,16 @@
#include "llvm/IR/IRBuilder.h" #include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InlineAsm.h" #include "llvm/IR/InlineAsm.h"
#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/LegacyPassManager.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/IR/Module.h" #include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h" #include "llvm/IR/Verifier.h"
#include "llvm/IR/DIBuilder.h" #include "llvm/IR/DIBuilder.h"
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/ExecutionEngine/Orc/ThreadSafeModule.h"
#include "llvm/Linker/Linker.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/MC/TargetRegistry.h" #include "llvm/MC/TargetRegistry.h"
@ -280,6 +286,13 @@ extern "C" StructType* NativityLLVMGetStructType(LLVMContext& context, Type** ty
auto* struct_type = StructType::get(context, types, is_packed); auto* struct_type = StructType::get(context, types, is_packed);
return struct_type; return struct_type;
} }
extern "C" LLVMContext* NativityLLVMTypeGetContext(Type& type)
{
auto& context = type.getContext();
return &context;
}
extern "C" Function* NativityLLVMModuleGetFunction(Module& module, const char* name_ptr, size_t name_len) extern "C" Function* NativityLLVMModuleGetFunction(Module& module, const char* name_ptr, size_t name_len)
{ {
auto name = StringRef(name_ptr, name_len); auto name = StringRef(name_ptr, name_len);
@ -737,15 +750,14 @@ extern "C" bool NativityLLVMVerifyModule(const Module& module, const char** mess
return !result; return !result;
} }
extern "C" const char* NativityLLVMFunctionToString(const Function& function, size_t* len) extern "C" void NativityLLVMFunctionToString(const Function& function, const char** ptr, size_t* len)
{ {
std::string buf; std::string buf;
raw_string_ostream os(buf); raw_string_ostream os(buf);
function.print(os); function.print(os);
os.flush(); os.flush();
*len = buf.size(); *len = buf.size();
auto* result = strdup(buf.c_str()); *ptr = strdup(buf.c_str());
return result;
} }
extern "C" Type* NativityLLVMAllocatGetAllocatedType(AllocaInst& alloca) extern "C" Type* NativityLLVMAllocatGetAllocatedType(AllocaInst& alloca)
@ -829,26 +841,24 @@ extern "C" Type* NativityLLVMArrayTypeGetElementType(ArrayType* array_type)
return element_type; return element_type;
} }
extern "C" const char* NativityLLVMModuleToString(const Module& module, size_t* len) extern "C" void NativityLLVMModuleToString(const Module& module, const char** ptr, size_t* len)
{ {
std::string buf; std::string buf;
raw_string_ostream os(buf); raw_string_ostream os(buf);
module.print(os, nullptr); module.print(os, nullptr);
os.flush(); os.flush();
*len = buf.size(); *len = buf.size();
auto* result = strdup(buf.c_str()); *ptr = strdup(buf.c_str());
return result;
} }
extern "C" const char* NativityLLVMValueToString(const Value& value, size_t* len) extern "C" void NativityLLVMValueToString(const Value& value, const char** ptr, size_t* len)
{ {
std::string buf; std::string buf;
raw_string_ostream os(buf); raw_string_ostream os(buf);
value.print(os, true); value.print(os, true);
os.flush(); os.flush();
*len = buf.size(); *len = buf.size();
auto* result = strdup(buf.c_str()); *ptr = strdup(buf.c_str());
return result;
} }
extern "C" BasicBlock* NativityLLVMBuilderGetInsertBlock(IRBuilder<>& builder) extern "C" BasicBlock* NativityLLVMBuilderGetInsertBlock(IRBuilder<>& builder)
@ -910,19 +920,20 @@ extern "C" const Target* NativityLLVMGetTarget(const char* target_triple_ptr, si
return target; return target;
} }
extern "C" TargetMachine* NativityLLVMTargetCreateTargetMachine(Target& target, const char* target_triple_ptr, size_t target_triple_len, const char* cpu_ptr, size_t cpu_len, const char* features_ptr, size_t features_len, Reloc::Model relocation_model, CodeModel::Model maybe_code_model, bool is_code_model_present, CodeGenOpt::Level optimization_level, bool jit) // TODO:
{ // extern "C" TargetMachine* NativityLLVMTargetCreateTargetMachine(Target& target, const char* target_triple_ptr, size_t target_triple_len, const char* cpu_ptr, size_t cpu_len, const char* features_ptr, size_t features_len, Reloc::Model relocation_model, CodeModel::Model maybe_code_model, bool is_code_model_present, CodeGenOpt::Level optimization_level, bool jit)
auto target_triple = StringRef(target_triple_ptr, target_triple_len); // {
auto cpu = StringRef(cpu_ptr, cpu_len); // auto target_triple = StringRef(target_triple_ptr, target_triple_len);
auto features = StringRef(features_ptr, features_len); // auto cpu = StringRef(cpu_ptr, cpu_len);
TargetOptions target_options; // auto features = StringRef(features_ptr, features_len);
std::optional<CodeModel::Model> code_model = std::nullopt; // TargetOptions target_options;
if (is_code_model_present) { // std::optional<CodeModel::Model> code_model = std::nullopt;
code_model = maybe_code_model; // if (is_code_model_present) {
} // code_model = maybe_code_model;
TargetMachine* target_machine = target.createTargetMachine(target_triple, cpu, features, target_options, relocation_model, code_model, optimization_level, jit); // }
return target_machine; // TargetMachine* target_machine = target.createTargetMachine(target_triple, cpu, features, target_options, relocation_model, code_model, optimization_level, jit);
} // return target_machine;
// }
extern "C" void NativityLLVMModuleSetTargetMachineDataLayout(Module& module, TargetMachine& target_machine) extern "C" void NativityLLVMModuleSetTargetMachineDataLayout(Module& module, TargetMachine& target_machine)
{ {