Skip to content

Commit

Permalink
initial tests with auto keyword for generic inputs/outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
sylefeb committed May 3, 2022
1 parent 40c9d63 commit 4a2c909
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
7 changes: 4 additions & 3 deletions antlr/silice.g4
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ RDEFINE : ':>' ;
BDEFINE : '<:>';
LDEFINEDBL : '<::' ;
BDEFINEDBL : '<::>';
AUTO : '<:auto:>' ;
AUTOBIND : '<:auto:>' ;
AUTO : 'auto' ;

ALWSASSIGNDBL : '::=' ;
ALWSASSIGN : ':=' ;
Expand Down Expand Up @@ -196,7 +197,7 @@ memClocks : (clk0=sclock ',' clk1=sclock) ;
memModifier : memClocks | memNoInputLatch | memDelayed | STRING;
memModifiers : '<' memModifier (',' memModifier)* ','? '>' ;

type : TYPE | (SAMEAS '(' base=IDENTIFIER ('.' member=IDENTIFIER)? ')') ;
type : TYPE | (SAMEAS '(' base=IDENTIFIER ('.' member=IDENTIFIER)? ')') | AUTO;
declarationWire : type alwaysAssigned;
declarationVarInitSet : '=' (value | UNINITIALIZED) ;
declarationVarInitCstr : '(' (value | UNINITIALIZED) ')';
Expand All @@ -206,7 +207,7 @@ declarationMemory : (BRAM | BROM | DUALBRAM | SIMPLEDUALBRAM) TYPE name=IDE
declarationInstance : blueprint=IDENTIFIER name=IDENTIFIER bpModifiers? ( '(' bpBindingList ')' ) ? ;
declaration : declarationVar | declarationInstance | declarationTable | declarationMemory | declarationWire;

bpBinding : left=IDENTIFIER (LDEFINE | LDEFINEDBL | RDEFINE | BDEFINE | BDEFINEDBL) right=idOrAccess | AUTO;
bpBinding : left=IDENTIFIER (LDEFINE | LDEFINEDBL | RDEFINE | BDEFINE | BDEFINEDBL) right=idOrAccess | AUTOBIND;
bpBindingList : bpBinding ',' bpBindingList | bpBinding | ;

/* -- io lists -- */
Expand Down
19 changes: 17 additions & 2 deletions src/Algorithm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ void Algorithm::getBindings(
if (bindings == nullptr) return;
while (bindings != nullptr) {
if (bindings->bpBinding() != nullptr) {
if (bindings->bpBinding()->AUTO() != nullptr) {
if (bindings->bpBinding()->AUTOBIND() != nullptr) {
_autobind = true;
} else {
// check if this is a group binding
Expand Down Expand Up @@ -1191,7 +1191,7 @@ void Algorithm::gatherTypeNfo(siliceParser::TypeContext *type, t_type_nfo &_nfo,
{
if (type->TYPE() != nullptr) {
splitType(type->TYPE()->getText(), _nfo);
} else {
} else if (type->SAMEAS() != nullptr) {
// find base
std::string base = type->base->getText() + (type->member != nullptr ? "_" + type->member->getText() : "");
base = translateVIOName(base, &_current->context);
Expand All @@ -1216,6 +1216,12 @@ void Algorithm::gatherTypeNfo(siliceParser::TypeContext *type, t_type_nfo &_nfo,
"no known definition for '%s' (sameas can only be applied to interfaces, groups and simple variables)", type->base->getText().c_str());
}
}
} else if (type->AUTO() != nullptr) {
_nfo.base_type = Parameterized;
_nfo.same_as = "";
_nfo.width = 0;
} else {
sl_assert(false);
}
}

Expand Down Expand Up @@ -3043,6 +3049,9 @@ void Algorithm::gatherIOs(siliceParser::InOutListContext* inout, t_combinational
}
m_Inputs.emplace_back(io);
m_InputNames.insert(make_pair(io.name, (int)m_Inputs.size() - 1));
if (io.type_nfo.base_type == Parameterized) {
m_Parameterized.push_back(io.name);
}
} else if (output) {
t_output_nfo io;
gatherOutputNfo(output, io, _current, _context);
Expand All @@ -3052,6 +3061,9 @@ void Algorithm::gatherIOs(siliceParser::InOutListContext* inout, t_combinational
}
m_Outputs.emplace_back(io);
m_OutputNames.insert(make_pair(io.name, (int)m_Outputs.size() - 1));
if (io.type_nfo.base_type == Parameterized) {
m_Parameterized.push_back(io.name);
}
} else if (inout) {
t_inout_nfo io;
gatherInoutNfo(inout, io, _current, _context);
Expand All @@ -3061,6 +3073,9 @@ void Algorithm::gatherIOs(siliceParser::InOutListContext* inout, t_combinational
}
m_InOuts.emplace_back(io);
m_InOutNames.insert(make_pair(io.name, (int)m_InOuts.size() - 1));
if (io.type_nfo.base_type == Parameterized) {
m_Parameterized.push_back(io.name);
}
} else if (iodef) {
gatherIoDef(iodef,_current,_context);
} else if (allouts) {
Expand Down
13 changes: 13 additions & 0 deletions tests/param1.si
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
algorithm test(
input uint4 a,
output sameas(a) b,
input sameas(a) c,
) {
b := a + c;
}

algorithm main(output int8 leds)
{
uint4 w <: 0;
test t(a <: w, b :> leds, c <: w);
}
13 changes: 13 additions & 0 deletions tests/param2.si
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
algorithm test(
input auto a,
output sameas(a) b,
input sameas(a) c,
) {
b := a + c;
}

algorithm main(output int8 leds)
{
uint4 w <: 0;
test t(a <: w, b :> leds, c <: w);
}

0 comments on commit 4a2c909

Please sign in to comment.