Merge branch 'master' into verilog-ams
[sverilog.git] / netmisc.h
blob439e86422b761ed3b141affca851fc854855c2b5
1 #ifndef __netmisc_H
2 #define __netmisc_H
3 /*
4 * Copyright (c) 1999-2008 Stephen Williams (steve@icarus.com)
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 # include "netlist.h"
25 * Search for a symbol using the "start" scope as the starting
26 * point. If the path includes a scope part, then locate the
27 * scope first.
29 * The return value is the scope where the symbol was found.
30 * If the symbol was not found, return 0. The output arguments
31 * get 0 except for the pointer to the object that represents
32 * the located symbol.
34 * The ex1 and ex2 output arguments are extended results. If the
35 * symbol is a parameter (par!=0) then ex1 is the msb expression and
36 * ex2 is the lsb expression for the range. If there is no range, then
37 * these values are set to 0.
39 extern NetScope* symbol_search(Design*des,
40 NetScope*start, pform_name_t path,
41 NetNet*&net, /* net/reg */
42 const NetExpr*&par,/* parameter */
43 NetEvent*&eve, /* named event */
44 const NetExpr*&ex1, const NetExpr*&ex2);
46 inline NetScope* symbol_search(Design*des,
47 NetScope*start, const pform_name_t&path,
48 NetNet*&net, /* net/reg */
49 const NetExpr*&par,/* parameter */
50 NetEvent*&eve /* named event */)
52 const NetExpr*ex1, *ex2;
53 return symbol_search(des, start, path, net, par, eve, ex1, ex2);
57 * This function transforms an expression by padding the high bits
58 * with V0 until the expression has the desired width. This may mean
59 * not transforming the expression at all, if it is already wide
60 * enough.
62 extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid);
63 extern NetNet*pad_to_width(Design*des, NetNet*n, unsigned w);
65 extern NetNet*pad_to_width_signed(Design*des, NetNet*n, unsigned w);
68 * Take the input expression and return a variation that assures that
69 * the expression is 1-bit wide and logical. This reflects the needs
70 * of conditions i.e. for "if" statements or logical operators.
72 extern NetExpr*condition_reduce(NetExpr*expr);
75 * This function transforms an expression by cropping the high bits
76 * off with a part select. The result has the width w passed in. This
77 * function does not pad, use pad_to_width if padding is desired.
79 extern NetNet*crop_to_width(Design*des, NetNet*n, unsigned w);
82 * This function takes as input a NetNet signal and adds a constant
83 * value to it. If the val is 0, then simply return sig. Otherwise,
84 * return a new NetNet value that is the output of an addition.
86 extern NetNet*add_to_net(Design*des, NetNet*sig, long val);
89 * These functions make various sorts of expressions, given operands
90 * of certain type. The order of the operands is preserved in cases
91 * where order matters.
93 * make_add_expr
94 * Make a NetEBAdd expression with <expr> the first argument and
95 * <val> the second. This may get turned into a subtract if <val> is
96 * less than zero. If val is exactly zero, then return <expr> as is.
98 * make_sub_expr
99 * Make a NetEBAdd(subtract) node that subtracts the given
100 * expression from the integer value.
102 extern NetExpr*make_add_expr(NetExpr*expr, long val);
103 extern NetExpr*make_sub_expr(long val, NetExpr*expr);
106 * In some cases the lval is accessible as a pointer to the head of
107 * a list of NetAssign_ objects. This function returns the width of
108 * the l-value represented by this list.
110 extern unsigned count_lval_width(const class NetAssign_*first);
113 * This function elaborates an expression, and tries to evaluate it
114 * right away. If the expression can be evaluated, this returns a
115 * constant expression. If it cannot be evaluated, it returns whatever
116 * it can. If the expression cannot be elaborated, return 0.
118 * The expr_width is the width of the context where the expression is
119 * being elaborated, or -1 if the expression is self-determined width.
121 * Also, the prune_width is the maximum width of the result, and it
122 * passed to the eval_tree method of the expression to limit constant
123 * results if possible.
125 class PExpr;
126 extern NetExpr* elab_and_eval(Design*des, NetScope*scope,
127 const PExpr*pe, int expr_wid,
128 int prune_width =-1);
130 * This procedure elaborates an expression and if the elaboration is
131 * successful the original expression is replaced with the new one.
133 void eval_expr(NetExpr*&expr, int prune_width =-1);
136 * Get the long integer value for the passed in expression, if
137 * possible. If it is not possible (the expression is not evaluated
138 * down to a constant) then return false and leave value unchanged.
140 bool eval_as_long(long&value, NetExpr*expr);
141 bool eval_as_double(double&value, NetExpr*expr);
143 extern std::list<hname_t> eval_scope_path(Design*des, NetScope*scope,
144 const pform_name_t&path);
147 * Return a human readable version of the operator.
149 const char *human_readable_op(const char op);
152 * Is the expression a constant value and if so what is its logical
153 * value.
155 * C_NON - the expression is not a constant value.
156 * C_0 - the expression is constant and it has a false value.
157 * C_1 - the expression is constant and it has a true value.
158 * C_X - the expression is constant and it has an 'bX value.
160 enum const_bool { C_NON, C_0, C_1, C_X };
161 const_bool const_logical(const NetExpr*expr);
163 #endif