Support VHDL user defined array types.

This commit is contained in:
Stephen Williams 2011-11-05 15:55:17 -07:00
parent 98d928f6e0
commit 2063c5ee9d
9 changed files with 69 additions and 14 deletions

View File

@ -59,7 +59,7 @@ GenerateStatement::~GenerateStatement()
}
ForGenerate::ForGenerate(perm_string gname, perm_string genvar,
range_t*rang, std::list<Architecture::Statement*>&s)
prange_t*rang, std::list<Architecture::Statement*>&s)
: GenerateStatement(gname, s), genvar_(genvar),
lsb_(rang->lsb()), msb_(rang->msb())
{

View File

@ -32,7 +32,7 @@ class ExpName;
class SequentialStmt;
class Signal;
class named_expr_t;
class range_t;
class prange_t;
/*
* The Architecture class carries the contents (name, statements,
@ -114,7 +114,7 @@ class ForGenerate : public GenerateStatement {
public:
ForGenerate(perm_string gname, perm_string genvar,
range_t*rang, std::list<Architecture::Statement*>&s);
prange_t*rang, std::list<Architecture::Statement*>&s);
~ForGenerate();
int elaborate(Entity*ent, Architecture*arc);

View File

@ -435,7 +435,7 @@ void named_expr_t::dump(ostream&out, int indent) const
expr_->dump(out, indent);
}
void range_t::dump(ostream&out, int indent) const
void prange_t::dump(ostream&out, int indent) const
{
left_->dump(out, indent);
out << setw(indent) << "" << (direction_ ? "downto" : "to");

View File

@ -175,7 +175,8 @@ const VType*parse_type_by_name(perm_string name)
const VType* vtype;
range_t* range;
prange_t* range;
std::list<prange_t*>*range_list;
ExpArithmetic::fun_t arithmetic_op;
@ -278,6 +279,7 @@ const VType*parse_type_by_name(perm_string name)
%type <sequ> loop_statement variable_assignment_statement
%type <range> range
%type <range_list> range_list index_constraint
%type <case_alt> case_statement_alternative
%type <case_alt_list> case_statement_alternative_list
@ -1110,6 +1112,11 @@ if_statement_else
{ $$ = 0; }
;
index_constraint
: '(' range_list ')'
{ $$ = $2; }
;
instantiation_list
: identifier_list
{
@ -1613,7 +1620,20 @@ process_sensitivity_list
range
: simple_expression direction simple_expression
{ range_t* tmp = new range_t($1, $3, $2);
{ prange_t* tmp = new prange_t($1, $3, $2);
$$ = tmp;
}
;
range_list
: range
{ list<prange_t*>*tmp = new list<prange_t*>;
tmp->push_back($1);
$$ = tmp;
}
| range_list ',' range
{ list<prange_t*>*tmp = $1;
tmp->push_back($3);
$$ = tmp;
}
;
@ -1876,6 +1896,12 @@ type_declaration
//active_scope->bind_name(name, tmp);
active_scope->bind_name(name, $4);
}
delete[]$2;
}
| K_type IDENTIFIER K_is error ';'
{ errormsg(@4, "Error in type definition for %s\n", $2);
yyerrok;
delete[]$2;
}
;
@ -1885,6 +1911,12 @@ type_definition
delete $2;
$$ = tmp;
}
/* constrained_array_definition */
| K_array index_constraint K_of subtype_indication
{ VTypeArray*tmp = new VTypeArray($4, $2);
delete $2;
$$ = tmp;
}
;
use_clause

View File

@ -67,11 +67,11 @@ class instant_list_t {
std::list<perm_string>* labels_;
};
class range_t {
class prange_t {
public:
range_t(Expression* left, Expression* right, bool dir)
prange_t(Expression* left, Expression* right, bool dir)
: left_(left), right_(right), direction_(dir) {}
~range_t() { delete left_; delete right_; }
~prange_t() { delete left_; delete right_; }
void dump(ostream&out, int indent) const;
Expression*msb() { return direction_? left_ : right_; }
@ -84,7 +84,7 @@ class range_t {
bool direction_;
private: //not implemented
range_t(const range_t&);
range_t operator=(const range_t&);
prange_t(const prange_t&);
prange_t operator=(const prange_t&);
};
#endif

View File

@ -168,7 +168,7 @@ LoopStatement::~LoopStatement()
}
}
ForLoopStatement::ForLoopStatement(perm_string scope_name, perm_string it, range_t* range, list<SequentialStmt*>* stmts)
ForLoopStatement::ForLoopStatement(perm_string scope_name, perm_string it, prange_t* range, list<SequentialStmt*>* stmts)
: LoopStatement(scope_name, stmts), it_(it), range_(range)
{
}

View File

@ -205,7 +205,7 @@ class WhileLoopStatement : public LoopStatement {
class ForLoopStatement : public LoopStatement {
public:
ForLoopStatement(perm_string loop_name,
perm_string index, range_t*, list<SequentialStmt*>*);
perm_string index, prange_t*, list<SequentialStmt*>*);
~ForLoopStatement();
int elaborate(Entity*ent, Architecture*arc);
@ -214,7 +214,7 @@ class ForLoopStatement : public LoopStatement {
private:
perm_string it_;
range_t* range_;
prange_t* range_;
};
class BasicLoopStatement : public LoopStatement {

View File

@ -18,6 +18,7 @@
*/
# include "vtype.h"
# include "parse_types.h"
# include <map>
# include <typeinfo>
@ -65,6 +66,26 @@ VTypeArray::VTypeArray(const VType*element, const vector<VTypeArray::range_t>&r,
{
}
/*
* Create a VTypeArray range set from a list of parsed ranges.
* FIXME: We are copying pointers from the prange_t object into the
* range_t. This means that we cannot delete the prange_t object
* unless we invent a way to remove the pointers from that object. So
* this is a memory leak. Something to fix.
*/
VTypeArray::VTypeArray(const VType*element, std::list<prange_t*>*r, bool sv)
: etype_(element), ranges_(r->size()), signed_flag_(sv)
{
for (size_t idx = 0 ; idx < ranges_.size() ; idx += 1) {
prange_t*curp = r->front();
r->pop_front();
Expression*msb = curp->msb();
Expression*lsb = curp->lsb();
ranges_[idx] = range_t(msb, lsb);
}
}
VTypeArray::~VTypeArray()
{
}

View File

@ -27,6 +27,7 @@
# include "StringHeap.h"
class Expression;
class prange_t;
/*
* A description of a VHDL type consists of a graph of VType
@ -140,6 +141,7 @@ class VTypeArray : public VType {
public:
VTypeArray(const VType*etype, const std::vector<range_t>&r, bool signed_vector =false);
VTypeArray(const VType*etype, std::list<prange_t*>*r, bool signed_vector =false);
~VTypeArray();
void write_to_stream(std::ostream&fd) const;