Support types in packages.
Types declared in packages should be written into the package library.
This commit is contained in:
parent
79435924f2
commit
ed3da959f3
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<perm_string,const VType*>::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<perm_string,const VType*>::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<perm_string,ComponentBase*>::const_iterator cur = old_components_.begin()
|
||||
; cur != old_components_.end() ; ++cur) {
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
|
|
|
|||
Loading…
Reference in New Issue