|
topazc
|
Code generator class. More...
#include <codegen.hpp>
Classes | |
| struct | PathPart |
| Structure of part of path to object. More... | |
Public Member Functions | |
| CodeGenerator (std::vector< AST::StmtPtr > &s, std::string lp, std::string fn, bool id) | |
| void | generate () |
| Method for generating LLVM IR code. | |
| void | print_ir () |
| Method for printing generated LLVM IR code. | |
| std::unique_ptr< llvm::Module > | get_module () |
| Method for getting current LLVM Module. | |
Private Member Functions | |
| void | generate_stmt (AST::Stmt &stmt) |
| Method for generating LLVM IR code for passing statement. | |
| void | generate_var_decl_stmt (AST::VarDeclStmt &vds) |
| Method for generating LLVM IR code for variable definition. | |
| void | generate_var_asgn_stmt (AST::VarAsgnStmt &vas) |
| Method for generating LLVM IR code for variable assignment. | |
| void | generate_func_decl_stmt (AST::FuncDeclStmt &fds) |
| Method for generating LLVM IR code for function definition. | |
| void | generate_func_call_stmt (AST::FuncCallStmt &fcs) |
| Method for generating LLVM IR code for function calling. | |
| void | generate_return_stmt (AST::ReturnStmt &rs) |
| Method for generating LLVM IR code for 'return'. | |
| void | generate_if_else_stmt (AST::IfElseStmt &ies) |
| Method for generating LLVM IR code for control flow operators. | |
| void | generate_while_cycle_stmt (AST::WhileCycleStmt &wcs) |
| Method for generating LLVM IR code for while cycle. | |
| void | generate_do_while_cycle_stmt (AST::DoWhileCycleStmt &dwcs) |
| Method for generating LLVM IR code for do-while cycle. | |
| void | generate_for_cycle_stmt (AST::ForCycleStmt &fcs) |
| Method for generating LLVM IR code for for cycle. | |
| void | generate_break_stmt (AST::BreakStmt &bs) |
| Method for generating LLVM IR code for break statement. | |
| void | generate_continue_stmt (AST::ContinueStmt &cs) |
| Method for generating LLVM IR code for continue statement. | |
| void | generate_module_stmt (AST::ModuleStmt &ms) |
| Method for generating LLVM IR code for module definition. | |
| void | generate_use_module_stmt (AST::UseModuleStmt &ums) |
| Method for generating LLVM IR code for import the module. | |
| void | generate_extern_stmt (AST::ExternStmt &es) |
| Method for generating LLVM IR code for extern calls. | |
| llvm::Value * | generate_expr (AST::Expr &expr) |
| Method for generating LLVM IR code for expressions. | |
| llvm::Value * | generate_literal_expr (AST::Literal &lit) |
| Method for generating LLVM IR code for literals. | |
| llvm::Value * | generate_binary_expr (AST::BinaryExpr &be) |
| Method for generating LLVM IR code for binary expressions. | |
| llvm::Value * | generate_unary_expr (AST::UnaryExpr &ue) |
| Method for generating LLVM IR code for unary expressions. | |
| llvm::Value * | generate_var_expr (AST::VarExpr &ve) |
| Method for generating LLVM IR code for variable expressions. | |
| llvm::Value * | generate_func_call_expr (AST::FuncCallExpr &fce) |
| Method for generating LLVM IR code for function calling expressions. | |
| llvm::Value * | generate_obj_chain_expr (AST::ChainObjects &co) |
| Method for generating LLVM IR code for chain of objects expression. | |
| llvm::Type * | type_to_llvm (AST::Type type) |
| Method for converting AST::Type to llvm::Type. | |
| llvm::Type * | get_common_type (llvm::Type *left, llvm::Type *right) |
| Method for getting comon type between two types. | |
| llvm::Value * | implicitly_cast (llvm::Value *val, llvm::Type *expected_type) |
| Method for implicitly cast value to expected type. | |
| std::string | get_mangled_name (std::string base_name) |
| Method for getting mangled name. | |
| std::vector< PathPart > | get_resolved_name (std::string mangled_name) |
| Method for getting resolved name by mangled name. | |
Private Attributes | |
| std::string | libs_path |
| std::string | file_name |
| std::vector< AST::StmtPtr > & | stmts |
| bool | is_debug |
| llvm::LLVMContext | context |
| llvm::IRBuilder | builder |
| std::unique_ptr< llvm::Module > | module |
| std::stack< std::map< std::string, llvm::Value * > > | variables |
| std::map< std::string, std::vector< llvm::Function * > > | functions |
| std::stack< llvm::Type * > | functions_ret_types |
| std::stack< std::pair< llvm::BasicBlock *, llvm::BasicBlock * > > | loop_blocks |
| std::stack< PathPart > | current_path |
Code generator class.
Definition at line 23 of file codegen.hpp.
|
inline |
Definition at line 54 of file codegen.hpp.
| void CodeGenerator::generate | ( | ) |
Method for generating LLVM IR code.
This method generating LLVM IR code for all AST statements
Definition at line 15 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for binary expressions.
This method generating LLVM IR code for binary expressions and returns it. If type of passed binary operator is unsupported by current version of compiler, then throwing exception
| be | Binary expression for generating |
Definition at line 549 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for break statement.
This method generating LLVM IR code for break statement
| bs | Break statement |
Definition at line 372 of file codegen.cpp.

|
private |
Method for generating LLVM IR code for continue statement.
This method generating LLVM IR code for continue statement
| cs | Continue statement |
Definition at line 376 of file codegen.cpp.

