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.
- 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.
- 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.
- 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.
- imports — vl-importlist
- Local package imports
- vardecls — vl-vardecllist
- Local variable declarations, including ones for the ports and
return value (see below).
- paramdecls — vl-paramdecllist
- Local parameter declarations
- blockitems — vl-blockitemlist
- The declarations within the function, in parse order. We sort
these out into the imports, vardecls, and paramdecls. It appears
that these may even contain event declarations, parameter declarations,
etc., which seems pretty absurd.
- 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.
- atts — vl-atts
- Any attributes associated with this function declaration.
- loc — vl-location
- Where this declaration was found in the source code.
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->portdecls
- Get the portdecls field from a vl-fundecl.
- Vl-fundecl->paramdecls
- Get the paramdecls field from a vl-fundecl.
- Vl-fundecl->blockitems
- Get the blockitems field from a vl-fundecl.
- Vl-fundecl->vardecls
- Get the vardecls 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.