lily/src/llvm.hpp

71 lines
2.5 KiB
C++

#pragma once
#include <map>
#include <vector>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/IRBuilder.h>
namespace lily {
extern llvm::LLVMContext context;
extern llvm::IRBuilder<> builder;
extern llvm::Module module;
extern llvm::StructType* stack_type;
extern llvm::PointerType* stack_pointer_type;
extern llvm::FunctionType* supercomb_function_type;
extern llvm::FunctionType* eval_function_type;
extern llvm::PointerType* supercomb_function_pointer_type;
extern llvm::Function* stack_init_func;
extern llvm::Function* stack_free_func;
extern llvm::Function* stack_push_func;
extern llvm::Function* stack_peek_func;
extern llvm::Function* stack_pop_func;
extern llvm::Function* stack_popn_func;
extern llvm::Function* stack_update_func;
extern llvm::Function* stack_alloc_func;
extern llvm::Function* stack_slide_func;
extern llvm::Function* stack_size_func;
extern llvm::Function* malloc_node_num_func;
extern llvm::Function* malloc_node_app_func;
extern llvm::Function* malloc_node_global_func;
extern llvm::Function* malloc_node_ind_func;
extern llvm::Function* malloc_node_data_func;
extern llvm::Function* pack_func;
extern llvm::Function* split_func;
extern llvm::Function* eval_func;
extern llvm::IntegerType* tag_type;
extern llvm::PointerType* node_pointer_type;
extern llvm::StructType* node_parent_type;
extern llvm::StructType* node_num_type;
extern llvm::StructType* node_app_type;
extern llvm::StructType* node_global_type;
extern llvm::StructType* node_indirect_type;
extern llvm::StructType* node_data_type;
llvm::ConstantInt* get_int32_constant(int value);
llvm::ConstantInt* get_int64_constant(int value);
llvm::ConstantInt* get_int8_constant(char value);
void llvm_init();
void llvm_generate(const std::string& filename);
class llvm_context {
private:
std::map<std::string, llvm::Function*> supercombinators;
std::map<std::string, int> arities;
llvm::Function* current_function;
public:
void add_supercombinator(const std::string& name, int arity);
llvm::Function* get_supercombinator_function(const std::string& name);
int get_supercombinator_arity(const std::string& name);
llvm::Function* get_current_function();
void set_current_function(llvm::Function* f);
};
}