Rework scope types and constants so we can tell imported from local names.
The package emit of types and constants needs to know which names are from the current type and which are imported from libraries. Rework the scope handling of those names so that the information is preserved.
This commit is contained in:
parent
13be45bd73
commit
6394a4d78d
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
Architecture::Architecture(perm_string name, const ScopeBase&ref,
|
||||
Architecture::Architecture(perm_string name, const ActiveScope&ref,
|
||||
list<Architecture::Statement*>&s)
|
||||
: Scope(ref), name_(name)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class Architecture : public Scope, public LineInfo {
|
|||
public:
|
||||
// Create an architecture from its name and its statements.
|
||||
// NOTE: The statement list passed in is emptied.
|
||||
Architecture(perm_string name, const ScopeBase&ref,
|
||||
Architecture(perm_string name, const ActiveScope&ref,
|
||||
std::list<Architecture::Statement*>&s);
|
||||
~Architecture();
|
||||
|
||||
|
|
|
|||
|
|
@ -32,12 +32,12 @@ int Architecture::elaborate(Entity*entity)
|
|||
// from the constant declaration itself. Elaborate the value
|
||||
// expression with the declared type.
|
||||
|
||||
for (map<perm_string,struct const_t*>::iterator cur = old_constants_.begin()
|
||||
; cur != old_constants_.end() ; ++cur) {
|
||||
for (map<perm_string,struct const_t*>::iterator cur = use_constants_.begin()
|
||||
; cur != use_constants_.end() ; ++cur) {
|
||||
cur->second->val->elaborate_expr(entity, this, cur->second->typ);
|
||||
}
|
||||
for (map<perm_string,struct const_t*>::iterator cur = new_constants_.begin()
|
||||
; cur != new_constants_.end() ; ++cur) {
|
||||
for (map<perm_string,struct const_t*>::iterator cur = cur_constants_.begin()
|
||||
; cur != cur_constants_.end() ; ++cur) {
|
||||
cur->second->val->elaborate_expr(entity, this, cur->second->typ);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ int Architecture::emit(ostream&out, Entity*entity)
|
|||
// of the full definition.
|
||||
|
||||
typedef_context_t typedef_ctx;
|
||||
for (map<perm_string,const VType*>::iterator cur = old_types_.begin()
|
||||
; cur != old_types_.end() ; ++cur) {
|
||||
for (map<perm_string,const VType*>::iterator cur = cur_types_.begin()
|
||||
; cur != cur_types_.end() ; ++cur) {
|
||||
|
||||
const VTypeDef*def = dynamic_cast<const VTypeDef*>(cur->second);
|
||||
if (def == 0)
|
||||
|
|
@ -79,15 +79,15 @@ int Architecture::emit(ostream&out, Entity*entity)
|
|||
errors += def->emit_typedef(out, typedef_ctx);
|
||||
}
|
||||
|
||||
for (map<perm_string,struct const_t*>::iterator cur = old_constants_.begin()
|
||||
; cur != old_constants_.end() ; ++cur) {
|
||||
for (map<perm_string,struct const_t*>::iterator cur = use_constants_.begin()
|
||||
; cur != use_constants_.end() ; ++cur) {
|
||||
|
||||
out << "localparam " << cur->first << " = ";
|
||||
errors += cur->second->val->emit(out, entity, this);
|
||||
out << ";" << endl;
|
||||
}
|
||||
for (map<perm_string,struct const_t*>::iterator cur = new_constants_.begin()
|
||||
; cur != new_constants_.end() ; ++cur) {
|
||||
for (map<perm_string,struct const_t*>::iterator cur = cur_constants_.begin()
|
||||
; cur != cur_constants_.end() ; ++cur) {
|
||||
|
||||
out << "localparam " << cur->first << " = ";
|
||||
errors += cur->second->val->emit(out, entity, this);
|
||||
|
|
|
|||
|
|
@ -101,31 +101,36 @@ void ComponentBase::dump_ports(ostream&out, int indent) const
|
|||
void Scope::dump_scope(ostream&out) const
|
||||
{
|
||||
// Dump types
|
||||
for (map<perm_string,const VType*>::const_iterator cur = old_types_.begin()
|
||||
; cur != old_types_.end() ; ++cur) {
|
||||
out << " -- imported types" << endl;
|
||||
for (map<perm_string,const VType*>::const_iterator cur = use_types_.begin()
|
||||
; cur != use_types_.end() ; ++cur) {
|
||||
out << " " << cur->first << ": ";
|
||||
cur->second->show(out);
|
||||
out << endl;
|
||||
}
|
||||
for (map<perm_string,const VType*>::const_iterator cur = new_types_.begin()
|
||||
; cur != new_types_.end() ; ++cur) {
|
||||
out << " -- Types from this scope" << endl;
|
||||
for (map<perm_string,const VType*>::const_iterator cur = cur_types_.begin()
|
||||
; cur != cur_types_.end() ; ++cur) {
|
||||
out << " " << cur->first << ": ";
|
||||
cur->second->show(out);
|
||||
out << endl;
|
||||
}
|
||||
|
||||
// Dump constants
|
||||
for (map<perm_string,const_t*>::const_iterator cur = old_constants_.begin()
|
||||
; cur != old_constants_.end() ; ++cur) {
|
||||
out << " -- imported constants" << endl;
|
||||
for (map<perm_string,const_t*>::const_iterator cur = use_constants_.begin()
|
||||
; cur != use_constants_.end() ; ++cur) {
|
||||
out << " constant " << cur->first << " = ";
|
||||
out << endl;
|
||||
}
|
||||
for (map<perm_string,const_t*>::const_iterator cur = new_constants_.begin()
|
||||
; cur != new_constants_.end() ; ++cur) {
|
||||
out << " -- Constants from this scope" << endl;
|
||||
for (map<perm_string,const_t*>::const_iterator cur = cur_constants_.begin()
|
||||
; cur != cur_constants_.end() ; ++cur) {
|
||||
out << " constant " << cur->first << " = ";
|
||||
out << endl;
|
||||
}
|
||||
// Dump signal declarations
|
||||
out << " -- Signals" << endl;
|
||||
for (map<perm_string,Signal*>::const_iterator cur = old_signals_.begin()
|
||||
; cur != old_signals_.end() ; ++cur) {
|
||||
if (cur->second)
|
||||
|
|
@ -141,6 +146,7 @@ void Scope::dump_scope(ostream&out) const
|
|||
out << " signal " << cur->first.str() << ": ???" << endl;
|
||||
}
|
||||
// Dump subprograms
|
||||
out << " -- Subprograms" << endl;
|
||||
for (map<perm_string,Subprogram*>::const_iterator cur = old_subprograms_.begin()
|
||||
; cur != old_subprograms_.end() ; ++cur) {
|
||||
out << " subprogram " << cur->first << " is" << endl;
|
||||
|
|
@ -154,6 +160,7 @@ void Scope::dump_scope(ostream&out) const
|
|||
out << " end subprogram " << cur->first << endl;
|
||||
}
|
||||
// Dump component declarations
|
||||
out << " -- Components" << endl;
|
||||
for (map<perm_string,ComponentBase*>::const_iterator cur = old_components_.begin()
|
||||
; cur != old_components_.end() ; ++cur) {
|
||||
out << " component " << cur->first << " is" << endl;
|
||||
|
|
|
|||
|
|
@ -90,6 +90,10 @@ class Expression : public LineInfo {
|
|||
// class fills in the details of what exactly happened.
|
||||
virtual int emit(ostream&out, Entity*ent, Architecture*arc) =0;
|
||||
|
||||
// The emit_package virtual message is similar, but is called
|
||||
// in a package context and to emit SV packages.
|
||||
virtual int emit_package(std::ostream&out);
|
||||
|
||||
// The evaluate virtual method tries to evaluate expressions
|
||||
// to constant literal values. Return true and set the val
|
||||
// argument if the evaluation works, or return false if it
|
||||
|
|
@ -478,6 +482,7 @@ class ExpInteger : public Expression {
|
|||
int elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype);
|
||||
void write_to_stream(std::ostream&fd);
|
||||
int emit(ostream&out, Entity*ent, Architecture*arc);
|
||||
int emit_package(std::ostream&out);
|
||||
bool is_primary(void) const;
|
||||
bool evaluate(ScopeBase*scope, int64_t&val) const;
|
||||
void dump(ostream&out, int indent = 0) const;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,14 @@ int Expression::emit(ostream&out, Entity*, Architecture*)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int Expression::emit_package(ostream&out)
|
||||
{
|
||||
out << " /* " << get_fileline() << ": internal error: "
|
||||
<< "I don't know how to emit_package this expression! "
|
||||
<< "type=" << typeid(*this).name() << " */ ";
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool Expression::is_primary(void) const
|
||||
{
|
||||
return false;
|
||||
|
|
@ -565,6 +573,12 @@ int ExpInteger::emit(ostream&out, Entity*, Architecture*)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ExpInteger::emit_package(ostream&out)
|
||||
{
|
||||
out << value_;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ExpInteger::is_primary(void) const
|
||||
{
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -256,7 +257,7 @@ static void import_ieee_use_std_logic_1164(ActiveScope*res, perm_string name)
|
|||
|
||||
if (all_flag || name == "std_logic_vector") {
|
||||
vector<VTypeArray::range_t> dims (1);
|
||||
res->bind_name(perm_string::literal("std_logic_vector"),
|
||||
res->use_name(perm_string::literal("std_logic_vector"),
|
||||
new VTypeArray(primitive_STDLOGIC, dims, false));
|
||||
}
|
||||
}
|
||||
|
|
@ -271,12 +272,12 @@ static void import_ieee_use_numeric_bit(ActiveScope*res, perm_string name)
|
|||
|
||||
if (all_flag || name == "signed") {
|
||||
vector<VTypeArray::range_t> dims (1);
|
||||
res->bind_name(perm_string::literal("signed"),
|
||||
res->use_name(perm_string::literal("signed"),
|
||||
new VTypeArray(primitive_STDLOGIC, dims, true));
|
||||
}
|
||||
if (all_flag || name == "unsigned") {
|
||||
vector<VTypeArray::range_t> dims (1);
|
||||
res->bind_name(perm_string::literal("unsigned"),
|
||||
res->use_name(perm_string::literal("unsigned"),
|
||||
new VTypeArray(primitive_BIT, dims, false));
|
||||
}
|
||||
}
|
||||
|
|
@ -287,12 +288,12 @@ static void import_ieee_use_numeric_std(ActiveScope*res, perm_string name)
|
|||
|
||||
if (all_flag || name == "signed") {
|
||||
vector<VTypeArray::range_t> dims (1);
|
||||
res->bind_name(perm_string::literal("signed"),
|
||||
res->use_name(perm_string::literal("signed"),
|
||||
new VTypeArray(primitive_STDLOGIC, dims, true));
|
||||
}
|
||||
if (all_flag || name == "unsigned") {
|
||||
vector<VTypeArray::range_t> dims (1);
|
||||
res->bind_name(perm_string::literal("unsigned"),
|
||||
res->use_name(perm_string::literal("unsigned"),
|
||||
new VTypeArray(primitive_STDLOGIC, dims, false));
|
||||
}
|
||||
}
|
||||
|
|
@ -334,14 +335,14 @@ static const VTypeArray* primitive_STRING = new VTypeArray(primitive_CHARACTER,
|
|||
|
||||
void generate_global_types(ActiveScope*res)
|
||||
{
|
||||
res->bind_name(perm_string::literal("boolean"), primitive_BOOLEAN);
|
||||
res->bind_name(perm_string::literal("bit"), primitive_BIT);
|
||||
res->bind_name(perm_string::literal("integer"), primitive_INTEGER);
|
||||
res->bind_name(perm_string::literal("std_logic"), primitive_STDLOGIC);
|
||||
res->bind_name(perm_string::literal("character"), primitive_CHARACTER);
|
||||
res->bind_name(perm_string::literal("bit_vector"),primitive_BOOL_VECTOR);
|
||||
res->bind_name(perm_string::literal("string"), primitive_STRING);
|
||||
res->bind_name(perm_string::literal("natural"), primitive_NATURAL);
|
||||
res->use_name(perm_string::literal("boolean"), primitive_BOOLEAN);
|
||||
res->use_name(perm_string::literal("bit"), primitive_BIT);
|
||||
res->use_name(perm_string::literal("integer"), primitive_INTEGER);
|
||||
res->use_name(perm_string::literal("std_logic"), primitive_STDLOGIC);
|
||||
res->use_name(perm_string::literal("character"), primitive_CHARACTER);
|
||||
res->use_name(perm_string::literal("bit_vector"),primitive_BOOL_VECTOR);
|
||||
res->use_name(perm_string::literal("string"), primitive_STRING);
|
||||
res->use_name(perm_string::literal("natural"), primitive_NATURAL);
|
||||
}
|
||||
|
||||
bool is_global_type(perm_string name)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -22,7 +23,7 @@
|
|||
# include "parse_misc.h"
|
||||
# include "ivl_assert.h"
|
||||
|
||||
Package::Package(perm_string n, const ScopeBase&ref)
|
||||
Package::Package(perm_string n, const ActiveScope&ref)
|
||||
: Scope(ref), name_(n)
|
||||
{
|
||||
}
|
||||
|
|
@ -45,29 +46,30 @@ void Package::set_library(perm_string lname)
|
|||
*/
|
||||
void Package::write_to_stream(ostream&fd) const
|
||||
{
|
||||
ivl_assert(*this, new_subprograms_.size() == 0);
|
||||
|
||||
fd << "package " << name_ << " is" << endl;
|
||||
|
||||
// Start out pre-declaring all the type definitions so that
|
||||
// there is no confusion later in the package between types
|
||||
// and identifiers.
|
||||
for (map<perm_string,const VType*>::const_iterator cur = old_types_.begin()
|
||||
; cur != old_types_.end() ; ++cur) {
|
||||
for (map<perm_string,const VType*>::const_iterator cur = use_types_.begin()
|
||||
; cur != use_types_.end() ; ++cur) {
|
||||
const VTypeDef*def = dynamic_cast<const VTypeDef*> (cur->second);
|
||||
if (def == 0)
|
||||
continue;
|
||||
fd << "type " << cur->first << ";" << endl;
|
||||
}
|
||||
for (map<perm_string,const VType*>::const_iterator cur = cur_types_.begin()
|
||||
; cur != cur_types_.end() ; ++cur) {
|
||||
const VTypeDef*def = dynamic_cast<const VTypeDef*> (cur->second);
|
||||
if (def == 0)
|
||||
continue;
|
||||
fd << "type " << cur->first << ";" << endl;
|
||||
}
|
||||
|
||||
for (map<perm_string,const VType*>::const_iterator cur = new_types_.begin()
|
||||
; cur != new_types_.end() ; ++cur) {
|
||||
const VTypeDef*def = dynamic_cast<const VTypeDef*> (cur->second);
|
||||
if (def == 0)
|
||||
continue;
|
||||
fd << "type " << cur->first << ";" << endl;
|
||||
}
|
||||
|
||||
for (map<perm_string,struct const_t*>::const_iterator cur = old_constants_.begin()
|
||||
; cur != old_constants_.end() ; ++ cur) {
|
||||
for (map<perm_string,struct const_t*>::const_iterator cur = cur_constants_.begin()
|
||||
; cur != cur_constants_.end() ; ++ cur) {
|
||||
fd << "constant " << cur->first << ": ";
|
||||
cur->second->typ->write_to_stream(fd);
|
||||
fd << " := ";
|
||||
|
|
@ -75,17 +77,8 @@ void Package::write_to_stream(ostream&fd) const
|
|||
fd << ";" << endl;
|
||||
}
|
||||
|
||||
for (map<perm_string,struct const_t*>::const_iterator cur = new_constants_.begin()
|
||||
; cur != new_constants_.end() ; ++ cur) {
|
||||
fd << "constant " << cur->first << ": ";
|
||||
cur->second->typ->write_to_stream(fd);
|
||||
fd << " := ";
|
||||
cur->second->val->write_to_stream(fd);
|
||||
fd << ";" << endl;
|
||||
}
|
||||
|
||||
for (map<perm_string,const VType*>::const_iterator cur = old_types_.begin()
|
||||
; cur != old_types_.end() ; ++cur) {
|
||||
for (map<perm_string,const VType*>::const_iterator cur = use_types_.begin()
|
||||
; cur != use_types_.end() ; ++cur) {
|
||||
|
||||
// Do not include global types in types dump
|
||||
if (is_global_type(cur->first))
|
||||
|
|
@ -95,12 +88,12 @@ void Package::write_to_stream(ostream&fd) const
|
|||
|
||||
fd << "type " << cur->first << " is ";
|
||||
cur->second->write_type_to_stream(fd);
|
||||
fd << ";" << endl;
|
||||
fd << "; -- imported" << endl;
|
||||
}
|
||||
for (map<perm_string,const VType*>::const_iterator cur = new_types_.begin()
|
||||
; cur != new_types_.end() ; ++cur) {
|
||||
for (map<perm_string,const VType*>::const_iterator cur = cur_types_.begin()
|
||||
; cur != cur_types_.end() ; ++cur) {
|
||||
|
||||
// Do not include primitive types in type dump
|
||||
// Do not include global types in types dump
|
||||
if (is_global_type(cur->first))
|
||||
continue;
|
||||
if (cur->first == "std_logic_vector")
|
||||
|
|
@ -115,10 +108,6 @@ void Package::write_to_stream(ostream&fd) const
|
|||
; cur != old_subprograms_.end() ; ++cur) {
|
||||
cur->second->write_to_stream(fd);
|
||||
}
|
||||
for (map<perm_string,Subprogram*>::const_iterator cur = new_subprograms_.begin()
|
||||
; cur != new_subprograms_.end() ; ++cur) {
|
||||
cur->second->write_to_stream(fd);
|
||||
}
|
||||
|
||||
for (map<perm_string,ComponentBase*>::const_iterator cur = old_components_.begin()
|
||||
; cur != old_components_.end() ; ++cur) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
#define __package_H
|
||||
/*
|
||||
* 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
|
||||
|
|
@ -26,7 +27,7 @@
|
|||
class Package : public Scope, public LineInfo {
|
||||
|
||||
public:
|
||||
Package(perm_string name, const ScopeBase&ref);
|
||||
Package(perm_string name, const ActiveScope&ref);
|
||||
~Package();
|
||||
|
||||
// The the library from which this package came. Having a
|
||||
|
|
|
|||
|
|
@ -20,14 +20,17 @@
|
|||
|
||||
# include "package.h"
|
||||
# include <iostream>
|
||||
# include "ivl_assert.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
int Package::emit_package(ostream&fd) const
|
||||
{
|
||||
ivl_assert(*this, new_subprograms_.empty());
|
||||
|
||||
// Don't emit the package if there is nothing in it that SV
|
||||
// cares about.
|
||||
if (new_types_.empty() && old_subprograms_.empty() && new_subprograms_.empty())
|
||||
if (cur_types_.empty() && cur_constants_.empty() && old_subprograms_.empty())
|
||||
return 0;
|
||||
|
||||
// If this package was imported from a library, then do not
|
||||
|
|
@ -44,10 +47,24 @@ int Package::emit_package(ostream&fd) const
|
|||
|
||||
// Only emit types that were defined within this package. Skip
|
||||
// the types that were imported from elsewhere.
|
||||
for (map<perm_string,const VType*>::const_iterator cur = new_types_.begin()
|
||||
; cur != new_types_.end() ; ++ cur) {
|
||||
for (map<perm_string,const VType*>::const_iterator cur = cur_types_.begin()
|
||||
; cur != cur_types_.end() ; ++ cur) {
|
||||
fd << "typedef ";
|
||||
errors += cur->second->emit_def(fd);
|
||||
fd << " " << cur->first << " ;" << endl;
|
||||
fd << " \\" << cur->first << " ;" << endl;
|
||||
}
|
||||
|
||||
for (map<perm_string,struct const_t*>::const_iterator cur = use_constants_.begin()
|
||||
; cur != use_constants_.end() ; ++cur) {
|
||||
fd << "localparam \\" << cur->first << " = ";
|
||||
errors += cur->second->val->emit_package(fd);
|
||||
fd << ";" << endl;
|
||||
}
|
||||
for (map<perm_string,struct const_t*>::const_iterator cur = cur_constants_.begin()
|
||||
; cur != cur_constants_.end() ; ++cur) {
|
||||
fd << "localparam " << cur->first << " = ";
|
||||
errors += cur->second->val->emit_package(fd);
|
||||
fd << ";" << endl;
|
||||
}
|
||||
|
||||
for (map<perm_string,Subprogram*>::const_iterator cur = old_subprograms_.begin()
|
||||
|
|
@ -55,11 +72,6 @@ int Package::emit_package(ostream&fd) const
|
|||
errors += cur->second->emit_package(fd);
|
||||
}
|
||||
|
||||
for (map<perm_string,Subprogram*>::const_iterator cur = new_subprograms_.begin()
|
||||
; cur != new_subprograms_.end() ; ++ cur) {
|
||||
errors += cur->second->emit_package(fd);
|
||||
}
|
||||
|
||||
fd << "endpackage" << endl;
|
||||
|
||||
return errors;
|
||||
|
|
|
|||
|
|
@ -30,13 +30,11 @@ using namespace std;
|
|||
* "old_*_" variables. This clears up the "new_*_" variables to
|
||||
* accumulate new scope values.
|
||||
*/
|
||||
ScopeBase::ScopeBase(const ScopeBase&ref)
|
||||
ScopeBase::ScopeBase(const ActiveScope&ref)
|
||||
{
|
||||
merge(ref.old_constants_.begin(), ref.old_constants_.end(),
|
||||
ref.new_constants_.begin(), ref.new_constants_.end(),
|
||||
insert_iterator<map<perm_string, struct const_t*> >(
|
||||
old_constants_, old_constants_.end())
|
||||
);
|
||||
use_constants_ = ref.use_constants_;
|
||||
cur_constants_ = ref.cur_constants_;
|
||||
|
||||
merge(ref.old_signals_.begin(), ref.old_signals_.end(),
|
||||
ref.new_signals_.begin(), ref.new_signals_.end(),
|
||||
insert_iterator<map<perm_string, Signal*> >(
|
||||
|
|
@ -52,11 +50,8 @@ ScopeBase::ScopeBase(const ScopeBase&ref)
|
|||
insert_iterator<map<perm_string, ComponentBase*> >(
|
||||
old_components_, old_components_.end())
|
||||
);
|
||||
merge(ref.old_types_.begin(), ref.old_types_.end(),
|
||||
ref.new_types_.begin(), ref.new_types_.end(),
|
||||
insert_iterator<map<perm_string, const VType*> >(
|
||||
old_types_, old_types_.end())
|
||||
);
|
||||
use_types_ = ref.use_types_;
|
||||
cur_types_ = ref.cur_types_;
|
||||
merge(ref.old_subprograms_.begin(), ref.old_subprograms_.end(),
|
||||
ref.new_subprograms_.begin(), ref.new_subprograms_.end(),
|
||||
insert_iterator<map<perm_string,Subprogram*> >(
|
||||
|
|
@ -79,17 +74,17 @@ void ScopeBase::cleanup()
|
|||
*/
|
||||
delete_all(new_signals_);
|
||||
delete_all(new_components_);
|
||||
delete_all(new_types_);
|
||||
delete_all(new_constants_);
|
||||
delete_all(cur_types_);
|
||||
delete_all(cur_constants_);
|
||||
delete_all(new_subprograms_);
|
||||
}
|
||||
|
||||
const VType*ScopeBase::find_type(perm_string by_name)
|
||||
{
|
||||
map<perm_string,const VType*>::const_iterator cur = new_types_.find(by_name);
|
||||
if (cur == new_types_.end()) {
|
||||
cur = old_types_.find(by_name);
|
||||
if (cur == old_types_.end())
|
||||
map<perm_string,const VType*>::const_iterator cur = cur_types_.find(by_name);
|
||||
if (cur == cur_types_.end()) {
|
||||
cur = use_types_.find(by_name);
|
||||
if (cur == use_types_.end())
|
||||
return 0;
|
||||
else
|
||||
return cur->second;
|
||||
|
|
@ -99,10 +94,10 @@ const VType*ScopeBase::find_type(perm_string by_name)
|
|||
|
||||
bool ScopeBase::find_constant(perm_string by_name, const VType*&typ, Expression*&exp)
|
||||
{
|
||||
map<perm_string,struct const_t*>::const_iterator cur = new_constants_.find(by_name);
|
||||
if (cur == new_constants_.end()) {
|
||||
cur = old_constants_.find(by_name);
|
||||
if (cur == old_constants_.end())
|
||||
map<perm_string,struct const_t*>::const_iterator cur = cur_constants_.find(by_name);
|
||||
if (cur == cur_constants_.end()) {
|
||||
cur = use_constants_.find(by_name);
|
||||
if (cur == use_constants_.end())
|
||||
return false;
|
||||
else {
|
||||
typ = cur->second->typ;
|
||||
|
|
@ -144,6 +139,10 @@ Variable* ScopeBase::find_variable(perm_string by_name) const
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This method is only used by the ActiveScope derived class to import
|
||||
* definition from another scope.
|
||||
*/
|
||||
void ScopeBase::do_use_from(const ScopeBase*that)
|
||||
{
|
||||
for (map<perm_string,ComponentBase*>::const_iterator cur = that->old_components_.begin()
|
||||
|
|
@ -172,26 +171,16 @@ void ScopeBase::do_use_from(const ScopeBase*that)
|
|||
old_subprograms_[cur->first] = cur->second;
|
||||
}
|
||||
|
||||
for (map<perm_string,const VType*>::const_iterator cur = that->old_types_.begin()
|
||||
; cur != that->old_types_.end() ; ++ cur) {
|
||||
for (map<perm_string,const VType*>::const_iterator cur = that->cur_types_.begin()
|
||||
; cur != that->cur_types_.end() ; ++ cur) {
|
||||
if (cur->second == 0)
|
||||
continue;
|
||||
old_types_[cur->first] = cur->second;
|
||||
}
|
||||
for (map<perm_string,const VType*>::const_iterator cur = that->new_types_.begin()
|
||||
; cur != that->new_types_.end() ; ++ cur) {
|
||||
if (cur->second == 0)
|
||||
continue;
|
||||
old_types_[cur->first] = cur->second;
|
||||
use_types_[cur->first] = cur->second;
|
||||
}
|
||||
|
||||
for (map<perm_string,const_t*>::const_iterator cur = that->old_constants_.begin()
|
||||
; cur != that->old_constants_.end() ; ++ cur) {
|
||||
old_constants_[cur->first] = cur->second;
|
||||
}
|
||||
for (map<perm_string,const_t*>::const_iterator cur = that->new_constants_.begin()
|
||||
; cur != that->new_constants_.end() ; ++ cur) {
|
||||
old_constants_[cur->first] = cur->second;
|
||||
for (map<perm_string,const_t*>::const_iterator cur = that->cur_constants_.begin()
|
||||
; cur != that->cur_constants_.end() ; ++ cur) {
|
||||
use_constants_[cur->first] = cur->second;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +197,7 @@ bool ActiveScope::is_vector_name(perm_string name) const
|
|||
return false;
|
||||
}
|
||||
|
||||
Scope::Scope(const ScopeBase&ref)
|
||||
Scope::Scope(const ActiveScope&ref)
|
||||
: ScopeBase(ref)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
#ifndef __scope_H
|
||||
#define __scope_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
|
||||
|
|
@ -28,8 +29,10 @@
|
|||
# include "subprogram.h"
|
||||
# include "vsignal.h"
|
||||
|
||||
class ActiveScope;
|
||||
class Architecture;
|
||||
class ComponentBase;
|
||||
class Package;
|
||||
class Subprogram;
|
||||
class VType;
|
||||
|
||||
|
|
@ -47,7 +50,7 @@ class ScopeBase {
|
|||
|
||||
public:
|
||||
ScopeBase() { }
|
||||
explicit ScopeBase(const ScopeBase&ref);
|
||||
explicit ScopeBase(const ActiveScope&ref);
|
||||
virtual ~ScopeBase() =0;
|
||||
|
||||
const VType* find_type(perm_string by_name);
|
||||
|
|
@ -68,6 +71,12 @@ class ScopeBase {
|
|||
for_each(c.begin(), c.end(), ::delete_pair_second<T>());
|
||||
}
|
||||
|
||||
// The new_*_ maps below are managed only by the ActiveScope
|
||||
// derived class. When any scope is constructed from the
|
||||
// ActiveScope, the new_*_ and old_*_ maps are merged and
|
||||
// installed into the old_*_ maps. Thus, all other derived
|
||||
// classes should only use the old_*_ maps.
|
||||
|
||||
// Signal declarations...
|
||||
std::map<perm_string,Signal*> old_signals_; //previous scopes
|
||||
std::map<perm_string,Signal*> new_signals_; //current scope
|
||||
|
|
@ -78,8 +87,8 @@ class ScopeBase {
|
|||
std::map<perm_string,ComponentBase*> old_components_; //previous scopes
|
||||
std::map<perm_string,ComponentBase*> new_components_; //current scope
|
||||
// Type declarations...
|
||||
std::map<perm_string,const VType*> old_types_; //previous scopes
|
||||
std::map<perm_string,const VType*> new_types_; //current scope
|
||||
std::map<perm_string,const VType*> use_types_; //imported types
|
||||
std::map<perm_string,const VType*> cur_types_; //current types
|
||||
// Constant declarations...
|
||||
struct const_t {
|
||||
~const_t() {delete typ; delete val;}
|
||||
|
|
@ -88,8 +97,8 @@ class ScopeBase {
|
|||
const VType*typ;
|
||||
Expression*val;
|
||||
};
|
||||
std::map<perm_string, struct const_t*> old_constants_; //previous scopes
|
||||
std::map<perm_string, struct const_t*> new_constants_; //current scope
|
||||
std::map<perm_string, struct const_t*> use_constants_; //imported constants
|
||||
std::map<perm_string, struct const_t*> cur_constants_; //current constants
|
||||
|
||||
std::map<perm_string, Subprogram*> old_subprograms_; //previous scopes
|
||||
std::map<perm_string, Subprogram*> new_subprograms_; //current scope
|
||||
|
|
@ -100,7 +109,7 @@ class ScopeBase {
|
|||
class Scope : public ScopeBase {
|
||||
|
||||
public:
|
||||
explicit Scope(const ScopeBase&ref);
|
||||
explicit Scope(const ActiveScope&ref);
|
||||
~Scope();
|
||||
|
||||
ComponentBase* find_component(perm_string by_name);
|
||||
|
|
@ -128,7 +137,7 @@ class ActiveScope : public ScopeBase {
|
|||
|
||||
~ActiveScope() { }
|
||||
|
||||
void use_from(const ScopeBase*that) { do_use_from(that); }
|
||||
void use_from(const Scope*that) { do_use_from(that); }
|
||||
|
||||
// This function returns true if the name is a vectorable
|
||||
// name. The parser uses this to distinguish between function
|
||||
|
|
@ -164,16 +173,19 @@ class ActiveScope : public ScopeBase {
|
|||
|
||||
void bind_name(perm_string name, const VType* t)
|
||||
{ map<perm_string, const VType*>::iterator it;
|
||||
if((it = old_types_.find(name)) != old_types_.end() )
|
||||
old_types_.erase(it);
|
||||
new_types_[name] = t;
|
||||
if((it = use_types_.find(name)) != use_types_.end() )
|
||||
use_types_.erase(it);
|
||||
cur_types_[name] = t;
|
||||
}
|
||||
|
||||
inline void use_name(perm_string name, const VType* t)
|
||||
{ use_types_[name] = t; }
|
||||
|
||||
void bind_name(perm_string name, const VType*obj, Expression*val)
|
||||
{ map<perm_string, const_t*>::iterator it;
|
||||
if((it = old_constants_.find(name)) != old_constants_.end() )
|
||||
old_constants_.erase(it);
|
||||
new_constants_[name] = new const_t(obj, val);
|
||||
if((it = use_constants_.find(name)) != use_constants_.end() )
|
||||
use_constants_.erase(it);
|
||||
cur_constants_[name] = new const_t(obj, val);
|
||||
}
|
||||
|
||||
void bind_name(perm_string name, Subprogram*obj)
|
||||
|
|
|
|||
Loading…
Reference in New Issue