Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migen/fhdl/tracer.py: update get_var_name() from amaranth #283

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

maribu
Copy link

@maribu maribu commented Jan 11, 2024

This fixes exceptions when running the litedram tests. See below for the log of one of the test failures this fixes. The other test failures are pretty much identical.

______________________________________________________________________________________________________ TestSimSerializers.test_sim_serializer_16_phase90 ______________________________________________________________________________________________________

self = <test.test_phy_utils.TestSimSerializers testMethod=test_sim_serializer_16_phase90>

    def test(self):
        new = default.copy()
        new.update(kwargs)
>       self.serializer_test(**new)

test/test_phy_utils.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test/test_phy_utils.py:54: in serializer_test
    dut = Serializer(clk=clk, clkdiv=clkdiv, i_dw=data_width, o_dw=1)
litedram/phy/utils.py:240: in __init__
    if i is None: i = Signal(i_dw)
/usr/lib/python3.11/site-packages/migen/fhdl/structure.py:395: in __init__
    self.backtrace = _tracer.trace_back(name)
/usr/lib/python3.11/site-packages/migen/fhdl/tracer.py:111: in trace_back
    varname = get_var_name(frame)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

frame = <frame at 0x7f1d84062b90, file '/home/maribu/Repos/software/aports/testing/py3-litex/src/litedram-2023.12/litedram/phy/utils.py', line 240, code __init__>

    def get_var_name(frame):
        code = frame.f_code
        call_index = frame.f_lasti
        while call_index > 0 and opname[code.co_code[call_index]] == "CACHE":
            call_index -= 2
        while True:
            call_opc = opname[code.co_code[call_index]]
            if call_opc in("EXTENDED_ARG",):
                call_index += 2
            else:
                break
        if call_opc not in _call_opcodes:
            return None
        index = call_index+_call_opcodes[call_opc]
        while True:
            opc = opname[code.co_code[index]]
            if opc == "STORE_NAME" or opc == "STORE_ATTR":
                name_index = int(code.co_code[index+1])
                return code.co_names[name_index]
            elif opc == "STORE_FAST":
                name_index = int(code.co_code[index+1])
                return code.co_varnames[name_index]
            elif opc == "STORE_DEREF":
                name_index = int(code.co_code[index+1])
                if version_info >= (3, 11):
                    name_index -= code.co_nlocals
>               return code.co_cellvars[name_index]
E               IndexError: tuple index out of range

/usr/lib/python3.11/site-packages/migen/fhdl/tracer.py:64: IndexError

This fixes exceptions when running the litedram tests. See below for the
log of one of the test failures this fixes. The other test failures
are pretty much identical.

```
______________________________________________________________________________________________________ TestSimSerializers.test_sim_serializer_16_phase90 ______________________________________________________________________________________________________

self = <test.test_phy_utils.TestSimSerializers testMethod=test_sim_serializer_16_phase90>

    def test(self):
        new = default.copy()
        new.update(kwargs)
>       self.serializer_test(**new)

test/test_phy_utils.py:106:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
test/test_phy_utils.py:54: in serializer_test
    dut = Serializer(clk=clk, clkdiv=clkdiv, i_dw=data_width, o_dw=1)
litedram/phy/utils.py:240: in __init__
    if i is None: i = Signal(i_dw)
/usr/lib/python3.11/site-packages/migen/fhdl/structure.py:395: in __init__
    self.backtrace = _tracer.trace_back(name)
/usr/lib/python3.11/site-packages/migen/fhdl/tracer.py:111: in trace_back
    varname = get_var_name(frame)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

frame = <frame at 0x7f1d84062b90, file '/home/maribu/Repos/software/aports/testing/py3-litex/src/litedram-2023.12/litedram/phy/utils.py', line 240, code __init__>

    def get_var_name(frame):
        code = frame.f_code
        call_index = frame.f_lasti
        while call_index > 0 and opname[code.co_code[call_index]] == "CACHE":
            call_index -= 2
        while True:
            call_opc = opname[code.co_code[call_index]]
            if call_opc in("EXTENDED_ARG",):
                call_index += 2
            else:
                break
        if call_opc not in _call_opcodes:
            return None
        index = call_index+_call_opcodes[call_opc]
        while True:
            opc = opname[code.co_code[index]]
            if opc == "STORE_NAME" or opc == "STORE_ATTR":
                name_index = int(code.co_code[index+1])
                return code.co_names[name_index]
            elif opc == "STORE_FAST":
                name_index = int(code.co_code[index+1])
                return code.co_varnames[name_index]
            elif opc == "STORE_DEREF":
                name_index = int(code.co_code[index+1])
                if version_info >= (3, 11):
                    name_index -= code.co_nlocals
>               return code.co_cellvars[name_index]
E               IndexError: tuple index out of range

/usr/lib/python3.11/site-packages/migen/fhdl/tracer.py:64: IndexError
```
algitbot pushed a commit to alpinelinux/aports that referenced this pull request Jan 18, 2024
This fixes unit test failures in py3-litedram, which builds upon
py3-migen.

See m-labs/migen#283 for an effort to upstream
the patch and the log of the error this fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant