CS计算机代考程序代写 python #!/usr/bin/python

#!/usr/bin/python
import getopt
import sys
import re
import os

#
# MAIN PROGRAM
#

def simpleCPUv1a_ld(argv):

if len(sys.argv) <= 1: print ("Usage: simpleCPUv1a_ld.py -i “)
print (” -o “)
return

# init variables #
version = ‘1.1’
source_filename = ‘default.mem’
output_filename = ‘memory.vhd’

s_config = ‘i:o:’
l_config = [‘input’, ‘output’]

input_file_present = False

# capture commandline options #
try:
options, remainder = getopt.getopt(sys.argv[1:], s_config, l_config)
except getopt.GetoptError as m:
print “Error: “, m
return

# extract options #
for opt, arg in options:
if opt in (‘-o’, ‘–output’):
if “.vhd” in arg:
output_filename = arg
else:
output_filename = ‘memory.vhd’
elif opt in (‘-i’, ‘–input’):
input_file_present = True
if “.mem” in arg:
source_filename = arg
else:
source_filename = arg + “.mem”

# exit if no input file present #
if input_file_present:
commandString = “./data2mem -bm mem.bmm -bd ” + source_filename + ” -o h ” + output_filename
#print commandString
os.system( commandString )
print “Success, memory image file ” + output_filename + ” generated for ” + source_filename
else:
print “Error: Input file not specified”
return

if __name__ == ‘__main__’:
simpleCPUv1a_ld(sys.argv)