Commit fa02fdc8 authored by erodrigu's avatar erodrigu
Browse files

Added optional outputs flag

parent ea4bd57e
......@@ -22,18 +22,19 @@ def get_command_line_arguments():
and the name of a routine (-r/--routine) and creates different versions
of this routine accouting for all different precision combinations that can happen.
An additional argument for the vault (-v/--vault) allows to skip the
creation of the vault if this is provided.
creation of the vault if this is provided. Optional output (-o/--output-folder) for creating
the files there, if not given the outputs are printed out.
"""
parser = ArgumentParser(usage=help_text)
parser.add_argument("-v", "--vault", dest="vault", required=False, help="Path to the vault")
parser.add_argument("-o", "--output-folder", dest="output_folder", required=False, help="Path to outputs folder")
parser.add_argument("-s", "--input-source", dest="input_source", required=True,
help="Path to the processed sources")
parser.add_argument("-r", "--routine", dest="routine_name", required=True,
help="Name of the routine to create different interfaces")
args = parser.parse_args()
return args.vault, args.input_source, args.routine_name
return args.vault, args.input_source, args.routine_name, args.output_folder
# Few functions
......@@ -138,13 +139,27 @@ def generate_routine_versions(precision_combinations, sensitive_variables, vault
# Join the routine lines and uodate nane
version_text = "\n".join(routine_lines).strip()
version_text = replace_routine_name(routine.name, new_routine_name, version_text)
code_versions[c_index] = version_text
code_versions[new_routine_name] = version_text
return code_versions
def write_routine_versions(code_versions, output_folder):
if output_folder is None:
# If there's no folder, print the outputs to terminal
for key, code in code_versions.items():
print(code)
else:
# Create folder if it doesn't exists
if not isdir(output_folder):
mkdir(output_folder)
# Create a file for each subroutine interface
for key, code in code_versions.items():
with open(output_folder + key, 'w') as f:
f.write(code)
if __name__ == "__main__":
# Get command line arguments
vault_path, path_to_input_sources, routine_name = get_command_line_arguments()
vault_path, path_to_input_sources, routine_name, output_folder = get_command_line_arguments()
# Get the vault
vault = prepare_vault(vault_path)
# Get routine from vault
......@@ -159,5 +174,4 @@ if __name__ == "__main__":
# Generate the different routine versions
code_versions = generate_routine_versions(precision_combinations, sensitive_variables, vault, routine_code.split("\n"), routine, filepath, indices)
for key, code in code_versions.items():
print(code)
write_routine_versions(code_versions, output_folder)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment