SV emit function ports in package subprograms.

This commit is contained in:
Stephen Williams 2013-05-19 18:36:29 -07:00
parent 164b5f9348
commit dca6171f5f
2 changed files with 35 additions and 1 deletions

View File

@ -182,6 +182,16 @@ static list<VTypeRecord::element_t*>* record_elements(list<perm_string>*names,
return res;
}
static void touchup_interface_for_functions(std::list<InterfacePort*>*ports)
{
for (list<InterfacePort*>::iterator cur = ports->begin()
; cur != ports->end() ; ++cur) {
InterfacePort*curp = *cur;
if (curp->mode == PORT_NONE)
curp->mode = PORT_IN;
}
}
%}
@ -1152,6 +1162,7 @@ function_specification /* IEEE 1076-2008 P4.2.1 */
{ perm_string type_name = lex_strings.make($7);
perm_string name = lex_strings.make($2);
const VType*type_mark = active_scope->find_type(type_name);
touchup_interface_for_functions($4);
Subprogram*tmp = new Subprogram(name, $4, type_mark);
FILE_NAME(tmp,@1);
delete[]$2;

View File

@ -33,11 +33,34 @@ int Subprogram::emit_package(ostream&fd) const
fd << "function ";
return_type_->emit_def(fd);
fd << " " << name_;
fd << ";" << endl;
fd << "(";
} else {
fd << "task " << name_ << ";" << endl;
}
for (list<InterfacePort*>::const_iterator cur = ports_->begin()
; cur != ports_->end() ; ++cur) {
if (cur != ports_->begin())
fd << ", ";
InterfacePort*curp = *cur;
switch (curp->mode) {
case PORT_IN:
fd << "input ";
break;
case PORT_OUT:
fd << "output ";
break;
case PORT_NONE:
fd << "inout /* PORT_NONE? */ ";
break;
}
errors += curp->type->emit_def(fd);
fd << " \\" << curp->name << " ";
}
fd << ");" << endl;
if (statements_) {
for (list<SequentialStmt*>::const_iterator cur = statements_->begin()
; cur != statements_->end() ; ++cur) {