back.rtlil: always output negative values as two's complement.
authorwhitequark <cz@m-labs.hk>
Mon, 24 Dec 2018 01:38:32 +0000 (01:38 +0000)
committerwhitequark <cz@m-labs.hk>
Mon, 24 Dec 2018 01:38:32 +0000 (01:38 +0000)
- is valid in RTLIL but means something entirely different.

nmigen/back/rtlil.py

index 0bd5f08629321702fd7df06261a35abadebc4373..91bd1c1ffed4dce4df9eb46ca0a367b3c68578ee 100644 (file)
@@ -361,7 +361,8 @@ class _RHSValueCompiler(_ValueCompiler):
         if isinstance(value.value, str):
             return "{}'{}".format(value.nbits, value.value)
         else:
-            return "{}'{:0{}b}".format(value.nbits, value.value, value.nbits)
+            value_twos_compl = value.value & ((1 << value.nbits) - 1)
+            return "{}'{:0{}b}".format(value.nbits, value_twos_compl, value.nbits)
 
     def on_Signal(self, value):
         wire_curr, wire_next = self.s.resolve(value)