2023-09-27 18:18:05 +00:00
|
|
|
#ifndef wg_COMPILER_HPP
|
|
|
|
#define wg_COMPILER_HPP
|
|
|
|
|
|
|
|
#include <llvm/IR/LLVMContext.h>
|
|
|
|
#include <llvm/IR/IRBuilder.h>
|
|
|
|
#include <llvm/IR/Module.h>
|
|
|
|
|
|
|
|
#include "commons.hpp"
|
|
|
|
#include "Node.hpp"
|
2023-09-28 19:37:10 +00:00
|
|
|
#include "SymTable.hpp"
|
2023-09-29 16:26:05 +00:00
|
|
|
#include "Mod.hpp"
|
2023-09-27 18:18:05 +00:00
|
|
|
|
|
|
|
namespace wg
|
|
|
|
{
|
2023-09-29 16:26:05 +00:00
|
|
|
WG_ERROR(compile_error);
|
|
|
|
|
2023-09-27 18:18:05 +00:00
|
|
|
class Compiler
|
|
|
|
{
|
|
|
|
public:
|
2023-09-29 16:26:05 +00:00
|
|
|
explicit Compiler(Mod& mod);
|
2023-09-27 18:18:05 +00:00
|
|
|
virtual ~Compiler();
|
|
|
|
|
2023-09-28 20:18:03 +00:00
|
|
|
void gen(std::filesystem::path obj);
|
2023-09-29 16:26:05 +00:00
|
|
|
|
|
|
|
void execute(std::shared_ptr<Node> node);
|
|
|
|
void imports(std::shared_ptr<Node> node);
|
|
|
|
void scan(std::shared_ptr<Node> node);
|
2023-09-27 21:05:04 +00:00
|
|
|
llvm::Value* compile(std::shared_ptr<Node> node);
|
2023-09-27 18:18:05 +00:00
|
|
|
|
2023-09-29 16:26:05 +00:00
|
|
|
private:
|
|
|
|
Mod& m_mod;
|
|
|
|
std::unordered_map<std::string, std::unique_ptr<Mod>> m_imports;
|
2023-09-27 18:18:05 +00:00
|
|
|
std::unique_ptr<llvm::IRBuilder<>> m_builder =
|
2023-09-29 16:26:05 +00:00
|
|
|
std::make_unique<llvm::IRBuilder<>>(m_mod.context());
|
2023-09-27 18:18:05 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|