From c6ea2f3bf5e7d374763bc9af8616bc70fb9549f8 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 19 Feb 2011 13:08:26 -0800 Subject: [PATCH] Stub support for "use" directives. Implement the parser infrastructure for handling library use clauses, and use that to handle specific packages of the ieee library. Make the numeric types come from the numeric_* packages instead of being built in. --- vhdlpp/entity_emit.cc | 1 + vhdlpp/parse.y | 20 +++++++++++++++----- vhdlpp/parse_misc.cc | 20 ++++++++++++++++++++ vhdlpp/parse_misc.h | 2 ++ vhdlpp/vtype.cc | 43 +++++++++++++++++++++++++++++++++++++++++-- vhdlpp/vtype.h | 2 ++ 6 files changed, 81 insertions(+), 7 deletions(-) diff --git a/vhdlpp/entity_emit.cc b/vhdlpp/entity_emit.cc index a35e1a3b2..21d711328 100644 --- a/vhdlpp/entity_emit.cc +++ b/vhdlpp/entity_emit.cc @@ -92,6 +92,7 @@ int Entity::emit(ostream&out) out << "[" << cur->second.msb << ":" << cur->second.lsb << "] "; out << cur->first << ";" << endl; + break; case VBOOL: out << "wire bool "; if (cur->second.signed_flag) diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index f0529c1a2..d2696ab03 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -379,14 +379,24 @@ primary relation : shift_expression { $$ = $1; } ; -selected_name + /* The *_use variant of selected_name is used by the "use" + clause. It is syntactically identical to other selected_name + rules, but is a convenient place to attach use_clause actions. */ +selected_name_use : IDENTIFIER '.' K_all + { library_use(@1, 0, $1, 0); + delete[]$1; + } | IDENTIFIER '.' IDENTIFIER '.' K_all + { library_use(@1, $1, $3, 0); + delete[]$1; + delete[]$3; + } ; -selected_names - : selected_names ',' selected_name - | selected_name +selected_names_use + : selected_names_use ',' selected_name_use + | selected_name_use ; shift_expression : simple_expression { $$ = $1; } ; @@ -409,7 +419,7 @@ subtype_indication term : factor { $$ = $1; } ; use_clause - : K_use selected_names ';' + : K_use selected_names_use ';' | K_use error ';' { errormsg(@1, "Syntax error in use clause.\n"); yyerrok; } ; diff --git a/vhdlpp/parse_misc.cc b/vhdlpp/parse_misc.cc index de1985bd6..31bc90252 100644 --- a/vhdlpp/parse_misc.cc +++ b/vhdlpp/parse_misc.cc @@ -101,3 +101,23 @@ void library_import(const YYLTYPE&loc, const std::list*names) } } } + +void library_use(const YYLTYPE&loc, const char*libname, const char*pack, const char*name) +{ + if (libname == 0) { + errormsg(loc, "error: No library name for this use clause?\n"); + return; + } + + perm_string use_library = lex_strings.make(libname); + perm_string use_package = lex_strings.make(pack); + perm_string use_name = name? lex_strings.make(name) : perm_string::literal("all"); + + // Special case handling for the IEEE library. + if (use_library == "ieee") { + import_ieee_use(use_package, use_name); + return; + } + + errormsg(loc, "sorry: Only the IEEE library is supported,\n"); +} diff --git a/vhdlpp/parse_misc.h b/vhdlpp/parse_misc.h index 108e49c74..b03bccc73 100644 --- a/vhdlpp/parse_misc.h +++ b/vhdlpp/parse_misc.h @@ -34,4 +34,6 @@ extern const VType* calculate_subtype(const char*base_name, extern void library_import(const YYLTYPE&loc, const std::list*names); +extern void library_use(const YYLTYPE&loc, const char*libname, const char*pack, const char*ident); + #endif diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 6ad6446ab..27ac85015 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -39,9 +39,48 @@ void preload_global_types(void) void import_ieee(void) { +} - vector dims (1); - global_types[perm_string::literal("unsigned")] = new VTypeArray(&primitive_BIT, dims); +static void import_ieee_use_std_logic_1164(perm_string) +{ +} + +static void import_ieee_use_numeric_bit(perm_string name) +{ + bool all_flag = name=="all"; + + if (all_flag || name == "unsigned") { + vector dims (1); + global_types[perm_string::literal("unsigned")] = new VTypeArray(&primitive_BIT, dims); + } +} + +static void import_ieee_use_numeric_std(perm_string name) +{ + bool all_flag = name=="all"; + + if (all_flag || name == "unsigned") { + vector dims (1); + global_types[perm_string::literal("unsigned")] = new VTypeArray(&primitive_STDLOGIC, dims); + } +} + +void import_ieee_use(perm_string package, perm_string name) +{ + if (package == "std_logic_1164") { + import_ieee_use_std_logic_1164(name); + return; + } + + if (package == "numeric_bit") { + import_ieee_use_numeric_bit(name); + return; + } + + if (package == "numeric_std") { + import_ieee_use_numeric_std(name); + return; + } } VType::~VType() diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index 62248cf00..c22b413d4 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -53,7 +53,9 @@ inline std::ostream&operator << (std::ostream&out, const VType&item) extern std::map global_types; extern void preload_global_types(void); + extern void import_ieee(void); +extern void import_ieee_use(perm_string package, perm_string name); /* * This class represents the primative types that are available to the