Vl-fundecl
Representation of a single Verilog function.
This is a product type introduced by defprod.
Fields
- name — stringp
- Name of this function, e.g., lower_bits below.
- rettype — vl-datatype
- Return type of the function, e.g., a function might return an
ordinary unsigned or signed result of some width, or might
return a real value, etc. For instance, the return type
of lower_bits below is :vl-unsigned.
- body — vl-stmt
- The body of the function. We represent this as an ordinary statement,
but it must follow certain rules as outlined in 10.4.4, e.g.,
it cannot have any time controls, cannot enable tasks, cannot
have non-blocking assignments, etc.
- loc — vl-location
- Where this declaration was found in the source code.
- portdecls — vl-portdecllist
- The arguments to the function, e.g., input [7:0] a below.
Functions must have at least one input. We check this in our
parser, but we don't syntactically enforce this requirement in
the vl-fundecl-p structure. In Verilog-2005, functions
may only have inputs (i.e., they can't have outputs or inouts),
but our vl-portdecl-p structures have a direction, so in
the context of a function declaration this direction should
always be :vl-input. In SystemVerilog functions can have
other kinds of ports, but functions with output/inout ports
have restrictions and can't be used in expressions like normal
functions.
- function-map — vl-function-specialization-map
- This field gives the SVEX compilation(s) of the
function. More specifically, each key in this alist is a list
of maybe-4vecs corresponding to the function arguments. The
non-nil elements denote constant arguments with the given
values. The value corresponding to each key is pair
containing an svex representing the function assuming those
constant values of the arguments, and a corresponding list of
constraints.
- lifetime — vl-lifetime-p
- Indicates whether an explicit automatic or static
lifetime was provided. An automatic function is supposed to be
reentrant and have its local parameters dynamically allocated
for each function call, with various consequences.
- vardecls — vl-vardecllist
- Local variable declarations, including ones for the ports and
return value (see below).
- paramdecls — vl-paramdecllist
- Local parameter declarations
- typedefs — vl-typedeflist
- Local type declarations.
- imports — vl-importlist
- Local package imports
- atts — vl-atts
- Any attributes associated with this function declaration.
- loaditems — vl-portdecl-or-blockitem-list
- Owned by shadowcheck; do not use elsewhere.
Declarations within the function, in parse order, before
sorting out into imports, vardecls, paramdecls, and
typedefs.
Functions are described in Section 10.4 of the Verilog-2005
standard. An example of a function is:
function [3:0] lower_bits;
input [7:0] a;
reg [1:0] lowest_pair;
reg [1:0] next_lowest_pair;
begin
lowest_pair = a[1:0];
next_lowest_pair = a[3:2];
lower_bits = {next_lowest_pair, lowest_pair};
end
endfunction
Note that functions don't have any inout or output ports. Instead, you
assign to a function's name to indicate its return value.
To simplify scoping issues, we put "hidden" variables declarations for the
ports and return value of the function into its decls. These ports are
marked with the VL_HIDDEN_DECL_FOR_TASKPORT attribute. The pretty printer
and other code rely on this attribute to produce the correct output. These
extra declarations are created automatically by the loader.
Subtopics
- Vl-fundecl-p
- Recognizer for vl-fundecl structures.
- Vl-fundecl-fix
- Fixing function for vl-fundecl structures.
- Make-vl-fundecl
- Basic constructor macro for vl-fundecl structures.
- Vl-fundecl-equiv
- Basic equivalence relation for vl-fundecl structures.
- Change-vl-fundecl
- Modifying constructor for vl-fundecl structures.
- Vl-fundecl->function-map
- Get the function-map field from a vl-fundecl.
- Vl-fundecl->loaditems
- Get the loaditems field from a vl-fundecl.
- Vl-fundecl->vardecls
- Get the vardecls field from a vl-fundecl.
- Vl-fundecl->typedefs
- Get the typedefs field from a vl-fundecl.
- Vl-fundecl->portdecls
- Get the portdecls field from a vl-fundecl.
- Vl-fundecl->paramdecls
- Get the paramdecls field from a vl-fundecl.
- Vl-fundecl->rettype
- Get the rettype field from a vl-fundecl.
- Vl-fundecl->name
- Get the name field from a vl-fundecl.
- Vl-fundecl->lifetime
- Get the lifetime field from a vl-fundecl.
- Vl-fundecl->imports
- Get the imports field from a vl-fundecl.
- Vl-fundecl->loc
- Get the loc field from a vl-fundecl.
- Vl-fundecl->body
- Get the body field from a vl-fundecl.
- Vl-fundecl->atts
- Get the atts field from a vl-fundecl.