Make C style comments work in false/suppressed ifdef/etc. blocks.
[iverilog.git] / netmisc.h
blobc66eef234994165d0af4a11ca008e4516bc67d01
1 #ifndef __netmisc_H
2 #define __netmisc_H
3 /*
4 * Copyright (c) 1999-2000 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
21 #ifdef HAVE_CVS_IDENT
22 #ident "$Id: netmisc.h,v 1.31 2007/06/02 03:42:13 steve Exp $"
23 #endif
25 # include "netlist.h"
28 * Search for a symbol using the "start" scope as the starting
29 * point. If the path includes a scope part, then locate the
30 * scope first.
32 * The return value is the scope where the symbol was found.
33 * If the symbol was not found, return 0. The output arguments
34 * get 0 except for the pointer to the object that represents
35 * the located symbol.
37 * The ex1 and ex2 output arguments are extended results. If the
38 * symbol is a parameter (par!=0) then ex1 is the msb expression and
39 * ex2 is the lsb expression for the range. If there is no range, then
40 * these values are set to 0.
42 extern NetScope* symbol_search(Design*des,
43 NetScope*start, pform_name_t path,
44 NetNet*&net, /* net/reg */
45 const NetExpr*&par,/* parameter */
46 NetEvent*&eve, /* named event */
47 const NetExpr*&ex1, const NetExpr*&ex2);
49 inline NetScope* symbol_search(Design*des,
50 NetScope*start, const pform_name_t&path,
51 NetNet*&net, /* net/reg */
52 const NetExpr*&par,/* parameter */
53 NetEvent*&eve /* named event */)
55 const NetExpr*ex1, *ex2;
56 return symbol_search(des, start, path, net, par, eve, ex1, ex2);
60 * This function transforms an expression by padding the high bits
61 * with V0 until the expression has the desired width. This may mean
62 * not transforming the expression at all, if it is already wide
63 * enough.
65 extern NetExpr*pad_to_width(NetExpr*expr, unsigned wid);
66 extern NetNet*pad_to_width(Design*des, NetNet*n, unsigned w);
68 extern NetNet*pad_to_width_signed(Design*des, NetNet*n, unsigned w);
71 * This function transforms an expression by cropping the high bits
72 * off with a part select. The result has the width w passed in. This
73 * function does not pad, use pad_to_width if padding is desired.
75 extern NetNet*crop_to_width(Design*des, NetNet*n, unsigned w);
78 * This function takes as input a NetNet signal and adds a constant
79 * value to it. If the val is 0, then simply return sig. Otherwise,
80 * return a new NetNet value that is the output of an addition.
82 extern NetNet*add_to_net(Design*des, NetNet*sig, long val);
85 * These functions make various sorts of expressions, given operands
86 * of certain type. The order of the operands is preserved in cases
87 * where order matters.
89 * make_add_expr
90 * Make a NetEBAdd expression with <expr> the first argument and
91 * <val> the second. This may get turned into a subtract if <val> is
92 * less then zero. If val is exactly zero, then return <expr> as is.
94 * make_sub_expr
95 * Make a NetEBAdd(subtract) node that subtracts the given
96 * expression from the integer value.
98 extern NetExpr*make_add_expr(NetExpr*expr, long val);
99 extern NetExpr*make_sub_expr(long val, NetExpr*expr);
102 * In some cases the lval is accessible as a pointer to the head of
103 * a list of NetAssign_ objects. This function returns the width of
104 * the l-value represented by this list.
106 extern unsigned count_lval_width(const class NetAssign_*first);
109 * This function elaborates an expression, and tries to evaluate it
110 * right away. If the expression can be evaluated, this returns a
111 * constant expression. If it cannot be evaluated, it returns whatever
112 * it can. If the expression cannot be elaborated, return 0.
114 * The expr_width is the width of the context where the expression is
115 * being elaborated, or -1 if the expression is self-determined width.
117 * Also, the prune_width is the maximum width of the result, and it
118 * passed to the eval_tree method of the expression to limit constant
119 * results if possible.
121 class PExpr;
122 extern NetExpr* elab_and_eval(Design*des, NetScope*scope,
123 const PExpr*pe, int expr_wid,
124 int prune_width =-1);
127 * Get the long integer value for the passed in expression, if
128 * possible. If it is not possible (the expression is not evaluated
129 * down to a constant) then return false and leave value unchanged.
131 bool eval_as_long(long&value, NetExpr*expr);
133 extern std::list<hname_t> eval_scope_path(Design*des, NetScope*scope,
134 const pform_name_t&path);
136 #endif