diff --git a/vhdlpp/package.cc b/vhdlpp/package.cc index 44f9ca3bc..d3d4a8b06 100644 --- a/vhdlpp/package.cc +++ b/vhdlpp/package.cc @@ -68,6 +68,12 @@ void Package::write_to_stream(ostream&fd) const for (map::const_iterator cur = cur_constants_.begin() ; cur != cur_constants_.end() ; ++ cur) { + if (cur->second==0 || cur->second->typ==0) { + fd << "-- const " << cur->first + << " has errors." << endl; + continue; + } + fd << "constant " << cur->first << ": "; cur->second->typ->write_to_stream(fd); fd << " := "; diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index 09c8e5f78..d21de7f84 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -6,8 +6,8 @@ %parse-param {perm_string parse_library_name} %{ /* - * Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com) - * Copyright CERN 2012 / Stephen Williams (steve@icarus.com) + * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) + * Copyright CERN 2012-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 @@ -674,6 +674,15 @@ composite_type_definition delete $2; $$ = tmp; } + + /* unbounded_array_definition IEEE 1076-2008 P5.3.2.1 */ + | K_array '(' index_subtype_definition_list ')' K_of subtype_indication + { sorrymsg(@1, "unbounded_array_definition not supported.\n"); + std::list r; + VTypeArray*tmp = new VTypeArray($6, &r); + $$ = tmp; + } + | record_type_definition { $$ = $1; } ; @@ -1342,6 +1351,16 @@ index_constraint } ; + /* The identifier should be a type name */ +index_subtype_definition /* IEEE 1076-2008 P5.3.2.1 */ + : IDENTIFIER K_range BOX + ; + +index_subtype_definition_list + : index_subtype_definition_list ',' index_subtype_definition + | index_subtype_definition + ; + instantiation_list : identifier_list { @@ -2189,12 +2208,13 @@ subtype_indication delete[]$1; $$ = tmp; } - | IDENTIFIER '(' simple_expression direction simple_expression ')' - { const VType*tmp = calculate_subtype_array(@1, $1, active_scope, $3, $4, $5); + | IDENTIFIER index_constraint + { const VType*tmp = calculate_subtype_array(@1, $1, active_scope, $2); if (tmp == 0) { errormsg(@1, "Unable to calculate bounds for array of %s.\n", $1); } delete[]$1; + delete $2; $$ = tmp; } | IDENTIFIER K_range simple_expression direction simple_expression @@ -2205,11 +2225,6 @@ subtype_indication delete[]$1; $$ = tmp; } - | IDENTIFIER '(' error ')' - { errormsg(@1, "Syntax error in subtype indication.\n"); - yyerrok; - $$ = new VTypeERROR; - } ; suffix diff --git a/vhdlpp/parse_misc.cc b/vhdlpp/parse_misc.cc index 10c058966..0049388bf 100644 --- a/vhdlpp/parse_misc.cc +++ b/vhdlpp/parse_misc.cc @@ -1,5 +1,6 @@ /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011,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 @@ -19,6 +20,7 @@ */ # include "parse_misc.h" +# include "parse_types.h" # include "parse_api.h" # include "entity.h" # include "architec.h" @@ -65,11 +67,11 @@ void bind_architecture_to_entity(const char*ename, Architecture*arch) } } -const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_name, - ScopeBase* /* scope */, - Expression*array_left, - bool /* downto*/ , - Expression*array_right) +static const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_name, + ScopeBase* /* scope */, + Expression*array_left, + bool /* downto*/ , + Expression*array_right) { const VType*base_type = parse_type_by_name(lex_strings.make(base_name)); @@ -98,6 +100,21 @@ const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_name, return base_type; } +const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_name, + ScopeBase*scope, list*ranges) +{ + if (ranges->size() == 1) { + prange_t*tmpr = ranges->front(); + Expression*lef = tmpr->expr_left(); + Expression*rig = tmpr->expr_right(); + return calculate_subtype_array(loc, base_name, scope, + lef, tmpr->is_downto(), rig); + } + + sorrymsg(loc, "Don't know how to handle multiple ranges here.\n"); + return 0; +} + const VType* calculate_subtype_range(const YYLTYPE&loc, const char*base_name, ScopeBase*scope, Expression*range_left, diff --git a/vhdlpp/parse_misc.h b/vhdlpp/parse_misc.h index d54a648f9..1e4c27669 100644 --- a/vhdlpp/parse_misc.h +++ b/vhdlpp/parse_misc.h @@ -1,7 +1,8 @@ #ifndef __parse_misc_H #define __parse_misc_H /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011,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 @@ -25,6 +26,7 @@ class ActiveScope; class Architecture; class Expression; class Package; +class prange_t; class ScopeBase; class VType; @@ -33,9 +35,7 @@ extern void bind_architecture_to_entity(const char*ename, Architecture*arch); extern const VType* calculate_subtype_array(const YYLTYPE&loc, const char*base_name, ScopeBase*scope, - Expression*array_left, - bool downto, - Expression*array_right); + std::list*ranges); extern const VType* calculate_subtype_range(const YYLTYPE&loc, const char*base_name, ScopeBase*scope, Expression*range_left, diff --git a/vhdlpp/parse_types.h b/vhdlpp/parse_types.h index 2a8b27520..fb9b5a9b5 100644 --- a/vhdlpp/parse_types.h +++ b/vhdlpp/parse_types.h @@ -1,7 +1,8 @@ #ifndef __parse_types_H #define __parse_types_H /* - * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2011,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 @@ -74,10 +75,12 @@ class prange_t { ~prange_t() { delete left_; delete right_; } void dump(ostream&out, int indent) const; - Expression*msb() { return direction_? left_ : right_; } - Expression*lsb() { return direction_? right_: left_; } + inline Expression*msb() { return direction_? left_ : right_; } + inline Expression*lsb() { return direction_? right_: left_; } inline bool is_downto() const { return direction_; } + inline Expression*expr_left() { return left_; } + inline Expression*expr_right() { return right_; } private: Expression *left_, *right_;