vhdlpp: Subprograms are linked to Package instead of generic Scope.

This commit is contained in:
Maciej Suminski 2016-02-24 10:19:20 +01:00
parent 78d6ee26dd
commit 94f7504372
6 changed files with 18 additions and 23 deletions

View File

@ -53,6 +53,7 @@ int Package::elaborate()
for(SubHeaderList::iterator it = subp_list.begin(); for(SubHeaderList::iterator it = subp_list.begin();
it != subp_list.end(); ++it) { it != subp_list.end(); ++it) {
(*it)->set_package(this);
errors += (*it)->elaborate(); errors += (*it)->elaborate();
} }
} }

View File

@ -317,11 +317,8 @@ SubprogramHeader*ScopeBase::match_subprogram(perm_string name,
return NULL; return NULL;
} }
void ActiveScope::set_package_header(Package*pkg)
void ScopeBase::generate_name() void ScopeBase::generate_name()
{ {
assert(package_header_ == 0);
package_header_ = pkg;
char buf[64]; char buf[64];
// Generate a name for the scope // Generate a name for the scope

View File

@ -101,6 +101,11 @@ class ScopeBase {
perm_string peek_name() const { return name_; } perm_string peek_name() const { return name_; }
void set_package_header(Package*pkg) {
assert(package_header_ == 0);
package_header_ = pkg;
}
protected: protected:
void cleanup(); void cleanup();
@ -158,6 +163,10 @@ class ScopeBase {
void do_use_from(const ScopeBase*that); void do_use_from(const ScopeBase*that);
// If this is a package body, then there is a Package header
// already declared.
Package*package_header_;
// Generates an unique name for the scope // Generates an unique name for the scope
void generate_name(); void generate_name();
@ -193,8 +202,6 @@ class ActiveScope : public ScopeBase {
~ActiveScope() { } ~ActiveScope() { }
void set_package_header(Package*);
// Pull items from "that" scope into "this" scope as is // Pull items from "that" scope into "this" scope as is
// defined by a "use" directive. The parser uses this method // defined by a "use" directive. The parser uses this method
// to implement the "use <pkg>::*" directive. // to implement the "use <pkg>::*" directive.
@ -276,10 +283,6 @@ class ActiveScope : public ScopeBase {
std::map<perm_string,VTypeDef*> incomplete_types; std::map<perm_string,VTypeDef*> incomplete_types;
private: private:
// If this is a package body, then there is a Package header
// already declared.
Package*package_header_;
Entity*context_entity_; Entity*context_entity_;
}; };

View File

@ -88,7 +88,7 @@ void SubprogramBody::write_to_stream(ostream&fd) const
SubprogramHeader::SubprogramHeader(perm_string nam, list<InterfacePort*>*ports, SubprogramHeader::SubprogramHeader(perm_string nam, list<InterfacePort*>*ports,
const VType*return_type) const VType*return_type)
: name_(nam), ports_(ports), return_type_(return_type), body_(NULL), parent_(NULL) : name_(nam), ports_(ports), return_type_(return_type), body_(NULL), package_(NULL)
{ {
} }
@ -172,12 +172,6 @@ const VType*SubprogramHeader::peek_param_type(int idx) const
return NULL; return NULL;
} }
void SubprogramHeader::set_parent(const ScopeBase*par)
{
ivl_assert(*this, !parent_);
parent_ = par;
}
bool SubprogramHeader::unbounded() const { bool SubprogramHeader::unbounded() const {
if(return_type_ && return_type_->is_unbounded()) if(return_type_ && return_type_->is_unbounded())
return true; return true;
@ -263,7 +257,7 @@ SubprogramHeader*SubprogramHeader::make_instance(std::vector<Expression*> argume
} }
body_inst->set_statements(body_->statements_); body_inst->set_statements(body_->statements_);
instance->set_parent(scope); instance->set_package(package_);
instance->set_body(body_inst); instance->set_body(body_inst);
instance->fix_return_type(); instance->fix_return_type();
} }

View File

@ -31,6 +31,7 @@
class InterfacePort; class InterfacePort;
class SequentialStmt; class SequentialStmt;
class Package;
class VType; class VType;
class SubprogramBody : public LineInfo, public ScopeBase { class SubprogramBody : public LineInfo, public ScopeBase {
@ -78,8 +79,8 @@ class SubprogramHeader : public LineInfo {
const VType*peek_param_type(int idx) const; const VType*peek_param_type(int idx) const;
const VType*peek_return_type() const { return return_type_; } const VType*peek_return_type() const { return return_type_; }
void set_parent(const ScopeBase*par); inline void set_package(const Package*pkg) { assert(!package_); package_ = pkg; }
inline const ScopeBase*get_parent() const { return parent_; } inline const Package*get_package() const { return package_; }
// Checks if either return type or parameters are unbounded vectors. // Checks if either return type or parameters are unbounded vectors.
bool unbounded() const; bool unbounded() const;
@ -138,7 +139,7 @@ class SubprogramHeader : public LineInfo {
std::list<InterfacePort*>*ports_; std::list<InterfacePort*>*ports_;
const VType*return_type_; const VType*return_type_;
SubprogramBody*body_; SubprogramBody*body_;
const ScopeBase*parent_; const Package*package_;
}; };
// Class to define functions headers defined in the standard VHDL libraries. // Class to define functions headers defined in the standard VHDL libraries.

View File

@ -107,10 +107,9 @@ int SubprogramHeader::emit_full_name(const std::vector<Expression*>&argv,
// the SV elaborator finds the correct VHDL elaborated // the SV elaborator finds the correct VHDL elaborated
// definition. It should not be emitted only if we call another // definition. It should not be emitted only if we call another
// function from the same package. // function from the same package.
const Package*pkg = dynamic_cast<const Package*>(parent_);
const SubprogramBody*subp = dynamic_cast<const SubprogramBody*>(scope); const SubprogramBody*subp = dynamic_cast<const SubprogramBody*>(scope);
if (pkg != 0 && (!subp || !subp->header() || subp->header()->get_parent() != pkg)) if (package_ && (!subp || !subp->header() || subp->header()->get_package() != package_))
out << "\\" << pkg->name() << " ::"; out << "\\" << package_->name() << " ::";
return emit_name(argv, out, ent, scope); return emit_name(argv, out, ent, scope);
} }