9#include <llvm/Support/raw_ostream.h>
10#include <llvm/IR/LLVMContext.h>
11#include <llvm/IR/BasicBlock.h>
12#include <llvm/IR/IRBuilder.h>
13#include <llvm/IR/Function.h>
14#include <llvm/IR/Module.h>
15#include <llvm/IR/Value.h>
16#include <llvm/IR/Type.h>
27 std::vector<AST::StmtPtr>&
stmts;
31 std::unique_ptr<llvm::Module>
module;
32 std::stack<std::map<std::string, llvm::Value*>>
variables;
33 std::map<std::string, std::vector<llvm::Function*>>
functions;
35 std::stack<std::pair<llvm::BasicBlock*, llvm::BasicBlock*>>
loop_blocks;
54 CodeGenerator(std::vector<AST::StmtPtr>& s, std::string lp, std::string fn,
bool id) :
context(),
builder(
context),
module(std::make_unique<llvm::Module>(fn,
context)),
stmts(s),
libs_path(lp),
file_name(fn),
is_debug(id) {
71 module->print(llvm::outs(), nullptr);
330 llvm::Value *
implicitly_cast(llvm::Value *val, llvm::Type *expected_type);
Header file for defining AST tree elements.
Binary expression container.
Chain of objects expression container.
Statement of do-while cycle.
Base class of expression.
Statement of extern calls.
Function calling expression container.
Statement of functions calling.
Statement of functions declaration.
Statement of control flow operator.
Statement of module definition.
Unary expression container.
Statement of import the module.
Statement of assignment of variable.
Statement of variable declaration.
Variable expression container.
Statement of while cycle.
void generate_while_cycle_stmt(AST::WhileCycleStmt &wcs)
Method for generating LLVM IR code for while cycle.
void generate_module_stmt(AST::ModuleStmt &ms)
Method for generating LLVM IR code for module definition.
void generate_do_while_cycle_stmt(AST::DoWhileCycleStmt &dwcs)
Method for generating LLVM IR code for do-while cycle.
void generate_var_asgn_stmt(AST::VarAsgnStmt &vas)
Method for generating LLVM IR code for variable assignment.
llvm::Value * generate_var_expr(AST::VarExpr &ve)
Method for generating LLVM IR code for variable expressions.
void generate_extern_stmt(AST::ExternStmt &es)
Method for generating LLVM IR code for extern calls.
llvm::LLVMContext context
llvm::Type * get_common_type(llvm::Type *left, llvm::Type *right)
Method for getting comon type between two types.
std::string get_mangled_name(std::string base_name)
Method for getting mangled name.
llvm::Value * generate_func_call_expr(AST::FuncCallExpr &fce)
Method for generating LLVM IR code for function calling expressions.
void generate_func_call_stmt(AST::FuncCallStmt &fcs)
Method for generating LLVM IR code for function calling.
void generate_continue_stmt(AST::ContinueStmt &cs)
Method for generating LLVM IR code for continue statement.
void generate_use_module_stmt(AST::UseModuleStmt &ums)
Method for generating LLVM IR code for import the module.
void generate_break_stmt(AST::BreakStmt &bs)
Method for generating LLVM IR code for break statement.
std::vector< PathPart > get_resolved_name(std::string mangled_name)
Method for getting resolved name by mangled name.
void generate_var_decl_stmt(AST::VarDeclStmt &vds)
Method for generating LLVM IR code for variable definition.
void generate_if_else_stmt(AST::IfElseStmt &ies)
Method for generating LLVM IR code for control flow operators.
void generate_return_stmt(AST::ReturnStmt &rs)
Method for generating LLVM IR code for 'return'.
std::stack< std::map< std::string, llvm::Value * > > variables
llvm::Value * generate_literal_expr(AST::Literal &lit)
Method for generating LLVM IR code for literals.
void generate_for_cycle_stmt(AST::ForCycleStmt &fcs)
Method for generating LLVM IR code for for cycle.
std::vector< AST::StmtPtr > & stmts
std::map< std::string, std::vector< llvm::Function * > > functions
CodeGenerator(std::vector< AST::StmtPtr > &s, std::string lp, std::string fn, bool id)
llvm::Value * generate_obj_chain_expr(AST::ChainObjects &co)
Method for generating LLVM IR code for chain of objects expression.
std::unique_ptr< llvm::Module > module
std::stack< std::pair< llvm::BasicBlock *, llvm::BasicBlock * > > loop_blocks
llvm::Value * generate_binary_expr(AST::BinaryExpr &be)
Method for generating LLVM IR code for binary expressions.
llvm::Value * generate_expr(AST::Expr &expr)
Method for generating LLVM IR code for expressions.
void generate_stmt(AST::Stmt &stmt)
Method for generating LLVM IR code for passing statement.
llvm::Value * generate_unary_expr(AST::UnaryExpr &ue)
Method for generating LLVM IR code for unary expressions.
llvm::Value * implicitly_cast(llvm::Value *val, llvm::Type *expected_type)
Method for implicitly cast value to expected type.
std::stack< llvm::Type * > functions_ret_types
llvm::Type * type_to_llvm(AST::Type type)
Method for converting AST::Type to llvm::Type.
void generate_func_decl_stmt(AST::FuncDeclStmt &fds)
Method for generating LLVM IR code for function definition.
std::unique_ptr< llvm::Module > get_module()
Method for getting current LLVM Module.
std::stack< PathPart > current_path
void print_ir()
Method for printing generated LLVM IR code.
void generate()
Method for generating LLVM IR code.
Structure for describing the type.
Structure of part of path to object.
Object
Object from path (module or class).
enum CodeGenerator::PathPart::Object object