Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lang/llvmir/parser: Factor out get_implicit_name(), use for implicit … #126

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions ppci/lang/llvmir/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ def __init__(self, context):
self.context = context
self._pfs = None
self.module = None
self.numbered_vals = []
# Counter to form implicit names.
self.numbered_val = 0

# LLVM IR has a habbit of using implicit names in various places, from
# function params to block labels. In this case, a "numbered name" is
# used.
def get_implicit_name(self):
name = "%{}".format(self.numbered_val)
self.numbered_val += 1
return name

def parse_module(self):
""" Parse a module """
Expand Down Expand Up @@ -118,10 +127,8 @@ def parse_function_header(self):
if arg_info.name:
argument.set_name(arg_info.name)
else:
# The parameter had no name, so number it?
name = "%{}".format(len(self.numbered_vals))
name = self.get_implicit_name()
argument.set_name(name)
self.numbered_vals.append((name, argument))
return function

def parse_target_definition(self):
Expand Down Expand Up @@ -238,7 +245,7 @@ def parse_basic_block(self):
if self.peek == "LBL":
label = self.consume("LBL").val
else:
label = None
label = self.get_implicit_name()
bb = self._pfs.define_bb(label)

# Parse instructions until terminator
Expand Down