Skip to content

[BUG] IndexError: tuple index out of range #2333

@17Reset

Description

@17Reset

Nested functions caused a crash due to confusion

D:\Downloads\TMP>pyarmor gen --recursive --enable-bcc  --obf-code 2 --output dist xqt_xcodegen_sv.py
INFO     Python 3.14.4
INFO     Pyarmor 9.2.4 (group), 006040, non-profits
INFO     Platform windows.x86_64
INFO     search inputs ...
INFO     find script xqt_xcodegen_sv.py
INFO     find 1 top resources
INFO     start to generate runtime files
INFO     target platforms {'windows.amd64'}
INFO     write dist\pyarmor_runtime_006040\pyarmor_runtime.pyd
INFO     generate runtime files OK
INFO     start to obfuscate scripts
INFO     process resource "xqt_xcodegen_sv"
INFO     obfuscating file xqt_xcodegen_sv.py
INFO     start to generate bcc code ...
INFO     generate bcc code successfully
INFO     write dist\xqt_xcodegen_sv.py
INFO     obfuscate scripts OK
D:\Downloads\TMP\dist>python xqt_xcodegen_sv.py
Traceback (most recent call last):
  File "<frozen __main__>", line 3, in <module>
  File "<frozen xqt_xcodegen_sv>", line 92, in <module>
  File "<frozen xqt_xcodegen_sv>", line 2, in xqt_xcodegen_sv
IndexError: tuple index out of range
def xqt_xcodegen_sv(
    module_name: str,
    module_description: str,
    spec_list: list,
    parameter_data: list,
    port_data: list,
    module_coding_template: str,
):
    def _format_parameter_data(data) -> str:
        formatted_lines = []
        for parameter_item in data:
            name = str(parameter_item.get('name', '') or '').strip()
            if not name:
                continue

            item_type = str(
                parameter_item.get('keyword', 'parameter') or 'parameter'
            ).strip()
            value = str(parameter_item.get('value', '') or '').strip()
            value_range = str(parameter_item.get('range', '') or '').strip()
            description = str(parameter_item.get('description', '') or '').strip()

            formatted_lines.append(
                f'- `{name}`\n'
                f'\t- Type: {item_type}\n'
                f'\t- Value: {value}\n'
                f'\t- Range: {value_range}\n'
                f'\t- Description: {description}'
            )

        return '\n'.join(formatted_lines)

    def _format_port_data(data) -> str:
        def _get_port_direction(port_item: dict) -> str:
            direction = str(port_item.get('direction', '') or '').strip().lower()

            return direction

        formatted_lines = []
        for port_item in data:
            name = str(port_item.get('name', '') or '').strip()
            if not name:
                continue

            direction = _get_port_direction(port_item)
            bit_width = str(port_item.get('bit_width', '') or '').strip()
            description = str(port_item.get('description', '') or '').strip()

            formatted_lines.append(
                f'- `{name}`\n'
                f'\t- Direction: {direction}\n'
                f'\t- Bit Width: {bit_width}\n'
                f'\t- Description: {description}'
            )

        return '\n'.join(formatted_lines)

    design_specification = ''
    for spec_line in spec_list:
        design_specification += f'- {spec_line}\n'

    module_port_parameters = _format_parameter_data(parameter_data)

    module_port_signals = _format_port_data(port_data)

    xcodegen_sv_prompt = f"""
***Design Description***
{module_description.rstrip()}

***Design Specification***
{design_specification.rstrip()}

***Module Name***
{module_name.strip()}

***Module Port Parameters***
{module_port_parameters.rstrip()}

***Module Port Signals***
{module_port_signals.rstrip()}

***Top-Module Coding Template***
```SystemVerilog
{module_coding_template}

"""

return xcodegen_sv_prompt

if name == "main":
print(xqt_xcodegen_sv('', '', [], [], [], ''))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions