openpower.decoder.pseudo package

Submodules

openpower.decoder.pseudo.lexer module

openpower.decoder.pseudo.lexer.DEDENT(lineno)
openpower.decoder.pseudo.lexer.INDENT(lineno)
class openpower.decoder.pseudo.lexer.IndentLexer(debug=0, optimize=0, lextab='lextab', reflags=0)

Bases: openpower.decoder.pseudo.lexer.PowerLexer

input(s, add_endmarker=True)
token()
class openpower.decoder.pseudo.lexer.PowerLexer

Bases: object

RESERVED = {'case': 'CASE', 'def': 'DEF', 'default': 'DEFAULT', 'do': 'DO', 'else': 'ELSE', 'for': 'FOR', 'if': 'IF', 'leave': 'BREAK', 'return': 'RETURN', 'switch': 'SWITCH', 'then': 'THEN', 'to': 'TO', 'while': 'WHILE'}
build(**kwargs)
t_APPEND = '\\|\\|'
t_ASSIGN = '<-'
t_ASSIGNEA = '<-iea'
t_BINARY(t)

0b[01]+

t_BITAND = '\\&'
t_BITOR = '\\|'
t_BITXOR = '\\^'
t_COLON = ':'
t_COMMA = ','
t_DIV = '/'
t_EQ = '='
t_GE = '>='
t_GT = '>'
t_GTU = '>u'
t_HEX(t)

0x[0-9a-fA-F_]+

t_INVERT = '¬'
t_LBRACK(t)

[

t_LE = '<='
t_LPAR(t)

(

t_LT = '<'
t_LTU = '<u'
t_MINUS = '-'
t_MOD = '%'
t_MULT = '\\*'
t_NAME(t)

[a-zA-Z_][a-zA-Z0-9_]*

t_NE = '!='
t_NUMBER(t)

(d+(.d*)?|.d+)([eE][-+]? d+)?

t_PLUS = '\\+'
t_RBRACK(t)

]

t_RPAR(t)

)

t_SEMICOLON = ';'
t_STRING(t)

