Link LLVM bindings
This commit is contained in:
parent
f24ec2864c
commit
b98727318b
@ -832,6 +832,42 @@ LLVMIntrinsicIndex = enum
|
|||||||
va_copy,
|
va_copy,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[extern] LLVMInitializeX86TargetInfo = fn [cc(c)] () void;
|
||||||
|
[extern] LLVMInitializeX86Target = fn [cc(c)] () void;
|
||||||
|
[extern] LLVMInitializeX86TargetMC = fn [cc(c)] () void;
|
||||||
|
[extern] LLVMInitializeX86AsmPrinter = fn [cc(c)] () void;
|
||||||
|
[extern] LLVMInitializeX86AsmParser = fn [cc(c)] () void;
|
||||||
|
[extern] LLVMInitializeX86Disassembler = fn [cc(c)] () void;
|
||||||
|
|
||||||
|
[extern] llvm_default_target_triple = fn [cc(c)] () []u8;
|
||||||
|
[extern] llvm_host_cpu_name = fn [cc(c)] () []u8;
|
||||||
|
[extern] llvm_host_cpu_features = fn [cc(c)] () []u8;
|
||||||
|
|
||||||
|
host_triple: []u8 = zero;
|
||||||
|
host_cpu_model: []u8 = zero;
|
||||||
|
host_cpu_features: []u8 = zero;
|
||||||
|
|
||||||
|
llvm_targets_initialized: u1 = 0;
|
||||||
|
|
||||||
|
llvm_initialize_targets = fn () void
|
||||||
|
{
|
||||||
|
if (!llvm_targets_initialized)
|
||||||
|
{
|
||||||
|
LLVMInitializeX86TargetInfo();
|
||||||
|
LLVMInitializeX86Target();
|
||||||
|
LLVMInitializeX86TargetMC();
|
||||||
|
LLVMInitializeX86AsmPrinter();
|
||||||
|
LLVMInitializeX86AsmParser();
|
||||||
|
LLVMInitializeX86Disassembler();
|
||||||
|
|
||||||
|
host_triple = llvm_default_target_triple();
|
||||||
|
host_cpu_model = llvm_host_cpu_name();
|
||||||
|
host_cpu_features = llvm_host_cpu_features();
|
||||||
|
|
||||||
|
llvm_targets_initialized = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[extern] LLVMContextCreate = fn [cc(c)] () &LLVMContext;
|
[extern] LLVMContextCreate = fn [cc(c)] () &LLVMContext;
|
||||||
|
|
||||||
ModuleLLVM = struct
|
ModuleLLVM = struct
|
||||||
@ -2614,6 +2650,7 @@ parse = fn (module: &Module) void
|
|||||||
|
|
||||||
emit = fn (module: &Module) void
|
emit = fn (module: &Module) void
|
||||||
{
|
{
|
||||||
|
llvm_initialize_targets();
|
||||||
>context = LLVMContextCreate();
|
>context = LLVMContextCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,9 +179,8 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
};
|
};
|
||||||
Slice<String> object_slice = array_to_slice(objects);
|
Slice<String> object_slice = array_to_slice(objects);
|
||||||
|
|
||||||
String c_abi_libraries[] = {
|
String c_abi_library = string_literal("build/libc_abi.a");
|
||||||
string_literal("build/libc_abi.a"),
|
String llvm_bindings_library = string_literal("build/libllvm_bindings.a");
|
||||||
};
|
|
||||||
Slice<String> library_names = {};
|
Slice<String> library_names = {};
|
||||||
Slice<String> library_paths = {};
|
Slice<String> library_paths = {};
|
||||||
String library_buffer[256];
|
String library_buffer[256];
|
||||||
@ -199,6 +198,7 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
builder.add(arena, arena_join_string(arena, array_to_slice(llvm_config_parts)));
|
builder.add(arena, arena_join_string(arena, array_to_slice(llvm_config_parts)));
|
||||||
builder.add("--libdir");
|
builder.add("--libdir");
|
||||||
builder.add("--libs");
|
builder.add("--libs");
|
||||||
|
builder.add("--system-libs");
|
||||||
auto arguments = builder.flush();
|
auto arguments = builder.flush();
|
||||||
auto llvm_config = os_execute(arena, arguments, environment, {
|
auto llvm_config = os_execute(arena, arguments, environment, {
|
||||||
.policies = { ExecuteStandardStreamPolicy::pipe, ExecuteStandardStreamPolicy::ignore },
|
.policies = { ExecuteStandardStreamPolicy::pipe, ExecuteStandardStreamPolicy::ignore },
|
||||||
@ -226,43 +226,73 @@ fn String compile_file(Arena* arena, Compile options)
|
|||||||
{
|
{
|
||||||
report_error();
|
report_error();
|
||||||
}
|
}
|
||||||
if (line != stream.length - 1)
|
|
||||||
{
|
|
||||||
report_error();
|
|
||||||
}
|
|
||||||
|
|
||||||
auto library_list = stream(0, line);
|
auto llvm_library_stream = stream(0, line);
|
||||||
|
|
||||||
|
stream = stream(line + 1);
|
||||||
|
|
||||||
u64 library_count = 0;
|
u64 library_count = 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
auto space = string_first_character(library_list, ' ');
|
auto space = string_first_character(llvm_library_stream, ' ');
|
||||||
if (space == string_no_match)
|
if (space == string_no_match)
|
||||||
{
|
{
|
||||||
auto library_argument = library_list(2);
|
auto library_argument = llvm_library_stream;
|
||||||
|
library_buffer[library_count] = library_argument(2);
|
||||||
|
library_count += 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Omit the first two characters: "-l"
|
||||||
|
auto library_argument = llvm_library_stream(2, space);
|
||||||
|
library_buffer[library_count] = library_argument;
|
||||||
|
library_count += 1;
|
||||||
|
llvm_library_stream = llvm_library_stream(space + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
line = string_first_character(stream, '\n');
|
||||||
|
if (line == string_no_match)
|
||||||
|
{
|
||||||
|
report_error();
|
||||||
|
}
|
||||||
|
assert(line == stream.length - 1);
|
||||||
|
auto system_library_stream = stream(0, line);
|
||||||
|
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
auto space = string_first_character(system_library_stream, ' ');
|
||||||
|
if (space == string_no_match)
|
||||||
|
{
|
||||||
|
auto library_argument = system_library_stream(2);
|
||||||
library_buffer[library_count] = library_argument;
|
library_buffer[library_count] = library_argument;
|
||||||
library_count += 1;
|
library_count += 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Omit the first two characters: "-l"
|
// Omit the first two characters: "-l"
|
||||||
auto library_argument = library_list(2, space);
|
auto library_argument = system_library_stream(2, space);
|
||||||
library_buffer[library_count] = library_argument;
|
library_buffer[library_count] = library_argument;
|
||||||
library_count += 1;
|
library_count += 1;
|
||||||
library_list = library_list(space + 1);
|
system_library_stream = system_library_stream(space + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
library_buffer[library_count] = string_literal("gcc");
|
library_buffer[library_count] = string_literal("gcc");
|
||||||
library_count += 1;
|
library_count += 1;
|
||||||
library_buffer[library_count] = string_literal("gcc_s");
|
library_buffer[library_count] = string_literal("gcc_s");
|
||||||
library_count += 1;
|
library_count += 1;
|
||||||
library_buffer[library_count] = string_literal("m");
|
|
||||||
|
library_buffer[library_count] = string_literal("lldCommon");
|
||||||
|
library_count += 1;
|
||||||
|
library_buffer[library_count] = string_literal("lldELF");
|
||||||
library_count += 1;
|
library_count += 1;
|
||||||
|
|
||||||
library_names = { library_buffer, library_count };
|
library_names = { library_buffer, library_count };
|
||||||
|
library_paths = { &llvm_bindings_library, 1 };
|
||||||
}
|
}
|
||||||
else if (base_name.equal(string_literal("c_abi")))
|
else if (base_name.equal(string_literal("c_abi")))
|
||||||
{
|
{
|
||||||
library_paths = array_to_slice(c_abi_libraries);
|
library_paths = { &c_abi_library, 1 };
|
||||||
}
|
}
|
||||||
|
|
||||||
compile(arena, {
|
compile(arena, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user