Skip to content
Snippets Groups Projects
Commit e2309d39 authored by Elizabeth's avatar Elizabeth
Browse files

Changed replacement to keep the original parameters but add new params

parent e3c0e806
No related branches found
No related tags found
No related merge requests found
......@@ -30,9 +30,6 @@ class KnobConfiguration:
self.modified_func_name = line_as_lst[-1]
self.params = line_as_lst[1:-2]
# Build the new function call
self.new_func_call = "%s(%s)" % (self.modified_func_name, ", ".join(self.params))
def get_new_path(old_path, orig_source_code_dir):
'''
......@@ -48,6 +45,26 @@ def get_new_path(old_path, orig_source_code_dir):
return os.path.join("..", orig_source_code_dir, old_path)
# "complete_line" = a valid line of code
def replace_function_calls(complete_line, knob_config):
orig_func_ind = complete_line.find(knob_config.orig_func_name)
new_line = []
line_start_ind = 0
last_ind = 0
while orig_func_ind != -1:
new_line.append(complete_line[line_start_ind : orig_func_ind])
line_start_ind = complete_line.find(")", orig_func_ind) + 1
old_func_call = complete_line[complete_line.find("(", orig_func_ind): line_start_ind]
new_line.append(knob_config.modified_func_name + old_func_call[:-1] + ", " \
+ ', '.join(knob_config.params) + ")")
orig_func_ind = complete_line.find(knob_config.orig_func_name, line_start_ind)
new_line.append(complete_line[line_start_ind : ])
#print(new_line)
return ''.join(new_line)
def generate_source_code(table, dir_name, filename, source_name):
'''
Generates source code for all configurations in the table for one original source
......@@ -65,7 +82,7 @@ def generate_source_code(table, dir_name, filename, source_name):
for knob_config in table:
source_file.seek(0, 0)
new_file_contents = [file_comment % (knob_config.orig_func_name, knob_config.new_func_call)]
new_file_contents = [file_comment % (knob_config.orig_func_name, knob_config.modified_func_name)]
# Store complete line to handle cases where one line of code is split into two lines
complete_line = ""
......@@ -93,20 +110,7 @@ def generate_source_code(table, dir_name, filename, source_name):
complete_line += line
orig_func_ind = complete_line.find(knob_config.orig_func_name)
if orig_func_ind != -1:
# Replace from an instance of origOp to first instance of ) after origOp
# with the new function call
new_line = []
line_start_ind = 0
last_ind = 0
while orig_func_ind != -1:
new_line.append(complete_line[line_start_ind : orig_func_ind])
new_line.append(knob_config.new_func_call)
line_start_ind = complete_line.find(")", orig_func_ind) + 1
orig_func_ind = complete_line.find(knob_config.orig_func_name, line_start_ind)
new_line.append(complete_line[line_start_ind : ])
new_file_contents.append(''.join(new_line))
new_file_contents.append(replace_function_calls(complete_line, knob_config))
else:
new_file_contents.append(complete_line)
complete_line = ""
......@@ -115,8 +119,7 @@ def generate_source_code(table, dir_name, filename, source_name):
new_file = open(new_filename, "w")
new_file.write(''.join(new_file_contents))
new_file.close()
print("Generated source code for configuration %s as %s" \
% (knob_config.new_func_call, new_filename))
print("Generated source code as %s" % new_filename)
source_file.close()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment