add switch case and default keywords
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Apr 2020 14:32:49 +0000 (15:32 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Sun, 5 Apr 2020 14:32:49 +0000 (15:32 +0100)
src/soc/decoder/pseudo/lexer.py
src/soc/decoder/pseudo/pywriter.py

index bd84e2f1398b519599971ffe5cf7107249b834a3..7c1d642054b5c867620293497d898a9645c48322 100644 (file)
@@ -31,10 +31,13 @@ NO_INDENT = 0
 MAY_INDENT = 1
 MUST_INDENT = 2
 
-# turn into python-like colon syntax from pseudo-code syntax
+# turn into python-like colon syntax from pseudo-code syntax.
+# identify tokens which tell us whether a "hidden colon" is needed.
+# this in turn means that track_tokens_filter "works" without needing
+# complex grammar rules
 def python_colonify(lexer, tokens):
 
-    forwhile_seen = False
+    fake_colon_needed = False
     for token in tokens:
         #print ("track colon token", token, token.type)
 
@@ -47,15 +50,15 @@ def python_colonify(lexer, tokens):
             token = copy(token)
             token.type = "COLON"
             yield token
-        elif token.type in ['DO', 'WHILE', 'FOR']:
-            forwhile_seen = True
+        elif token.type in ['DO', 'WHILE', 'FOR', 'SWITCH', 'CASE', 'DEFAULT']:
+            fake_colon_needed = True
             yield token
         elif token.type == 'NEWLINE':
-            if forwhile_seen:
+            if fake_colon_needed:
                 ctok = copy(token)
                 ctok.type = "COLON"
                 yield ctok
-                forwhile_seen = False
+                fake_colon_needed = False
             yield token
         else:
             yield token
@@ -260,6 +263,9 @@ class PowerLexer:
         'BITAND',
         'BITXOR',
         'RETURN',
+        'SWITCH',
+        'CASE',
+        'DEFAULT',
         'WS',
         'NEWLINE',
         'COMMA',
@@ -328,6 +334,9 @@ class PowerLexer:
       "while": "WHILE",
       "do": "DO",
       "return": "RETURN",
+      "switch": "SWITCH",
+      "case": "CASE",
+      "default": "DEFAULT",
       }
 
     def t_NAME(self, t):
index d8e60686904ba53e9a9bc4f298bb3ad5b730a458..052ee95e481ce5724c10c6d74a886f00c92330eb 100644 (file)
@@ -72,8 +72,9 @@ class PyISAWriter(ISA):
 
 if __name__ == '__main__':
     isa = PyISAWriter()
-    isa.write_pysource('stringldst')
+    isa.write_pysource('system')
     exit(0)
+    isa.write_pysource('stringldst')
     isa.write_pysource('fixedshift')
     isa.write_pysource('condition')
     isa.write_pysource('fixedtrap')