From c52d01663899cb651e08d9289d52d21066066f06 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 5 Apr 2020 19:16:18 +0100 Subject: [PATCH] add HEX to parser --- src/soc/decoder/power_pseudo.py | 6 +++++- src/soc/decoder/pseudo/lexer.py | 7 +++++++ src/soc/decoder/pseudo/parser.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/soc/decoder/power_pseudo.py b/src/soc/decoder/power_pseudo.py index a16c77bb..f6d67529 100644 --- a/src/soc/decoder/power_pseudo.py +++ b/src/soc/decoder/power_pseudo.py @@ -177,7 +177,11 @@ switch (n) x <- 9 """ -code = switchtest +hextest = """ +RT <- 0x0001_a000_0000_0000 +""" + +code = hextest #code = lswx #code = testcond #code = testdo diff --git a/src/soc/decoder/pseudo/lexer.py b/src/soc/decoder/pseudo/lexer.py index 2e637365..2518970f 100644 --- a/src/soc/decoder/pseudo/lexer.py +++ b/src/soc/decoder/pseudo/lexer.py @@ -234,6 +234,7 @@ class PowerLexer: 'WHILE', 'BREAK', 'NAME', + 'HEX', # hex numbers 'NUMBER', # Python decimals 'BINARY', # Python binary 'STRING', # single quoted strings only; syntax of raw strings @@ -279,6 +280,12 @@ class PowerLexer: def build(self,**kwargs): self.lexer = lex.lex(module=self, **kwargs) + def t_HEX(self, t): + r"""0x[0-9a-f_]+""" + val = t.value.replace("_", "") + t.value = SelectableInt(int(val, 16), (len(val)-2)*16) + return t + def t_BINARY(self, t): r"""0b[01]+""" t.value = SelectableInt(int(t.value, 2), len(t.value)-2) diff --git a/src/soc/decoder/pseudo/parser.py b/src/soc/decoder/pseudo/parser.py index 70b154e7..d8d0969c 100644 --- a/src/soc/decoder/pseudo/parser.py +++ b/src/soc/decoder/pseudo/parser.py @@ -596,6 +596,7 @@ class PowerParser: def p_atom_number(self, p): """atom : BINARY | NUMBER + | HEX | STRING""" p[0] = ast.Constant(p[1]) -- 2.30.2