Support procedure call generation for $display

This commit is contained in:
Nick Gasson 2008-06-04 13:27:42 +01:00
parent 94006cb44c
commit dd30c1b39d
3 changed files with 88 additions and 1 deletions

View File

@ -53,7 +53,13 @@ static int draw_stask_display(vhdl_process *proc, ivl_statement_t stmt)
// TODO: Write the data into the line // TODO: Write the data into the line
// TODO: Write_Line(Output, Verilog_Display_Line) // Write_Line(Output, Verilog_Display_Line)
vhdl_var_ref *output_ref = new vhdl_var_ref("Output");
vhdl_var_ref *line_ref = new vhdl_var_ref(display_line);
vhdl_pcall_stmt *write_line = new vhdl_pcall_stmt("Write_Line");
write_line->add_expr(output_ref);
write_line->add_expr(line_ref);
proc->add_stmt(write_line);
return 0; return 0;
} }

View File

@ -283,3 +283,40 @@ void vhdl_var_decl::emit(std::ofstream &of, int level) const
of << ";"; of << ";";
emit_comment(of, level, true); emit_comment(of, level, true);
} }
void vhdl_expr_list::add_expr(vhdl_expr *e)
{
exprs_.push_back(e);
}
vhdl_expr_list::~vhdl_expr_list()
{
delete_children<vhdl_expr>(exprs_);
}
void vhdl_expr_list::emit(std::ofstream &of, int level) const
{
of << "(";
int size = exprs_.size();
std::list<vhdl_expr*>::const_iterator it;
for (it = exprs_.begin(); it != exprs_.end(); ++it) {
(*it)->emit(of, level);
if (--size > 0)
of << ", ";
}
of << ")";
}
void vhdl_pcall_stmt::emit(std::ofstream &of, int level) const
{
of << name_;
exprs_.emit(of, level);
of << ";";
}
void vhdl_var_ref::emit(std::ofstream &of, int level) const
{
of << name_;
}

View File

@ -65,6 +65,34 @@ private:
std::string name_; std::string name_;
}; };
class vhdl_expr : public vhdl_element {
public:
virtual ~vhdl_expr() {}
};
/*
* A normal scalar variable reference.
*/
class vhdl_var_ref : public vhdl_expr {
public:
vhdl_var_ref(const char *name) : name_(name) {}
void emit(std::ofstream &of, int level) const;
private:
std::string name_;
};
class vhdl_expr_list : public vhdl_element {
public:
~vhdl_expr_list();
void emit(std::ofstream &of, int level) const;
void add_expr(vhdl_expr *e);
private:
std::list<vhdl_expr*> exprs_;
};
/* /*
* A concurrent statement appears in architecture bodies but not * A concurrent statement appears in architecture bodies but not
* processes. * processes.
@ -98,6 +126,22 @@ public:
}; };
/*
* A procedure call. Which is a statement, unlike a function
* call which is an expression.
*/
class vhdl_pcall_stmt : public vhdl_seq_stmt {
public:
vhdl_pcall_stmt(const char *name) : name_(name) {}
void emit(std::ofstream &of, int level) const;
void add_expr(vhdl_expr *e) { exprs_.add_expr(e); }
private:
std::string name_;
vhdl_expr_list exprs_;
};
/* /*
* A declaration of some sort (variable, component, etc.). * A declaration of some sort (variable, component, etc.).
* Declarations have names, which is the identifier of the variable, * Declarations have names, which is the identifier of the variable,