From 9bb91d7834d6247d61330da56797db78c6f2b4a4 Mon Sep 17 00:00:00 2001
From: Elizabeth <hashim.sharif91@gmail.com>
Date: Sat, 26 Oct 2019 15:08:08 -0500
Subject: [PATCH] Cleaned up code

---
 .../source_code_autogenerator.py               | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py b/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py
index 8dbdcf3780..0ee30bf36d 100644
--- a/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py
+++ b/llvm/projects/hpvm-tensor-rt/code_autogenerators/source_code_autogenerator.py
@@ -46,7 +46,18 @@ def get_new_path(old_path, orig_source_code_dir):
 
 
 # "complete_line" = a valid line of code  
-def replace_function_calls(complete_line, knob_config):
+def get_new_function_calls(complete_line, knob_config):
+    '''
+    Returns a copy of an inputted line of code such that all instances of old 
+    function calls are replaced with newFunctionCall(old params, knobs)
+
+    Note: The old calls aren't completely overriden, as we still need the old parameters but
+    insert new parameters as well
+
+    Args:
+        complete_line: A complete line of code to process
+        knob_config: KnobConfiguration object representing current configuration 
+    '''
     orig_func_ind = complete_line.find(knob_config.orig_func_name)
     new_line = []
     line_start_ind = 0
@@ -57,8 +68,7 @@ def replace_function_calls(complete_line, knob_config):
         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) + ")")
+        new_line.append("%s%s, %s)" % (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)
@@ -110,7 +120,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:
-				new_file_contents.append(replace_function_calls(complete_line, knob_config))
+				new_file_contents.append(get_new_function_calls(complete_line, knob_config))
             else:
                 new_file_contents.append(complete_line)
             complete_line = ""
-- 
GitLab