vhdlpp: Added ExpCast class.

This commit is contained in:
Maciej Suminski 2015-01-22 11:26:53 +01:00
parent 51b9191021
commit 9b3bd039bb
5 changed files with 55 additions and 0 deletions

View File

@ -423,3 +423,13 @@ ExpUNot::ExpUNot(Expression*op1)
ExpUNot::~ExpUNot()
{
}
ExpCast::ExpCast(Expression*base, const VType*type) :
base_(base), type_(type)
{
}
ExpCast::~ExpCast()
{
}

View File

@ -674,4 +674,25 @@ class ExpUNot : public ExpUnary {
void dump(ostream&out, int indent = 0) const;
};
/*
* Class that wraps other expressions to cast them to other types.
*/
class ExpCast : public Expression {
public:
ExpCast(Expression*base, const VType*type);
~ExpCast();
inline int elaborate_expr(Entity*ent, Architecture*arc, const VType*) {
return base_->elaborate_expr(ent, arc, type_);
}
void write_to_stream(std::ostream&fd);
int emit(ostream&out, Entity*ent, Architecture*arc);
void dump(ostream&out, int indent = 0) const;
private:
Expression*base_;
const VType*type_;
};
#endif /* IVL_expression_H */

View File

@ -68,3 +68,11 @@ void ExpConcat::dump(ostream&out, int indent) const
operand1_->dump(out, indent);
operand2_->dump(out, indent);
}
void ExpCast::dump(ostream&out, int indent) const
{
out << "Casting ";
base_->dump(out, indent+4);
out << " to ";
type_->emit_def(out, empty_perm_string);
}

View File

@ -860,3 +860,13 @@ int ExpUNot::emit(ostream&out, Entity*ent, Architecture*arc)
out << ")";
return errors;
}
int ExpCast::emit(ostream&out, Entity*ent, Architecture*arc)
{
int errors = 0;
errors += type_->emit_def(out, empty_perm_string);
out << "'(";
errors += base_->emit(out, ent, arc);
out << ")";
return errors;
}

View File

@ -230,3 +230,9 @@ void ExpUNot::write_to_stream(ostream&fd)
write_to_stream_operand1(fd);
}
void ExpCast::write_to_stream(ostream&fd)
{
// Type casting is introduced only for a few specific cases in
// SystemVerilog, so no need to use it here
base_->write_to_stream(fd);
}