예제 #1
0
 def translate(self):
     # aseemble the code
     self.parse()
     # write assembled code to .hack file
     fh.writeAsmFile(self._filePath, self._codeList)
예제 #2
0
    # check to see if the directory is valid
    if not fh.dirExists(fileDir):
        sys.exit("Incorrect file directory!")

    # get the file paths for all vm files in directory
    filePaths = fh.getVmFiles(fileDir)

    # the cformatter object
    cf = CFormatter()

    # intialize the code list for each file
    codeList = []
    # iterate over each file path
    for i, filePath in enumerate(filePaths):
        tr = Translator(filePath, cf)
        if i == 0:
            tr.handleInit()
        # assemble the code
        tr.parse()
        # store current codelist in the combined one
        codeList += tr.getCodeList()

    # write assembled code to .asm file
    fh.writeAsmFile(fileDir, codeList)