[Libre-soc-bugs] [Bug 1197] New: `fallthrough` in parser is incorrect

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Wed Nov 1 22:47:41 GMT 2023


https://bugs.libre-soc.org/show_bug.cgi?id=1197

            Bug ID: 1197
           Summary: `fallthrough` in parser is incorrect
           Product: Libre-SOC's first SoC
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: CONFIRMED
          Severity: major
          Priority: ---
         Component: Source Code
          Assignee: lkcl at lkcl.net
          Reporter: programmerjake at gmail.com
                CC: libre-soc-bugs at lists.libre-soc.org
   NLnet milestone: ---

from reading through all occurrences of `switch` in Power ISA v3.1B (there
aren't many), I think our parser incorrectly implements it:
mtspr:
    switch (n)
      case(129): see(Book_III_p975)
      case(808, 809, 810, 811):
      default:
        stuff-here

our parser converts that to:
    switch (n)
      case(129): see(Book_III_p975)
      case(808, 809, 810, 811): fallthrough
      default:
        stuff-here

which it then interprets (if it successfully detected the fallthrough keyword
instead of trying to call `self.fallthrough()`) as:
    if n == 129:
        see(Book_III_p975)
    elif n in [808, 809, 810, 811] or True:  # True for default
        stuff-here

which is *wrong*. mtspr's description says if n is 808, 809, 810, or 811, then
it *does nothing*, not tries to run the default case. This also matches the
description of how `switch` is supposed to work, which has no falling-through
(so like VB's Select, not like C's switch).

so, in other words, it should be:
    if n == 129:
        see(Book_III_p975)
    elif n in [808, 809, 810, 811]:
        pass  # not fallthrough
    else:
        stuff-here

I propose we remove all `fallthrough` logic completely and change p_switch_case
to make `suite` optional, replacing omitted `suite` with `pass`:
(untested code, but should work)

    def p_switch_case(self, p):
        """switch_case : CASE LPAR atomlist RPAR COLON
                       | CASE LPAR atomlist RPAR COLON suite
        """
        if len(p) == 6:
            suite = [ast.Pass()]
        else:
            suite = p[6]
        p[0] = (p[3], suite)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list