compat.fhdl.bitcontainer: import/wrap Migen code.
authorwhitequark <cz@m-labs.hk>
Wed, 12 Dec 2018 14:11:19 +0000 (14:11 +0000)
committerwhitequark <cz@m-labs.hk>
Wed, 12 Dec 2018 15:22:34 +0000 (15:22 +0000)
nmigen/compat/__init__.py [new file with mode: 0644]
nmigen/compat/fhdl/__init__.py [new file with mode: 0644]
nmigen/compat/fhdl/bitcontainer.py [new file with mode: 0644]
nmigen/tools.py

diff --git a/nmigen/compat/__init__.py b/nmigen/compat/__init__.py
new file mode 100644 (file)
index 0000000..47014fa
--- /dev/null
@@ -0,0 +1,11 @@
+# from .fhdl.structure import *
+# from .fhdl.module import *
+# from .fhdl.specials import *
+from .fhdl.bitcontainer import *
+# from .fhdl.decorators import *
+# from .fhdl.simplify import *
+
+# from .sim import *
+
+# from .genlib.record import *
+# from .genlib.fsm import *
diff --git a/nmigen/compat/fhdl/__init__.py b/nmigen/compat/fhdl/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/nmigen/compat/fhdl/bitcontainer.py b/nmigen/compat/fhdl/bitcontainer.py
new file mode 100644 (file)
index 0000000..5b766ed
--- /dev/null
@@ -0,0 +1,21 @@
+from ... import tools
+from ...fhdl import ast
+from ...tools import deprecated
+
+
+__all__ = ["log2_int", "bits_for", "value_bits_sign"]
+
+
+@deprecated("instead of `log2_int`, use `nmigen.tools.log2_int`")
+def log2_int(n, need_pow2=True):
+    return tools.log2_int(n, need_pow2)
+
+
+@deprecated("instead of `bits_for`, use `nmigen.tools.bits_for`")
+def bits_for(n, require_sign_bit=False):
+    return tools.bits_for(n, require_sign_bit)
+
+
+@deprecated("instead of `value_bits_sign(v)`, use `v.bits_sign()`")
+def value_bits_sign(v):
+    return ast.Value.wrap(v).bits_sign()
index 4df7958ca790608dd813ec85c954035a779d9c1a..3a2b96871fe6c3f0adbca19e904c1cc4d499ae00 100644 (file)
@@ -1,7 +1,9 @@
 from collections import Iterable
+import functools
+import warnings
 
 
-__all__ = ["flatten", "union", "log2_int", "bits_for"]
+__all__ = ["flatten", "union", "log2_int", "bits_for", "deprecated"]
 
 
 def flatten(i):
@@ -40,3 +42,13 @@ def bits_for(n, require_sign_bit=False):
     if require_sign_bit:
         r += 1
     return r
+
+
+def deprecated(message):
+    def decorator(f):
+        @functools.wraps(f)
+        def wrapper(*args, **kwargs):
+            warnings.warn(message, DeprecationWarning, stacklevel=2)
+            return f(*args, **kwargs)
+        return wrapper
+    return decorator