Added support for real type in vhdlpp.

This commit is contained in:
Maciej Suminski 2014-08-06 15:00:35 +02:00
parent c7a36722e3
commit 5ed60a151f
12 changed files with 117 additions and 5 deletions

View File

@ -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_;

View File

@ -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)
{

View File

@ -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:

View File

@ -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;

View File

@ -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;

View File

@ -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");

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;