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.
This commit is contained in:
parent
8a5225e61f
commit
c6ea2f3bf5
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
;
|
||||
|
|
|
|||
|
|
@ -101,3 +101,23 @@ void library_import(const YYLTYPE&loc, const std::list<perm_string>*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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,6 @@ extern const VType* calculate_subtype(const char*base_name,
|
|||
|
||||
extern void library_import(const YYLTYPE&loc, const std::list<perm_string>*names);
|
||||
|
||||
extern void library_use(const YYLTYPE&loc, const char*libname, const char*pack, const char*ident);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -39,9 +39,48 @@ void preload_global_types(void)
|
|||
|
||||
void import_ieee(void)
|
||||
{
|
||||
}
|
||||
|
||||
vector<VTypeArray::range_t> 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<VTypeArray::range_t> 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<VTypeArray::range_t> 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()
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ inline std::ostream&operator << (std::ostream&out, const VType&item)
|
|||
extern std::map<perm_string, const VType*> 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
|
||||
|
|
|
|||
Loading…
Reference in New Issue