‘([^']+|'|\)*’

t_WS(t)

[ ]+

t_comment(t)

[ ]*043[^n]*

t_error(t)
t_newline(t)

n+

tokens = ('DEF', 'IF', 'THEN', 'ELSE', 'FOR', 'TO', 'DO', 'WHILE', 'BREAK', 'NAME', 'HEX', 'NUMBER', 'BINARY', 'STRING', 'LPAR', 'RPAR', 'LBRACK', 'RBRACK', 'COLON', 'EQ', 'ASSIGNEA', 'ASSIGN', 'LTU', 'GTU', 'NE', 'LE', 'GE', 'LT', 'GT', 'PLUS', 'MINUS', 'MULT', 'DIV', 'MOD', 'INVERT', 'APPEND', 'BITOR', 'BITAND', 'BITXOR', 'RETURN', 'SWITCH', 'CASE', 'DEFAULT', 'WS', 'NEWLINE', 'COMMA', 'SEMICOLON', 'INDENT', 'DEDENT', 'ENDMARKER')
openpower.decoder.pseudo.lexer.annoying_case_hack_filter(code)

add annoying “silent keyword” (fallthrough)

this which tricks the parser into taking the (silent) case statement as a “small expression”. it can then be spotted and used to indicate “fall through” to the next case (in the parser)

also skips blank lines

bugs: any function that starts with the letters “case” or “default” will be detected erroneously. fixing that involves doing a token lexer which spots the fact that “case” and “default” are words, separating them from space, colon, bracket etc.

http://bugs.libre-riscv.org/show_bug.cgi?id=280

openpower.decoder.pseudo.lexer.count_spaces(l)
openpower.decoder.pseudo.lexer.filter(lexer, add_endmarker=True)
openpower.decoder.pseudo.lexer.indentation_filter(tokens)
openpower.decoder.pseudo.lexer.python_colonify(lexer, tokens)
openpower.decoder.pseudo.lexer.track_tokens_filter(lexer, tokens)

openpower.decoder.pseudo.pagereader module

OpenPOWER ISA page parser

returns an OrderedDict of namedtuple “Ops” containing details of all instructions listed in markdown files.

format must be strictly as follows (no optional sections) including whitespace:

# Compare Logical

X-Form

  • cmpl BF,L,RA,RB

    if L = 0 then a <- [0]*32 || (RA)[32:63]

    b <- [0]*32 || (RB)[32:63]

    else a <- (RA)

    b <- (RB)

    if a <u b then c <- 0b100 else if a >u b then c <- 0b010 else c <- 0b001 CR[4*BF+32:4*BF+35] <- c || XER[SO]

Special Registers Altered:

CR field BF Another field

this translates to:

# heading blank Some-Form blank * instruction registerlist * instruction registerlist blank 4-space-indented pseudo-code 4-space-indented pseudo-code blank Special Registers Altered: 4-space-indented register description blank blank(s) (optional for convenience at end-of-page)
class openpower.decoder.pseudo.pagereader.ISA

Bases: object

add_op(o, d)
pprint_ops()
read_file(fname)
read_file_for_rewrite(fname)
class openpower.decoder.pseudo.pagereader.Ops(desc, form, opcode, regs, pcode, sregs, page)

Bases: tuple

desc

Alias for field number 0

form

Alias for field number 1

opcode

Alias for field number 2

page

Alias for field number 6

pcode

Alias for field number 4

regs

Alias for field number 3

sregs

Alias for field number 5

openpower.decoder.pseudo.pagereader.get_isa_dir()

openpower.decoder.pseudo.parser module

openpower.decoder.pseudo.parser.Assign(autoassign, assignname, left, right, iea_mode)
class openpower.decoder.pseudo.parser.GardenSnakeCompiler(debug=False, form=None, incl_carry=False)

Bases: object

compile(code, mode='exec', filename='<string>')
class openpower.decoder.pseudo.parser.GardenSnakeParser(lexer=None, debug=False, form=None, incl_carry=False)

Bases: openpower.decoder.pseudo.parser.PowerParser

parse(code)
class openpower.decoder.pseudo.parser.PowerParser(form, include_carry_in_write=False)

Bases: object

p_arglist(p)

arglist : arglist COMMA argument | argument

p_argument(p)

argument : test

p_atom_listmaker(p)

atom : LBRACK listmaker RBRACK

p_atom_name(p)

atom : NAME

p_atom_number(p)

atom : BINARY | NUMBER | HEX | STRING

p_atom_tuple(p)

atom : LPAR testlist RPAR

p_atomlist(p)

atomlist : atom COMMA atomlist | atom

p_break_stmt(p)

break_stmt : BREAK

p_comparison(p)

comparison : comparison PLUS comparison | comparison MINUS comparison | comparison MULT comparison | comparison DIV comparison | comparison MOD comparison | comparison EQ comparison | comparison NE comparison | comparison LE comparison | comparison GE comparison | comparison LTU comparison | comparison GTU comparison | comparison LT comparison | comparison GT comparison | comparison BITOR comparison | comparison BITXOR comparison | comparison BITAND comparison | PLUS comparison | comparison MINUS | INVERT comparison | comparison APPEND comparison | power

p_compound_stmt(p)

compound_stmt : if_stmt | while_stmt | switch_stmt | for_stmt | funcdef

p_error(p)
p_expr_stmt(p)

expr_stmt : testlist ASSIGNEA testlist | testlist ASSIGN testlist | testlist

p_file_input(p)

file_input : file_input NEWLINE | file_input stmt | NEWLINE | stmt

p_file_input_end(p)

file_input_end : file_input ENDMARKER

p_flow_stmt(p)

flow_stmt : return_stmt

p_for_stmt(p)

for_stmt : FOR atom EQ test TO test COLON suite | DO atom EQ test TO test COLON suite

p_funcdef(p)

funcdef : DEF NAME parameters COLON suite

p_if_stmt(p)

if_stmt : IF test COLON suite ELSE COLON if_stmt | IF test COLON suite ELSE COLON suite | IF test COLON suite

p_listmaker(p)

listmaker : test COMMA listmaker | test

p_parameters(p)

parameters : LPAR RPAR | LPAR varargslist RPAR

p_power(p)

power : atom | atom trailerlist

p_return_stmt(p)

return_stmt : RETURN testlist

p_simple_stmt(p)

simple_stmt : small_stmts NEWLINE | small_stmts SEMICOLON NEWLINE

p_small_stmt(p)

small_stmt : flow_stmt | break_stmt | expr_stmt

p_small_stmts(p)

small_stmts : small_stmts SEMICOLON small_stmt | small_stmt

p_stmt_compound(p)

stmt : compound_stmt

p_stmt_simple(p)

stmt : simple_stmt

p_stmts(p)

stmts : stmts stmt | stmt

p_subscript(p)

subscript : test COLON test | test

p_suite(p)

suite : simple_stmt | NEWLINE INDENT stmts DEDENT

p_switch_case(p)

switch_case : CASE LPAR atomlist RPAR COLON suite

p_switch_default(p)

switch_default : DEFAULT COLON suite

p_switch_list(p)

switch_list : switch_case switch_list | switch_case

p_switch_smt(p)

switch_stmt : SWITCH LPAR atom RPAR COLON NEWLINE INDENT switches DEDENT

p_switches(p)

switches : switch_list switch_default | switch_default

p_test(p)

test : comparison

p_testlist(p)

testlist : testlist_multi COMMA | testlist_multi

p_testlist_multi(p)

testlist_multi : testlist_multi COMMA test | test

p_trailer(p)

trailer : trailer_arglist | trailer_subscript

p_trailer_arglist(p)

trailer_arglist : LPAR arglist RPAR

p_trailer_subscript(p)

trailer_subscript : LBRACK subscript RBRACK

p_trailerlist(p)

trailerlist : trailer trailerlist | trailer

p_varargslist(p)

varargslist : varargslist COMMA NAME | NAME

p_while_stmt(p)

while_stmt : DO WHILE test COLON suite ELSE COLON suite | DO WHILE test COLON suite

precedence = (('left', 'EQ', 'NE', 'GT', 'LT', 'LE', 'GE', 'LTU', 'GTU'), ('left', 'BITOR'), ('left', 'BITXOR'), ('left', 'BITAND'), ('left', 'PLUS', 'MINUS'), ('left', 'MULT', 'DIV', 'MOD'), ('left', 'INVERT'))
openpower.decoder.pseudo.parser.apply_trailer(atom, trailer)
openpower.decoder.pseudo.parser.check_concat(node)
openpower.decoder.pseudo.parser.identify_sint_mul_pattern(p)
openpower.decoder.pseudo.parser.make_eq_compare(arg)
openpower.decoder.pseudo.parser.make_ge_compare(arg)
openpower.decoder.pseudo.parser.make_gt_compare(arg)
openpower.decoder.pseudo.parser.make_le_compare(arg)
openpower.decoder.pseudo.parser.make_lt_compare(arg)
openpower.decoder.pseudo.parser.make_ne_compare(arg)

openpower.decoder.pseudo.parsetab module

openpower.decoder.pseudo.pywriter module

class openpower.decoder.pseudo.pywriter.PyISAWriter

Bases: openpower.decoder.pseudo.pagereader.ISA

patch_if_needed(source)
write_isa_class()
write_pysource(pagename)
openpower.decoder.pseudo.pywriter.get_isasrc_dir()
openpower.decoder.pseudo.pywriter.pywriter()

Module contents