diff --git a/vhdlpp/library.cc b/vhdlpp/library.cc index 776789eb1..f262a1f15 100644 --- a/vhdlpp/library.cc +++ b/vhdlpp/library.cc @@ -338,6 +338,17 @@ void generate_global_types(ActiveScope*res) res->bind_name(perm_string::literal("natural"), primitive_NATURAL); } +bool is_global_type(perm_string name) +{ + if (name == "boolean") return true; + if (name == "bit") return true; + if (name == "integer") return true; + if (name == "std_logic") return true; + if (name == "bit_vector") return true; + if (name == "natural") return true; + return false; +} + void library_set_work_path(const char*path) { assert(library_work_path == 0); diff --git a/vhdlpp/package.cc b/vhdlpp/package.cc index 211b422f9..b9bbe58a8 100644 --- a/vhdlpp/package.cc +++ b/vhdlpp/package.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2012 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 @@ -19,6 +19,7 @@ # include "package.h" # include "entity.h" +# include "parse_misc.h" Package::Package(perm_string n, const ScopeBase&ref) : Scope(ref), name_(n) @@ -30,10 +31,42 @@ Package::~Package() ScopeBase::cleanup(); } +/* + * The Package::write_to_stream is used to write the package to the + * work space (or library) so writes proper VHDL that the library + * parser can bring back in as needed. + */ void Package::write_to_stream(ostream&fd) const { fd << "package " << name_ << " is" << endl; + for (map::const_iterator cur = old_types_.begin() + ; cur != old_types_.end() ; ++cur) { + + // Do not include global types in types dump + if (is_global_type(cur->first)) + continue; + if (cur->first == "std_logic_vector") + continue; + + fd << cur->first << ": "; + cur->second->write_to_stream(fd); + fd << ";" << endl; + } + for (map::const_iterator cur = new_types_.begin() + ; cur != new_types_.end() ; ++cur) { + + // Do not include primitive types in type dump + if (is_global_type(cur->first)) + continue; + if (cur->first == "std_logic_vector") + continue; + + fd << cur->first << ": "; + cur->second->write_to_stream(fd); + fd << ";" << endl; + } + for (map::const_iterator cur = old_components_.begin() ; cur != old_components_.end() ; ++cur) { diff --git a/vhdlpp/parse_misc.h b/vhdlpp/parse_misc.h index d62c3e92c..9bb36b28d 100644 --- a/vhdlpp/parse_misc.h +++ b/vhdlpp/parse_misc.h @@ -63,4 +63,6 @@ extern void library_use(const YYLTYPE&loc, ActiveScope*res, const char*libname, extern void generate_global_types(ActiveScope*res); +extern bool is_global_type(perm_string type_name); + #endif diff --git a/vhdlpp/scope.cc b/vhdlpp/scope.cc index a0c51bb2e..7dbfe0e23 100644 --- a/vhdlpp/scope.cc +++ b/vhdlpp/scope.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2012 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 @@ -24,6 +24,12 @@ using namespace std; +/* + * If the merge_flag is passed in, then the new scope is a merge of + * the parent scopes. This brings in all of the parent scopes into the + * "old_*_" variables. This clears up the "new_*_" variables to + * accumulate new scope values. + */ ScopeBase::ScopeBase(const ScopeBase&ref) { merge(ref.old_constants_.begin(), ref.old_constants_.end(), diff --git a/vhdlpp/scope.h b/vhdlpp/scope.h index 121b46627..8e5997781 100644 --- a/vhdlpp/scope.h +++ b/vhdlpp/scope.h @@ -1,7 +1,7 @@ #ifndef __scope_H #define __scope_H /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2012 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 @@ -95,7 +95,7 @@ class ScopeBase { class Scope : public ScopeBase { public: - Scope(const ScopeBase&ref); + explicit Scope(const ScopeBase&ref); ~Scope(); ComponentBase* find_component(perm_string by_name); diff --git a/vhdlpp/vtype_stream.cc b/vhdlpp/vtype_stream.cc index 179096211..c39dd76f9 100644 --- a/vhdlpp/vtype_stream.cc +++ b/vhdlpp/vtype_stream.cc @@ -34,7 +34,7 @@ void VTypeArray::write_to_stream(ostream&fd) const // Special case: std_logic_vector if (etype_ == primitive_STDLOGIC) { fd << "std_logic_vector"; - if (! ranges_.empty()) { + if (! ranges_.empty() && ! ranges_[0].is_box()) { assert(ranges_.size() < 2); fd << " ("; if (ranges_[0].msb())