2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_PGenerate_H
|
|
|
|
|
#define IVL_PGenerate_H
|
2006-04-10 04:40:18 +02:00
|
|
|
/*
|
2025-10-13 22:14:57 +02:00
|
|
|
* Copyright (c) 2006-2025 Stephen Williams (steve@icarus.com)
|
2006-04-10 04:40:18 +02:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2006-04-10 04:40:18 +02:00
|
|
|
*/
|
|
|
|
|
|
2019-09-24 00:17:31 +02:00
|
|
|
# include "PNamedItem.h"
|
2006-04-10 04:40:18 +02:00
|
|
|
# include "StringHeap.h"
|
|
|
|
|
# include "HName.h"
|
2008-06-20 06:31:53 +02:00
|
|
|
# include "PScope.h"
|
2006-04-10 04:40:18 +02:00
|
|
|
# include <list>
|
|
|
|
|
# include <map>
|
2008-11-28 04:45:22 +01:00
|
|
|
# include <valarray>
|
2007-05-24 06:07:11 +02:00
|
|
|
# include "pform_types.h"
|
2006-04-10 04:40:18 +02:00
|
|
|
|
|
|
|
|
class Design;
|
|
|
|
|
class NetScope;
|
|
|
|
|
class PExpr;
|
2008-06-19 06:54:58 +02:00
|
|
|
class PFunction;
|
2007-03-05 06:59:10 +01:00
|
|
|
class PProcess;
|
2008-06-19 06:54:58 +02:00
|
|
|
class PTask;
|
2006-04-10 04:40:18 +02:00
|
|
|
class PGate;
|
|
|
|
|
class PWire;
|
|
|
|
|
|
|
|
|
|
/*
|
2008-02-10 07:19:42 +01:00
|
|
|
* This represents a generate scheme. The interpretation of the
|
|
|
|
|
* members depends on the scheme_type.
|
|
|
|
|
*
|
|
|
|
|
* GS_LOOP
|
|
|
|
|
*
|
|
|
|
|
* GS_CASE
|
|
|
|
|
* loop_test is the expression to be compared.
|
|
|
|
|
* generates contains only GS_CASE_ITEM schemes.
|
|
|
|
|
* GS_CASE_ITEM
|
|
|
|
|
* The parent points to the GS_CASE that contains this item.
|
|
|
|
|
* the loop_test is compared with the parent->loop_test expression.
|
2006-04-10 04:40:18 +02:00
|
|
|
*/
|
2019-09-24 00:17:31 +02:00
|
|
|
class PGenerate : public PNamedItem, public LexicalScope {
|
2006-04-10 04:40:18 +02:00
|
|
|
|
|
|
|
|
public:
|
2010-01-08 23:49:48 +01:00
|
|
|
explicit PGenerate(LexicalScope*parent, unsigned id_number);
|
2025-10-13 22:14:57 +02:00
|
|
|
~PGenerate() override;
|
2006-04-10 04:40:18 +02:00
|
|
|
|
|
|
|
|
// Generate schemes have an ID number, for when the scope is
|
|
|
|
|
// implicit.
|
|
|
|
|
const unsigned id_number;
|
|
|
|
|
perm_string scope_name;
|
|
|
|
|
|
2008-06-20 06:31:53 +02:00
|
|
|
// This is used during parsing to stack lexical scopes within
|
|
|
|
|
// this generate scheme.
|
2010-01-08 23:49:48 +01:00
|
|
|
// LexicalScope*lexical_scope;
|
2008-06-20 06:31:53 +02:00
|
|
|
|
2008-02-10 07:19:42 +01:00
|
|
|
enum scheme_t {GS_NONE, GS_LOOP, GS_CONDIT, GS_ELSE,
|
2008-11-15 03:35:39 +01:00
|
|
|
GS_CASE, GS_CASE_ITEM, GS_NBLOCK};
|
2006-04-10 04:40:18 +02:00
|
|
|
scheme_t scheme_type;
|
|
|
|
|
|
2021-08-03 22:29:46 +02:00
|
|
|
bool directly_nested;
|
|
|
|
|
|
2006-04-10 04:40:18 +02:00
|
|
|
// generate loops have an index variable and three
|
|
|
|
|
// expressions: for (index = <init>; <test>; index=<step>)
|
2020-01-31 21:29:22 +01:00
|
|
|
// the index is local if it was declared in the init expression,
|
|
|
|
|
// e.g. for (genvar index = <init>; <test>; index=<step>)
|
|
|
|
|
bool local_index;
|
2006-04-10 04:40:18 +02:00
|
|
|
perm_string loop_index;
|
|
|
|
|
PExpr*loop_init;
|
|
|
|
|
PExpr*loop_test;
|
|
|
|
|
PExpr*loop_step;
|
2008-11-28 04:45:22 +01:00
|
|
|
// Case items may have multiple guard expression values. It is
|
|
|
|
|
// enough for any on of the guards to match the case statement
|
|
|
|
|
// test value.
|
|
|
|
|
std::valarray<PExpr*> item_test;
|
2006-04-10 04:40:18 +02:00
|
|
|
|
2012-08-16 01:07:50 +02:00
|
|
|
// defparam assignments found in this scope.
|
2021-11-04 17:12:04 +01:00
|
|
|
typedef std::pair<pform_name_t,PExpr*> named_expr_t;
|
|
|
|
|
std::list<named_expr_t>defparms;
|
2012-08-16 01:07:50 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PGate*> gates;
|
2006-04-10 04:40:18 +02:00
|
|
|
void add_gate(PGate*);
|
|
|
|
|
|
2008-06-19 06:54:58 +02:00
|
|
|
// Tasks instantiated within this scheme.
|
2021-11-04 17:12:04 +01:00
|
|
|
std::map<perm_string,PTask*> tasks;
|
|
|
|
|
std::map<perm_string,PFunction*>funcs;
|
2008-06-19 06:54:58 +02:00
|
|
|
|
2008-06-18 06:45:37 +02:00
|
|
|
// Generate schemes can contain further generate schemes.
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PGenerate*> generate_schemes;
|
2010-01-08 23:49:48 +01:00
|
|
|
// PGenerate*parent;
|
2007-06-02 05:42:12 +02:00
|
|
|
|
2006-04-10 04:40:18 +02:00
|
|
|
// This method is called by the elaboration of a module to
|
|
|
|
|
// generate scopes. the container is the scope that is to
|
|
|
|
|
// contain the generated scope.
|
|
|
|
|
bool generate_scope(Design*des, NetScope*container);
|
|
|
|
|
|
2007-06-22 04:04:48 +02:00
|
|
|
// Elaborate signals within any of the generated scopes that
|
|
|
|
|
// were made by this generate block within the given container scope.
|
|
|
|
|
bool elaborate_sig(Design*des, NetScope*container) const;
|
|
|
|
|
bool elaborate(Design*des, NetScope*container) const;
|
2006-04-10 04:40:18 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
void dump(std::ostream&out, unsigned indent) const;
|
2006-04-10 04:40:18 +02:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
SymbolType symbol_type() const override;
|
2019-09-24 00:17:31 +02:00
|
|
|
|
2006-04-10 04:40:18 +02:00
|
|
|
private:
|
2021-12-13 22:20:09 +01:00
|
|
|
void check_for_valid_genvar_value_(long value);
|
2006-04-10 04:40:18 +02:00
|
|
|
bool generate_scope_loop_(Design*des, NetScope*container);
|
2007-06-22 04:04:48 +02:00
|
|
|
bool generate_scope_condit_(Design*des, NetScope*container, bool else_flag);
|
2008-02-10 07:19:42 +01:00
|
|
|
bool generate_scope_case_(Design*des, NetScope*container);
|
2008-11-15 03:35:39 +01:00
|
|
|
bool generate_scope_nblock_(Design*des, NetScope*container);
|
2007-06-22 04:04:48 +02:00
|
|
|
|
|
|
|
|
// Elaborate_scope within a generated scope.
|
|
|
|
|
void elaborate_subscope_(Design*des, NetScope*scope);
|
2008-11-28 04:45:22 +01:00
|
|
|
void elaborate_subscope_direct_(Design*des, NetScope*scope);
|
2006-04-10 04:40:18 +02:00
|
|
|
|
|
|
|
|
// These are the scopes created by generate_scope.
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<NetScope*>scope_list_;
|
2006-04-10 04:40:18 +02:00
|
|
|
// internal function called on each scope generated by this scheme.
|
|
|
|
|
bool elaborate_sig_(Design*des, NetScope*scope) const;
|
2008-11-28 04:45:22 +01:00
|
|
|
bool elaborate_sig_direct_(Design*des, NetScope*scope) const;
|
2006-04-10 04:40:18 +02:00
|
|
|
bool elaborate_(Design*des, NetScope*scope) const;
|
2008-11-28 04:45:22 +01:00
|
|
|
bool elaborate_direct_(Design*des, NetScope*scope) const;
|
2006-04-10 04:40:18 +02:00
|
|
|
|
|
|
|
|
private: // not implemented
|
|
|
|
|
PGenerate(const PGenerate&);
|
|
|
|
|
PGenerate& operator= (const PGenerate&);
|
|
|
|
|
};
|
|
|
|
|
|
2008-11-28 04:45:22 +01:00
|
|
|
extern std::ostream& operator << (std::ostream&, PGenerate::scheme_t);
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_PGenerate_H */
|