2008-05-28 18:17:39 +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_ELEMENT_HH
|
|
|
|
|
#define INC_VHDL_ELEMENT_HH
|
|
|
|
|
|
|
|
|
|
#include <fstream>
|
2008-05-29 17:24:16 +02:00
|
|
|
#include <list>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2008-06-02 18:45:58 +02:00
|
|
|
class vhdl_entity;
|
|
|
|
|
|
2008-06-02 01:12:47 +02:00
|
|
|
/*
|
|
|
|
|
* Any VHDL syntax element. Each element can also contain a comment.
|
|
|
|
|
*/
|
2008-05-28 18:17:39 +02:00
|
|
|
class vhdl_element {
|
2008-05-31 16:28:25 +02:00
|
|
|
public:
|
|
|
|
|
virtual ~vhdl_element() {}
|
|
|
|
|
|
2008-05-29 17:24:16 +02:00
|
|
|
virtual void emit(std::ofstream &of, int level=0) const = 0;
|
|
|
|
|
|
|
|
|
|
void set_comment(std::string comment);
|
|
|
|
|
protected:
|
|
|
|
|
void emit_comment(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
std::string comment_;
|
2008-05-28 18:17:39 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-02 01:12:47 +02:00
|
|
|
typedef std::list<vhdl_element*> element_list_t;
|
|
|
|
|
|
2008-06-03 20:20:45 +02:00
|
|
|
class vhdl_type : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~vhdl_type() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A type at the moment is just a name. It shouldn't get
|
|
|
|
|
* too much more complex, as Verilog's type system is much
|
|
|
|
|
* simpler than VHDL's.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_scalar_type : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_scalar_type(const char *name) : name_(name) {}
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
std::string name_;
|
|
|
|
|
};
|
2008-06-02 01:12:47 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A concurrent statement appears in architecture bodies but not
|
|
|
|
|
* processes.
|
|
|
|
|
*/
|
2008-05-29 17:24:16 +02:00
|
|
|
class vhdl_conc_stmt : public vhdl_element {
|
2008-05-31 16:28:25 +02:00
|
|
|
public:
|
|
|
|
|
virtual ~vhdl_conc_stmt() {}
|
2008-05-29 17:24:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_conc_stmt*> conc_stmt_list_t;
|
|
|
|
|
|
2008-06-02 01:12:47 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Any sequential statement in a process.
|
|
|
|
|
*/
|
2008-05-29 17:24:16 +02:00
|
|
|
class vhdl_seq_stmt : public vhdl_element {
|
2008-05-31 16:28:25 +02:00
|
|
|
public:
|
|
|
|
|
virtual ~vhdl_seq_stmt() {}
|
2008-05-29 17:24:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_seq_stmt*> seq_stmt_list_t;
|
|
|
|
|
|
2008-06-03 18:39:24 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Delay simulation indefinitely, until an event, or for a
|
|
|
|
|
* specified time.
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_wait_stmt : public vhdl_seq_stmt {
|
|
|
|
|
public:
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-02 18:45:58 +02:00
|
|
|
/*
|
|
|
|
|
* 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:
|
|
|
|
|
vhdl_decl(const char *name) : name_(name) {}
|
|
|
|
|
virtual ~vhdl_decl() {};
|
|
|
|
|
|
|
|
|
|
const std::string &get_name() const { return name_; }
|
|
|
|
|
protected:
|
|
|
|
|
std::string name_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
virtual ~vhdl_component_decl() {};
|
|
|
|
|
|
|
|
|
|
static vhdl_component_decl *component_decl_for(const vhdl_entity *ent);
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
vhdl_component_decl(const char *name);
|
|
|
|
|
|
|
|
|
|
// TODO: Ports, etc.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-03 20:20:45 +02:00
|
|
|
/*
|
|
|
|
|
* A variable declaration inside a process (although this isn't
|
|
|
|
|
* enforced here).
|
|
|
|
|
*/
|
|
|
|
|
class vhdl_var_decl : public vhdl_decl {
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2008-06-02 18:45:58 +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);
|
|
|
|
|
virtual ~vhdl_comp_inst() {}
|
|
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
|
|
|
|
private:
|
|
|
|
|
std::string comp_name_, inst_name_;
|
|
|
|
|
|
|
|
|
|
// TODO: Port mappings, etc.
|
|
|
|
|
};
|
|
|
|
|
|
2008-06-02 01:12:47 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Container for sequential statements.
|
|
|
|
|
*/
|
2008-05-29 17:24:16 +02:00
|
|
|
class vhdl_process : public vhdl_conc_stmt {
|
|
|
|
|
public:
|
2008-06-02 17:17:01 +02:00
|
|
|
vhdl_process(const char *name = "");
|
2008-05-31 17:08:57 +02:00
|
|
|
virtual ~vhdl_process();
|
2008-05-29 17:24:16 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level) const;
|
2008-06-02 18:45:58 +02:00
|
|
|
void add_stmt(vhdl_seq_stmt *stmt);
|
2008-05-28 18:17:39 +02:00
|
|
|
private:
|
2008-05-29 17:24:16 +02:00
|
|
|
seq_stmt_list_t stmts_;
|
2008-06-02 17:17:01 +02:00
|
|
|
std::string name_;
|
2008-05-28 18:17:39 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-02 01:12:47 +02:00
|
|
|
|
|
|
|
|
/*
|
2008-06-02 18:45:58 +02:00
|
|
|
* An architecture which implements an entity.
|
2008-06-02 01:12:47 +02:00
|
|
|
*/
|
2008-05-28 18:17:39 +02:00
|
|
|
class vhdl_arch : public vhdl_element {
|
|
|
|
|
public:
|
|
|
|
|
vhdl_arch(const char *entity, const char *name="Behavioural");
|
2008-05-31 17:08:57 +02:00
|
|
|
virtual ~vhdl_arch();
|
2008-05-28 18:17:39 +02:00
|
|
|
|
2008-05-29 17:24:16 +02:00
|
|
|
void emit(std::ofstream &of, int level=0) const;
|
2008-06-02 18:45:58 +02:00
|
|
|
bool have_declared_component(const std::string &name) const;
|
|
|
|
|
void add_decl(vhdl_decl *decl);
|
|
|
|
|
void add_stmt(vhdl_conc_stmt *stmt);
|
2008-05-28 18:17:39 +02:00
|
|
|
private:
|
2008-05-29 17:24:16 +02:00
|
|
|
conc_stmt_list_t stmts_;
|
2008-06-02 18:45:58 +02:00
|
|
|
decl_list_t decls_;
|
2008-06-02 17:17:01 +02:00
|
|
|
std::string name_, entity_;
|
2008-05-28 18:17:39 +02:00
|
|
|
};
|
|
|
|
|
|
2008-06-02 01:12:47 +02:00
|
|
|
/*
|
|
|
|
|
* An entity defines the ports, parameters, etc. of a module. Each
|
|
|
|
|
* entity is associated with a single architecture (although
|
2008-06-02 18:45:58 +02:00
|
|
|
* technically this need not be the case). Entities are `derived'
|
|
|
|
|
* from instantiations of Verilog module scopes in the hierarchy.
|
2008-06-02 01:12:47 +02:00
|
|
|
*/
|
2008-05-31 16:28:25 +02:00
|
|
|
class vhdl_entity : public vhdl_element {
|
|
|
|
|
public:
|
2008-06-02 17:17:01 +02:00
|
|
|
vhdl_entity(const char *name, const char *derived_from,
|
|
|
|
|
vhdl_arch *arch);
|
2008-05-31 17:08:57 +02:00
|
|
|
virtual ~vhdl_entity();
|
2008-05-31 16:28:25 +02:00
|
|
|
|
|
|
|
|
void emit(std::ofstream &of, int level=0) const;
|
|
|
|
|
vhdl_arch *get_arch() const { return arch_; }
|
2008-06-02 17:17:01 +02:00
|
|
|
const std::string &get_name() const { return name_; }
|
|
|
|
|
|
|
|
|
|
const std::string &get_derived_from() const { return derived_from_; }
|
2008-05-31 16:28:25 +02:00
|
|
|
private:
|
2008-06-02 17:17:01 +02:00
|
|
|
std::string name_;
|
2008-05-31 16:28:25 +02:00
|
|
|
vhdl_arch *arch_; // Entity may only have a single architecture
|
2008-06-02 17:17:01 +02:00
|
|
|
std::string derived_from_;
|
2008-05-31 16:28:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<vhdl_entity*> entity_list_t;
|
|
|
|
|
|
|
|
|
|
|
2008-05-28 18:17:39 +02:00
|
|
|
#endif
|
2008-05-29 17:24:16 +02:00
|
|
|
|