Stub support for library import.

This provides a stub implementation for library import. Use this
stub to make up a slightly more functional ieee library implementation.
This commit is contained in:
Stephen Williams 2011-02-19 11:39:00 -08:00
parent 7d552980a6
commit 8a5225e61f
6 changed files with 58 additions and 8 deletions

View File

@ -40,14 +40,15 @@ inline void FILE_NAME(LineInfo*tmp, const struct yyltype&where)
static void yyerror(const char*msg);
static void errormsg(const YYLTYPE&loc, const char*msg, ...);
int parse_errors = 0;
%}
%union {
port_mode_t port_mode;
char*text;
std::list<perm_string>* name_list;
bool flag;
int64_t uni_integer;
@ -116,7 +117,8 @@ int parse_errors = 0;
%type <vtype> subtype_indication
%type <text> identifier_opt
%type <text> identifier_opt logical_name
%type <name_list> logical_name_list
%%
@ -315,6 +317,9 @@ interface_list
library_clause
: K_library logical_name_list ';'
{ library_import(@1, $2);
delete $2;
}
| K_library error ';'
{ errormsg(@1, "Syntax error in library clause.\n"); yyerrok; }
;
@ -326,11 +331,21 @@ library_unit
| architecture_body
;
logical_name : IDENTIFIER ;
logical_name : IDENTIFIER { $$ = $1; } ;
logical_name_list
: logical_name_list ',' logical_name
{ std::list<perm_string>*tmp = $1;
tmp->push_back(lex_strings.make($3));
delete[]$3;
$$ = tmp;
}
| logical_name
{ std::list<perm_string>*tmp = new std::list<perm_string>;
tmp->push_back(lex_strings.make($1));
delete[]$1;
$$ = tmp;
}
;
mode
@ -440,7 +455,7 @@ static void yyerror(const char*msg)
static const char*file_path = "";
static void errormsg(const YYLTYPE&loc, const char*fmt, ...)
void errormsg(const YYLTYPE&loc, const char*fmt, ...)
{
va_list ap;
va_start(ap, fmt);

View File

@ -42,10 +42,24 @@ struct yyltype {
*/
extern void reset_lexor(FILE*fd, const char*path);
/*
* The parser calls yylex to get the next lexical token. It is only
* called by the bison-generated parser.
*/
extern int yylex(void);
/*
* This is the bison-generated parser.
*/
extern int yyparse(void);
/*
* Use this functio during parse to generate error messages. The "loc"
* is the location of the token that triggered the error, and the fmt
* is printf-style format.
*/
extern void errormsg(const YYLTYPE&loc, const char*fmt, ...) __attribute__((format (printf, 2, 3)));
/*
* Set this to a non-zero value to enable parser debug output.
*/

View File

@ -87,3 +87,17 @@ const VType* calculate_subtype(const char*base_name,
return base_type;
}
void library_import(const YYLTYPE&loc, const std::list<perm_string>*names)
{
for (std::list<perm_string>::const_iterator cur = names->begin()
; cur != names->end() ; ++cur) {
if (*cur == "ieee") {
// The ieee library is special and handled by an
// internal function.
import_ieee();
} else {
errormsg(loc, "sorry: library import (%s) not implemented.\n", cur->str());
}
}
}

View File

@ -19,6 +19,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
# include "parse_api.h"
class Architecture;
class Expression;
class VType;
@ -30,4 +32,6 @@ extern const VType* calculate_subtype(const char*base_name,
bool downto,
Expression*array_right);
extern void library_import(const YYLTYPE&loc, const std::list<perm_string>*names);
#endif

View File

@ -35,12 +35,14 @@ void preload_global_types(void)
global_types[perm_string::literal("bit")] = &primitive_BIT;
global_types[perm_string::literal("integer")] = &primitive_INTEGER;
global_types[perm_string::literal("std_logic")] = &primitive_STDLOGIC;
{ vector<VTypeArray::range_t> dims (1);
global_types[perm_string::literal("unsigned")] = new VTypeArray(&primitive_BIT, dims);
}
}
void import_ieee(void)
{
vector<VTypeArray::range_t> dims (1);
global_types[perm_string::literal("unsigned")] = new VTypeArray(&primitive_BIT, dims);
}
VType::~VType()
{

View File

@ -53,6 +53,7 @@ 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);
/*
* This class represents the primative types that are available to the