2008-06-08 14:27:48 +02:00
|
|
|
/*
|
|
|
|
|
* VHDL abstract syntax elements.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2008 Nick Gasson (nick@nickg.me.uk)
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef INC_VHDL_SYNTAX_HH
|
|
|
|
|
#define INC_VHDL_SYNTAX_HH
|
|
|
|
|
|
|
|
|
|
#include "vhdl_element.hh"
|
|
|
|
|
#include "vhdl_type.hh"
|
|
|
|
|
|
2008-06-24 19:12:00 +02:00
|
|
|
class vhdl_scope;
|
2008-06-08 14:27:48 +02:00
|
|
|
class vhdl_entity;
|
|
|
|
|
class vhdl_arch;
|
|
|
|
|
|
|
|
|
|
class vhdl_expr : public vhdl_element {
|
|
|
|
|
public:
|
2008-06-21 17:40:18 +02:00
|
|
|
vhdl_expr(vhdl_type* type, bool isconst=false)
|
|
|
|
|
: type_(type), isconst_(isconst) {}
|
2008-06-08 14:27:48 +02:00
|
|
|
virtual ~vhdl_expr();
|
|
|
|
|
|
|
|
|
|
const vhdl_type *get_type() const { return type_; }
|
2008-06-21 17:40:18 +02:00
|
|
|
bool constant() const { return isconst_; }
|
2008-06-08 14:27:48 +02:00
|
|
|
virtual vhdl_expr *cast(const vhdl_type *to);
|
2008-06-23 14:04:28 +02:00
|
|
|
virtual vhdl_expr *resize(int newwidth);
|
2008-06-08 14:27:48 +02:00
|
|
|
private:
|
|
|
|
|
vhdl_type *type_;
|
2008-06-21 17:40:18 +02:00
|
|
|
bool isconst_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-06-21 17:17:44 +02:00
|
|
|
* A scalar or array variable reference.
|
2008-06-08 14:27:48 +02:00
|
|
|
*/
|
|
|
|
|
class vhdl_var_ref : public vhdl_expr {
|
|
|
|
|
public:
|
2008-06-21 17:17:44 +02:00
|
|
|
vhdl_var_ref(const char *name, vhdl_type *type,
|
|
|
|
|
vhdl_expr *slice = NULL)
|
|
|
|
|
: vhdl_expr(type), name_(name), slice_(slice) {}
|
|
|
|
|
~vhdl_var_ref();
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-16 21:06:06 +02:00
|
|
|
const std::string &get_name() const { return name_; }
|
2008-06-27 15:58:03 +02:00
|
|
|
void set_slice(vhdl_expr *s) { slice_ = s; }
|
2008-06-08 14:27:48 +02:00
|
|
|
private:
|
|
|
|
|
std::string name_;
|
2008-06-21 17:17:44 +02:00
|
|
|
vhdl_expr *slice_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-09 15:39:58 +02:00
|
|
|
enum vhdl_binop_t {
|
2008-06-24 15:58:58 +02:00
|
|
|
VHDL_BINOP_AND = 0,
|
2008-06-09 15:39:58 +02:00
|
|
|
VHDL_BINOP_OR,
|
2008-06-12 12:36:21 +02:00
|
|
|
VHDL_BINOP_EQ,
|
2008-06-16 13:47:41 +02:00
|
|
|
VHDL_BINOP_NEQ,
|
2008-06-14 18:09:31 +02:00
|
|
|
VHDL_BINOP_ADD,
|
2008-06-16 20:49:24 +02:00
|
|
|
VHDL_BINOP_SUB,
|
|
|
|
|
VHDL_BINOP_MULT,
|
2008-06-21 16:16:22 +02:00
|
|
|
VHDL_BINOP_LT,
|
|
|
|
|
VHDL_BINOP_GT,
|
2008-06-21 16:19:33 +02:00
|
|
|
VHDL_BINOP_SL,
|
|
|
|
|
VHDL_BINOP_SR,
|
2008-06-24 11:55:45 +02:00
|
|
|
VHDL_BINOP_XOR,
|
2008-06-09 15:39:58 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-09 15:53:50 +02:00
|
|
|
/*
|
|
|
|
|
* A binary expression contains a list of operands rather
|
|
|
|
|
* than just two: this is to model n-input gates and the
|
|
|
|
|
* like. A second constructor is provided to handle the
|
|
|
|
|
* common case of a true binary expression.
|
|
|
|
|
*/
|
2008-06-09 15:39:58 +02:00
|
|
|
class vhdl_binop_expr : public vhdl_expr {
|
|
|
|
|
public:
|
2008-06-09 15:53:50 +02:00
|
|
|
vhdl_binop_expr(vhdl_binop_t op, vhdl_type *type)
|
|
|
|
|
: vhdl_expr(type), op_(op) {}
|
2008-06-09 15:39:58 +02:00
|
|
|
vhdl_binop_expr(vhdl_expr *left, vhdl_binop_t op,
|
2008-06-09 15:53:50 +02:00
|
|
|
vhdl_expr *right, vhdl_type *type);
|
2008-06-09 15:39:58 +02:00
|
|
|
~vhdl_binop_expr();
|
|
|
|
|
|
2008-06-09 15:53:50 +02:00
|
|
|
void add_expr(vhdl_expr *e);
|
2008-06-09 15:39:58 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
2008-06-09 15:53:50 +02:00
|
|
|
std::list<vhdl_expr*> operands_;
|
2008-06-09 15:39:58 +02:00
|
|
|
vhdl_binop_t op_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum vhdl_unaryop_t {
|
|
|
|
|
VHDL_UNARYOP_NOT,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class vhdl_unaryop_expr : public vhdl_expr {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_unaryop_expr(vhdl_unaryop_t op, vhdl_expr *operand,
|
|
|
|
|
vhdl_type *type)
|
|
|
|
|
: vhdl_expr(type), op_(op), operand_(operand) {}
|
|
|
|
|
~vhdl_unaryop_expr();
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_unaryop_t op_;
|
|
|
|
|
vhdl_expr *operand_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
class vhdl_const_string : public vhdl_expr {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_const_string(const char *value)
|
2008-06-21 17:40:18 +02:00
|
|
|
: vhdl_expr(vhdl_type::string(), true), value_(value) {}
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
std::string value_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class vhdl_const_bits : public vhdl_expr {
|
|
|
|
|
public:
|
2008-06-23 15:28:27 +02:00
|
|
|
vhdl_const_bits(const char *value, int width, bool issigned);
|
2008-06-08 14:27:48 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
const std::string &get_value() const { return value_; }
|
|
|
|
|
vhdl_expr *cast(const vhdl_type *to);
|
|
|
|
|
private:
|
|
|
|
|
std::string value_;
|
2008-06-23 15:28:27 +02:00
|
|
|
bool qualified_, signed_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class vhdl_const_bit : public vhdl_expr {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_const_bit(char bit)
|
2008-06-21 17:40:18 +02:00
|
|
|
: vhdl_expr(vhdl_type::std_logic(), true), bit_(bit) {}
|
2008-06-08 14:27:48 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
char bit_;
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-19 13:16:19 +02:00
|
|
|
enum time_unit_t {
|
|
|
|
|
TIME_UNIT_NS,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class vhdl_const_time : public vhdl_expr {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_const_time(int64_t value, time_unit_t units)
|
2008-06-21 17:40:18 +02:00
|
|
|
: vhdl_expr(vhdl_type::time(), true), value_(value), units_(units) {}
|
2008-06-19 13:16:19 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
int64_t value_;
|
|
|
|
|
time_unit_t units_;
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-09 13:46:55 +02:00
|
|
|
class vhdl_const_int : public vhdl_expr {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_const_int(int64_t value)
|
2008-06-21 17:40:18 +02:00
|
|
|
: vhdl_expr(vhdl_type::integer(), true), value_(value) {}
|
2008-06-09 13:46:55 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
int64_t value_;
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
class vhdl_expr_list : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
~vhdl_expr_list();
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-17 21:16:16 +02:00
|
|
|
bool empty() const { return exprs_.empty(); }
|
2008-06-08 14:27:48 +02:00
|
|
|
void add_expr(vhdl_expr *e);
|
|
|
|
|
private:
|
|
|
|
|
std::list<vhdl_expr*> exprs_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A function call within an expression.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_fcall : public vhdl_expr {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_fcall(const char *name, vhdl_type *rtype)
|
|
|
|
|
: vhdl_expr(rtype), name_(name) {};
|
|
|
|
|
~vhdl_fcall() {}
|
|
|
|
|
|
|
|
|
|
void add_expr(vhdl_expr *e) { exprs_.add_expr(e); }
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
vhdl_expr_list exprs_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A concurrent statement appears in architecture bodies but not
|
|
|
|
|
* processes.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_conc_stmt : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~vhdl_conc_stmt() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_conc_stmt*> conc_stmt_list_t;
|
|
|
|
|
|
2008-06-09 15:21:55 +02:00
|
|
|
/*
|
|
|
|
|
* A concurrent signal assignment (i.e. not part of a process).
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_cassign_stmt : public vhdl_conc_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_cassign_stmt(vhdl_var_ref *lhs, vhdl_expr *rhs)
|
|
|
|
|
: lhs_(lhs), rhs_(rhs) {}
|
|
|
|
|
~vhdl_cassign_stmt();
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_var_ref *lhs_;
|
|
|
|
|
vhdl_expr *rhs_;
|
|
|
|
|
};
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Any sequential statement in a process.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_seq_stmt : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~vhdl_seq_stmt() {}
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-11 15:11:37 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A list of sequential statements. For example inside a
|
|
|
|
|
* process, loop, or if statement.
|
|
|
|
|
*/
|
|
|
|
|
class stmt_container {
|
|
|
|
|
public:
|
|
|
|
|
~stmt_container();
|
|
|
|
|
|
|
|
|
|
void add_stmt(vhdl_seq_stmt *stmt);
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-13 15:17:24 +02:00
|
|
|
bool empty() const { return stmts_.empty(); }
|
2008-06-11 15:11:37 +02:00
|
|
|
private:
|
|
|
|
|
std::list<vhdl_seq_stmt*> stmts_;
|
|
|
|
|
};
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-06-18 13:51:11 +02:00
|
|
|
* Shared between blocking and non-blocking assignment.
|
2008-06-08 14:27:48 +02:00
|
|
|
*/
|
2008-06-18 13:51:11 +02:00
|
|
|
class vhdl_abstract_assign_stmt : public vhdl_seq_stmt {
|
2008-06-08 14:27:48 +02:00
|
|
|
public:
|
2008-06-18 13:51:11 +02:00
|
|
|
vhdl_abstract_assign_stmt(vhdl_var_ref *lhs, vhdl_expr *rhs)
|
2008-06-12 12:24:43 +02:00
|
|
|
: lhs_(lhs), rhs_(rhs), after_(NULL) {}
|
2008-06-18 13:51:11 +02:00
|
|
|
virtual ~vhdl_abstract_assign_stmt();
|
2008-06-08 14:27:48 +02:00
|
|
|
|
2008-06-12 12:24:43 +02:00
|
|
|
void set_after(vhdl_expr *after) { after_ = after; }
|
2008-06-18 13:51:11 +02:00
|
|
|
protected:
|
2008-06-08 14:27:48 +02:00
|
|
|
vhdl_var_ref *lhs_;
|
2008-06-12 12:24:43 +02:00
|
|
|
vhdl_expr *rhs_, *after_;
|
2008-06-18 13:51:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Similar to Verilog non-blocking assignment, except the LHS
|
|
|
|
|
* must be a signal not a variable.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_nbassign_stmt : public vhdl_abstract_assign_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_nbassign_stmt(vhdl_var_ref *lhs, vhdl_expr *rhs)
|
|
|
|
|
: vhdl_abstract_assign_stmt(lhs, rhs) {}
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-18 13:51:11 +02:00
|
|
|
|
2008-06-18 14:06:27 +02:00
|
|
|
class vhdl_assign_stmt : public vhdl_abstract_assign_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_assign_stmt(vhdl_var_ref *lhs, vhdl_expr *rhs)
|
|
|
|
|
: vhdl_abstract_assign_stmt(lhs, rhs) {}
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-09 13:40:59 +02:00
|
|
|
enum vhdl_wait_type_t {
|
2008-06-19 13:16:19 +02:00
|
|
|
VHDL_WAIT_INDEF, // Suspend indefinitely
|
|
|
|
|
VHDL_WAIT_FOR, // Wait for a constant amount of time
|
2008-06-09 13:40:59 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
/*
|
|
|
|
|
* Delay simulation indefinitely, until an event, or for a
|
|
|
|
|
* specified time.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_wait_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
2008-06-09 13:40:59 +02:00
|
|
|
vhdl_wait_stmt(vhdl_wait_type_t type = VHDL_WAIT_INDEF,
|
|
|
|
|
vhdl_expr *expr = NULL)
|
|
|
|
|
: type_(type), expr_(expr) {}
|
|
|
|
|
~vhdl_wait_stmt();
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-09 13:40:59 +02:00
|
|
|
private:
|
|
|
|
|
vhdl_wait_type_t type_;
|
|
|
|
|
vhdl_expr *expr_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class vhdl_null_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-11 14:37:21 +02:00
|
|
|
class vhdl_assert_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_assert_stmt(const char *reason)
|
|
|
|
|
: reason_(reason) {}
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
std::string reason_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-11 15:11:37 +02:00
|
|
|
class vhdl_if_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
2008-06-12 12:36:21 +02:00
|
|
|
vhdl_if_stmt(vhdl_expr *test);
|
2008-06-11 15:11:37 +02:00
|
|
|
~vhdl_if_stmt();
|
|
|
|
|
|
|
|
|
|
stmt_container *get_then_container() { return &then_part_; }
|
|
|
|
|
stmt_container *get_else_container() { return &else_part_; }
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_expr *test_;
|
|
|
|
|
stmt_container then_part_, else_part_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-21 16:03:36 +02:00
|
|
|
/*
|
|
|
|
|
* A single branch in a case statement consisting of an
|
|
|
|
|
* expression part and a statement container.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_case_branch : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_case_branch(vhdl_expr *when) : when_(when) {}
|
|
|
|
|
~vhdl_case_branch();
|
|
|
|
|
|
|
|
|
|
stmt_container *get_container() { return &stmts_; }
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_expr *when_;
|
|
|
|
|
stmt_container stmts_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_case_branch*> case_branch_list_t;
|
|
|
|
|
|
|
|
|
|
class vhdl_case_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_case_stmt(vhdl_expr *test) : test_(test) {}
|
|
|
|
|
~vhdl_case_stmt();
|
|
|
|
|
|
|
|
|
|
void add_branch(vhdl_case_branch *b) { branches_.push_back(b); }
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_expr *test_;
|
|
|
|
|
case_branch_list_t branches_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-21 16:13:44 +02:00
|
|
|
class vhdl_while_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_while_stmt(vhdl_expr *test) : test_(test) {}
|
|
|
|
|
~vhdl_while_stmt();
|
|
|
|
|
|
|
|
|
|
stmt_container *get_container() { return &stmts_; }
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_expr *test_;
|
|
|
|
|
stmt_container stmts_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-08 14:27:48 +02:00
|
|
|
/*
|
|
|
|
|
* A procedure call. Which is a statement, unlike a function
|
|
|
|
|
* call which is an expression.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_pcall_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_pcall_stmt(const char *name) : name_(name) {}
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
void add_expr(vhdl_expr *e) { exprs_.add_expr(e); }
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
vhdl_expr_list exprs_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A declaration of some sort (variable, component, etc.).
|
|
|
|
|
* Declarations have names, which is the identifier of the variable,
|
|
|
|
|
* constant, etc. not the type.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_decl : public vhdl_element {
|
|
|
|
|
public:
|
2008-06-13 15:10:28 +02:00
|
|
|
vhdl_decl(const char *name, vhdl_type *type = NULL,
|
|
|
|
|
vhdl_expr *initial = NULL)
|
|
|
|
|
: name_(name), type_(type), initial_(initial) {}
|
2008-06-09 17:27:04 +02:00
|
|
|
virtual ~vhdl_decl();
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
const std::string &get_name() const { return name_; }
|
2008-06-25 18:29:09 +02:00
|
|
|
const vhdl_type *get_type() const;
|
2008-06-27 13:18:39 +02:00
|
|
|
void set_type(vhdl_type *t) { type_ = t; }
|
2008-06-13 15:10:28 +02:00
|
|
|
void set_initial(vhdl_expr *initial);
|
2008-06-24 21:13:18 +02:00
|
|
|
bool has_initial() const { return initial_ != NULL; }
|
2008-06-08 14:27:48 +02:00
|
|
|
protected:
|
|
|
|
|
std::string name_;
|
|
|
|
|
vhdl_type *type_;
|
2008-06-13 15:10:28 +02:00
|
|
|
vhdl_expr *initial_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_decl*> decl_list_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A forward declaration of a component. At the moment it is assumed
|
|
|
|
|
* that components declarations will only ever be for entities
|
|
|
|
|
* generated by this code generator. This is enforced by making the
|
|
|
|
|
* constructor private (use component_decl_for instead).
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_component_decl : public vhdl_decl {
|
|
|
|
|
public:
|
2008-06-24 19:12:00 +02:00
|
|
|
static vhdl_component_decl *component_decl_for(vhdl_entity *ent);
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_component_decl(const char *name);
|
|
|
|
|
|
2008-06-10 12:24:16 +02:00
|
|
|
decl_list_t ports_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A variable declaration inside a process (although this isn't
|
|
|
|
|
* enforced here).
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_var_decl : public vhdl_decl {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_var_decl(const char *name, vhdl_type *type)
|
|
|
|
|
: vhdl_decl(name, type) {}
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A signal declaration in architecture.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_signal_decl : public vhdl_decl {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_signal_decl(const char *name, vhdl_type *type)
|
|
|
|
|
: vhdl_decl(name, type) {}
|
2008-06-09 17:27:04 +02:00
|
|
|
virtual void emit(std::ofstream &of, int level) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-25 19:00:48 +02:00
|
|
|
/*
|
|
|
|
|
* A parameter to a function.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_param_decl : public vhdl_decl {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_param_decl(const char *name, vhdl_type *type)
|
|
|
|
|
: vhdl_decl(name, type) {}
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-09 17:27:04 +02:00
|
|
|
enum vhdl_port_mode_t {
|
|
|
|
|
VHDL_PORT_IN,
|
|
|
|
|
VHDL_PORT_OUT,
|
|
|
|
|
VHDL_PORT_INOUT,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A port declaration is like a signal declaration except
|
|
|
|
|
* it has a direction and appears in the entity rather than
|
|
|
|
|
* the architecture.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_port_decl : public vhdl_decl {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_port_decl(const char *name, vhdl_type *type,
|
|
|
|
|
vhdl_port_mode_t mode)
|
|
|
|
|
: vhdl_decl(name, type), mode_(mode) {}
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-09 17:27:04 +02:00
|
|
|
private:
|
|
|
|
|
vhdl_port_mode_t mode_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-10 14:58:41 +02:00
|
|
|
/*
|
|
|
|
|
* A mapping from port name to an expression.
|
|
|
|
|
*/
|
|
|
|
|
struct port_map_t {
|
|
|
|
|
std::string name;
|
|
|
|
|
vhdl_expr *expr;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<port_map_t> port_map_list_t;
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Instantiation of component. This is really only a placeholder
|
|
|
|
|
* at the moment until the port mappings are worked out.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_comp_inst : public vhdl_conc_stmt {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_comp_inst(const char *inst_name, const char *comp_name);
|
2008-06-10 15:00:15 +02:00
|
|
|
~vhdl_comp_inst();
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-10 14:58:41 +02:00
|
|
|
void map_port(const char *name, vhdl_expr *expr);
|
2008-06-08 14:27:48 +02:00
|
|
|
private:
|
|
|
|
|
std::string comp_name_, inst_name_;
|
2008-06-10 14:58:41 +02:00
|
|
|
port_map_list_t mapping_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2008-06-24 19:12:00 +02:00
|
|
|
* Contains a list of declarations in a hierarchy.
|
2008-06-24 20:06:06 +02:00
|
|
|
* A scope can be `initializing' where assignments automatically
|
|
|
|
|
* create initial values for declarations.
|
2008-06-08 14:27:48 +02:00
|
|
|
*/
|
2008-06-24 19:12:00 +02:00
|
|
|
class vhdl_scope {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_scope();
|
|
|
|
|
~vhdl_scope();
|
|
|
|
|
|
|
|
|
|
void add_decl(vhdl_decl *decl);
|
|
|
|
|
vhdl_decl *get_decl(const std::string &name) const;
|
|
|
|
|
bool have_declared(const std::string &name) const;
|
2008-06-24 19:52:25 +02:00
|
|
|
vhdl_scope *get_parent();
|
2008-06-24 19:12:00 +02:00
|
|
|
|
|
|
|
|
bool empty() const { return decls_.empty(); }
|
|
|
|
|
const decl_list_t &get_decls() const { return decls_; }
|
2008-06-24 19:52:25 +02:00
|
|
|
void set_parent(vhdl_scope *p) { parent_ = p; }
|
2008-06-24 20:06:06 +02:00
|
|
|
|
|
|
|
|
bool initializing() const { return init_; }
|
|
|
|
|
void set_initializing(bool i) { init_ = i; }
|
2008-06-25 23:15:57 +02:00
|
|
|
|
|
|
|
|
void set_allow_signal_assignment(bool b) { sig_assign_ = b; }
|
|
|
|
|
bool allow_signal_assignment() const { return sig_assign_; }
|
2008-06-24 19:12:00 +02:00
|
|
|
private:
|
|
|
|
|
decl_list_t decls_;
|
|
|
|
|
vhdl_scope *parent_;
|
2008-06-25 23:15:57 +02:00
|
|
|
bool init_, sig_assign_;
|
2008-06-24 19:12:00 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-25 13:48:46 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Any sort of procedural element: process, function, or
|
|
|
|
|
* procedure. Roughly these map onto Verilog's processes,
|
|
|
|
|
* functions, and tasks.
|
|
|
|
|
*/
|
2008-06-24 20:50:57 +02:00
|
|
|
class vhdl_procedural {
|
|
|
|
|
public:
|
2008-06-24 21:01:06 +02:00
|
|
|
virtual ~vhdl_procedural() {}
|
|
|
|
|
|
2008-06-25 19:00:48 +02:00
|
|
|
virtual stmt_container *get_container() { return &stmts_; }
|
|
|
|
|
virtual vhdl_scope *get_scope() { return &scope_; }
|
2008-06-24 20:50:57 +02:00
|
|
|
protected:
|
|
|
|
|
stmt_container stmts_;
|
2008-06-24 20:54:22 +02:00
|
|
|
vhdl_scope scope_;
|
2008-06-24 20:50:57 +02:00
|
|
|
};
|
2008-06-24 19:12:00 +02:00
|
|
|
|
2008-06-25 13:48:46 +02:00
|
|
|
|
|
|
|
|
class vhdl_function : public vhdl_decl, public vhdl_procedural {
|
|
|
|
|
public:
|
2008-06-25 19:00:48 +02:00
|
|
|
vhdl_function(const char *name, vhdl_type *ret_type);
|
|
|
|
|
|
2008-06-25 13:48:46 +02:00
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-25 19:00:48 +02:00
|
|
|
vhdl_scope *get_scope() { return &variables_; }
|
|
|
|
|
void add_param(vhdl_param_decl *p) { scope_.add_decl(p); }
|
2008-06-25 13:48:46 +02:00
|
|
|
private:
|
2008-06-25 19:00:48 +02:00
|
|
|
vhdl_scope variables_;
|
2008-06-25 13:48:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-24 20:50:57 +02:00
|
|
|
class vhdl_process : public vhdl_conc_stmt, public vhdl_procedural {
|
2008-06-08 14:27:48 +02:00
|
|
|
public:
|
2008-06-24 20:06:06 +02:00
|
|
|
vhdl_process(const char *name = "") : name_(name) {}
|
2008-06-08 14:27:48 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
void add_sensitivity(const char *name);
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
string_list_t sens_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* An architecture which implements an entity.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_arch : public vhdl_element {
|
|
|
|
|
public:
|
2008-06-24 20:06:06 +02:00
|
|
|
vhdl_arch(const char *entity, const char *name)
|
|
|
|
|
: name_(name), entity_(entity) {}
|
2008-06-08 14:27:48 +02:00
|
|
|
virtual ~vhdl_arch();
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level=0) const;
|
2008-06-24 19:52:25 +02:00
|
|
|
void add_stmt(vhdl_process *proc);
|
2008-06-08 14:27:48 +02:00
|
|
|
void add_stmt(vhdl_conc_stmt *stmt);
|
2008-06-24 19:52:25 +02:00
|
|
|
vhdl_scope *get_scope() { return &scope_; }
|
2008-06-08 14:27:48 +02:00
|
|
|
private:
|
|
|
|
|
conc_stmt_list_t stmts_;
|
2008-06-24 19:52:25 +02:00
|
|
|
vhdl_scope scope_;
|
2008-06-08 14:27:48 +02:00
|
|
|
std::string name_, entity_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* An entity defines the ports, parameters, etc. of a module. Each
|
|
|
|
|
* entity is associated with a single architecture (although
|
|
|
|
|
* technically this need not be the case). Entities are `derived'
|
|
|
|
|
* from instantiations of Verilog module scopes in the hierarchy.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_entity : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_entity(const char *name, const char *derived_from,
|
|
|
|
|
vhdl_arch *arch);
|
|
|
|
|
virtual ~vhdl_entity();
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level=0) const;
|
2008-06-09 17:27:04 +02:00
|
|
|
void add_port(vhdl_port_decl *decl);
|
2008-06-08 14:27:48 +02:00
|
|
|
vhdl_arch *get_arch() const { return arch_; }
|
|
|
|
|
const std::string &get_name() const { return name_; }
|
2008-06-24 19:12:00 +02:00
|
|
|
const std::string &get_derived_from() const { return derived_from_; }
|
|
|
|
|
|
|
|
|
|
vhdl_scope *get_scope() { return &ports_; }
|
2008-06-08 14:27:48 +02:00
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
vhdl_arch *arch_; // Entity may only have a single architecture
|
|
|
|
|
std::string derived_from_;
|
2008-06-24 19:12:00 +02:00
|
|
|
vhdl_scope ports_;
|
2008-06-08 14:27:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_entity*> entity_list_t;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|