开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Unexpected V2K keyword `or'


Sergey Smolov
 

Hello, I try to perform a "reduced or" operation (i.e. a bit-by-bit "or") on a vector of bits. Here is my code:

import Vector::*;

typedef Reg#(Bool) BoolReg;
typedef Vector#(TotalCheckerNum, Reg#(Bit#(1))) CheckerReg;

CheckerReg checkers_ready <- replicateM(mkReg(0));
BoolReg active??????????? <- mkRegU;

rule somerule;
? Vector#(TotalCheckerNum, Bool) rdy_vals = readVReg(checkers_ready);
? active <= or(rdy_vals);
endrule

The 'TotalCheckerNum' typedef is a constant. The compiler says that there is no such "or" function:

Unexpected V2K keyword `or'; expected operator or expression

but the "or" function is mentioned at the BSV Reference Guide Revision: 21 July 2017 ("C.3.4 Tests on Vectors"). What can be wrong here? Thanks in advance.


 

I believe that you can use a backslash to escape names that wouldn't otherwise parse:

active <= \or (rdy_vals);

Note that there needs to be a space after the name.? Otherwise, every character until the next space -- including the parentheses -- will be escaped as part of the name.

BSC supports two source languages: BSV (based on SystemVerilog) and BH (based on Haskell).? Some packages, like Vector, were written before BSV syntax was introduced, so they use names that later turned out to be SystemVerilog keywords.? In some cases, this was fixed by creating a new name; for example, there is a "const" function, but this is also a SV keyword, so an alias "constFn" was created, that can be used in BSV.? I don't see "orFn", so I guess we didn't define a new name for that situation.? Fortunately, SV has a syntax for escaping names, using the backslash character.? That should work in this case.

Julie


On Tue, Apr 27, 2021 at 7:22 PM Sergey Smolov <ssedai@...> wrote:
Hello, I try to perform a "reduced or" operation (i.e. a bit-by-bit "or") on a vector of bits. Here is my code:

import Vector::*;

typedef Reg#(Bool) BoolReg;
typedef Vector#(TotalCheckerNum, Reg#(Bit#(1))) CheckerReg;

CheckerReg checkers_ready <- replicateM(mkReg(0));
BoolReg active??????????? <- mkRegU;

rule somerule;
? Vector#(TotalCheckerNum, Bool) rdy_vals = readVReg(checkers_ready);
? active <= or(rdy_vals);
endrule

The 'TotalCheckerNum' typedef is a constant. The compiler says that there is no such "or" function:

Unexpected V2K keyword `or'; expected operator or expression

but the "or" function is mentioned at the BSV Reference Guide Revision: 21 July 2017 ("C.3.4 Tests on Vectors"). What can be wrong here? Thanks in advance.




Sergey Smolov
 

Yeah, it works, thank you for the detailed clarification:-)