From: Jacob Lifshay Date: Tue, 25 Jul 2023 01:42:27 +0000 (-0700) Subject: add support for C conditional operator X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a65b3700aa3b181b5881fa55d3946dbc26be3967;p=openpower-isa.git add support for C conditional operator its used by setbc's pseudocode and by the bfp_* functions --- diff --git a/src/openpower/decoder/pseudo/lexer.py b/src/openpower/decoder/pseudo/lexer.py index 339a1980..b454b2ac 100644 --- a/src/openpower/decoder/pseudo/lexer.py +++ b/src/openpower/decoder/pseudo/lexer.py @@ -363,6 +363,7 @@ class PowerLexer: 'WS', 'NEWLINE', 'COMMA', + 'QMARK', 'PERIOD', 'SEMICOLON', 'INDENT', @@ -424,6 +425,7 @@ class PowerLexer: t_BITOR = r'\|' t_BITAND = r'\&' t_BITXOR = r'\^' + t_QMARK = r'\?' # Ply nicely documented how to do this. diff --git a/src/openpower/decoder/pseudo/parser.py b/src/openpower/decoder/pseudo/parser.py index a8ab32cb..a409d86a 100644 --- a/src/openpower/decoder/pseudo/parser.py +++ b/src/openpower/decoder/pseudo/parser.py @@ -820,8 +820,12 @@ class PowerParser: # as I don't support 'and', 'or', and 'not' this works down to 'comparison' def p_test(self, p): - "test : comparison" - p[0] = p[1] + """test : comparison + | comparison QMARK test COLON test""" + if len(p) == 2: + p[0] = p[1] + else: + p[0] = ast.IfExp(test=p[1], body=p[3], orelse=p[5]) # arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] # | '**' test)