diff --git a/documents/references.md b/documents/references.md index 88477c44228c8d2476ee234c0717a363ea46449c..31804cffbbe9859d905787c7bd907a9044e6e92c 100644 --- a/documents/references.md +++ b/documents/references.md @@ -4,17 +4,18 @@ All references to external logic. Includes anything from stack overflow links to notes about logic from previous works. -## C -### All Printf Format Types -<https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm> +## Python +### Parsing Command Line Args with ArgParse +<https://docs.python.org/3/library/argparse.html> + ## Makefile * Purpose of ".PHONY" - <https://stackoverflow.com/a/2145605> * Have one command execute another - <https://stackoverflow.com/a/48552668> * Surpress output messages - <https://stackoverflow.com/a/3148530> -## Bash +## Bash ### Getting Last Argument <https://www.cyberciti.biz/faq/linux-unix-bsd-apple-osx-bash-get-last-argument/> diff --git a/main.py b/main.py index 0f8ff2b58844a2507b6030032cb34337c693e335..14eb0de39bf0eeb518be08492d51b1b50ca69d5e 100644 --- a/main.py +++ b/main.py @@ -14,20 +14,36 @@ Cache Settings Arguments: """ # System Imports. +import argparse # User Imports. -def main(): +def main(set_count, line_count, block_size, file_name, verbose): """ Program main. """ - pass + print('main():') + print(' set_count: {0}'.format(set_count)) + print(' line_count: {0}'.format(line_count)) + print(' block_size: {0}'.format(block_size)) + print(' file_name: {0}'.format(file_name)) + print(' verbose: {0}'.format(verbose)) if __name__ == '__main__': print('Starting program.') - main() + # Define our argparser and get command line args. + parser = argparse.ArgumentParser(description='Cache Simulator') + parser.add_argument('-v', '-V', action='store_true', default=False, help='Flag for verbose mode.', dest='verbose') + parser.add_argument('-s', '-S', action='store', required=True, help='Total sets.', dest='set_count') + parser.add_argument('-e', '-E', action='store', required=True, help='Lines per set.', dest='line_count') + parser.add_argument('-b', '-B', action='store', required=True, help='Bits per block.', dest='block_size') + parser.add_argument('-t', '-T', action='store', required=True, help='File to read in.', dest='file_name') + args = parser.parse_args() + + # If args parsed properly, run program main. + main(args.set_count, args.line_count, args.block_size, args.file_name, args.verbose) print('Terminating program.') diff --git a/run.sh b/run.sh index cb95844ca92785ac9e40488995cb8e8d616b4a47..7a5ab47a328aae5d48204fc28fc82044f34050a2 100755 --- a/run.sh +++ b/run.sh @@ -57,7 +57,7 @@ function execute_single_file () { then file=$return_value - echo -e "${color_blue}Found input file \"$file\". Attempting to compile C code.${color_reset}" + echo -e "${color_blue}Found input file \"$file\".${color_reset}" # Run input file on example cache simulator file. echo "" @@ -67,7 +67,7 @@ function execute_single_file () { # Run input file on compiled C code. echo "" - echo -e "${color_blue}Running input file on compiled C code. Runtime args:${color_reset}" + echo -e "${color_blue}Running input file on Python code. Runtime args:${color_reset}" echo -e "${color_blue} -v -s 4 -E 1 -b 4 -t $file${color_reset}" python3 main.py -v -s 4 -E 1 -b 4 -t $file