Be more precise about operands in AST.

This commit is contained in:
cfreksen 2017-10-29 14:20:12 +01:00
parent 8128f72264
commit 1ffe310f97
No known key found for this signature in database
GPG Key ID: EAC13EE101008978
2 changed files with 20 additions and 7 deletions

5
ll.py
View File

@ -49,3 +49,8 @@ Ptrtoint = namedtuple('Ptrtoint', ['pointer_ty', 'oper', 'to_ty'])
Ret = namedtuple('Ret', ['ty', 'oper']) Ret = namedtuple('Ret', ['ty', 'oper'])
Br = namedtuple('Br', ['label']) Br = namedtuple('Br', ['label'])
Cbr = namedtuple('Cbr', ['ty', 'oper', 'then_label', 'else_label']) Cbr = namedtuple('Cbr', ['ty', 'oper', 'then_label', 'else_label'])
Null = namedtuple('Null', [])
Const = namedtuple('Const', ['val'])
Gid = namedtuple('Gid', ['val'])
Id = namedtuple('Id', ['val'])

View File

@ -439,13 +439,21 @@ class LLVMParser(object):
'terminator : BR ty operand COMMA LABEL PercentID COMMA LABEL PercentID' 'terminator : BR ty operand COMMA LABEL PercentID COMMA LABEL PercentID'
p[0] = ll.Cbr(p[2], p[3], p[6], p[9]) p[0] = ll.Cbr(p[2], p[3], p[6], p[9])
def p_operand(self, p): def p_operand_null(self, p):
'''operand : NULL 'operand : NULL'
| INT p[0] = ll.Null
| AtID
| PercentID''' def p_operand_const(self, p):
# TODO: distinguish ids 'operand : INT'
p[0] = p[1] p[0] = ll.Const(p[1])
def p_operand_gid(self, p):
'operand : AtID'
p[0] = ll.Gid(p[1])
def p_operand_id(self, p):
'operand : PercentID'
p[0] = ll.Id(p[1])
def p_named_block_list_single(self, p): def p_named_block_list_single(self, p):
'named_block_list : ID COLON block' 'named_block_list : ID COLON block'