2019-11-02 17:53:15 -07:00
|
|
|
#include "llvm_context.hpp"
|
|
|
|
#include <llvm/IR/DerivedTypes.h>
|
|
|
|
|
2019-11-04 18:25:54 -08:00
|
|
|
using namespace llvm;
|
|
|
|
|
2019-11-02 17:53:15 -07:00
|
|
|
void llvm_state::create_types() {
|
2019-11-04 18:25:54 -08:00
|
|
|
stack_type = StructType::create(ctx, "stack");
|
|
|
|
stack_ptr_type = PointerType::getUnqual(stack_type);
|
|
|
|
tag_type = IntegerType::getInt8Ty(ctx);
|
|
|
|
struct_types["node_base"] = StructType::create(ctx, "node_base");
|
|
|
|
struct_types["node_app"] = StructType::create(ctx, "node_app");
|
|
|
|
struct_types["node_num"] = StructType::create(ctx, "node_num");
|
|
|
|
struct_types["node_global"] = StructType::create(ctx, "node_global");
|
|
|
|
struct_types["node_ind"] = StructType::create(ctx, "node_ind");
|
|
|
|
struct_types["node_data"] = StructType::create(ctx, "node_data");
|
|
|
|
node_ptr_type = PointerType::getUnqual(struct_types.at("node_base"));
|
2019-11-02 17:53:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void llvm_state::create_functions() {
|
2019-11-04 18:25:54 -08:00
|
|
|
auto void_type = Type::getVoidTy(ctx);
|
|
|
|
auto sizet_type = IntegerType::getInt64Ty(ctx);
|
|
|
|
functions["stack_init"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_init",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_free"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_free",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_push"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type, node_ptr_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_pop"] = Function::Create(
|
|
|
|
FunctionType::get(node_ptr_type, { stack_ptr_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_peek"] = Function::Create(
|
|
|
|
FunctionType::get(node_ptr_type, { stack_ptr_type, sizet_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_popn"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type, sizet_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_slide"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type, sizet_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_update"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type, sizet_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_alloc"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type, sizet_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_pack"] = Function::Create(
|
|
|
|
FunctionType::get(void_type, { stack_ptr_type, sizet_type, tag_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
|
|
|
functions["stack_split"] = Function::Create(
|
|
|
|
FunctionType::get(node_ptr_type, { stack_ptr_type, sizet_type }, false),
|
|
|
|
Function::LinkageTypes::ExternalLinkage,
|
|
|
|
"stack_push",
|
|
|
|
&module
|
|
|
|
);
|
2019-11-02 17:53:15 -07:00
|
|
|
}
|