blog-static/code/compiler/12/global_scope.hpp

35 lines
922 B
C++
Raw Normal View History

#pragma once
#include <memory>
#include <string>
#include <vector>
#include <llvm/IR/Function.h>
#include "instruction.hpp"
struct ast;
using ast_ptr = std::unique_ptr<ast>;
struct global_definition {
std::string name;
std::vector<std::string> params;
ast_ptr body;
std::vector<instruction_ptr> instructions;
llvm::Function* generated_function;
global_definition(std::string n, std::vector<std::string> ps, ast_ptr b)
: name(std::move(n)), params(std::move(ps)), body(std::move(b)) {}
void compile();
void declare_llvm(llvm_context& ctx);
void generate_llvm(llvm_context& ctx);
};
using global_definition_ptr = std::unique_ptr<global_definition>;
struct global_scope {
std::map<std::string, int> occurence_count;
std::vector<global_definition_ptr> definitions;
global_definition_ptr& add_definition(std::string n, std::vector<std::string> ps, ast_ptr b);
};