wip
This commit is contained in:
parent
c07849aa79
commit
d87bcccfc4
@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <lib.h>
|
#include <lib.h>
|
||||||
|
#include <llvm.h>
|
||||||
|
|
||||||
#define report_error() trap_raw()
|
#define report_error() trap_raw()
|
||||||
|
|
||||||
|
@ -1,5 +1,20 @@
|
|||||||
#include <compiler.h>
|
#include <compiler.h>
|
||||||
|
|
||||||
|
fn void llvm_initialize(Module* module)
|
||||||
|
{
|
||||||
|
llvm_initialize_all();
|
||||||
|
}
|
||||||
|
|
||||||
void emit(Module* module)
|
void emit(Module* module)
|
||||||
{
|
{
|
||||||
|
llvm_initialize(module);
|
||||||
|
auto context = LLVMContextCreate();
|
||||||
|
auto m = llvm_context_create_module(context, module->name);
|
||||||
|
llvm::DIBuilder* di_builder = 0;
|
||||||
|
if (module->has_debug_info)
|
||||||
|
{
|
||||||
|
di_builder = LLVMCreateDIBuilder(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
trap_raw();
|
||||||
}
|
}
|
||||||
|
@ -33,9 +33,9 @@ fn StringRef string_ref(String string)
|
|||||||
return StringRef((char*)string.pointer, string.length);
|
return StringRef((char*)string.pointer, string.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT Module* llvm_context_create_module(LLVMContext& context, String name)
|
EXPORT Module* llvm_context_create_module(LLVMContext* context, String name)
|
||||||
{
|
{
|
||||||
return new Module(string_ref(name), context);
|
return new Module(string_ref(name), *context);
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPORT unsigned llvm_integer_type_get_bit_count(const IntegerType& integer_type)
|
EXPORT unsigned llvm_integer_type_get_bit_count(const IntegerType& integer_type)
|
||||||
|
22
src/llvm.h
22
src/llvm.h
@ -1,9 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <lib.h>
|
#include <lib.h>
|
||||||
|
|
||||||
namespace llvm
|
namespace llvm
|
||||||
{
|
{
|
||||||
class Type;
|
class Type;
|
||||||
class Value;
|
class Value;
|
||||||
|
class Module;
|
||||||
|
class Builder;
|
||||||
|
class DIBuilder;
|
||||||
|
class LLVMContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bool llvm_initialized = false;
|
fn bool llvm_initialized = false;
|
||||||
@ -19,6 +25,11 @@ extern "C" String llvm_default_target_triple();
|
|||||||
extern "C" String llvm_host_cpu_name();
|
extern "C" String llvm_host_cpu_name();
|
||||||
extern "C" String llvm_host_cpu_features();
|
extern "C" String llvm_host_cpu_features();
|
||||||
|
|
||||||
|
extern "C" llvm::LLVMContext* LLVMContextCreate();
|
||||||
|
extern "C" llvm::Module* llvm_context_create_module(llvm::LLVMContext* context, String name);
|
||||||
|
extern "C" llvm::Builder* LLVMCreateBuilderInContext(llvm::LLVMContext* context, String name);
|
||||||
|
extern "C" llvm::DIBuilder* LLVMCreateDIBuilder(llvm::Module* module);
|
||||||
|
|
||||||
struct LLVMGlobal
|
struct LLVMGlobal
|
||||||
{
|
{
|
||||||
String host_triple;
|
String host_triple;
|
||||||
@ -28,9 +39,10 @@ struct LLVMGlobal
|
|||||||
|
|
||||||
global_variable LLVMGlobal llvm_global;
|
global_variable LLVMGlobal llvm_global;
|
||||||
|
|
||||||
fn void initialize_all()
|
fn void llvm_initialize_all_raw()
|
||||||
{
|
{
|
||||||
assert(!llvm_initialized);
|
assert(!llvm_initialized);
|
||||||
|
|
||||||
LLVMInitializeX86TargetInfo();
|
LLVMInitializeX86TargetInfo();
|
||||||
LLVMInitializeX86Target();
|
LLVMInitializeX86Target();
|
||||||
LLVMInitializeX86TargetMC();
|
LLVMInitializeX86TargetMC();
|
||||||
@ -44,3 +56,11 @@ fn void initialize_all()
|
|||||||
.host_cpu_features = llvm_host_cpu_features(),
|
.host_cpu_features = llvm_host_cpu_features(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn void llvm_initialize_all()
|
||||||
|
{
|
||||||
|
if (!llvm_initialized)
|
||||||
|
{
|
||||||
|
llvm_initialize_all_raw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user