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

Ignore comments and add error checking. #542

Open
wants to merge 1 commit into
base: main
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
18 changes: 15 additions & 3 deletions scripts/gen_gpio_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,10 @@ def usage():

if os.path.isfile(user_defines_path):
with open(user_defines_path, 'r') as ifile:
infolines = ifile.read().splitlines()
for line in infolines:
raw_data = ifile.read()
comment_pattern = r'//.*|/\*[\s\S]*?\*/'
data_without_comments = re.sub(comment_pattern, '', raw_data)
for line in data_without_comments.splitlines():
tokens = line.split()
if len(tokens) >= 3:
if tokens[0] == '`define':
Expand Down Expand Up @@ -219,14 +221,24 @@ def usage():
print('No configuration specified for GPIO ' + str(i) + '; skipping.')
continue

valid_value = r"^13'h[0-9a-fA-F]{4}$"
value_match = re.match(valid_value, config_value)
if not value_match:
print('Error: Default value ' + config_value + ' is not a 4-digit hex number; skipping')
continue

try:
default_str = config_value[-4:]
binval = '{:013b}'.format(int(default_str, 16))
if len(binval) > 13:
print('Error: Default value ' + config_value + ' is not a 4-digit hex number; skipping')
continue

except:
print('Error: Default value ' + config_value + ' is not a 4-digit hex number; skipping')
continue

cell_name = 'gpio_defaults_block_' + default_str
cell_name = 'gpio_defaults_block_' + default_str.lower()
mag_file = magpath + '/' + cell_name + '.mag'
cellsused[i] = cell_name

Expand Down