2013-05-12 05:00:00 +02:00
|
|
|
/*
|
|
|
|
|
* 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 "package.h"
|
2014-09-29 11:31:18 +02:00
|
|
|
# include "subprogram.h"
|
2013-05-12 05:00:00 +02:00
|
|
|
# include <iostream>
|
2013-05-13 04:17:12 +02:00
|
|
|
# include "ivl_assert.h"
|
2013-05-12 05:00:00 +02:00
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
int Package::emit_package(ostream&fd) const
|
|
|
|
|
{
|
|
|
|
|
// Don't emit the package if there is nothing in it that SV
|
|
|
|
|
// cares about.
|
2013-05-19 02:36:29 +02:00
|
|
|
if (cur_types_.empty() && cur_constants_.empty() && cur_subprograms_.empty())
|
2013-05-12 05:00:00 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// If this package was imported from a library, then do not
|
|
|
|
|
// emit it again.
|
|
|
|
|
if (from_library_.str() != 0) {
|
|
|
|
|
fd << "/* Suppress package " << name()
|
|
|
|
|
<< " from library " << from_library_ << " */" << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int errors = 0;
|
|
|
|
|
|
|
|
|
|
fd << "package \\" << name() << " ;" << endl;
|
|
|
|
|
|
|
|
|
|
// Only emit types that were defined within this package. Skip
|
|
|
|
|
// the types that were imported from elsewhere.
|
2013-05-13 04:17:12 +02:00
|
|
|
for (map<perm_string,const VType*>::const_iterator cur = cur_types_.begin()
|
|
|
|
|
; cur != cur_types_.end() ; ++ cur) {
|
|
|
|
|
fd << "typedef ";
|
2015-01-23 14:14:34 +01:00
|
|
|
errors += cur->second->emit_def(fd,
|
|
|
|
|
dynamic_cast<const VTypeDef*>(cur->second) ? empty_perm_string : cur->first);
|
2014-08-22 10:49:55 +02:00
|
|
|
fd << " ;" << endl;
|
2013-05-12 05:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
2014-09-09 15:20:26 +02:00
|
|
|
//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;
|
|
|
|
|
//}
|
2013-05-12 05:00:00 +02:00
|
|
|
|
2013-05-19 02:36:29 +02:00
|
|
|
for (map<perm_string,Subprogram*>::const_iterator cur = cur_subprograms_.begin()
|
|
|
|
|
; cur != cur_subprograms_.end() ; ++ cur) {
|
2015-02-04 14:29:41 +01:00
|
|
|
// Do not emit unbounded functions, we will just need fixed instances later
|
|
|
|
|
if(!cur->second->unbounded())
|
|
|
|
|
errors += cur->second->emit_package(fd);
|
2013-05-12 05:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fd << "endpackage" << endl;
|
|
|
|
|
|
|
|
|
|
return errors;
|
|
|
|
|
}
|