2 * Copyright (c) 1998-2007 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: pform.cc,v 1.148 2007/06/12 04:05:45 steve Exp $"
25 # include "compiler.h"
27 # include "parse_misc.h"
28 # include "parse_api.h"
31 # include "PGenerate.h"
40 map
<perm_string
,Module
*> pform_modules
;
41 map
<perm_string
,PUdp
*> pform_primitives
;
44 * The lexor accesses the vl_* variables.
50 /* This tracks the current module being processed. There can only be
51 exactly one module currently being parsed, since verilog does not
52 allow nested module definitions. */
53 static Module
*pform_cur_module
= 0;
55 bool pform_library_flag
= false;
57 /* increment this for generate schemes within a module, and set it
58 to zero when a new module starts. */
59 static unsigned scope_generate_counter
= 1;
61 /* This tracks the current generate scheme being processed. This is
62 always within a module. */
63 static PGenerate
*pform_cur_generate
= 0;
65 static NetNet::Type pform_default_nettype
= NetNet::WIRE
;
68 * These variables track the current time scale, as well as where the
69 * timescale was set. This supports warnings about tangled timescales.
71 static int pform_time_unit
= 0;
72 static int pform_time_prec
= 0;
74 static char*pform_timescale_file
= 0;
75 static unsigned pform_timescale_line
= 0;
78 * The scope stack and the following functions handle the processing
79 * of scope. As I enter a scope, the push function is called, and as I
80 * leave a scope the pop function is called. Entering tasks, functions
81 * and named blocks causes scope to be pushed and popped. The module
82 * name is not included in this scope stack.
84 * The hier_name function, therefore, converts the name to the scoped
85 * name within the module currently in progress. It never includes an
88 * The scope stack does not include any scope created by a generate
92 static pform_name_t scope_stack
;
94 void pform_push_scope(char*name
)
96 scope_stack
.push_back(name_component_t(lex_strings
.make(name
)));
99 void pform_pop_scope()
101 scope_stack
.pop_back();
104 static pform_name_t
hier_name(const char*tail
)
106 pform_name_t name
= scope_stack
;
107 name
.push_back(name_component_t(lex_strings
.make(tail
)));
111 static PWire
*get_wire_in_module(const pform_name_t
&name
)
113 /* Note that if we are processing a generate, then the
114 scope depth will be empty because generate schemes
115 cannot be within sub-scopes. Only directly in
117 if (pform_cur_generate
)
118 return pform_cur_generate
->get_wire(name
);
120 return pform_cur_module
->get_wire(name
);
123 void pform_set_default_nettype(NetNet::Type type
,
124 const char*file
, unsigned lineno
)
126 pform_default_nettype
= type
;
128 if (pform_cur_module
) {
129 cerr
<< file
<<":"<<lineno
<< ": error: "
130 << "`default_nettype directives must appear" << endl
;
131 cerr
<< file
<<":"<<lineno
<< ": : "
132 << "outside module definitions. The containing" << endl
;
133 cerr
<< file
<<":"<<lineno
<< ": : "
134 << "module " << pform_cur_module
->mod_name()
135 << " starts on line "
136 << pform_cur_module
->get_line() << "." << endl
;
142 * The lexor calls this function to set the active timescale when it
143 * detects a `timescale directive. The function saves the directive
144 * values (for use by modules) and if warnings are enabled checks to
145 * see if some modules have no timescale.
147 void pform_set_timescale(int unit
, int prec
,
148 const char*file
, unsigned lineno
)
150 bool first_flag
= true;
152 assert(unit
>= prec
);
153 pform_time_unit
= unit
;
154 pform_time_prec
= prec
;
156 if (pform_timescale_file
) {
157 free(pform_timescale_file
);
161 pform_timescale_file
= strdup(file
);
162 pform_timescale_line
= lineno
;
164 if (warn_timescale
&& first_flag
&& (pform_modules
.size() > 0)) {
165 cerr
<< file
<< ":" << lineno
<< ": warning: "
166 << "Some modules have no timescale. This may cause"
168 cerr
<< file
<< ":" << lineno
<< ": : "
169 << "confusing timing results. Affected modules are:"
172 map
<perm_string
,Module
*>::iterator mod
;
173 for (mod
= pform_modules
.begin()
174 ; mod
!= pform_modules
.end() ; mod
++) {
175 const Module
*mp
= (*mod
).second
;
177 cerr
<< file
<< ":" << lineno
<< ": : "
178 << " -- module " << (*mod
).first
179 << " declared here: " << mp
->get_line() << endl
;
185 verinum
* pform_verinum_with_size(verinum
*siz
, verinum
*val
,
186 const char*file
, unsigned lineno
)
188 assert(siz
->is_defined());
189 unsigned long size
= siz
->as_ulong();
193 switch (val
->get(val
->len()-1)) {
205 verinum
*res
= new verinum(pad
, size
, true);
207 unsigned copy
= val
->len();
208 if (res
->len() < copy
)
211 for (unsigned idx
= 0 ; idx
< copy
; idx
+= 1) {
212 res
->set(idx
, val
->get(idx
));
215 res
->has_sign(val
->has_sign());
217 bool trunc_flag
= false;
218 for (unsigned idx
= copy
; idx
< val
->len() ; idx
+= 1) {
219 if (val
->get(idx
) != pad
) {
226 cerr
<< file
<< ":" << lineno
<< ": warning: Numeric constant "
227 << "truncated to " << copy
<< " bits." << endl
;
235 void pform_startmodule(const char*name
, const char*file
, unsigned lineno
,
236 svector
<named_pexpr_t
*>*attr
)
238 assert( pform_cur_module
== 0 );
240 perm_string lex_name
= lex_strings
.make(name
);
241 pform_cur_module
= new Module(lex_name
);
242 pform_cur_module
->time_unit
= pform_time_unit
;
243 pform_cur_module
->time_precision
= pform_time_prec
;
244 pform_cur_module
->default_nettype
= pform_default_nettype
;
246 pform_cur_module
->set_file(file
);
247 pform_cur_module
->set_lineno(lineno
);
248 pform_cur_module
->library_flag
= pform_library_flag
;
250 /* The generate scheme numbering starts with *1*, not
251 zero. That's just the way it is, thanks to the standard. */
252 scope_generate_counter
= 1;
254 if (warn_timescale
&& pform_timescale_file
255 && (strcmp(pform_timescale_file
,file
) != 0)) {
257 cerr
<< pform_cur_module
->get_line() << ": warning: "
258 << "timescale for " << name
259 << " inherited from another file." << endl
;
260 cerr
<< pform_timescale_file
<< ":" << pform_timescale_line
261 << ": ...: The inherited timescale is here." << endl
;
264 for (unsigned idx
= 0 ; idx
< attr
->count() ; idx
+= 1) {
265 named_pexpr_t
*tmp
= (*attr
)[idx
];
266 pform_cur_module
->attributes
[tmp
->name
] = tmp
->parm
;
272 * This function is called by the parser to make a simple port
273 * reference. This is a name without a .X(...), so the internal name
274 * should be generated to be the same as the X.
276 Module::port_t
* pform_module_port_reference(char*name
,
280 Module::port_t
*ptmp
= new Module::port_t
;
281 PEIdent
*tmp
= new PEIdent(lex_strings
.make(name
));
283 tmp
->set_lineno(lineno
);
284 ptmp
->name
= lex_strings
.make(name
);
285 ptmp
->expr
= svector
<PEIdent
*>(1);
291 void pform_module_set_ports(svector
<Module::port_t
*>*ports
)
293 assert(pform_cur_module
);
295 /* The parser parses ``module foo()'' as having one
296 unconnected port, but it is really a module with no
297 ports. Fix it up here. */
298 if (ports
&& (ports
->count() == 1) && ((*ports
)[0] == 0)) {
304 pform_cur_module
->ports
= *ports
;
309 void pform_endmodule(const char*name
)
311 assert(pform_cur_module
);
312 perm_string mod_name
= pform_cur_module
->mod_name();
313 assert(strcmp(name
, mod_name
) == 0);
315 map
<perm_string
,Module
*>::const_iterator test
=
316 pform_modules
.find(mod_name
);
318 if (test
!= pform_modules
.end()) {
320 msg
<< "Module " << name
<< " was already declared here: "
321 << (*test
).second
->get_line() << endl
;
322 VLerror(msg
.str().c_str());
323 pform_cur_module
= 0;
326 pform_modules
[mod_name
] = pform_cur_module
;
327 pform_cur_module
= 0;
330 void pform_genvars(list
<perm_string
>*names
)
332 list
<perm_string
>::const_iterator cur
;
333 for (cur
= names
->begin(); cur
!= names
->end() ; *cur
++) {
334 pform_cur_module
->genvars
.push_back( *cur
);
340 void pform_start_generate_for(const struct vlltype
&li
,
341 char*ident1
, PExpr
*init
,
343 char*ident2
, PExpr
*next
)
345 PGenerate
*gen
= new PGenerate(scope_generate_counter
++);
347 gen
->set_file(li
.text
);
348 gen
->set_lineno(li
.first_line
);
350 // For now, assume that generates do not nest.
351 gen
->parent
= pform_cur_generate
;
352 pform_cur_generate
= gen
;
354 pform_cur_generate
->scheme_type
= PGenerate::GS_LOOP
;
356 pform_cur_generate
->loop_index
= lex_strings
.make(ident1
);
357 pform_cur_generate
->loop_init
= init
;
358 pform_cur_generate
->loop_test
= test
;
359 pform_cur_generate
->loop_step
= next
;
365 void pform_start_generate_if(const struct vlltype
&li
, PExpr
*test
)
367 PGenerate
*gen
= new PGenerate(scope_generate_counter
++);
369 gen
->set_file(li
.text
);
370 gen
->set_lineno(li
.first_line
);
372 // For now, assume that generates do not nest.
373 gen
->parent
= pform_cur_generate
;
374 pform_cur_generate
= gen
;
376 pform_cur_generate
->scheme_type
= PGenerate::GS_CONDIT
;
378 pform_cur_generate
->loop_init
= 0;
379 pform_cur_generate
->loop_test
= test
;
380 pform_cur_generate
->loop_step
= 0;
383 void pform_start_generate_else(const struct vlltype
&li
)
385 assert(pform_cur_generate
);
386 assert(pform_cur_generate
->scheme_type
== PGenerate::GS_CONDIT
);
388 PGenerate
*cur
= pform_cur_generate
;
391 PGenerate
*gen
= new PGenerate(scope_generate_counter
++);
393 gen
->set_file(li
.text
);
394 gen
->set_lineno(li
.first_line
);
396 // For now, assume that generates do not nest.
397 gen
->parent
= pform_cur_generate
;
398 pform_cur_generate
= gen
;
400 pform_cur_generate
->scheme_type
= PGenerate::GS_ELSE
;
402 pform_cur_generate
->loop_init
= 0;
403 pform_cur_generate
->loop_test
= cur
->loop_test
;
404 pform_cur_generate
->loop_step
= 0;
407 void pform_generate_block_name(char*name
)
409 assert(pform_cur_generate
!= 0);
410 assert(pform_cur_generate
->scope_name
== 0);
411 pform_cur_generate
->scope_name
= lex_strings
.make(name
);
415 void pform_endgenerate()
417 assert(pform_cur_generate
!= 0);
418 assert(pform_cur_module
);
420 // If there is no explicit block name then generate a temporary
421 // name. This will be replaced by the correct name later, once
422 // we know all the explicit names in the surrounding scope. If
423 // the naming scheme used here is changed, PGenerate::elaborate
424 // must be changed to match.
425 if (pform_cur_generate
->scope_name
== 0) {
427 snprintf(tmp
, sizeof tmp
, "$gen%d", pform_cur_generate
->id_number
);
428 pform_cur_generate
->scope_name
= lex_strings
.make(tmp
);
431 PGenerate
*cur
= pform_cur_generate
;
432 pform_cur_generate
= cur
->parent
;
434 if (pform_cur_generate
!= 0)
435 pform_cur_generate
->generates
.push_back(cur
);
437 pform_cur_module
->generate_schemes
.push_back(cur
);
440 bool pform_expression_is_constant(const PExpr
*ex
)
442 return ex
->is_constant(pform_cur_module
);
445 MIN_TYP_MAX min_typ_max_flag
= TYP
;
446 unsigned min_typ_max_warn
= 10;
448 PExpr
* pform_select_mtm_expr(PExpr
*min
, PExpr
*typ
, PExpr
*max
)
452 switch (min_typ_max_flag
) {
470 if (min_typ_max_warn
> 0) {
471 cerr
<< res
->get_line() << ": warning: choosing ";
472 switch (min_typ_max_flag
) {
484 cerr
<< " expression." << endl
;
485 min_typ_max_warn
-= 1;
491 static void process_udp_table(PUdp
*udp
, list
<string
>*table
,
492 const char*file
, unsigned lineno
)
494 const bool synchronous_flag
= udp
->sequential
;
496 /* Interpret and check the table entry strings, to make sure
497 they correspond to the inputs, output and output type. Make
498 up vectors for the fully interpreted result that can be
499 placed in the PUdp object.
501 The table strings are made up by the parser to be two or
502 three substrings seperated by ';', i.e.:
504 0101:1:1 (synchronous device entry)
505 0101:0 (combinational device entry)
507 The parser doesn't check that we got the right kind here,
508 so this loop must watch out. */
509 svector
<string
> input (table
->size());
510 svector
<char> current (table
->size());
511 svector
<char> output (table
->size());
513 for (list
<string
>::iterator cur
= table
->begin()
514 ; cur
!= table
->end()
515 ; cur
++, idx
+= 1) {
518 /* Pull the input values from the string. */
519 assert(tmp
.find(':') == (udp
->ports
.count() - 1));
520 input
[idx
] = tmp
.substr(0, udp
->ports
.count()-1);
521 tmp
= tmp
.substr(udp
->ports
.count()-1);
523 assert(tmp
[0] == ':');
525 /* If this is a synchronous device, get the current
527 if (synchronous_flag
) {
528 if (tmp
.size() != 4) {
529 cerr
<< file
<<":"<<lineno
<< ": error: "
530 << "Invalid table format for"
531 << " sequential primitive." << endl
;
535 assert(tmp
.size() == 4);
536 current
[idx
] = tmp
[1];
539 } else if (tmp
.size() != 2) {
540 cerr
<< file
<<":"<<lineno
<< ": error: "
541 << "Invalid table format for"
542 << " combinational primitive." << endl
;
547 /* Finally, extract the desired output. */
548 assert(tmp
.size() == 2);
549 output
[idx
] = tmp
[1];
554 udp
->tcurrent
= current
;
555 udp
->toutput
= output
;
558 void pform_make_udp(perm_string name
, list
<string
>*parms
,
559 svector
<PWire
*>*decl
, list
<string
>*table
,
561 const char*file
, unsigned lineno
)
563 unsigned local_errors
= 0;
564 assert(parms
->size() > 0);
566 /* Put the declarations into a map, so that I can check them
567 off with the parameters in the list. If the port is already
568 in the map, merge the port type. I will rebuild a list
569 of parameters for the PUdp object. */
570 map
<string
,PWire
*> defs
;
571 for (unsigned idx
= 0 ; idx
< decl
->count() ; idx
+= 1) {
573 pform_name_t pname
= (*decl
)[idx
]->path();
574 string port_name
= peek_tail_name(pname
).str();
576 if (PWire
*cur
= defs
[port_name
]) {
578 assert((*decl
)[idx
]);
579 if ((*decl
)[idx
]->get_port_type() != NetNet::PIMPLICIT
) {
580 rc
= cur
->set_port_type((*decl
)[idx
]->get_port_type());
583 if ((*decl
)[idx
]->get_wire_type() != NetNet::IMPLICIT
) {
584 rc
= cur
->set_wire_type((*decl
)[idx
]->get_wire_type());
589 defs
[port_name
] = (*decl
)[idx
];
594 /* Put the parameters into a vector of wire descriptions. Look
595 in the map for the definitions of the name. In this loop,
596 the parms list in the list of ports in the port list of the
597 UDP declaration, and the defs map maps that name to a
598 PWire* created by an input or output declaration. */
599 svector
<PWire
*> pins (parms
->size());
600 svector
<string
> pin_names (parms
->size());
601 { list
<string
>::iterator cur
;
603 for (cur
= parms
->begin(), idx
= 0
604 ; cur
!= parms
->end()
606 pins
[idx
] = defs
[*cur
];
607 pin_names
[idx
] = *cur
;
611 /* Check that the output is an output and the inputs are
612 inputs. I can also make sure that only the single output is
613 declared a register, if anything. The possible errors are:
615 -- an input port (not the first) is missing an input
618 -- An input port is declared output.
621 assert(pins
.count() > 0);
624 cerr
<< file
<<":"<<lineno
<< ": error: "
625 << "Output port of primitive " << name
626 << " missing output declaration." << endl
;
627 cerr
<< file
<<":"<<lineno
<< ": : "
628 << "Try: output " << pin_names
[0] << ";"
634 if (pins
[0]->get_port_type() != NetNet::POUTPUT
) {
635 cerr
<< file
<<":"<<lineno
<< ": error: "
636 << "The first port of a primitive"
637 << " must be an output." << endl
;
638 cerr
<< file
<<":"<<lineno
<< ": : "
639 << "Try: output " << pin_names
[0] << ";"
647 for (unsigned idx
= 1 ; idx
< pins
.count() ; idx
+= 1) {
648 if (pins
[idx
] == 0) {
649 cerr
<< file
<<":"<<lineno
<< ": error: "
650 << "Port " << (idx
+1)
651 << " of primitive " << name
<< " missing"
652 << " input declaration." << endl
;
653 cerr
<< file
<<":"<<lineno
<< ": : "
654 << "Try: input " << pin_names
[idx
] << ";"
660 if (pins
[idx
]->get_port_type() != NetNet::PINPUT
) {
661 cerr
<< file
<<":"<<lineno
<< ": error: "
662 << "Input port " << (idx
+1)
663 << " of primitive " << name
664 << " has an output (or missing) declaration." << endl
;
665 cerr
<< file
<<":"<<lineno
<< ": : "
666 << "Note that only the first port can be an output."
668 cerr
<< file
<<":"<<lineno
<< ": : "
669 << "Try \"input " << name
<< ";\""
676 if (pins
[idx
]->get_wire_type() == NetNet::REG
) {
677 cerr
<< file
<<":"<<lineno
<< ": error: "
678 << "Port " << (idx
+1)
679 << " of primitive " << name
<< " is an input port"
680 << " with a reg declaration." << endl
;
681 cerr
<< file
<<":"<<lineno
<< ": : "
682 << "primitive inputs cannot be reg."
690 if (local_errors
> 0) {
699 /* Verify the "initial" statement, if present, to be sure that
700 it only assigns to the output and the output is
701 registered. Then save the initial value that I get. */
702 verinum::V init
= verinum::Vx
;
705 assert(pins
[0]->get_wire_type() == NetNet::REG
);
707 PAssign
*pa
= dynamic_cast<PAssign
*>(init_expr
);
710 const PEIdent
*id
= dynamic_cast<const PEIdent
*>(pa
->lval());
714 //assert(id->name() == pins[0]->name());
716 const PENumber
*np
= dynamic_cast<const PENumber
*>(pa
->rval());
719 init
= np
->value()[0];
722 // Put the primitive into the primitives table
723 if (pform_primitives
[name
]) {
724 VLerror("UDP primitive already exists.");
727 PUdp
*udp
= new PUdp(name
, parms
->size());
729 // Detect sequential udp.
730 if (pins
[0]->get_wire_type() == NetNet::REG
)
731 udp
->sequential
= true;
733 // Make the port list for the UDP
734 for (unsigned idx
= 0 ; idx
< pins
.count() ; idx
+= 1)
735 udp
->ports
[idx
] = peek_tail_name(pins
[idx
]->path());
737 process_udp_table(udp
, table
, file
, lineno
);
740 pform_primitives
[name
] = udp
;
744 /* Delete the excess tables and lists from the parser. */
751 void pform_make_udp(perm_string name
, bool synchronous_flag
,
752 perm_string out_name
, PExpr
*init_expr
,
753 list
<perm_string
>*parms
, list
<string
>*table
,
754 const char*file
, unsigned lineno
)
757 svector
<PWire
*> pins(parms
->size() + 1);
759 /* Make the PWire for the output port. */
760 pins
[0] = new PWire(hier_name(out_name
),
761 synchronous_flag
? NetNet::REG
: NetNet::WIRE
,
764 pins
[0]->set_file(file
);
765 pins
[0]->set_lineno(lineno
);
767 /* Make the PWire objects for the input ports. */
768 { list
<perm_string
>::iterator cur
;
770 for (cur
= parms
->begin(), idx
= 1
771 ; cur
!= parms
->end()
773 assert(idx
< pins
.count());
774 pins
[idx
] = new PWire(hier_name(*cur
),
778 pins
[idx
]->set_file(file
);
779 pins
[idx
]->set_lineno(lineno
);
781 assert(idx
== pins
.count());
784 /* Verify the initial expression, if present, to be sure that
785 it only assigns to the output and the output is
786 registered. Then save the initial value that I get. */
787 verinum::V init
= verinum::Vx
;
790 assert(pins
[0]->get_wire_type() == NetNet::REG
);
792 PAssign
*pa
= dynamic_cast<PAssign
*>(init_expr
);
795 const PEIdent
*id
= dynamic_cast<const PEIdent
*>(pa
->lval());
799 //assert(id->name() == pins[0]->name());
801 const PENumber
*np
= dynamic_cast<const PENumber
*>(pa
->rval());
804 init
= np
->value()[0];
807 // Put the primitive into the primitives table
808 if (pform_primitives
[name
]) {
809 VLerror("UDP primitive already exists.");
812 PUdp
*udp
= new PUdp(name
, pins
.count());
814 // Detect sequential udp.
815 udp
->sequential
= synchronous_flag
;
817 // Make the port list for the UDP
818 for (unsigned idx
= 0 ; idx
< pins
.count() ; idx
+= 1)
819 udp
->ports
[idx
] = peek_tail_name(pins
[idx
]->path());
823 process_udp_table(udp
, table
, file
, lineno
);
826 pform_primitives
[name
] = udp
;
835 * This function is used to set the net range for a port that uses
836 * the new (1364-2001) list_of_port_declarations, but omitted a
837 * register/wire/etc. that would have triggered it to be set elsewhere.
840 * Since implicitly defined list of port declarations are no longer
841 * considered fully defined we no longer need this routine to force
842 * them to be fully defined.
844 void pform_set_net_range(const char* name)
846 PWire*cur = get_wire_in_module(hier_name(name));
848 VLerror("error: name is not a valid net.");
851 cur->set_net_range();
856 * This function attaches a range to a given name. The function is
857 * only called by the parser within the scope of the net declaration,
858 * and the name that I receive only has the tail component.
860 static void pform_set_net_range(const char* name
,
861 const svector
<PExpr
*>*range
,
863 ivl_variable_type_t dt
,
866 PWire
*cur
= get_wire_in_module(hier_name(name
));
868 VLerror("error: name is not a valid net.");
873 /* This is the special case that we really mean a
874 scalar. Set a fake range. */
875 cur
->set_range(0, 0, rt
);
878 assert(range
->count() == 2);
881 cur
->set_range((*range
)[0], (*range
)[1], rt
);
883 cur
->set_signed(signed_flag
);
885 if (dt
!= IVL_VT_NO_TYPE
)
886 cur
->set_data_type(dt
);
889 void pform_set_net_range(list
<perm_string
>*names
,
890 svector
<PExpr
*>*range
,
892 ivl_variable_type_t dt
,
895 assert((range
== 0) || (range
->count() == 2));
897 for (list
<perm_string
>::iterator cur
= names
->begin()
898 ; cur
!= names
->end()
900 perm_string txt
= *cur
;
901 pform_set_net_range(txt
, range
, signed_flag
, dt
, rt
);
910 * This is invoked to make a named event. This is the declaration of
911 * the event, and not necessarily the use of it.
913 static void pform_make_event(perm_string name
, const char*fn
, unsigned ln
)
915 PEvent
*event
= new PEvent(name
);
917 event
->set_lineno(ln
);
918 pform_cur_module
->events
[name
] = event
;
921 void pform_make_events(list
<perm_string
>*names
, const char*fn
, unsigned ln
)
923 list
<perm_string
>::iterator cur
;
924 for (cur
= names
->begin() ; cur
!= names
->end() ; cur
++) {
925 perm_string txt
= *cur
;
926 pform_make_event(txt
, fn
, ln
);
933 * pform_makegates is called when a list of gates (with the same type)
934 * are ready to be instantiated. The function runs through the list of
935 * gates and calls the pform_makegate function to make the individual gate.
937 void pform_makegate(PGBuiltin::Type type
,
938 struct str_pair_t str
,
939 svector
<PExpr
*>* delay
,
941 svector
<named_pexpr_t
*>*attr
)
943 if (info
.parms_by_name
) {
944 cerr
<< info
.file
<< ":" << info
.lineno
<< ": Gates do not "
945 "have port names." << endl
;
950 perm_string dev_name
= lex_strings
.make(info
.name
);
951 PGBuiltin
*cur
= new PGBuiltin(type
, dev_name
, info
.parms
, delay
);
953 cur
->set_range(info
.range
[0], info
.range
[1]);
956 for (unsigned idx
= 0 ; idx
< attr
->count() ; idx
+= 1) {
957 named_pexpr_t
*tmp
= (*attr
)[idx
];
958 cur
->attributes
[tmp
->name
] = tmp
->parm
;
962 cur
->strength0(str
.str0
);
963 cur
->strength1(str
.str1
);
964 cur
->set_file(info
.file
);
965 cur
->set_lineno(info
.lineno
);
967 if (pform_cur_generate
)
968 pform_cur_generate
->add_gate(cur
);
970 pform_cur_module
->add_gate(cur
);
973 void pform_makegates(PGBuiltin::Type type
,
974 struct str_pair_t str
,
975 svector
<PExpr
*>*delay
,
976 svector
<lgate
>*gates
,
977 svector
<named_pexpr_t
*>*attr
)
979 for (unsigned idx
= 0 ; idx
< gates
->count() ; idx
+= 1) {
980 pform_makegate(type
, str
, delay
, (*gates
)[idx
], attr
);
984 for (unsigned idx
= 0 ; idx
< attr
->count() ; idx
+= 1) {
985 named_pexpr_t
*cur
= (*attr
)[idx
];
995 * A module is different from a gate in that there are different
996 * constraints, and sometimes different syntax. The X_modgate
997 * functions handle the instantiations of modules (and UDP objects) by
998 * making PGModule objects.
1000 * The first pform_make_modgate handles the case of a module
1001 * instantiated with ports passed by position. The "wires" is an
1002 * ordered array of port expressions.
1004 * The second pform_make_modgate handles the case of a module
1005 * instantiated with ports passed by name. The "bind" argument is the
1006 * ports matched with names.
1008 static void pform_make_modgate(perm_string type
,
1010 struct parmvalue_t
*overrides
,
1011 svector
<PExpr
*>*wires
,
1012 PExpr
*msb
, PExpr
*lsb
,
1013 const char*fn
, unsigned ln
)
1015 PGModule
*cur
= new PGModule(type
, name
, wires
);
1017 cur
->set_lineno(ln
);
1018 cur
->set_range(msb
,lsb
);
1020 if (overrides
&& overrides
->by_name
) {
1021 unsigned cnt
= overrides
->by_name
->count();
1022 named
<PExpr
*>*byname
= new named
<PExpr
*>[cnt
];
1024 for (unsigned idx
= 0 ; idx
< cnt
; idx
+= 1) {
1025 named_pexpr_t
*curp
= (*overrides
->by_name
)[idx
];
1026 byname
[idx
].name
= curp
->name
;
1027 byname
[idx
].parm
= curp
->parm
;
1030 cur
->set_parameters(byname
, cnt
);
1032 } else if (overrides
&& overrides
->by_order
) {
1033 cur
->set_parameters(overrides
->by_order
);
1036 if (pform_cur_generate
)
1037 pform_cur_generate
->add_gate(cur
);
1039 pform_cur_module
->add_gate(cur
);
1042 static void pform_make_modgate(perm_string type
,
1044 struct parmvalue_t
*overrides
,
1045 svector
<named_pexpr_t
*>*bind
,
1046 PExpr
*msb
, PExpr
*lsb
,
1047 const char*fn
, unsigned ln
)
1049 unsigned npins
= bind
->count();
1050 named
<PExpr
*>*pins
= new named
<PExpr
*>[npins
];
1051 for (unsigned idx
= 0 ; idx
< npins
; idx
+= 1) {
1052 named_pexpr_t
*curp
= (*bind
)[idx
];
1053 pins
[idx
].name
= curp
->name
;
1054 pins
[idx
].parm
= curp
->parm
;
1057 PGModule
*cur
= new PGModule(type
, name
, pins
, npins
);
1059 cur
->set_lineno(ln
);
1060 cur
->set_range(msb
,lsb
);
1062 if (overrides
&& overrides
->by_name
) {
1063 unsigned cnt
= overrides
->by_name
->count();
1064 named
<PExpr
*>*byname
= new named
<PExpr
*>[cnt
];
1066 for (unsigned idx
= 0 ; idx
< cnt
; idx
+= 1) {
1067 named_pexpr_t
*curp
= (*overrides
->by_name
)[idx
];
1068 byname
[idx
].name
= curp
->name
;
1069 byname
[idx
].parm
= curp
->parm
;
1072 cur
->set_parameters(byname
, cnt
);
1074 } else if (overrides
&& overrides
->by_order
) {
1076 cur
->set_parameters(overrides
->by_order
);
1080 if (pform_cur_generate
)
1081 pform_cur_generate
->add_gate(cur
);
1083 pform_cur_module
->add_gate(cur
);
1086 void pform_make_modgates(perm_string type
,
1087 struct parmvalue_t
*overrides
,
1088 svector
<lgate
>*gates
)
1091 for (unsigned idx
= 0 ; idx
< gates
->count() ; idx
+= 1) {
1092 lgate cur
= (*gates
)[idx
];
1093 perm_string cur_name
= lex_strings
.make(cur
.name
);
1095 if (cur
.parms_by_name
) {
1096 pform_make_modgate(type
, cur_name
, overrides
,
1098 cur
.range
[0], cur
.range
[1],
1099 cur
.file
, cur
.lineno
);
1101 } else if (cur
.parms
) {
1103 /* If there are no parameters, the parser will be
1104 tricked into thinking it is one empty
1105 parameter. This fixes that. */
1106 if ((cur
.parms
->count() == 1) && (cur
.parms
[0][0] == 0)) {
1108 cur
.parms
= new svector
<PExpr
*>(0);
1110 pform_make_modgate(type
, cur_name
, overrides
,
1112 cur
.range
[0], cur
.range
[1],
1113 cur
.file
, cur
.lineno
);
1116 svector
<PExpr
*>*wires
= new svector
<PExpr
*>(0);
1117 pform_make_modgate(type
, cur_name
, overrides
,
1119 cur
.range
[0], cur
.range
[1],
1120 cur
.file
, cur
.lineno
);
1127 static PGAssign
* pform_make_pgassign(PExpr
*lval
, PExpr
*rval
,
1128 svector
<PExpr
*>*del
,
1129 struct str_pair_t str
)
1131 svector
<PExpr
*>*wires
= new svector
<PExpr
*>(2);
1138 cur
= new PGAssign(wires
);
1140 cur
= new PGAssign(wires
, del
);
1142 cur
->strength0(str
.str0
);
1143 cur
->strength1(str
.str1
);
1145 if (pform_cur_generate
)
1146 pform_cur_generate
->add_gate(cur
);
1148 pform_cur_module
->add_gate(cur
);
1153 void pform_make_pgassign_list(svector
<PExpr
*>*alist
,
1154 svector
<PExpr
*>*del
,
1155 struct str_pair_t str
,
1160 for (unsigned idx
= 0 ; idx
< alist
->count()/2 ; idx
+= 1) {
1161 tmp
= pform_make_pgassign((*alist
)[2*idx
],
1165 tmp
->set_lineno(lineno
);
1170 * this function makes the initial assignment to a register as given
1171 * in the source. It handles the case where a reg variable is assigned
1172 * where it it declared:
1176 * This is equivalent to the combination of statements:
1179 * initial foo = <expr>;
1181 * and that is how it is parsed. This syntax is not part of the
1182 * IEEE1364-1995 standard, but is approved by OVI as enhancement
1185 void pform_make_reginit(const struct vlltype
&li
,
1186 const char*name
, PExpr
*expr
)
1188 const pform_name_t sname
= hier_name(name
);
1189 PWire
*cur
= pform_cur_module
->get_wire(sname
);
1191 VLerror(li
, "internal error: reginit to non-register?");
1196 PEIdent
*lval
= new PEIdent(sname
);
1197 lval
->set_file(li
.text
);
1198 lval
->set_lineno(li
.first_line
);
1199 PAssign
*ass
= new PAssign(lval
, expr
);
1200 ass
->set_file(li
.text
);
1201 ass
->set_lineno(li
.first_line
);
1202 PProcess
*top
= new PProcess(PProcess::PR_INITIAL
, ass
);
1203 top
->set_file(li
.text
);
1204 top
->set_lineno(li
.first_line
);
1206 pform_cur_module
->add_behavior(top
);
1210 * This function is used by the parser when I have port definition of
1211 * the form like this:
1213 * input wire signed [7:0] nm;
1215 * The port_type, type, signed_flag and range are known all at once,
1216 * so we can create the PWire object all at once instead of piecemeal
1217 * as is done for the old method.
1219 void pform_module_define_port(const struct vlltype
&li
,
1221 NetNet::PortType port_type
,
1224 svector
<PExpr
*>*range
,
1225 svector
<named_pexpr_t
*>*attr
)
1227 pform_name_t name
= hier_name(nm
);
1228 PWire
*cur
= pform_cur_module
->get_wire(name
);
1231 msg
<< nm
<< " definition conflicts with "
1232 << "definition at " << cur
->get_line()
1234 VLerror(msg
.str().c_str());
1239 cur
= new PWire(name
, type
, port_type
, IVL_VT_LOGIC
);
1240 cur
->set_file(li
.text
);
1241 cur
->set_lineno(li
.first_line
);
1243 cur
->set_signed(signed_flag
);
1246 cur
->set_range(0, 0, (type
== NetNet::IMPLICIT
) ? SR_PORT
:
1250 assert(range
->count() == 2);
1251 assert((*range
)[0]);
1252 assert((*range
)[1]);
1253 cur
->set_range((*range
)[0], (*range
)[1],
1254 (type
== NetNet::IMPLICIT
) ? SR_PORT
: SR_BOTH
);
1258 for (unsigned idx
= 0 ; idx
< attr
->count() ; idx
+= 1) {
1259 named_pexpr_t
*tmp
= (*attr
)[idx
];
1260 cur
->attributes
[tmp
->name
] = tmp
->parm
;
1263 pform_cur_module
->add_wire(cur
);
1267 * This function makes a single signal (a wire, a reg, etc) as
1268 * requested by the parser. The name is unscoped, so I attach the
1269 * current scope to it (with the scoped_name function) and I try to
1270 * resolve it with an existing PWire in the scope.
1272 * The wire might already exist because of an implicit declaration in
1273 * a module port, i.e.:
1275 * module foo (bar...
1279 * The output (or other port direction indicator) may or may not have
1280 * been seen already, so I do not do any checking with it yet. But I
1281 * do check to see if the name has already been declared, as this
1282 * function is called for every declaration.
1286 * this is the basic form of pform_makwire. This takes a single simple
1287 * name, port type, net type, data type, and attributes, and creates
1288 * the variable/net. Other forms of pform_makewire ultimately call
1289 * this one to create the wire and stash it.
1291 void pform_makewire(const vlltype
&li
, const char*nm
,
1292 NetNet::Type type
, NetNet::PortType pt
,
1293 ivl_variable_type_t dt
,
1294 svector
<named_pexpr_t
*>*attr
)
1296 pform_name_t name
= hier_name(nm
);
1298 PWire
*cur
= get_wire_in_module(name
);
1300 // If this is not implicit ("implicit" meaning we don't know
1301 // what the type is yet) then set thay type now.
1302 if (cur
&& type
!= NetNet::IMPLICIT
) {
1303 bool rc
= cur
->set_wire_type(type
);
1306 msg
<< nm
<< " definition conflicts with "
1307 << "definition at " << cur
->get_line()
1309 VLerror(msg
.str().c_str());
1310 cerr
<< "XXXX type=" << type
<<", curtype=" << cur
->get_wire_type() << endl
;
1315 bool new_wire_flag
= false;
1317 new_wire_flag
= true;
1318 cur
= new PWire(name
, type
, pt
, dt
);
1321 cur
->set_file(li
.text
);
1322 cur
->set_lineno(li
.first_line
);
1326 cur
->set_data_type(dt
);
1327 cur
->set_range(0, 0, SR_NET
);
1328 cur
->set_signed(true);
1335 for (unsigned idx
= 0 ; idx
< attr
->count() ; idx
+= 1) {
1336 named_pexpr_t
*tmp
= (*attr
)[idx
];
1337 cur
->attributes
[tmp
->name
] = tmp
->parm
;
1341 if (new_wire_flag
) {
1342 if (pform_cur_generate
)
1343 pform_cur_generate
->add_wire(cur
);
1345 pform_cur_module
->add_wire(cur
);
1350 * This form takes a list of names and some type information, and
1351 * generates a bunch of variables/nets. We use the basic
1352 * pform_makewire above.
1354 void pform_makewire(const vlltype
&li
,
1355 svector
<PExpr
*>*range
,
1357 list
<perm_string
>*names
,
1359 NetNet::PortType pt
,
1360 ivl_variable_type_t dt
,
1361 svector
<named_pexpr_t
*>*attr
,
1364 for (list
<perm_string
>::iterator cur
= names
->begin()
1365 ; cur
!= names
->end()
1367 perm_string txt
= *cur
;
1368 pform_makewire(li
, txt
, type
, pt
, dt
, attr
);
1369 /* This has already been done for real variables. */
1370 if (dt
!= IVL_VT_REAL
) {
1371 pform_set_net_range(txt
, range
, signed_flag
, dt
, rt
);
1381 * This form makes nets with delays and continuous assignments.
1383 void pform_makewire(const vlltype
&li
,
1384 svector
<PExpr
*>*range
,
1386 svector
<PExpr
*>*delay
,
1388 net_decl_assign_t
*decls
,
1390 ivl_variable_type_t dt
)
1392 net_decl_assign_t
*first
= decls
->next
;
1396 net_decl_assign_t
*next
= first
->next
;
1398 pform_makewire(li
, first
->name
, type
, NetNet::NOT_A_PORT
, dt
, 0);
1399 /* This has already been done for real variables. */
1400 if (dt
!= IVL_VT_REAL
) {
1401 pform_set_net_range(first
->name
, range
, signed_flag
, dt
,
1405 perm_string first_name
= lex_strings
.make(first
->name
);
1406 pform_name_t name
= hier_name(first_name
);
1407 PWire
*cur
= get_wire_in_module(name
);
1409 PEIdent
*lval
= new PEIdent(first_name
);
1410 lval
->set_file(li
.text
);
1411 lval
->set_lineno(li
.first_line
);
1412 PGAssign
*ass
= pform_make_pgassign(lval
, first
->expr
,
1414 ass
->set_file(li
.text
);
1415 ass
->set_lineno(li
.first_line
);
1424 void pform_set_port_type(perm_string nm
, NetNet::PortType pt
,
1425 const char*file
, unsigned lineno
)
1427 pform_name_t name
= hier_name(nm
);
1428 PWire
*cur
= pform_cur_module
->get_wire(name
);
1430 cur
= new PWire(name
, NetNet::IMPLICIT
, NetNet::PIMPLICIT
, IVL_VT_LOGIC
);
1431 cur
->set_file(file
);
1432 cur
->set_lineno(lineno
);
1433 pform_cur_module
->add_wire(cur
);
1436 switch (cur
->get_port_type()) {
1437 case NetNet::PIMPLICIT
:
1438 if (! cur
->set_port_type(pt
))
1439 VLerror("error setting port direction.");
1442 case NetNet::NOT_A_PORT
:
1443 cerr
<< file
<< ":" << lineno
<< ": error: "
1444 << "port " << nm
<< " is not in the port list."
1450 cerr
<< file
<< ":" << lineno
<< ": error: "
1451 << "port " << nm
<< " already has a port declaration."
1460 * This function is called by the parser to create task ports. The
1461 * resulting wire (which should be a register) is put into a list to
1462 * be packed into the task parameter list.
1464 * It is possible that the wire (er, register) was already created,
1465 * but we know that if the name matches it is a part of the current
1466 * task, so in that case I just assign direction to it.
1468 * The following example demonstrates some of the issues:
1477 * This function is called when the parser matches the "input a" and
1478 * the "input b" statements. For ``a'', this function is called before
1479 * the wire is declared as a register, so I create the foo.a
1480 * wire. For ``b'', I will find that there is already a foo.b and I
1481 * just set the port direction. In either case, the ``reg a, b''
1482 * statement is caught by the block_item non-terminal and processed
1485 * Ports are implicitly type reg, because it must be possible for the
1486 * port to act as an l-value in a procedural assignment. It is obvious
1487 * for output and inout ports that the type is reg, because the task
1488 * only contains behavior (no structure) to a procedural assignment is
1489 * the *only* way to affect the output. It is less obvious for input
1490 * ports, but in practice an input port receives its value as if by a
1491 * procedural assignment from the calling behavior.
1493 * This function also handles the input ports of function
1494 * definitions. Input ports to function definitions have the same
1495 * constraints as those of tasks, so this works fine. Functions have
1496 * no output or inout ports.
1498 svector
<PWire
*>*pform_make_task_ports(NetNet::PortType pt
,
1499 ivl_variable_type_t vtype
,
1501 svector
<PExpr
*>*range
,
1502 list
<perm_string
>*names
,
1507 svector
<PWire
*>*res
= new svector
<PWire
*>(0);
1508 for (list
<perm_string
>::iterator cur
= names
->begin()
1509 ; cur
!= names
->end() ; cur
++ ) {
1511 perm_string txt
= *cur
;
1512 pform_name_t name
= hier_name(txt
);
1514 /* Look for a preexisting wire. If it exists, set the
1515 port direction. If not, create it. */
1516 PWire
*curw
= pform_cur_module
->get_wire(name
);
1518 curw
->set_port_type(pt
);
1520 curw
= new PWire(name
, NetNet::IMPLICIT_REG
, pt
, vtype
);
1521 curw
->set_file(file
);
1522 curw
->set_lineno(lineno
);
1523 pform_cur_module
->add_wire(curw
);
1526 curw
->set_signed(signed_flag
);
1528 /* If there is a range involved, it needs to be set. */
1530 curw
->set_range((*range
)[0], (*range
)[1], SR_PORT
);
1532 svector
<PWire
*>*tmp
= new svector
<PWire
*>(*res
, curw
);
1544 void pform_set_task(perm_string name
, PTask
*task
)
1546 pform_cur_module
->add_task(name
, task
);
1550 void pform_set_function(perm_string name
, PFunction
*func
)
1552 pform_cur_module
->add_function(name
, func
);
1555 void pform_set_attrib(perm_string name
, perm_string key
, char*value
)
1557 pform_name_t path
= hier_name(name
);
1559 if (PWire
*cur
= pform_cur_module
->get_wire(path
)) {
1560 cur
->attributes
[key
] = new PEString(value
);
1562 } else if (PGate
*cur
= pform_cur_module
->get_gate(name
)) {
1563 cur
->attributes
[key
] = new PEString(value
);
1567 VLerror("Unable to match name for setting attribute.");
1573 * Set the attribute of a TYPE. This is different from an object in
1574 * that this applies to every instantiation of the given type.
1576 void pform_set_type_attrib(perm_string name
, const string
&key
,
1579 map
<perm_string
,PUdp
*>::const_iterator udp
= pform_primitives
.find(name
);
1580 if (udp
== pform_primitives
.end()) {
1581 VLerror("type name is not (yet) defined.");
1586 (*udp
).second
->attributes
[key
] = new PEString(value
);
1590 * This function attaches a memory index range to an existing
1591 * register. (The named wire must be a register.
1593 void pform_set_reg_idx(const char*name
, PExpr
*l
, PExpr
*r
)
1596 if (pform_cur_generate
) {
1597 cur
= pform_cur_generate
->get_wire(hier_name(name
));
1599 cur
= pform_cur_module
->get_wire(hier_name(name
));
1602 VLerror("internal error: name is not a valid memory for index.");
1606 cur
->set_memory_idx(l
, r
);
1609 void pform_set_parameter(perm_string name
, bool signed_flag
,
1610 svector
<PExpr
*>*range
, PExpr
*expr
)
1613 pform_cur_module
->parameters
[name
].expr
= expr
;
1616 assert(range
->count() == 2);
1617 assert((*range
)[0]);
1618 assert((*range
)[1]);
1619 pform_cur_module
->parameters
[name
].msb
= (*range
)[0];
1620 pform_cur_module
->parameters
[name
].lsb
= (*range
)[1];
1622 pform_cur_module
->parameters
[name
].msb
= 0;
1623 pform_cur_module
->parameters
[name
].lsb
= 0;
1625 pform_cur_module
->parameters
[name
].signed_flag
= signed_flag
;
1627 pform_cur_module
->param_names
.push_back(name
);
1630 void pform_set_localparam(perm_string name
, bool signed_flag
,
1631 svector
<PExpr
*>*range
, PExpr
*expr
)
1634 pform_cur_module
->localparams
[name
].expr
= expr
;
1637 assert(range
->count() == 2);
1638 assert((*range
)[0]);
1639 assert((*range
)[1]);
1640 pform_cur_module
->localparams
[name
].msb
= (*range
)[0];
1641 pform_cur_module
->localparams
[name
].lsb
= (*range
)[1];
1643 pform_cur_module
->localparams
[name
].msb
= 0;
1644 pform_cur_module
->localparams
[name
].lsb
= 0;
1646 pform_cur_module
->localparams
[name
].signed_flag
= signed_flag
;
1649 void pform_set_specparam(perm_string name
, PExpr
*expr
)
1652 pform_cur_module
->specparams
[name
] = expr
;
1655 void pform_set_defparam(const pform_name_t
&name
, PExpr
*expr
)
1658 pform_cur_module
->defparms
[name
] = expr
;
1664 extern PSpecPath
* pform_make_specify_path(const struct vlltype
&li
,
1665 list
<perm_string
>*src
, char pol
,
1666 bool full_flag
, list
<perm_string
>*dst
)
1668 PSpecPath
*path
= new PSpecPath(src
->size(), dst
->size());
1669 path
->set_file(li
.text
);
1670 path
->set_lineno(li
.first_line
);
1673 list
<perm_string
>::const_iterator cur
;
1676 for (idx
= 0, cur
= src
->begin() ; cur
!= src
->end() ; idx
++, cur
++) {
1677 path
->src
[idx
] = *cur
;
1679 assert(idx
== path
->src
.size());
1682 for (idx
= 0, cur
= dst
->begin() ; cur
!= dst
->end() ; idx
++, cur
++) {
1683 path
->dst
[idx
] = *cur
;
1685 assert(idx
== path
->dst
.size());
1691 extern PSpecPath
*pform_make_specify_edge_path(const struct vlltype
&li
,
1692 int edge_flag
, /*posedge==true */
1693 list
<perm_string
>*src
, char pol
,
1694 bool full_flag
, list
<perm_string
>*dst
,
1695 PExpr
*data_source_expression
)
1697 PSpecPath
*tmp
= pform_make_specify_path(li
, src
, pol
, full_flag
, dst
);
1698 tmp
->edge
= edge_flag
;
1699 tmp
->data_source_expression
= data_source_expression
;
1703 extern PSpecPath
* pform_assign_path_delay(PSpecPath
*path
, svector
<PExpr
*>*del
)
1708 assert(path
->delays
.size() == 0);
1710 path
->delays
.resize(del
->count());
1711 for (unsigned idx
= 0 ; idx
< path
->delays
.size() ; idx
+= 1)
1712 path
->delays
[idx
] = (*del
)[idx
];
1720 extern void pform_module_specify_path(PSpecPath
*obj
)
1724 pform_cur_module
->specify_paths
.push_back(obj
);
1727 void pform_set_port_type(const struct vlltype
&li
,
1728 list
<perm_string
>*names
,
1729 svector
<PExpr
*>*range
,
1731 NetNet::PortType pt
)
1733 for (list
<perm_string
>::iterator cur
= names
->begin()
1734 ; cur
!= names
->end()
1736 perm_string txt
= *cur
;
1737 pform_set_port_type(txt
, pt
, li
.text
, li
.first_line
);
1738 pform_set_net_range(txt
, range
, signed_flag
, IVL_VT_NO_TYPE
,
1747 static void pform_set_reg_integer(const char*nm
)
1749 pform_name_t name
= hier_name(nm
);
1750 PWire
*cur
= pform_cur_module
->get_wire(name
);
1752 cur
= new PWire(name
, NetNet::INTEGER
,
1755 cur
->set_signed(true);
1756 pform_cur_module
->add_wire(cur
);
1758 bool rc
= cur
->set_wire_type(NetNet::INTEGER
);
1760 cur
->set_data_type(IVL_VT_LOGIC
);
1761 cur
->set_signed(true);
1765 cur
->set_range(new PENumber(new verinum(integer_width
-1, integer_width
)),
1766 new PENumber(new verinum((uint64_t)0, integer_width
)),
1768 cur
->set_signed(true);
1771 void pform_set_reg_integer(list
<perm_string
>*names
)
1773 for (list
<perm_string
>::iterator cur
= names
->begin()
1774 ; cur
!= names
->end()
1776 perm_string txt
= *cur
;
1777 pform_set_reg_integer(txt
);
1782 static void pform_set_reg_time(const char*nm
)
1784 pform_name_t name
= hier_name(nm
);
1785 PWire
*cur
= pform_cur_module
->get_wire(name
);
1787 cur
= new PWire(name
, NetNet::REG
, NetNet::NOT_A_PORT
, IVL_VT_LOGIC
);
1788 pform_cur_module
->add_wire(cur
);
1790 bool rc
= cur
->set_wire_type(NetNet::REG
);
1792 rc
= cur
->set_data_type(IVL_VT_LOGIC
);
1797 cur
->set_range(new PENumber(new verinum(TIME_WIDTH
-1, integer_width
)),
1798 new PENumber(new verinum((uint64_t)0, integer_width
)),
1802 void pform_set_reg_time(list
<perm_string
>*names
)
1804 for (list
<perm_string
>::iterator cur
= names
->begin()
1805 ; cur
!= names
->end()
1807 perm_string txt
= *cur
;
1808 pform_set_reg_time(txt
);
1813 svector
<PWire
*>* pform_make_udp_input_ports(list
<perm_string
>*names
)
1815 svector
<PWire
*>*out
= new svector
<PWire
*>(names
->size());
1818 for (list
<perm_string
>::iterator cur
= names
->begin()
1819 ; cur
!= names
->end()
1821 perm_string txt
= *cur
;
1823 tmp
.push_back(name_component_t(txt
));
1824 PWire
*pp
= new PWire(tmp
,
1836 PProcess
* pform_make_behavior(PProcess::Type type
, Statement
*st
,
1837 svector
<named_pexpr_t
*>*attr
)
1839 PProcess
*pp
= new PProcess(type
, st
);
1842 for (unsigned idx
= 0 ; idx
< attr
->count() ; idx
+= 1) {
1843 named_pexpr_t
*tmp
= (*attr
)[idx
];
1844 pp
->attributes
[tmp
->name
] = tmp
->parm
;
1849 if (pform_cur_generate
)
1850 pform_cur_generate
->add_behavior(pp
);
1852 pform_cur_module
->add_behavior(pp
);
1859 extern void reset_lexor();
1861 int pform_parse(const char*path
, FILE*file
)
1866 if (strcmp(path
, "-") == 0)
1869 vl_input
= fopen(path
, "r");
1870 if (vl_input
== 0) {
1871 cerr
<< "Unable to open " <<vl_file
<< "." << endl
;
1888 cerr
<< "I give up." << endl
;
1895 void pform_error_nested_modules()
1897 assert( pform_cur_module
!= 0 );
1898 cerr
<< pform_cur_module
->get_line() << ": error: original module "
1899 "(" << pform_cur_module
->mod_name() << ") defined here." << endl
;