add tools.py from nmigen (imports fixed)