From b711f16f055c67b2627e2bc4a0e03d774018a54c Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 5 Jan 2016 13:54:05 +0100 Subject: [PATCH] vhdlpp: 'image attribute. --- vhdlpp/expression_elaborate.cc | 3 +++ vhdlpp/expression_emit.cc | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index f0758c631..a84bfbdd9 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -605,6 +605,9 @@ int ExpTypeAttribute::elaborate_expr(Entity*, ScopeBase*, const VType*) const VType* ExpTypeAttribute::probe_type(Entity*, ScopeBase*) const { + if(name_ == "image") + return &primitive_STRING; + return NULL; } diff --git a/vhdlpp/expression_emit.cc b/vhdlpp/expression_emit.cc index 97e0d5b48..53ccde727 100644 --- a/vhdlpp/expression_emit.cc +++ b/vhdlpp/expression_emit.cc @@ -376,6 +376,30 @@ int ExpTypeAttribute::emit(ostream&out, Entity*ent, ScopeBase*scope) { int errors = 0; + // Special case: The image attribute + if (name_=="image") { + if(!args_ || args_->size() != 1) { + out << "/* Invalid 'image attribute */" << endl; + cerr << get_fileline() << ": error: 'image attribute takes " + << "exactly one argument." << endl; + ++errors; + } else { + out << "$sformatf(\""; + + if(base_->type_match(&primitive_INTEGER)) + out << "%0d"; + else if(base_->type_match(&primitive_REAL)) + out << "%f"; + else if(base_->type_match(&primitive_CHARACTER)) + out << "'%c'"; + + out << "\","; + args_->front()->emit(out, ent, scope); + out << ")"; + } + return errors; + } + // Fallback out << "$ivl_attribute("; errors += base_->emit_def(out, empty_perm_string);