From 5ed60a151f711b60e870817d6815b6bcf2ea86ea Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 6 Aug 2014 15:00:35 +0200 Subject: [PATCH] Added support for real type in vhdlpp. --- vhdlpp/debug.cc | 13 +++++++++++++ vhdlpp/expression.cc | 18 +++++++++++++++++- vhdlpp/expression.h | 24 +++++++++++++++++++++++- vhdlpp/expression_elaborate.cc | 18 ++++++++++++++++++ vhdlpp/expression_emit.cc | 17 +++++++++++++++++ vhdlpp/expression_stream.cc | 5 +++++ vhdlpp/library.cc | 3 +++ vhdlpp/parse.y | 8 +++++++- vhdlpp/vtype.cc | 3 +++ vhdlpp/vtype.h | 6 ++++-- vhdlpp/vtype_emit.cc | 4 ++++ vhdlpp/vtype_stream.cc | 3 +++ 12 files changed, 117 insertions(+), 5 deletions(-) diff --git a/vhdlpp/debug.cc b/vhdlpp/debug.cc index a6f9542b9..f6152b94c 100644 --- a/vhdlpp/debug.cc +++ b/vhdlpp/debug.cc @@ -1,5 +1,6 @@ /* * Copyright (c) 2011 Stephen Williams (steve@icarus.com) + * Copyright (c) 2014 CERN / Maciej Suminski (maciej.suminski@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -335,6 +336,12 @@ void ExpInteger::dump(ostream&out, int indent) const << " at " << get_fileline() << endl; } +void ExpReal::dump(ostream&out, int indent) const +{ + out << setw(indent) << "" << "Integer " << value_ + << " at " << get_fileline() << endl; +} + void ExpLogical::dump(ostream&out, int indent) const { const char*fun_name = "?"; @@ -460,6 +467,12 @@ ostream& ExpInteger::dump_inline(ostream&out) const return out; } +ostream& ExpReal::dump_inline(ostream&out) const +{ + out << value_; + return out; +} + void Subprogram::dump(ostream&fd) const { fd << " " << name_; diff --git a/vhdlpp/expression.cc b/vhdlpp/expression.cc index 74e143c63..526d06be2 100644 --- a/vhdlpp/expression.cc +++ b/vhdlpp/expression.cc @@ -1,6 +1,7 @@ /* * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) - * Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com) + * Copyright CERN 2012-2014 / Stephen Williams (steve@icarus.com), + * Maciej Suminski (maciej.suminski@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -297,6 +298,21 @@ bool ExpInteger::evaluate(ScopeBase*, int64_t&val) const return true; } +ExpReal::ExpReal(double val) +: value_(val) +{ +} + +ExpReal::~ExpReal() +{ +} + +bool ExpReal::evaluate(ScopeBase*, double&val) const +{ + val = value_; + return true; +} + ExpLogical::ExpLogical(ExpLogical::fun_t ty, Expression*op1, Expression*op2) : ExpBinary(op1, op2), fun_(ty) { diff --git a/vhdlpp/expression.h b/vhdlpp/expression.h index 9cf5b2485..d26a8c5df 100644 --- a/vhdlpp/expression.h +++ b/vhdlpp/expression.h @@ -2,7 +2,8 @@ #define IVL_expression_H /* * Copyright (c) 2011-2014 Stephen Williams (steve@icarus.com) - * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) + * Copyright CERN 2014 / Stephen Williams (steve@icarus.com), + * Maciej Suminski (maciej.suminski@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -462,6 +463,7 @@ class ExpEdge : public ExpUnary { private: fun_t fun_; }; + class ExpFunc : public Expression { public: @@ -505,6 +507,26 @@ class ExpInteger : public Expression { int64_t value_; }; +class ExpReal : public Expression { + + public: + ExpReal(double val); + ~ExpReal(); + + const VType*probe_type(Entity*ent, Architecture*arc) const; + int elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype); + void write_to_stream(std::ostream&fd); + int emit(ostream&out, Entity*ent, Architecture*arc); + int emit_package(std::ostream&out); + bool is_primary(void) const; + bool evaluate(ScopeBase*scope, double&val) const; + void dump(ostream&out, int indent = 0) const; + virtual ostream& dump_inline(ostream&out) const; + + private: + double value_; +}; + class ExpLogical : public ExpBinary { public: diff --git a/vhdlpp/expression_elaborate.cc b/vhdlpp/expression_elaborate.cc index df0935d5d..0cff0344c 100644 --- a/vhdlpp/expression_elaborate.cc +++ b/vhdlpp/expression_elaborate.cc @@ -692,6 +692,24 @@ int ExpInteger::elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype) return errors; } +const VType* ExpReal::probe_type(Entity*, Architecture*) const +{ + return primitive_REAL; +} + +int ExpReal::elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype) +{ + int errors = 0; + + if (ltype == 0) { + ltype = probe_type(ent, arc); + } + + ivl_assert(*this, ltype != 0); + + return errors; +} + int ExpLogical::elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype) { int errors = 0; diff --git a/vhdlpp/expression_emit.cc b/vhdlpp/expression_emit.cc index f6cd315d0..8ba1d1120 100644 --- a/vhdlpp/expression_emit.cc +++ b/vhdlpp/expression_emit.cc @@ -605,6 +605,23 @@ bool ExpInteger::is_primary(void) const return true; } +int ExpReal::emit(ostream&out, Entity*, Architecture*) +{ + out << value_; + return 0; +} + +int ExpReal::emit_package(ostream&out) +{ + out << value_; + return 0; +} + +bool ExpReal::is_primary(void) const +{ + return true; +} + int ExpLogical::emit(ostream&out, Entity*ent, Architecture*arc) { int errors = 0; diff --git a/vhdlpp/expression_stream.cc b/vhdlpp/expression_stream.cc index b8da43179..901bfab9e 100644 --- a/vhdlpp/expression_stream.cc +++ b/vhdlpp/expression_stream.cc @@ -164,6 +164,11 @@ void ExpInteger::write_to_stream(ostream&fd) fd << value_; } +void ExpReal::write_to_stream(ostream&fd) +{ + fd << value_; +} + void ExpLogical::write_to_stream(ostream&) { ivl_assert(*this, !"Not supported"); diff --git a/vhdlpp/library.cc b/vhdlpp/library.cc index 681388647..d5a80a106 100644 --- a/vhdlpp/library.cc +++ b/vhdlpp/library.cc @@ -346,6 +346,7 @@ static void import_ieee_use(ActiveScope*res, perm_string package, perm_string na const VTypePrimitive* primitive_BOOLEAN = new VTypePrimitive(VTypePrimitive::BOOLEAN); const VTypePrimitive* primitive_BIT = new VTypePrimitive(VTypePrimitive::BIT); const VTypePrimitive* primitive_INTEGER = new VTypePrimitive(VTypePrimitive::INTEGER); +const VTypePrimitive* primitive_REAL = new VTypePrimitive(VTypePrimitive::REAL); const VTypePrimitive* primitive_STDLOGIC = new VTypePrimitive(VTypePrimitive::STDLOGIC); const VTypePrimitive* primitive_CHARACTER= new VTypePrimitive(VTypePrimitive::CHARACTER); @@ -360,6 +361,7 @@ void generate_global_types(ActiveScope*res) res->use_name(perm_string::literal("boolean"), primitive_BOOLEAN); res->use_name(perm_string::literal("bit"), primitive_BIT); res->use_name(perm_string::literal("integer"), primitive_INTEGER); + res->use_name(perm_string::literal("real"), primitive_REAL); res->use_name(perm_string::literal("std_logic"), primitive_STDLOGIC); res->use_name(perm_string::literal("character"), primitive_CHARACTER); res->use_name(perm_string::literal("bit_vector"),primitive_BOOL_VECTOR); @@ -372,6 +374,7 @@ bool is_global_type(perm_string name) if (name == "boolean") return true; if (name == "bit") return true; if (name == "integer") return true; + if (name == "real") return true; if (name == "std_logic") return true; if (name == "character") return true; if (name == "bit_vector") return true; diff --git a/vhdlpp/parse.y b/vhdlpp/parse.y index 453344930..e9ac90604 100644 --- a/vhdlpp/parse.y +++ b/vhdlpp/parse.y @@ -7,7 +7,8 @@ %{ /* * Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com) - * Copyright CERN 2012-2013 / Stephen Williams (steve@icarus.com) + * Copyright CERN 2012-2014 / Stephen Williams (steve@icarus.com), + * Maciej Suminski (maciej.suminski@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -1741,6 +1742,11 @@ primary FILE_NAME(tmp, @1); $$ = tmp; } + | REAL_LITERAL + { ExpReal*tmp = new ExpReal($1); + FILE_NAME(tmp, @1); + $$ = tmp; + } | STRING_LITERAL { ExpString*tmp = new ExpString($1); FILE_NAME(tmp,@1); diff --git a/vhdlpp/vtype.cc b/vhdlpp/vtype.cc index 34787c6a0..9d35bd36b 100644 --- a/vhdlpp/vtype.cc +++ b/vhdlpp/vtype.cc @@ -59,6 +59,9 @@ void VTypePrimitive::show(ostream&out) const case INTEGER: out << "INTEGER"; break; + case REAL: + out << "REAL"; + break; case STDLOGIC: out << "std_logic"; break; diff --git a/vhdlpp/vtype.h b/vhdlpp/vtype.h index 0c99a11d7..e3d0bacea 100644 --- a/vhdlpp/vtype.h +++ b/vhdlpp/vtype.h @@ -2,7 +2,8 @@ #define IVL_vtype_H /* * Copyright (c) 2011-2014 Stephen Williams (steve@icarus.com) - * Copyright CERN 2013 / Stephen Williams (steve@icarus.com) + * Copyright CERN 2013 / Stephen Williams (steve@icarus.com), + * Maciej Suminski (maciej.suminski@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -124,7 +125,7 @@ class VTypeERROR : public VType { class VTypePrimitive : public VType { public: - enum type_t { BOOLEAN, BIT, INTEGER, STDLOGIC, CHARACTER }; + enum type_t { BOOLEAN, BIT, INTEGER, REAL, STDLOGIC, CHARACTER }; public: VTypePrimitive(type_t); @@ -145,6 +146,7 @@ class VTypePrimitive : public VType { extern const VTypePrimitive* primitive_BOOLEAN; extern const VTypePrimitive* primitive_BIT; extern const VTypePrimitive* primitive_INTEGER; +extern const VTypePrimitive* primitive_REAL; extern const VTypePrimitive* primitive_STDLOGIC; extern const VTypePrimitive* primitive_CHARACTER; diff --git a/vhdlpp/vtype_emit.cc b/vhdlpp/vtype_emit.cc index 7508ee8c4..d5f8b32da 100644 --- a/vhdlpp/vtype_emit.cc +++ b/vhdlpp/vtype_emit.cc @@ -1,5 +1,6 @@ /* * Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com) + * Copyright (c) 2014 CERN / Maciej Suminski (maciej.suminski@cern.ch) * * This source code is free software; you can redistribute it * and/or modify it in source code form under the terms of the GNU @@ -136,6 +137,9 @@ int VTypePrimitive::emit_primitive_type(ostream&out) const case INTEGER: out << "bool [31:0]"; break; + case REAL: + out << "real"; + break; case CHARACTER: out << "char"; break; diff --git a/vhdlpp/vtype_stream.cc b/vhdlpp/vtype_stream.cc index ed21e5a99..89c347d8f 100644 --- a/vhdlpp/vtype_stream.cc +++ b/vhdlpp/vtype_stream.cc @@ -102,6 +102,9 @@ void VTypePrimitive::write_to_stream(ostream&fd) const case INTEGER: fd << "integer"; break; + case REAL: + fd << "real"; + break; case STDLOGIC: fd << "std_logic"; break;