updated binary and unary operator printing (resolves #72)

This commit is contained in:
Zachary Snow 2020-02-15 14:11:09 -05:00
parent aea64e903c
commit b124a561f2
4 changed files with 33 additions and 2 deletions

View File

@ -75,8 +75,8 @@ instance Show Expr where
show (Repeat e l ) = printf "{%s {%s}}" (show e) (commas $ map show l)
show (Concat l ) = printf "{%s}" (commas $ map show l)
show (Stream o e l) = printf "{%s %s%s}" (show o) (show e) (show $ Concat l)
show (UniOp o e ) = printf "%s%s" (show o) (show e)
show (BinOp o a b) = printf "(%s %s %s)" (show a) (show o) (show b)
show (UniOp o e ) = printf "%s%s" (show o) (showUniOpPrec e)
show (BinOp o a b) = printf "%s %s %s" (showBinOpPrec a) (show o) (showBinOpPrec b)
show (Dot e n ) = printf "%s.%s" (show e) n
show (Mux c a b) = printf "(%s ? %s : %s)" (show c) (show a) (show b)
show (Call e l ) = printf "%s%s" (show e) (show l)
@ -175,6 +175,15 @@ readNumber n =
'\'' : 'd' : rest -> rest
_ -> n
showUniOpPrec :: Expr -> String
showUniOpPrec (e @ UniOp{}) = printf "(%s)" (show e)
showUniOpPrec (e @ BinOp{}) = printf "(%s)" (show e)
showUniOpPrec e = show e
showBinOpPrec :: Expr -> String
showBinOpPrec (e @ BinOp{}) = printf "(%s)" (show e)
showBinOpPrec e = show e
-- basic expression simplfication utility to help us generate nicer code in the
-- common case of ranges like `[FOO-1:0]`
simplify :: Expr -> Expr

5
test/basic/uniop_prec.sv Normal file
View File

@ -0,0 +1,5 @@
module Example(a, b);
input logic [1:0] a;
output logic b;
assign b = !(&a);
endmodule

5
test/basic/uniop_prec.v Normal file
View File

@ -0,0 +1,5 @@
module Example(a, b);
input wire [1:0] a;
output wire b;
assign b = !(&a);
endmodule

View File

@ -0,0 +1,12 @@
module top;
reg [1:0] a;
wire b;
Example example(a, b);
initial begin
$monitor("%2d %b %b", $time, a, b);
#1;
#1; a[0] = 1;
#1; a[1] = 1;
#1; a[0] = 1'sbx;
end
endmodule