|
Nearly CC
An educational compiler skeleton
|
A HighLevelCodegen visitor generates high-level IR code for a single function definition. More...
#include "highlevel_codegen.h"


Public Member Functions | |
| HighLevelCodegen (const Options &options, int next_label_num) | |
| Constructor. More... | |
| void | generate (const std::shared_ptr< Function > &function) |
| Create a high-level InstructionSequence from a function definition AST. More... | |
| std::shared_ptr< InstructionSequence > | get_hl_iseq () |
| Get a shared pointer to the high-level InstructionSequence containing the generated code. More... | |
| int | get_next_label_num () const |
| Get the next unused control-flow label number. More... | |
| virtual void | visit_function_definition (Node *n) |
Visit a Node with the AST_FUNCTION_DEFINITION tag value. More... | |
| virtual void | visit_statement_list (Node *n) |
Visit a Node with the AST_STATEMENT_LIST tag value. More... | |
| virtual void | visit_expression_statement (Node *n) |
Visit a Node with the AST_EXPRESSION_STATEMENT tag value. More... | |
| virtual void | visit_return_statement (Node *n) |
Visit a Node with the AST_RETURN_STATEMENT tag value. More... | |
| virtual void | visit_return_expression_statement (Node *n) |
Visit a Node with the AST_RETURN_EXPRESSION_STATEMENT tag value. More... | |
| virtual void | visit_while_statement (Node *n) |
Visit a Node with the AST_WHILE_STATEMENT tag value. More... | |
| virtual void | visit_do_while_statement (Node *n) |
Visit a Node with the AST_DO_WHILE_STATEMENT tag value. More... | |
| virtual void | visit_for_statement (Node *n) |
Visit a Node with the AST_FOR_STATEMENT tag value. More... | |
| virtual void | visit_if_statement (Node *n) |
Visit a Node with the AST_IF_STATEMENT tag value. More... | |
| virtual void | visit_if_else_statement (Node *n) |
Visit a Node with the AST_IF_ELSE_STATEMENT tag value. More... | |
| virtual void | visit_binary_expression (Node *n) |
Visit a Node with the AST_BINARY_EXPRESSION tag value. More... | |
| virtual void | visit_unary_expression (Node *n) |
Visit a Node with the AST_UNARY_EXPRESSION tag value. More... | |
| virtual void | visit_function_call_expression (Node *n) |
Visit a Node with the AST_FUNCTION_CALL_EXPRESSION tag value. More... | |
| virtual void | visit_field_ref_expression (Node *n) |
Visit a Node with the AST_FIELD_REF_EXPRESSION tag value. More... | |
| virtual void | visit_indirect_field_ref_expression (Node *n) |
Visit a Node with the AST_INDIRECT_FIELD_REF_EXPRESSION tag value. More... | |
| virtual void | visit_array_element_ref_expression (Node *n) |
Visit a Node with the AST_ARRAY_ELEMENT_REF_EXPRESSION tag value. More... | |
| virtual void | visit_variable_ref (Node *n) |
Visit a Node with the AST_VARIABLE_REF tag value. More... | |
| virtual void | visit_literal_value (Node *n) |
Visit a Node with the AST_LITERAL_VALUE tag value. More... | |
| virtual void | visit_implicit_conversion (Node *n) |
Visit a Node with the AST_IMPLICIT_CONVERSION tag value. More... | |
| virtual void | visit (Node *n) |
| Visit given AST Node. More... | |
| virtual void | visit_unit (Node *n) |
Visit a Node with the AST_UNIT tag value. More... | |
| virtual void | visit_variable_declaration (Node *n) |
Visit a Node with the AST_VARIABLE_DECLARATION tag value. More... | |
| virtual void | visit_struct_type (Node *n) |
Visit a Node with the AST_STRUCT_TYPE tag value. More... | |
| virtual void | visit_union_type (Node *n) |
Visit a Node with the AST_UNION_TYPE tag value. More... | |
| virtual void | visit_basic_type (Node *n) |
Visit a Node with the AST_BASIC_TYPE tag value. More... | |
| virtual void | visit_declarator_list (Node *n) |
Visit a Node with the AST_DECLARATOR_LIST tag value. More... | |
| virtual void | visit_named_declarator (Node *n) |
Visit a Node with the AST_NAMED_DECLARATOR tag value. More... | |
| virtual void | visit_pointer_declarator (Node *n) |
Visit a Node with the AST_POINTER_DECLARATOR tag value. More... | |
| virtual void | visit_array_declarator (Node *n) |
Visit a Node with the AST_ARRAY_DECLARATOR tag value. More... | |
| virtual void | visit_function_declaration (Node *n) |
Visit a Node with the AST_FUNCTION_DECLARATION tag value. More... | |
| virtual void | visit_function_parameter_list (Node *n) |
Visit a Node with the AST_FUNCTION_PARAMETER_LIST tag value. More... | |
| virtual void | visit_function_parameter (Node *n) |
Visit a Node with the AST_FUNCTION_PARAMETER tag value. More... | |
| virtual void | visit_empty_statement (Node *n) |
Visit a Node with the AST_EMPTY_STATEMENT tag value. More... | |
| virtual void | visit_struct_type_definition (Node *n) |
Visit a Node with the AST_STRUCT_TYPE_DEFINITION tag value. More... | |
| virtual void | visit_union_type_definition (Node *n) |
Visit a Node with the AST_UNION_TYPE_DEFINITION tag value. More... | |
| virtual void | visit_field_definition_list (Node *n) |
Visit a Node with the AST_FIELD_DEFINITION_LIST tag value. More... | |
| virtual void | visit_postfix_expression (Node *n) |
Visit a Node with the AST_POSTFIX_EXPRESSION tag value. More... | |
| virtual void | visit_conditional_expression (Node *n) |
Visit a Node with the AST_CONDITIONAL_EXPRESSION tag value. More... | |
| virtual void | visit_cast_expression (Node *n) |
Visit a Node with the AST_CAST_EXPRESSION tag value. More... | |
| virtual void | visit_argument_expression_list (Node *n) |
Visit a Node with the AST_ARGUMENT_EXPRESSION_LIST tag value. More... | |
| virtual void | visit_children (Node *n) |
Call visit on each child Node of the given parent Node. More... | |
| virtual void | visit_token (Node *n) |
| This method is called if the Node being visited is a token (terminal symbol). More... | |
A HighLevelCodegen visitor generates high-level IR code for a single function definition.
Code generation is initiated by calling the generate() member function, which in turn visits the function definition AST node.
| HighLevelCodegen::HighLevelCodegen | ( | const Options & | options, |
| int | next_label_num | ||
| ) |
Constructor.
| options | the command-line Options |
| next_label_num | the next value that should be used when generating a control-flow label (this is used to ensure that control-flow labels aren't reused between functions) |
| void HighLevelCodegen::generate | ( | const std::shared_ptr< Function > & | function | ) |
Create a high-level InstructionSequence from a function definition AST.
The resulting InstructionSequence should be stored in the Function object.
| function | shared pointer to the Function object |
|
inline |
Get a shared pointer to the high-level InstructionSequence containing the generated code.
|
inline |
Get the next unused control-flow label number.
|
virtualinherited |
|
virtualinherited |
|
virtualinherited |
|
virtual |
Visit a Node with the AST_ARRAY_ELEMENT_REF_EXPRESSION tag value.
| n | a Node with the AST_ARRAY_ELEMENT_REF_EXPRESSION tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
Visit a Node with the AST_BASIC_TYPE tag value.
| n | a Node with the AST_BASIC_TYPE tag value |
Reimplemented in SemanticAnalysis.
|
virtual |
Visit a Node with the AST_BINARY_EXPRESSION tag value.
| n | a Node with the AST_BINARY_EXPRESSION tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
Visit a Node with the AST_CAST_EXPRESSION tag value.
| n | a Node with the AST_CAST_EXPRESSION tag value |
Reimplemented in SemanticAnalysis.
|
virtualinherited |
|
virtualinherited |
Visit a Node with the AST_CONDITIONAL_EXPRESSION tag value.
| n | a Node with the AST_CONDITIONAL_EXPRESSION tag value |
Reimplemented in SemanticAnalysis.
|
virtualinherited |
Visit a Node with the AST_DECLARATOR_LIST tag value.
| n | a Node with the AST_DECLARATOR_LIST tag value |
Reimplemented in LocalStorageAllocation.
|
virtual |
Visit a Node with the AST_DO_WHILE_STATEMENT tag value.
| n | a Node with the AST_DO_WHILE_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
|
virtual |
Visit a Node with the AST_EXPRESSION_STATEMENT tag value.
| n | a Node with the AST_EXPRESSION_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
|
virtual |
Visit a Node with the AST_FIELD_REF_EXPRESSION tag value.
| n | a Node with the AST_FIELD_REF_EXPRESSION tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_FOR_STATEMENT tag value.
| n | a Node with the AST_FOR_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_FUNCTION_CALL_EXPRESSION tag value.
| n | a Node with the AST_FUNCTION_CALL_EXPRESSION tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
Visit a Node with the AST_FUNCTION_DECLARATION tag value.
| n | a Node with the AST_FUNCTION_DECLARATION tag value |
Reimplemented in SemanticAnalysis.
|
virtual |
Visit a Node with the AST_FUNCTION_DEFINITION tag value.
| n | a Node with the AST_FUNCTION_DEFINITION tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
Visit a Node with the AST_FUNCTION_PARAMETER tag value.
| n | a Node with the AST_FUNCTION_PARAMETER tag value |
Reimplemented in SemanticAnalysis, and LocalStorageAllocation.
|
virtualinherited |
|
virtual |
Visit a Node with the AST_IF_ELSE_STATEMENT tag value.
| n | a Node with the AST_IF_ELSE_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_IF_STATEMENT tag value.
| n | a Node with the AST_IF_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_IMPLICIT_CONVERSION tag value.
| n | a Node with the AST_IMPLICIT_CONVERSION tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_INDIRECT_FIELD_REF_EXPRESSION tag value.
| n | a Node with the AST_INDIRECT_FIELD_REF_EXPRESSION tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_LITERAL_VALUE tag value.
| n | a Node with the AST_LITERAL_VALUE tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
|
virtualinherited |
|
virtualinherited |
Visit a Node with the AST_POSTFIX_EXPRESSION tag value.
| n | a Node with the AST_POSTFIX_EXPRESSION tag value |
Reimplemented in SemanticAnalysis.
|
virtual |
Visit a Node with the AST_RETURN_EXPRESSION_STATEMENT tag value.
| n | a Node with the AST_RETURN_EXPRESSION_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_RETURN_STATEMENT tag value.
| n | a Node with the AST_RETURN_STATEMENT tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_STATEMENT_LIST tag value.
| n | a Node with the AST_STATEMENT_LIST tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
Visit a Node with the AST_STRUCT_TYPE tag value.
| n | a Node with the AST_STRUCT_TYPE tag value |
Reimplemented in SemanticAnalysis.
|
virtualinherited |
Visit a Node with the AST_STRUCT_TYPE_DEFINITION tag value.
| n | a Node with the AST_STRUCT_TYPE_DEFINITION tag value |
Reimplemented in SemanticAnalysis, and LocalStorageAllocation.
|
virtualinherited |
|
virtual |
Visit a Node with the AST_UNARY_EXPRESSION tag value.
| n | a Node with the AST_UNARY_EXPRESSION tag value |
Reimplemented from ASTVisitor.
|
virtualinherited |
Visit a Node with the AST_UNION_TYPE tag value.
| n | a Node with the AST_UNION_TYPE tag value |
Reimplemented in SemanticAnalysis.
|
virtualinherited |
|
virtualinherited |
|
virtualinherited |
Visit a Node with the AST_VARIABLE_DECLARATION tag value.
| n | a Node with the AST_VARIABLE_DECLARATION tag value |
Reimplemented in SemanticAnalysis.
|
virtual |
Visit a Node with the AST_VARIABLE_REF tag value.
| n | a Node with the AST_VARIABLE_REF tag value |
Reimplemented from ASTVisitor.
|
virtual |
Visit a Node with the AST_WHILE_STATEMENT tag value.
| n | a Node with the AST_WHILE_STATEMENT tag value |
Reimplemented from ASTVisitor.