|
private |
Method for generating LLVM IR code for do-while cycle.
This method generating LLVM IR code for do-while cycle
| dwcs | Do-while cycle |
Definition at line 314 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for expressions.
This method generating LLVM IR cide for passing expression. If passed expression is unsupported by current version of compiler, then throwing exception
| expr | Expression for code generating |
Definition at line 497 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for extern calls.
This method generating LLVM IR code for extern calls
| es | Extern calls |
Definition at line 479 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for for cycle.
This method generating LLVM IR code for for cycle
| fcs | For cycle |
Definition at line 338 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for function calling expressions.
This method generating LLVM IR code for function calling expressions and returns it
| fce | Function calling expression for generating |
Definition at line 689 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for function calling.
This method generating LLVM IR code for function calling
| fds | Function calling statement |
Definition at line 197 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for function definition.
This method generating LLVM IR code for function definition
| fds | Function declaration statement |
Definition at line 107 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for control flow operators.
This method generating LLVM IR code for control flow operators
| ies | Control flow operator |
Definition at line 257 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for literals.
This method generating LLVM IR code for literals and returns it. If type of passed literal is TYPE_STRING_LIT, then generating global string variable with value as literal value
| lit | Literal for generating |
Definition at line 521 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for module definition.
This method generating LLVM IR code for module definition
| ms | Module definition statement |
Definition at line 380 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for chain of objects expression.
This method generating LLVM IR code for all expressions in path from chain
| co | Chain of objects expression for generating |
Definition at line 736 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for 'return'.
This method generating LLVM IR code for 'return'
| rs | Return statement |
Definition at line 244 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for passing statement.
This method generating LLVM IR code for passing statement. If passed statement is unsupported by current version of compiler, then throwing exception
| stmt | Statement for code generating |
Definition at line 21 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for unary expressions.
This method generating LLVM IR code for unary expressions and returns it. If type of passed unary operator is unsupported by current version of compiler, then throwing exception
| be | Unary expression for generating |
Definition at line 629 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for import the module.
This method generating LLVM IR code for import the module
| ums | Importing module |
Definition at line 390 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for variable assignment.
This method generating LLVM IR code for variable assignment
| vds | Variable assignment statement |
Definition at line 89 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for variable definition.
This method generating LLVM IR code for variable definition. If variable definition in the global view scope, then generating global variable. Otherwise generating local variable
| vds | Variable declaration statement |
Definition at line 69 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for variable expressions.
This method generating LLVM IR code for variable expressions and returns it
| ve | Variable expression for generating |
Definition at line 665 of file codegen.cpp.


|
private |
Method for generating LLVM IR code for while cycle.
This method generating LLVM IR code for while cycle
| wcs | While cycle |
Definition at line 290 of file codegen.cpp.


|
private |
Method for getting comon type between two types.
This method getting common type between two passed types and returns it. If common type does not exist, then throwing exception
| left | Type to be implicitly cast |
| right | Type to be implicitly cast to |
Definition at line 789 of file codegen.cpp.

|
private |
Method for getting mangled name.
This method returns mangled name based passed object name and CodeGenerator::current_path. Names of parts of path separated '-' (if current part of path is module) or '#' (if current part of path is class)
| base_name | Based name for mangling |
Definition at line 846 of file codegen.cpp.

|
inline |
Method for getting current LLVM Module.
This method returning current LLVM Module. This method needs the entry point 'main'
Definition at line 81 of file codegen.hpp.

|
private |
Method for getting resolved name by mangled name.
This method returns resolved name by passed mangled name
| mangled_name | Mangled name for resolving |
Definition at line 862 of file codegen.cpp.

|
private |
Method for implicitly cast value to expected type.
This method implicitly cast passed value to passed expected type and returns casted value. If cast is imposible, then returns nullptr
| val | Value for casting |
| expected_type | Type to be converted to |
Definition at line 813 of file codegen.cpp.

|
inline |
Method for printing generated LLVM IR code.
This method printing generated LLVM IR code into llvm::outs(). This method needs the entry point 'main'
Definition at line 70 of file codegen.hpp.

|
private |
Method for converting AST::Type to llvm::Type.
This method converting passed AST::Type to llvm::Type and returns it. If type of passed AST::Type is unsupported by current version of compiler, then throwing exception
| type | AST::Type for converting |
Definition at line 753 of file codegen.cpp.


|
private |
LLVM IR Builder
Definition at line 30 of file codegen.hpp.
|
private |
LLVM Context
Definition at line 29 of file codegen.hpp.
|
private |
Stack to current path to some object
Definition at line 51 of file codegen.hpp.
|
private |
Absolute path to the Topaz source code
Definition at line 26 of file codegen.hpp.
|
private |
Functions table
Definition at line 33 of file codegen.hpp.
|
private |
Stack of functions return types
Definition at line 34 of file codegen.hpp.
|
private |
Flag for debug exception
Definition at line 28 of file codegen.hpp.
|
private |
Absolute path to the Topaz libraries
Definition at line 25 of file codegen.hpp.
|
private |
Stack of branches into cycles. First for 'break', second for 'continue'
Definition at line 35 of file codegen.hpp.
|
private |
LLVM Module (module name is relative path to the Topaz source code)
Definition at line 31 of file codegen.hpp.
|
private |
AST Tree (statements from Parser)
Definition at line 27 of file codegen.hpp.
|
private |
View scope of the variables table
Definition at line 32 of file codegen.hpp.