#pragma once #include #include #include #include #include "instruction.hpp" #include "mangler.hpp" struct ast; using ast_ptr = std::unique_ptr; struct global_function { std::string name; std::vector params; ast_ptr body; std::vector instructions; llvm::Function* generated_function; global_function(std::string n, std::vector 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_function_ptr = std::unique_ptr; struct global_constructor { std::string name; int8_t tag; size_t arity; global_constructor(std::string n, int8_t t, size_t a) : name(std::move(n)), tag(t), arity(a) {} void generate_llvm(llvm_context& ctx); }; using global_constructor_ptr = std::unique_ptr; class global_scope { private: std::vector functions; std::vector constructors; mangler* mng; public: global_scope(mangler& m) : mng(&m) {} global_function& add_function( const std::string& n, std::vector ps, ast_ptr b); global_constructor& add_constructor(const std::string& n, int8_t t, size_t a); void compile(); void generate_llvm(llvm_context& ctx); };