simplify imports, migen.fhdl.std -> migen

This commit is contained in:
Sebastien Bourdeauducq 2015-09-12 19:34:07 +08:00
parent b43495aab1
commit 336728413a
52 changed files with 134 additions and 102 deletions

View File

@ -47,7 +47,7 @@ http://m-labs.hk/gateware.html
#### Quick intro
```python
from migen.fhdl.std import *
from migen import *
from migen.build.platforms import m1
plat = m1.Platform()
led = plat.request("user_led")

View File

@ -8,7 +8,7 @@ FHDL differs from MyHDL [myhdl]_ in fundamental ways. MyHDL follows the event-dr
.. [myhdl] http://www.myhdl.org
FHDL is made of several elements, which are briefly explained below. They all can be imported from the ``migen.fhdl.std`` module.
FHDL is made of several elements, which are briefly explained below. They all can be imported directly from the ``migen`` module.
Expressions
***********

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
@ -24,4 +24,5 @@ class Example(Module):
outa = Array(Signal() for a in range(dy))
self.specials += Instance("test", o_O=outa[y], i_I=ina[x])
print(verilog.convert(Example()))
if __name__ == "__main__":
print(verilog.convert(Example()))

View File

@ -1,7 +1,5 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
from migen.genlib.fsm import FSM, NextState, NextValue
class Example(Module):
def __init__(self):
@ -26,5 +24,6 @@ class Example(Module):
self.bl = myfsm.before_leaving("FOO")
self.al = myfsm.after_leaving("FOO")
example = Example()
print(verilog.convert(example, {example.s, example.counter, example.be, example.ae, example.bl, example.al}))
if __name__ == "__main__":
example = Example()
print(verilog.convert(example, {example.s, example.counter, example.be, example.ae, example.bl, example.al}))

View File

@ -1,8 +1,7 @@
from random import Random
from migen.fhdl.std import *
from migen import *
from migen.genlib.cdc import GrayCounter
from migen.sim import Simulator
def tb(dut):

View File

@ -1,7 +1,6 @@
import subprocess
from migen.fhdl.std import *
from migen.fhdl.specials import Instance
from migen import *
from migen.fhdl.verilog import convert

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
from migen.genlib.divider import Divider
@ -14,5 +14,6 @@ class MultiMod(Module):
self.submodules.foo = CDM()
self.submodules.bar = CDM()
mm = MultiMod()
print(verilog.convert(mm, {mm.foo.cd_sys.clk, mm.bar.cd_sys.clk}))
if __name__ == "__main__":
mm = MultiMod()
print(verilog.convert(mm, {mm.foo.cd_sys.clk, mm.bar.cd_sys.clk}))

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
@ -11,5 +11,7 @@ class Example(Module):
self.ios = {p1.adr, p1.dat_r, p1.we, p1.dat_w,
p2.adr, p2.dat_r, p2.re}
example = Example()
print(verilog.convert(example, example.ios))
if __name__ == "__main__":
example = Example()
print(verilog.convert(example, example.ios))

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
from functools import reduce

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl.specials import SynthesisDirective
from migen.fhdl import verilog
from migen.genlib.cdc import *
@ -16,6 +16,8 @@ class XilinxMultiReg:
def lower(dr):
return XilinxMultiRegImpl(dr.i, dr.o, dr.odomain, dr.n)
ps = PulseSynchronizer("from", "to")
v = verilog.convert(ps, {ps.i, ps.o}, special_overrides={MultiReg: XilinxMultiReg})
print(v)
if __name__ == "__main__":
ps = PulseSynchronizer("from", "to")
v = verilog.convert(ps, {ps.i, ps.o}, special_overrides={MultiReg: XilinxMultiReg})
print(v)

View File

@ -1,6 +1,6 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
from migen.genlib.record import *
L = [
("position", [
@ -19,6 +19,8 @@ class Test(Module):
slave = Record(L)
self.comb += master.connect(slave)
print(verilog.convert(Test()))
print(layout_len(L))
print(layout_partial(L, "position/x", "color"))
if __name__ == "__main__":
print(verilog.convert(Test()))
print(layout_len(L))
print(layout_partial(L, "position/x", "color"))

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
@ -14,4 +14,6 @@ class Example(Module):
self.comb += s3.eq(0)
self.comb += d.eq(Cat(d[::-1], Cat(s1[:1], s3[-4:])[:3]))
print(verilog.convert(Example()))
if __name__ == "__main__":
print(verilog.convert(Example()))

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
@ -8,5 +8,6 @@ class Example(Module):
self.t = TSTriple(n)
self.specials += self.t.get_tristate(self.pad)
e = Example()
print(verilog.convert(e, ios={e.pad, e.t.o, e.t.oe, e.t.i}))
if __name__ == "__main__":
e = Example()
print(verilog.convert(e, ios={e.pad, e.t.o, e.t.oe, e.t.i}))

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
from migen.genlib import divider
@ -14,5 +14,6 @@ class Example(Module):
d1.ready_o, d1.quotient_o, d1.remainder_o, d1.start_i, d1.dividend_i, d1.divisor_i,
d2.ready_o, d2.quotient_o, d2.remainder_o, d2.start_i, d2.dividend_i, d2.divisor_i}
example = Example(16)
print(verilog.convert(example, example.ios | {example.ce, example.reset}))
if __name__ == "__main__":
example = Example(16)
print(verilog.convert(example, example.ios | {example.ce, example.reset}))

View File

@ -1,5 +1,4 @@
from migen.fhdl.std import *
from migen.sim import Simulator
from migen import *
# Our simple counter, which increments at every cycle.

View File

@ -1,5 +1,4 @@
from migen.fhdl.std import *
from migen.sim import Simulator
from migen import *
# A slightly more elaborate counter.

View File

@ -1,13 +1,13 @@
from functools import reduce
from operator import add
from math import cos, pi
from scipy import signal
import matplotlib.pyplot as plt
from migen.fhdl.std import *
from migen import *
from migen.fhdl import verilog
from migen.sim import Simulator
from functools import reduce
from operator import add
# A synthesizable FIR filter.
class FIR(Module):

View File

@ -1,5 +1,4 @@
from migen.fhdl.std import *
from migen.sim.generic import run_simulation
from migen import *
class Mem(Module):

View File

@ -0,0 +1,10 @@
from migen.fhdl.structure import *
from migen.fhdl.module import *
from migen.fhdl.specials import *
from migen.fhdl.bitcontainer import *
from migen.fhdl.decorators import *
from migen.sim import *
from migen.genlib.record import *
from migen.genlib.fsm import *

View File

@ -1,4 +1,5 @@
from migen.fhdl.std import Instance, Module
from migen.fhdl.module import Module
from migen.fhdl.specials import Instance
from migen.genlib.io import DifferentialInput, DifferentialOutput

View File

@ -1,12 +1,11 @@
import os
import sys
from migen.fhdl.std import Signal
from migen.fhdl.structure import Signal
from migen.genlib.record import Record
from migen.genlib.io import CRG
from migen.fhdl import verilog, edif
from migen.util.misc import autotype
from migen.build import tools

View File

@ -1,6 +1,6 @@
from migen.fhdl.std import *
from migen.fhdl.module import Module
from migen.fhdl.specials import Instance
from migen.genlib.io import *
from migen.genlib.resetsync import AsyncResetSynchronizer
@ -36,6 +36,6 @@ class LatticeDDROutput:
return LatticeDDROutputImpl(dr.i1, dr.i2, dr.o, dr.clk)
lattice_special_overrides = {
AsyncResetSynchronizer: LatticeAsyncResetSynchronizer,
DDROutput: LatticeDDROutput
AsyncResetSynchronizer: LatticeAsyncResetSynchronizer,
DDROutput: LatticeDDROutput
}

View File

@ -4,18 +4,14 @@
import os
import subprocess
from migen.fhdl.std import *
from migen.fhdl.structure import _Fragment
from migen.build import tools
from migen.build.generic_platform import *
from migen.build.sim import common
def _build_tb(platform, vns, serial, template):
def io_name(ressource, subsignal=None):
res = platform.lookup_request(ressource)
def io_name(resource, subsignal=None):
res = platform.lookup_request(resource)
if subsignal is not None:
res = getattr(res, subsignal)
return vns.get_name(res)

View File

@ -2,7 +2,9 @@ import os
import sys
from distutils.version import StrictVersion
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.specials import Instance
from migen.fhdl.module import Module
from migen.fhdl.specials import SynthesisDirective
from migen.genlib.cdc import *
from migen.genlib.resetsync import AsyncResetSynchronizer

View File

@ -2,7 +2,6 @@ import os
import subprocess
import sys
from migen.fhdl.std import *
from migen.fhdl.structure import _Fragment
from migen.build.generic_platform import *
from migen.build import tools

View File

@ -5,9 +5,7 @@ import os
import subprocess
import sys
from migen.fhdl.std import *
from migen.fhdl.structure import _Fragment
from migen.build.generic_platform import *
from migen.build import tools
from migen.build.xilinx import common

View File

@ -1,6 +1,9 @@
from migen.fhdl import structure as f
__all__ = ["log2_int", "bits_for", "flen", "fiter", "fslice", "freversed"]
def log2_int(n, need_pow2=True):
l = 1
r = 0

View File

@ -5,6 +5,12 @@ from migen.fhdl.module import Module
from migen.fhdl.tools import insert_reset, rename_clock_domain
__all__ = ["DecorateModule",
"InsertCE", "InsertReset", "RenameClockDomains",
"CEInserter", "ResetInserter", "ClockDomainsRenamer",
"ModuleTransformer"]
class ModuleTransformer:
# overload this in derived classes
def transform_instance(self, i):

View File

@ -1,7 +1,6 @@
from collections import OrderedDict
from collections import namedtuple
from collections import OrderedDict, namedtuple
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.namer import build_namespace
from migen.fhdl.tools import list_special_ios
from migen.fhdl.structure import _Fragment

View File

@ -7,6 +7,9 @@ from migen.fhdl.structure import _Fragment
from migen.fhdl.tools import rename_clock_domain
__all__ = ["Module", "FinalizeError"]
class FinalizeError(Exception):
pass

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.specials import _MemoryPort
from migen.fhdl.decorators import ModuleTransformer
from migen.util.misc import gcd_multiple

View File

@ -7,6 +7,10 @@ from migen.fhdl.tracer import get_obj_var_name
from migen.fhdl.verilog import _printexpr as verilog_printexpr
__all__ = ["TSTriple", "Instance", "Memory",
"READ_FIRST", "WRITE_FIRST", "NO_CHANGE"]
class Special(HUID):
def iter_expressions(self):
for x in []:
@ -171,6 +175,7 @@ class Instance(Special):
r += ");\n\n"
return r
(READ_FIRST, WRITE_FIRST, NO_CHANGE) = range(3)
@ -319,7 +324,7 @@ class Memory(Special):
memory_filename = add_data_file(gn(memory) + ".init", content)
r += "initial begin\n"
r += "$readmemh(\"" + memory_filename + "\", " + gn(memory) + ");\n"
r += "\t$readmemh(\"" + memory_filename + "\", " + gn(memory) + ");\n"
r += "end\n\n"

View File

@ -1,7 +0,0 @@
from migen.fhdl.structure import *
from migen.fhdl.module import Module, FinalizeError
from migen.fhdl.specials import TSTriple, Instance, Memory
from migen.fhdl.bitcontainer import log2_int, bits_for, flen, fiter, fslice, freversed
from migen.fhdl.decorators import DecorateModule, InsertCE, InsertReset, RenameClockDomains
from migen.fhdl.decorators import (CEInserter, ResetInserter,
ClockDomainsRenamer, ModuleTransformer)

View File

@ -1,7 +1,7 @@
from migen.fhdl.std import *
from migen.fhdl.bitcontainer import value_bits_sign
from migen.fhdl.structure import *
from migen.fhdl.module import Module
from migen.fhdl.specials import Special
from migen.fhdl.tools import list_signals
from migen.fhdl.bitcontainer import value_bits_sign
class NoRetiming(Special):

View File

@ -1,9 +1,10 @@
from migen.fhdl.std import *
"""
Encoders and decoders between binary and one-hot representation
"""
from migen.fhdl.structure import *
from migen.fhdl.module import Module
class Encoder(Module):
"""Encode one-hot to binary

View File

@ -1,4 +1,5 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.module import Module
class Divider(Module):

View File

@ -1,4 +1,6 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.module import Module
from migen.fhdl.specials import Memory
from migen.genlib.cdc import NoRetiming, MultiReg, GrayCounter
from migen.genlib.record import layout_len, Record

View File

@ -1,11 +1,14 @@
from collections import OrderedDict
from migen.fhdl.std import *
from migen.fhdl.module import FinalizeError
from migen.fhdl.structure import *
from migen.fhdl.module import Module, FinalizeError
from migen.fhdl.visit import NodeTransformer
from migen.fhdl.bitcontainer import value_bits_sign
__all__ = ["AnonymousState", "NextState", "NextValue", "FSM"]
class AnonymousState:
pass

View File

@ -1,6 +1,6 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.module import Module
from migen.fhdl.specials import Special
from migen.fhdl.tools import list_signals
class DifferentialInput(Special):

View File

@ -1,4 +1,5 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.module import Module
def split(v, *counts):

View File

@ -1,4 +1,4 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.tracer import get_obj_var_name
from functools import reduce

View File

@ -1,6 +1,5 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.specials import Special
from migen.fhdl.tools import list_signals
class AsyncResetSynchronizer(Special):

View File

@ -1,4 +1,6 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.module import Module
(SP_WITHDRAW, SP_CE) = range(2)

View File

@ -1,4 +1,5 @@
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.module import Module
class BitonicSort(Module):

View File

@ -1,11 +1,14 @@
import operator
from collections import defaultdict
from migen.fhdl.std import *
from migen.fhdl.structure import *
from migen.fhdl.structure import _Operator, _Assign, _Fragment
from migen.fhdl.tools import list_inputs
__all__ = ["Simulator"]
class ClockState:
def __init__(self, period, times_before_tick):
self.period = period

View File

@ -1,5 +1,4 @@
from migen.fhdl.std import *
from migen.sim import Simulator
from migen import *
from migen.fhdl import verilog

View File

@ -1,6 +1,6 @@
import unittest
from migen.fhdl.std import *
from migen import *
from migen.genlib.coding import *
from migen.test.support import SimCase, SimBench

View File

@ -1,6 +1,6 @@
import unittest
from migen.fhdl.std import *
from migen import *
from migen.genlib.fifo import SyncFIFO
from migen.test.support import SimCase, SimBench

View File

@ -1,6 +1,6 @@
import unittest
from migen.fhdl.std import *
from migen import *
from migen.test.support import SimCase

View File

@ -1,6 +1,6 @@
import unittest
from migen.fhdl.std import *
from migen import *
def _same_slices(a, b):

View File

@ -1,7 +1,7 @@
import unittest
from random import randrange
from migen.fhdl.std import *
from migen import *
from migen.genlib.sort import *
from migen.test.support import SimCase

View File

@ -2,7 +2,7 @@ import unittest
import subprocess
import os
from migen.fhdl.std import *
from migen import *
from migen.fhdl.verilog import convert