def main(): path = Util.getCommandLineArgument(1) code_writer = CodeWriter(path.replace('.vm', '') + '.asm') if os.path.isdir(path): files = FileSet(path, 'vm') while files.hasMoreFiles(): filename = files.nextFile() Main.parse(filename, code_writer) elif os.path.isfile(path): Main.parse(path, code_writer) code_writer.Close()
def main(): print("******************************************") print("*** FileSet Report ***") print("******************************************") print() fileORdir = Util.getCommandLineArgument(1) level = Util.getCommandLineArgument(2) files = FileSet(fileORdir, "hack") files.report() print() print("******************************************") print("*** Processing Report ***") print("******************************************") print() while files.hasMoreFiles(): inputFileSpec = files.nextFile() print("Processing: %s" % inputFileSpec) outputFileSpec = os.path.splitext(inputFileSpec)[0]+".dis" inputFile = open(inputFileSpec, "rU") outputFile = open(outputFileSpec, "w") parser = Parser(inputFile) while parser.hasMoreInstructions(): parser.advance() if (parser.instructionType() == "A_TYPE"): value = parser.value() inst = Code.a_type(value) if (parser.instructionType() == "C_TYPE"): dest = parser.dest() comp = parser.comp() jump = parser.jump() destMnemonic = Code.destMnemonic(dest) compMnemonic = Code.compMnemonic(comp) jumpMnemonic = Code.jumpMnemonic(jump) inst = Code.c_type(destMnemonic, compMnemonic, jumpMnemonic) if (parser.instructionType() == "INVALID"): inst = Code.invalid_type() inst += Util.repeatedChar(" ", 20-len(inst)) inst += "// %05i:" % parser.address() inst += " [%s]" % parser.hexInstruction() inst += " %s\n" % parser.parsedInstruction() outputFile.write(inst) outputFile.close() inputFile.close() print() print("Processing of file(s) complete.")
def main(): path = Util.getCommandLineArgument(1) if os.path.isdir(path): files = FileSet(path, 'jack') while files.hasMoreFiles(): filename = files.nextFile() Main.compile_jack(filename) elif os.path.isfile(path): Main.compile_jack(path) else: print '{} is not a file or dir'.format(path)