Skip to content

!uc-def:lines - remove usage of file.tell() - this is buggy on windows #43

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

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
28 changes: 22 additions & 6 deletions scripts/uc-def/uc-def
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,19 @@ def verify_access_flags(data):
raise Exception("'%c' flag of flags '%s' not valid" % (i, data))

def next_useful_line(tag, strip_newline=True, strip_comment=True):
if not ('input_lines' in tag):
tag['input_lines'] = tag['input_file'].readlines()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can parse the file in stream style, why would we go for read the whole content to memory file.
file.tell() - this is buggy on windows any pointer on the specific problem?
also, i guess it 1byte ovehead on each line. if we talk of overhead, we should convert the script in C program.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont want spend my time making bugreport and testsuit to python.
short: on my winXP git has checkoput .ucf with linux \n lienends. looks like python string engine converts somehow internaly to windows \r\n lineneds. therefore tell() counts 1 more byte per string. after 20 strings tell() position points after actual string begin about 20bytes.

tag['input_lineno'] = 0;
while True:
tag['last_useful_pos'] = tag['input_file'].tell()
linepos = tag['input_lineno'];
tag['last_useful_pos'] = linepos
tag['last_line_number'] = tag['line_number']
inp = tag['input_file'].readline()
lines = tag['input_lines']
if (linepos < len(lines)):
inp = lines[linepos]
tag['input_lineno'] = linepos + 1
else:
inp = ''

if not len(inp):
break
Expand Down Expand Up @@ -78,7 +87,7 @@ def next_useful_line(tag, strip_newline=True, strip_comment=True):

def restore_last_useful_line(tag):
tag['line_number'] = tag['last_line_number']
tag['input_file'].seek(tag['last_useful_pos'])
tag['input_lineno'] = tag['last_useful_pos']

def get_line_number(tag):
return tag['line_number']
Expand Down Expand Up @@ -597,13 +606,16 @@ def generate_bit(bit, register, family, offset, register_size, output_file):
extra_arg = ", ".join(extra_arg)
extra_arg = "(%s)" % extra_arg

mask_long = ''
if (int(offset) >= 16) or (len(extra_arg) > 0):
mask_long = 'ul'
actual_name = None
for register_name in register['bit_name']:
for bit_name in bit['name']:
if register['bit_name'].index(register_name) == bit['name'].index(bit_name) == 0:
actual_name = "%s_%s_%s" % (family['name'], register_name, bit_name)
output_file.write("#define %s_SHIFT%s (%s%s)\n" % (actual_name, extra_arg, offset, extra_offset))
output_file.write("#define %s%s (1 << %s_SHIFT%s)\n" % (actual_name, extra_arg, actual_name, extra_arg))
output_file.write("#define %s%s (1%s << %s_SHIFT%s)\n" % (actual_name, extra_arg, mask_long, actual_name, extra_arg))
else:
alias_name = "%s_%s_%s" % (family['name'], register_name, bit_name)
output_file.write("/* Alias of %s */\n" % actual_name)
Expand Down Expand Up @@ -644,6 +656,10 @@ def generate_bits(bits, register, family, offset, register_size, output_file):
all_arg = "v, %s" % extra_arg
bracketed_extra_arg = "(%s)" % extra_arg

mask_long = ''
#import ipdb; ipdb.set_trace()
if (int(offset) >= 16) or (len(extra_offset) > 0):
mask_long = 'ul'
actual_name = None
for register_name in register['bits_name']:
for bits_name in bits['name']:
Expand All @@ -652,8 +668,8 @@ def generate_bits(bits, register, family, offset, register_size, output_file):
#print original macro
actual_name = "%s_%s_%s" % (family['name'], register_name, bits_name)
output_file.write("#define %s_SHIFT%s (%s%s)\n" % (actual_name, bracketed_extra_arg, offset, extra_offset))
output_file.write("#define %s_MASK%s (%s << (%s_SHIFT%s))\n" % \
(actual_name, bracketed_extra_arg, mask, actual_name, bracketed_extra_arg))
output_file.write("#define %s_MASK%s (%s%s << (%s_SHIFT%s))\n" % \
(actual_name, bracketed_extra_arg, mask, mask_long, actual_name, bracketed_extra_arg))
output_file.write("#define %s(%s) (((v) << (%s_SHIFT%s)) & (%s_MASK%s))\n" % \
(actual_name, all_arg, actual_name, bracketed_extra_arg, actual_name, bracketed_extra_arg))
output_file.write("#define %s_GET(%s) (((v) & (%s_MASK%s)) >> (%s_SHIFT%s))\n" % \
Expand Down