Added support for real type in vhdlpp.
This commit is contained in:
parent
c7a36722e3
commit
5ed60a151f
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011 Stephen Williams (steve@icarus.com)
|
* 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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* 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;
|
<< " 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
|
void ExpLogical::dump(ostream&out, int indent) const
|
||||||
{
|
{
|
||||||
const char*fun_name = "?";
|
const char*fun_name = "?";
|
||||||
|
|
@ -460,6 +467,12 @@ ostream& ExpInteger::dump_inline(ostream&out) const
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ostream& ExpReal::dump_inline(ostream&out) const
|
||||||
|
{
|
||||||
|
out << value_;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
void Subprogram::dump(ostream&fd) const
|
void Subprogram::dump(ostream&fd) const
|
||||||
{
|
{
|
||||||
fd << " " << name_;
|
fd << " " << name_;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
* 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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* 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;
|
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)
|
ExpLogical::ExpLogical(ExpLogical::fun_t ty, Expression*op1, Expression*op2)
|
||||||
: ExpBinary(op1, op2), fun_(ty)
|
: ExpBinary(op1, op2), fun_(ty)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
#define IVL_expression_H
|
#define IVL_expression_H
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2014 Stephen Williams (steve@icarus.com)
|
* 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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -462,6 +463,7 @@ class ExpEdge : public ExpUnary {
|
||||||
private:
|
private:
|
||||||
fun_t fun_;
|
fun_t fun_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ExpFunc : public Expression {
|
class ExpFunc : public Expression {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -505,6 +507,26 @@ class ExpInteger : public Expression {
|
||||||
int64_t value_;
|
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 {
|
class ExpLogical : public ExpBinary {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -692,6 +692,24 @@ int ExpInteger::elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype)
|
||||||
return errors;
|
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 ExpLogical::elaborate_expr(Entity*ent, Architecture*arc, const VType*ltype)
|
||||||
{
|
{
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
|
||||||
|
|
@ -605,6 +605,23 @@ bool ExpInteger::is_primary(void) const
|
||||||
return true;
|
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 ExpLogical::emit(ostream&out, Entity*ent, Architecture*arc)
|
||||||
{
|
{
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,11 @@ void ExpInteger::write_to_stream(ostream&fd)
|
||||||
fd << value_;
|
fd << value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ExpReal::write_to_stream(ostream&fd)
|
||||||
|
{
|
||||||
|
fd << value_;
|
||||||
|
}
|
||||||
|
|
||||||
void ExpLogical::write_to_stream(ostream&)
|
void ExpLogical::write_to_stream(ostream&)
|
||||||
{
|
{
|
||||||
ivl_assert(*this, !"Not supported");
|
ivl_assert(*this, !"Not supported");
|
||||||
|
|
|
||||||
|
|
@ -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_BOOLEAN = new VTypePrimitive(VTypePrimitive::BOOLEAN);
|
||||||
const VTypePrimitive* primitive_BIT = new VTypePrimitive(VTypePrimitive::BIT);
|
const VTypePrimitive* primitive_BIT = new VTypePrimitive(VTypePrimitive::BIT);
|
||||||
const VTypePrimitive* primitive_INTEGER = new VTypePrimitive(VTypePrimitive::INTEGER);
|
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_STDLOGIC = new VTypePrimitive(VTypePrimitive::STDLOGIC);
|
||||||
const VTypePrimitive* primitive_CHARACTER= new VTypePrimitive(VTypePrimitive::CHARACTER);
|
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("boolean"), primitive_BOOLEAN);
|
||||||
res->use_name(perm_string::literal("bit"), primitive_BIT);
|
res->use_name(perm_string::literal("bit"), primitive_BIT);
|
||||||
res->use_name(perm_string::literal("integer"), primitive_INTEGER);
|
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("std_logic"), primitive_STDLOGIC);
|
||||||
res->use_name(perm_string::literal("character"), primitive_CHARACTER);
|
res->use_name(perm_string::literal("character"), primitive_CHARACTER);
|
||||||
res->use_name(perm_string::literal("bit_vector"),primitive_BOOL_VECTOR);
|
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 == "boolean") return true;
|
||||||
if (name == "bit") return true;
|
if (name == "bit") return true;
|
||||||
if (name == "integer") return true;
|
if (name == "integer") return true;
|
||||||
|
if (name == "real") return true;
|
||||||
if (name == "std_logic") return true;
|
if (name == "std_logic") return true;
|
||||||
if (name == "character") return true;
|
if (name == "character") return true;
|
||||||
if (name == "bit_vector") return true;
|
if (name == "bit_vector") return true;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
%{
|
%{
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2013 Stephen Williams (steve@icarus.com)
|
* 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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* and/or modify it in source code form under the terms of the GNU
|
||||||
|
|
@ -1741,6 +1742,11 @@ primary
|
||||||
FILE_NAME(tmp, @1);
|
FILE_NAME(tmp, @1);
|
||||||
$$ = tmp;
|
$$ = tmp;
|
||||||
}
|
}
|
||||||
|
| REAL_LITERAL
|
||||||
|
{ ExpReal*tmp = new ExpReal($1);
|
||||||
|
FILE_NAME(tmp, @1);
|
||||||
|
$$ = tmp;
|
||||||
|
}
|
||||||
| STRING_LITERAL
|
| STRING_LITERAL
|
||||||
{ ExpString*tmp = new ExpString($1);
|
{ ExpString*tmp = new ExpString($1);
|
||||||
FILE_NAME(tmp,@1);
|
FILE_NAME(tmp,@1);
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,9 @@ void VTypePrimitive::show(ostream&out) const
|
||||||
break;
|
break;
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
out << "INTEGER";
|
out << "INTEGER";
|
||||||
|
break;
|
||||||
|
case REAL:
|
||||||
|
out << "REAL";
|
||||||
break;
|
break;
|
||||||
case STDLOGIC:
|
case STDLOGIC:
|
||||||
out << "std_logic";
|
out << "std_logic";
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
#define IVL_vtype_H
|
#define IVL_vtype_H
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2014 Stephen Williams (steve@icarus.com)
|
* 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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* 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 {
|
class VTypePrimitive : public VType {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum type_t { BOOLEAN, BIT, INTEGER, STDLOGIC, CHARACTER };
|
enum type_t { BOOLEAN, BIT, INTEGER, REAL, STDLOGIC, CHARACTER };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VTypePrimitive(type_t);
|
VTypePrimitive(type_t);
|
||||||
|
|
@ -145,6 +146,7 @@ class VTypePrimitive : public VType {
|
||||||
extern const VTypePrimitive* primitive_BOOLEAN;
|
extern const VTypePrimitive* primitive_BOOLEAN;
|
||||||
extern const VTypePrimitive* primitive_BIT;
|
extern const VTypePrimitive* primitive_BIT;
|
||||||
extern const VTypePrimitive* primitive_INTEGER;
|
extern const VTypePrimitive* primitive_INTEGER;
|
||||||
|
extern const VTypePrimitive* primitive_REAL;
|
||||||
extern const VTypePrimitive* primitive_STDLOGIC;
|
extern const VTypePrimitive* primitive_STDLOGIC;
|
||||||
extern const VTypePrimitive* primitive_CHARACTER;
|
extern const VTypePrimitive* primitive_CHARACTER;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2012 Stephen Williams (steve@icarus.com)
|
* 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
|
* This source code is free software; you can redistribute it
|
||||||
* and/or modify it in source code form under the terms of the GNU
|
* 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:
|
case INTEGER:
|
||||||
out << "bool [31:0]";
|
out << "bool [31:0]";
|
||||||
break;
|
break;
|
||||||
|
case REAL:
|
||||||
|
out << "real";
|
||||||
|
break;
|
||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
out << "char";
|
out << "char";
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,9 @@ void VTypePrimitive::write_to_stream(ostream&fd) const
|
||||||
case INTEGER:
|
case INTEGER:
|
||||||
fd << "integer";
|
fd << "integer";
|
||||||
break;
|
break;
|
||||||
|
case REAL:
|
||||||
|
fd << "real";
|
||||||
|
break;
|
||||||
case STDLOGIC:
|
case STDLOGIC:
|
||||||
fd << "std_logic";
|
fd << "std_logic";
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue