vhdlpp: Skip package name emission when calling functions from the same package.

This commit is contained in:
Maciej Suminski 2016-01-22 11:55:53 +01:00
parent f1c07b86a3
commit 3b165a5f25
4 changed files with 37 additions and 23 deletions

View File

@ -625,16 +625,7 @@ int ExpFunc::emit(ostream&out, Entity*ent, ScopeBase*scope) const
return 1;
}
// If this function has an elaborated definition, and if
// that definition is in a package, then include the
// package name as a scope qualifier. This assures that
// the SV elaborator finds the correct VHDL elaborated
// definition.
const Package*pkg = dynamic_cast<const Package*> (def_->get_parent());
if (pkg != 0)
out << "\\" << pkg->name() << " ::";
errors += def_->emit_name(argv_, out, ent, scope);
def_->emit_full_name(argv_, out, ent, scope);
out << " (";
def_->emit_args(argv_, out, ent, scope);
out << ")";

View File

@ -210,26 +210,27 @@ void VariableSeqAssignment::write_to_stream(ostream&fd)
int ProcedureCall::emit(ostream&out, Entity*ent, ScopeBase*scope)
{
int errors = 0;
std::vector<Expression*>params;
vector<Expression*>argv;
if(!def_) {
cerr << get_fileline() << ": error: unknown procedure: " << name_ << endl;
return 1;
}
// Convert the parameter list to vector
if(param_list_) {
params.reserve(param_list_->size());
argv.reserve(param_list_->size());
for(std::list<named_expr_t*>::iterator it = param_list_->begin();
it != param_list_->end(); ++it)
params.push_back((*it)->expr());
argv.push_back((*it)->expr());
}
const Package*pkg = dynamic_cast<const Package*> (def_->get_parent());
if (pkg != 0)
out << "\\" << pkg->name() << " ::";
errors += def_->emit_name(params, out, ent, scope);
def_->emit_full_name(argv, out, ent, scope);
out << " (";
if(param_list_) {
errors += def_->emit_args(params, out, ent, scope);
}
if(param_list_)
errors += def_->emit_args(argv, out, ent, scope);
out << ");" << endl;
return errors;

View File

@ -94,11 +94,15 @@ class SubprogramHeader : public LineInfo {
int elaborate() { return (body_ ? body_->elaborate() : 0); }
// Emits the function name, including the package if required.
int emit_full_name(const std::vector<Expression*>&argv,
std::ostream&out, Entity*, ScopeBase*) const;
// Function name used in the emission step. The main purpose of this
// method is to handle functions offered by standard VHDL libraries.
// Allows to return different function names depending on the arguments
// (think of size casting or signed/unsigned functions).
virtual int emit_name(const std::vector<Expression*>&,
virtual int emit_name(const std::vector<Expression*>&argv,
std::ostream&out, Entity*, ScopeBase*) const;
// Emit arguments for a specific call. It allows to reorder or skip

View File

@ -21,6 +21,7 @@
# include "subprogram.h"
# include "sequential.h"
# include "vtype.h"
# include "package.h"
# include <iostream>
using namespace std;
@ -97,6 +98,23 @@ int SubprogramHeader::emit_package(ostream&fd) const
return errors;
}
int SubprogramHeader::emit_full_name(const std::vector<Expression*>&argv,
std::ostream&out, Entity*ent, ScopeBase*scope) const
{
// If this function has an elaborated definition, and if
// that definition is in a package, then include the
// package name as a scope qualifier. This assures that
// the SV elaborator finds the correct VHDL elaborated
// definition. It should not be emitted only if we call another
// function from the same package.
const Package*pkg = dynamic_cast<const Package*>(parent_);
const SubprogramBody*subp = dynamic_cast<const SubprogramBody*>(scope);
if (pkg != 0 && (!subp || !subp->header() || subp->header()->get_parent() != pkg))
out << "\\" << pkg->name() << " ::";
return emit_name(argv, out, ent, scope);
}
int SubprogramHeader::emit_name(const std::vector<Expression*>&,
std::ostream&out, Entity*, ScopeBase*) const
{