Translate VHDL string literals to bit vectors

This commit is contained in:
Stephen Williams 2011-08-20 11:11:47 -07:00
parent 13c17a2485
commit 78788d17fe
2 changed files with 56 additions and 7 deletions

View File

@ -30,6 +30,7 @@ class Entity;
class Architecture; class Architecture;
class ScopeBase; class ScopeBase;
class VType; class VType;
class VTypeArray;
class VTypePrimitive; class VTypePrimitive;
class ExpName; class ExpName;
@ -377,8 +378,12 @@ class ExpString : public Expression {
int elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype); int elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype);
int emit(ostream&out, Entity*ent, Architecture*arc); int emit(ostream&out, Entity*ent, Architecture*arc);
bool is_primary(void) const;
void dump(ostream&out, int indent = 0) const; void dump(ostream&out, int indent = 0) const;
private:
int emit_as_array_(ostream&out, Entity*ent, Architecture*arc, const VTypeArray*arr);
private: private:
std::vector<char> value_; std::vector<char> value_;
}; };

View File

@ -339,16 +339,60 @@ int ExpRelation::emit(ostream&out, Entity*ent, Architecture*arc)
return errors; return errors;
} }
int ExpString::emit(ostream& out, Entity*, Architecture*) bool ExpString::is_primary(void) const
{ {
return true;
}
int ExpString::emit(ostream& out, Entity*ent, Architecture*arc)
{
const VType*type = peek_type();
assert(type != 0);
if (const VTypeArray*arr = dynamic_cast<const VTypeArray*>(type)) {
return emit_as_array_(out, ent, arc, arr);
}
out << "\""; out << "\"";
for(vector<char>::const_iterator it = value_.begin(); for(vector<char>::const_iterator it = value_.begin()
it != value_.end(); ++it) ; it != value_.end(); ++it)
out << *it; out << *it;
out << "\""; out << "\"";
return 0; return 0;
} }
int ExpString::emit_as_array_(ostream& out, Entity*, Architecture*, const VTypeArray*arr)
{
int errors = 0;
assert(arr->dimensions() == 1);
const VTypePrimitive*etype = dynamic_cast<const VTypePrimitive*> (arr->element_type());
assert(etype);
assert(etype->type() != VTypePrimitive::INTEGER);
out << value_.size() << "'b";
for (size_t idx = 0 ; idx < value_.size() ; idx += 1) {
switch (value_[idx]) {
case '0':
out << "0";
break;
case '1':
out << "1";
break;
case 'z': case 'Z':
assert(etype->type() == VTypePrimitive::STDLOGIC);
out << "z";
break;
default:
assert(etype->type() == VTypePrimitive::STDLOGIC);
out << "x";
break;
}
}
return errors;
}
int ExpUAbs::emit(ostream&out, Entity*ent, Architecture*arc) int ExpUAbs::emit(ostream&out, Entity*ent, Architecture*arc)
{ {
int errors = 0; int errors = 0;