Elaborate VHDL entity port types/expressions.
We need to elaborate expressions so that function calls in expressions (i.e. ranges) get bound to their proper scope. This binding is in turn used to emit package scopes. This is particularly interesting for ports of entities.
This commit is contained in:
parent
3d5765949e
commit
d630e4dfe9
|
|
@ -59,14 +59,17 @@ LIBS = @LIBS@ @EXTRALIBS@
|
|||
M = StringHeap.o LineInfo.o
|
||||
|
||||
O = main.o architec.o compiler.o entity.o \
|
||||
expression.o package.o scope.o sequential.o vsignal.o vtype.o \
|
||||
expression.o package.o scope.o sequential.o subprogram.o vsignal.o vtype.o \
|
||||
vtype_match.o \
|
||||
architec_elaborate.o entity_elaborate.o expression_elaborate.o \
|
||||
expression_evaluate.o \
|
||||
sequential_elaborate.o \
|
||||
vtype_elaborate.o \
|
||||
entity_stream.o expression_stream.o vtype_stream.o \
|
||||
lexor.o lexor_keyword.o parse.o \
|
||||
parse_misc.o library.o vhdlreal.o vhdlint.o \
|
||||
architec_emit.o entity_emit.o expression_emit.o sequential_emit.o vtype_emit.o \
|
||||
architec_emit.o entity_emit.o expression_emit.o package_emit.o \
|
||||
sequential_emit.o subprogram_emit.o vtype_emit.o \
|
||||
debug.o architec_debug.o expression_debug.o sequential_debug.o \
|
||||
$M
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -113,6 +114,10 @@ int Entity::elaborate_ports_(void)
|
|||
continue;
|
||||
}
|
||||
|
||||
// Elaborate the type to elaborate any expressions that
|
||||
// are used by the types.
|
||||
errors += type->elaborate(this, bind_arch_);
|
||||
|
||||
VType::decl_t cur_decl;
|
||||
cur_decl.type = type;
|
||||
declarations_[cur_port->name] = cur_decl;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -260,12 +261,12 @@ ExpEdge::~ExpEdge()
|
|||
}
|
||||
|
||||
ExpFunc::ExpFunc(perm_string nn)
|
||||
: name_(nn), argv_(0)
|
||||
: name_(nn), def_(0)
|
||||
{
|
||||
}
|
||||
|
||||
ExpFunc::ExpFunc(perm_string nn, list<Expression*>*args)
|
||||
: name_(nn), argv_(args->size())
|
||||
: name_(nn), argv_(args->size()), def_(0)
|
||||
{
|
||||
for (size_t idx = 0; idx < argv_.size() ; idx += 1) {
|
||||
ivl_assert(*this, !args->empty());
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __expression_H
|
||||
#define __expression_H
|
||||
/*
|
||||
* Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -31,6 +32,7 @@ class prange_t;
|
|||
class Entity;
|
||||
class Architecture;
|
||||
class ScopeBase;
|
||||
class Subprogram;
|
||||
class VType;
|
||||
class VTypeArray;
|
||||
class VTypePrimitive;
|
||||
|
|
@ -474,6 +476,7 @@ class ExpFunc : public Expression {
|
|||
private:
|
||||
perm_string name_;
|
||||
std::vector<Expression*> argv_;
|
||||
Subprogram*def_;
|
||||
};
|
||||
|
||||
class ExpInteger : public Expression {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2012 / Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -637,6 +637,12 @@ int ExpFunc::elaborate_expr(Entity*ent, Architecture*arc, const VType*)
|
|||
{
|
||||
int errors = 0;
|
||||
|
||||
ivl_assert(*this, arc);
|
||||
Subprogram*prog = arc->find_subprogram(name_);
|
||||
|
||||
ivl_assert(*this, def_==0);
|
||||
def_ = prog;
|
||||
|
||||
for (size_t idx = 0 ; idx < argv_.size() ; idx += 1) {
|
||||
const VType*tmp = argv_[idx]->probe_type(ent, arc);
|
||||
errors += argv_[idx]->elaborate_expr(ent, arc, tmp);
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@
|
|||
# include "expression.h"
|
||||
# include "vtype.h"
|
||||
# include "architec.h"
|
||||
# include "package.h"
|
||||
# include "parse_types.h"
|
||||
# include <typeinfo>
|
||||
# include <iostream>
|
||||
|
|
@ -565,6 +566,17 @@ int ExpFunc::emit(ostream&out, Entity*ent, Architecture*arc)
|
|||
out << ")";
|
||||
|
||||
} else {
|
||||
// If this function has an elaborated defintion, 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.
|
||||
if (def_) {
|
||||
const Package*pkg = dynamic_cast<const Package*> (def_->get_parent());
|
||||
if (pkg != 0)
|
||||
out << "\\" << pkg->name() << " ::";
|
||||
}
|
||||
|
||||
out << "\\" << name_ << " (";
|
||||
for (size_t idx = 0; idx < argv_.size() ; idx += 1) {
|
||||
if (idx > 0) out << ", ";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -57,6 +58,15 @@ ScopeBase::ScopeBase(const ActiveScope&ref)
|
|||
|
||||
use_subprograms_ = ref.use_subprograms_;
|
||||
cur_subprograms_ = ref.cur_subprograms_;
|
||||
|
||||
// This constructor is invoked when the parser is finished with
|
||||
// an active scope and is making the actual scope. At this point
|
||||
// we know that "this" is the parent scope for the subprograms,
|
||||
// so set it now.
|
||||
for (map<perm_string,Subprogram*>::iterator cur = cur_subprograms_.begin()
|
||||
; cur != cur_subprograms_.end() ; ++ cur) {
|
||||
cur->second->set_parent(this);
|
||||
}
|
||||
}
|
||||
|
||||
ScopeBase::~ScopeBase()
|
||||
|
|
@ -148,7 +158,7 @@ Subprogram* ScopeBase::find_subprogram(perm_string name) const
|
|||
return cur->second;
|
||||
|
||||
cur = use_subprograms_.find(name);
|
||||
if (cur != use_subprograms_.find(name))
|
||||
if (cur != use_subprograms_.end())
|
||||
return cur->second;
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ using namespace std;
|
|||
|
||||
Subprogram::Subprogram(perm_string nam, list<InterfacePort*>*ports,
|
||||
const VType*return_type)
|
||||
: name_(nam), ports_(ports), return_type_(return_type), statements_(0)
|
||||
: name_(nam), parent_(0), ports_(ports), return_type_(return_type), statements_(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -35,6 +35,12 @@ Subprogram::~Subprogram()
|
|||
{
|
||||
}
|
||||
|
||||
void Subprogram::set_parent(const ScopeBase*par)
|
||||
{
|
||||
ivl_assert(*this, parent_ == 0);
|
||||
parent_ = par;
|
||||
}
|
||||
|
||||
void Subprogram::set_program_body(list<SequentialStmt*>*stmt)
|
||||
{
|
||||
ivl_assert(*this, statements_==0);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
# include <list>
|
||||
|
||||
class InterfacePort;
|
||||
class ScopeBase;
|
||||
class SequentialStmt;
|
||||
class VType;
|
||||
|
||||
|
|
@ -36,6 +37,9 @@ class Subprogram : public LineInfo {
|
|||
const VType*return_type);
|
||||
~Subprogram();
|
||||
|
||||
void set_parent(const ScopeBase*par);
|
||||
inline const ScopeBase*get_parent() const { return parent_; }
|
||||
|
||||
inline const perm_string&name() const { return name_; }
|
||||
|
||||
void set_program_body(std::list<SequentialStmt*>*statements);
|
||||
|
|
@ -52,6 +56,7 @@ class Subprogram : public LineInfo {
|
|||
|
||||
private:
|
||||
perm_string name_;
|
||||
const ScopeBase*parent_;
|
||||
std::list<InterfacePort*>*ports_;
|
||||
const VType*return_type_;
|
||||
std::list<SequentialStmt*>*statements_;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __vtype_H
|
||||
#define __vtype_H
|
||||
/*
|
||||
* Copyright (c) 2011 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -27,6 +28,8 @@
|
|||
# include <inttypes.h>
|
||||
# include "StringHeap.h"
|
||||
|
||||
class Architecture;
|
||||
class Entity;
|
||||
class Expression;
|
||||
class prange_t;
|
||||
class VTypeDef;
|
||||
|
|
@ -45,6 +48,10 @@ class VType {
|
|||
VType() { }
|
||||
virtual ~VType() =0;
|
||||
|
||||
// This is rarely used, but some types may have expressions
|
||||
// that need to be elaborated.
|
||||
virtual int elaborate(Entity*end, Architecture*arc) const;
|
||||
|
||||
// This virtual method returns true if that is equivalent to
|
||||
// this type. This method is used for example to compare
|
||||
// function prototypes.
|
||||
|
|
@ -170,6 +177,7 @@ class VTypeArray : public VType {
|
|||
VTypeArray(const VType*etype, std::list<prange_t*>*r, bool signed_vector =false);
|
||||
~VTypeArray();
|
||||
|
||||
int elaborate(Entity*ent, Architecture*arc) const;
|
||||
void write_to_stream(std::ostream&fd) const;
|
||||
void show(std::ostream&) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2013 Stephen Williams (steve@icarus.com)
|
||||
* Copyright CERN 2013 / Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
* General Public License as published by the Free Software
|
||||
* Foundation; either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
# include "vtype.h"
|
||||
# include "expression.h"
|
||||
|
||||
int VType::elaborate(Entity*, Architecture*) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int VTypeArray::elaborate(Entity*ent, Architecture*arc) const
|
||||
{
|
||||
int errors = 0;
|
||||
etype_->elaborate(ent, arc);
|
||||
|
||||
for (vector<range_t>::const_iterator cur = ranges_.begin()
|
||||
; cur != ranges_.end() ; ++ cur) {
|
||||
|
||||
Expression*tmp = cur->msb();
|
||||
if (tmp) errors += tmp->elaborate_expr(ent, arc, 0);
|
||||
|
||||
tmp = cur->lsb();
|
||||
if (tmp) errors += tmp->elaborate_expr(ent, arc, 0);
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
Loading…
Reference in New Issue