28 #include "ast_visitor.h"
39 std::shared_ptr<Function> m_function;
42 int m_start_temp_vreg, m_next_temp_vreg;
44 std::map<std::string, int> m_strmap;
46 std::string m_return_label_name;
62 void generate(
const std::shared_ptr<Function> &
function);
67 std::shared_ptr<InstructionSequence>
get_hl_iseq() {
return m_function->get_hl_iseq(); }
94 std::string next_label();
99 Operand to_rvalue(
Operand operand,
const std::shared_ptr<Type> &type);
101 Operand get_indirect_field_ref(
Operand ptr_to_struct,
unsigned field_offset);
Base class for AST visitors.
Definition: ast_visitor.h:7
A HighLevelCodegen visitor generates high-level IR code for a single function definition.
Definition: highlevel_codegen.h:36
virtual void visit_function_call_expression(Node *n)
Visit a Node with the AST_FUNCTION_CALL_EXPRESSION tag value.
Definition: highlevel_codegen.cpp:489
virtual void visit_do_while_statement(Node *n)
Visit a Node with the AST_DO_WHILE_STATEMENT tag value.
Definition: highlevel_codegen.cpp:258
virtual void visit_return_expression_statement(Node *n)
Visit a Node with the AST_RETURN_EXPRESSION_STATEMENT tag value.
Definition: highlevel_codegen.cpp:200
virtual void visit_indirect_field_ref_expression(Node *n)
Visit a Node with the AST_INDIRECT_FIELD_REF_EXPRESSION tag value.
Definition: highlevel_codegen.cpp:573
virtual void visit_array_element_ref_expression(Node *n)
Visit a Node with the AST_ARRAY_ELEMENT_REF_EXPRESSION tag value.
Definition: highlevel_codegen.cpp:604
int get_next_label_num() const
Get the next unused control-flow label number.
Definition: highlevel_codegen.h:71
virtual void visit_literal_value(Node *n)
Visit a Node with the AST_LITERAL_VALUE tag value.
Definition: highlevel_codegen.cpp:669
virtual void visit_for_statement(Node *n)
Visit a Node with the AST_FOR_STATEMENT tag value.
Definition: highlevel_codegen.cpp:277
virtual void visit_if_statement(Node *n)
Visit a Node with the AST_IF_STATEMENT tag value.
Definition: highlevel_codegen.cpp:306
virtual void visit_field_ref_expression(Node *n)
Visit a Node with the AST_FIELD_REF_EXPRESSION tag value.
Definition: highlevel_codegen.cpp:535
virtual void visit_unary_expression(Node *n)
Visit a Node with the AST_UNARY_EXPRESSION tag value.
Definition: highlevel_codegen.cpp:424
void generate(const std::shared_ptr< Function > &function)
Create a high-level InstructionSequence from a function definition AST.
Definition: highlevel_codegen.cpp:97
virtual void visit_function_definition(Node *n)
Visit a Node with the AST_FUNCTION_DEFINITION tag value.
Definition: highlevel_codegen.cpp:112
virtual void visit_statement_list(Node *n)
Visit a Node with the AST_STATEMENT_LIST tag value.
Definition: highlevel_codegen.cpp:167
virtual void visit_return_statement(Node *n)
Visit a Node with the AST_RETURN_STATEMENT tag value.
Definition: highlevel_codegen.cpp:191
virtual void visit_binary_expression(Node *n)
Visit a Node with the AST_BINARY_EXPRESSION tag value.
Definition: highlevel_codegen.cpp:351
virtual void visit_if_else_statement(Node *n)
Visit a Node with the AST_IF_ELSE_STATEMENT tag value.
Definition: highlevel_codegen.cpp:325
virtual void visit_variable_ref(Node *n)
Visit a Node with the AST_VARIABLE_REF tag value.
Definition: highlevel_codegen.cpp:656
HighLevelCodegen(const Options &options, int next_label_num)
Constructor.
Definition: highlevel_codegen.cpp:83
virtual void visit_expression_statement(Node *n)
Visit a Node with the AST_EXPRESSION_STATEMENT tag value.
Definition: highlevel_codegen.cpp:180
virtual void visit_while_statement(Node *n)
Visit a Node with the AST_WHILE_STATEMENT tag value.
Definition: highlevel_codegen.cpp:234
std::shared_ptr< InstructionSequence > get_hl_iseq()
Get a shared pointer to the high-level InstructionSequence containing the generated code.
Definition: highlevel_codegen.h:67
virtual void visit_implicit_conversion(Node *n)
Visit a Node with the AST_IMPLICIT_CONVERSION tag value.
Definition: highlevel_codegen.cpp:729
HighLevelOpcode enumeration and associated helper functions and the HighLevelInstructionProperties cl...
InstructionSequence and friends.