def read(filePath): read_for_fill(filePath) file = open(filePath, 'r') label = [] num_lines = sum(1 for line in open(filePath)) for i in range(num_lines): mchcode = '--------------------------------' s = file.readline() if s == '': # check file end break instruction = s d = s.rstrip().split('\t') print('----------------------------------------------') print(d) # -------- Label ERROR!!! constraints check -------- if len(d) > 4: if isint(d[4]) == False: d[4] = check_for_fill(d[4]) print(d, '***') if d[4] == 'ERROR': print('ERROR Undefined Label!!!') break #instruction = d instruction = write_for_fill(d) #print(instruction) if d[0] != '': if (d[0] in label): print('ERROR label constraints!!!') break label.append(d[0]) # ------------------ TYPE ------------------- if d[1] == 'add' or d[1] == 'nand': # callR-type print('= R-type') #R_type.run_R_type(instruction) elif d[1] == 'lw' or d[1] == 'sw' or [1] == 'beq': # callI-type print('= I-type') mchcode = itype.iType(instruction) elif d[1] == 'halt' or d[1] == 'noop': # callO-type print('= O-type') elif d[1] == '.fill': # call.fill print('= .fill') elif d[1] == 'jalr': print('= J-type') mchcode = jtype.J_type(instruction) # ------------------------------------------ error_detect.error_detect(mchcode) # Error detect function write(mchcode) # Write to file for u in range(len(label)): print('Address[', u, ']=', label[u]) #return mchcode file.close()
if d[1] == 'add' or d[1] == 'nand': mchcode = rtype.rType(instruction) #toFile.write(mchcode) print("mcgcode[bin] : ", mchcode) print("mcgcode[dec] : ", function.binaryToDecimal(mchcode, 32)) elif d[1] == 'lw' or d[1] == 'sw' or d[1] == 'beq': # callI-type mchcode = itype.iType(instruction) print("mcgcode[bin] : " + mchcode) print("mcgcode[dec] : ", function.binaryToDecimal(mchcode, 32)) elif d[1] == 'halt' or d[1] == 'noop': # callO-type mchcode = otype.oType(instruction) print("mcgcode[bin] : " + mchcode) print("mcgcode[dec] : ", function.binaryToDecimal(mchcode, 32)) elif d[1] == 'jalr': mchcode = jtype.jType(instruction) #toFile.write(mchcode) print("mcgcode[bin] : " + mchcode) print("mcgcode[dec] : ", function.binaryToDecimal(mchcode, 32)) elif d[1] == '.fill': mchcode = toFile.dotFill(instruction) print("mcgcode[bin] : " + mchcode) print("mcgcode[dec] : ", function.binaryToDecimal(mchcode, 32)) # ------------------------------------------ if d[1] != '.fill': function.error_detect(mchcode) # Error detect function toFile.write(mchcode) # Write to file print('----------------------------------------------') ## test git hub