diff --git a/vhdlpp/compiler.h b/vhdlpp/compiler.h index a2ba77083..3cd1b820a 100644 --- a/vhdlpp/compiler.h +++ b/vhdlpp/compiler.h @@ -34,8 +34,4 @@ extern StringHeapLex lex_strings; extern StringHeapLex filename_strings; -extern void library_set_work_path(const char*work_path); -extern void library_add_directory(const char*directory); -extern int emit_packages(void); - #endif /* IVL_compiler_H */ diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index 481a26597..917a6c28a 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -24,6 +24,7 @@ # include "entity.h" # include "vsignal.h" # include "subprogram.h" +# include "library.h" # include # include # include "parse_types.h" @@ -711,6 +712,9 @@ int ExpFunc::elaborate_expr(Entity*ent, Architecture*arc, const VType*) ivl_assert(*this, arc); Subprogram*prog = arc->find_subprogram(name_); + if(!prog) + prog = library_find_subprogram(name_); + ivl_assert(*this, def_==0); def_ = prog; diff --git a/vhdlpp/library.cc b/vhdlpp/library.cc index 214d42162..f86c590e9 100644 --- a/vhdlpp/library.cc +++ b/vhdlpp/library.cc @@ -69,7 +69,25 @@ void library_add_directory(const char*directory) return; } - library_search_path .push_front(directory); + library_search_path.push_front(directory); +} + +Subprogram*library_find_subprogram(perm_string name) +{ + Subprogram*subp = NULL; + map::const_iterator lib_it; + + for(lib_it = libraries.begin(); lib_it != libraries.end(); ++lib_it) { + const struct library_contents&lib = lib_it->second; + map::const_iterator pack_it; + + for(pack_it = lib.packages.begin(); pack_it != lib.packages.end(); ++pack_it) { + if((subp = pack_it->second->find_subprogram(name))) + return subp; + } + } + + return NULL; } static void store_package_in_work(const Package*pack); diff --git a/vhdlpp/library.h b/vhdlpp/library.h new file mode 100644 index 000000000..ab6464f45 --- /dev/null +++ b/vhdlpp/library.h @@ -0,0 +1,32 @@ +#ifndef IVL_library_H +#define IVL_library_H +/* + * Copyright (c) 2011-2014 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. + */ + +class Subprogram; + +extern void library_set_work_path(const char*work_path); +extern void library_add_directory(const char*directory); + +extern Subprogram*library_find_subprogram(perm_string name); + +extern int emit_packages(void); + +#endif /* IVL_library_H */ + diff --git a/vhdlpp/main.cc b/vhdlpp/main.cc index f0351dcd9..b142d3845 100644 --- a/vhdlpp/main.cc +++ b/vhdlpp/main.cc @@ -75,6 +75,7 @@ const char NOTICE[] = ; # include "compiler.h" +# include "library.h" # include "parse_api.h" # include "vtype.h" # include