File tree Expand file tree Collapse file tree 1 file changed +28
-12
lines changed
netlist-to-vhdl/Language/Netlist Expand file tree Collapse file tree 1 file changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -165,19 +165,35 @@ stmt (Case d ps def) =
165
165
nest 2 (stmt s)
166
166
167
167
168
+ to_bits :: Integral a => Int -> a -> [Bit ]
169
+ to_bits size val = map (\ x -> if odd x then T else F )
170
+ $ reverse
171
+ $ take size
172
+ $ map (`mod` 2 )
173
+ $ iterate (`div` 2 )
174
+ $ val
175
+
176
+ bit_char :: Bit -> Char
177
+ bit_char T = ' 1'
178
+ bit_char F = ' 0'
179
+ bit_char U = ' U' -- 'U' means uninitialized,
180
+ -- 'X' means forced to unknown.
181
+ -- not completely sure that 'U' is the right choice here.
182
+ bit_char Z = ' Z'
183
+
184
+ bits :: [Bit ] -> Doc
185
+ bits = doubleQuotes . text . map bit_char
186
+
187
+ expr_lit :: Maybe Size -> ExprLit -> Doc
188
+ expr_lit Nothing (ExprNum i) = int $ fromIntegral i
189
+ expr_lit (Just sz) (ExprNum i) = bits (to_bits sz i)
190
+ expr_lit _ (ExprBit x) = quotes (char (bit_char x))
191
+ -- ok to ignore the size here?
192
+ expr_lit Nothing (ExprBitVector xs) = bits xs
193
+ expr_lit (Just sz) (ExprBitVector xs) = bits $ take sz xs
194
+
168
195
expr :: Expr -> Doc
169
- expr (ExprNum i) = int $ fromIntegral i
170
- expr (ExprBit x) = quotes (int x)
171
- -- expr (ExprLit 1 val) = quotes (integer val) -- AJG: 1 element arrays are still arrays.
172
- expr (ExprLit size val) = doubleQuotes
173
- $ text
174
- $ map (\ x -> if x then ' 1' else ' 0' )
175
- $ map odd
176
- $ reverse
177
- $ take size
178
- $ map (`mod` 2 )
179
- $ iterate (`div` 2 )
180
- $ val
196
+ expr (ExprLit mb_sz lit) = expr_lit mb_sz lit
181
197
expr (ExprVar n) = text n
182
198
expr (ExprIndex s i) = text s <> parens (expr i)
183
199
expr (ExprSlice s h l)
You can’t perform that action at this time.
0 commit comments