Add forward declarations for functions
This patch adds a forward declaration for every user funciton. This fixes VHDL compile problems if a function calls another before it has been declared.
This commit is contained in:
parent
c1b5424ca6
commit
c8cbac58f5
|
|
@ -529,6 +529,11 @@ static int draw_function(ivl_scope_t scope, ivl_scope_t parent)
|
||||||
}
|
}
|
||||||
set_active_entity(NULL);
|
set_active_entity(NULL);
|
||||||
|
|
||||||
|
// Add a forward declaration too in case it is called by
|
||||||
|
// another function that has already been added
|
||||||
|
ent->get_arch()->get_scope()->add_forward_decl
|
||||||
|
(new vhdl_forward_fdecl(func));
|
||||||
|
|
||||||
ent->get_arch()->get_scope()->add_decl(func);
|
ent->get_arch()->get_scope()->add_decl(func);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,11 @@ void vhdl_scope::add_decl(vhdl_decl *decl)
|
||||||
decls_.push_back(decl);
|
decls_.push_back(decl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vhdl_scope::add_forward_decl(vhdl_decl *decl)
|
||||||
|
{
|
||||||
|
decls_.push_front(decl);
|
||||||
|
}
|
||||||
|
|
||||||
vhdl_decl *vhdl_scope::get_decl(const std::string &name) const
|
vhdl_decl *vhdl_scope::get_decl(const std::string &name) const
|
||||||
{
|
{
|
||||||
decl_list_t::const_iterator it;
|
decl_list_t::const_iterator it;
|
||||||
|
|
@ -831,6 +836,16 @@ void vhdl_function::emit(std::ostream &of, int level) const
|
||||||
of << "end function;";
|
of << "end function;";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vhdl_forward_fdecl::emit(std::ostream &of, int level) const
|
||||||
|
{
|
||||||
|
of << "function " << f_->get_name() << " (";
|
||||||
|
emit_children<vhdl_decl>(of, f_->scope_.get_decls(), level, ";");
|
||||||
|
of << ") ";
|
||||||
|
newline(of, level);
|
||||||
|
of << "return " << f_->type_->get_string() << ";";
|
||||||
|
newline(of, level);
|
||||||
|
}
|
||||||
|
|
||||||
void vhdl_param_decl::emit(std::ostream &of, int level) const
|
void vhdl_param_decl::emit(std::ostream &of, int level) const
|
||||||
{
|
{
|
||||||
of << name_ << " : ";
|
of << name_ << " : ";
|
||||||
|
|
|
||||||
|
|
@ -608,6 +608,7 @@ public:
|
||||||
~vhdl_scope();
|
~vhdl_scope();
|
||||||
|
|
||||||
void add_decl(vhdl_decl *decl);
|
void add_decl(vhdl_decl *decl);
|
||||||
|
void add_forward_decl(vhdl_decl *decl);
|
||||||
vhdl_decl *get_decl(const std::string &name) const;
|
vhdl_decl *get_decl(const std::string &name) const;
|
||||||
bool have_declared(const std::string &name) const;
|
bool have_declared(const std::string &name) const;
|
||||||
bool contained_within(const vhdl_scope *other) const;
|
bool contained_within(const vhdl_scope *other) const;
|
||||||
|
|
@ -647,6 +648,7 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
class vhdl_function : public vhdl_decl, public vhdl_procedural {
|
class vhdl_function : public vhdl_decl, public vhdl_procedural {
|
||||||
|
friend class vhdl_forward_fdecl;
|
||||||
public:
|
public:
|
||||||
vhdl_function(const char *name, vhdl_type *ret_type);
|
vhdl_function(const char *name, vhdl_type *ret_type);
|
||||||
|
|
||||||
|
|
@ -657,6 +659,16 @@ private:
|
||||||
vhdl_scope variables_;
|
vhdl_scope variables_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class vhdl_forward_fdecl : public vhdl_decl {
|
||||||
|
public:
|
||||||
|
vhdl_forward_fdecl(const vhdl_function *f)
|
||||||
|
: vhdl_decl((f->get_name() + "_Forward").c_str()), f_(f) {}
|
||||||
|
|
||||||
|
void emit(std::ostream &of, int level) const;
|
||||||
|
private:
|
||||||
|
const vhdl_function *f_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class vhdl_process : public vhdl_conc_stmt, public vhdl_procedural {
|
class vhdl_process : public vhdl_conc_stmt, public vhdl_procedural {
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue