62 lines
2.1 KiB
C++
62 lines
2.1 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::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;
|
||
|
|
||
|
llvm::Value* get_int32_constant(int value);
|
||
|
llvm::Value* get_int64_constant(int value);
|
||
|
llvm::Value* 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;
|
||
|
llvm::Function* current_function;
|
||
|
public:
|
||
|
llvm::Function* get_supercombinator(const std::string& name);
|
||
|
void add_supercombinator(const std::string& name);
|
||
|
llvm::Function* get_current_function();
|
||
|
void set_current_function(llvm::Function* f);
|
||
|
};
|
||
|
}
|