def assem_move(size, words, special, line): logging.debug("Move size:%d, words:%s" % (size, hl_parser.format_word_list(words))) if (len(words) != 2): err.report_error("Move needs 2 arguments") return token = tokens.Token("move", err, line) token.add_bits(0, 6, 3, 1) sdindex = 1 # source if (words[0].type() == "const"): if (not special and words[0].val() >= 0 and words[0].val() <= 3): token.add_bits(0, 3, 0x3, words[0].val()) token.add_bits(0, 2, 0x1, size) else: if (size == 0): token.add_bits(0, 2, 0xf, 0xa) token.add_byte(sdindex, words[0].val()) sdindex += 1 else: if (not special): token.add_bits(0, 2, 0xf, 0xb) elif (special == "time"): token.add_bits(0, 2, 0xf, 0xf) else: err.report_error("Source for lcd moves must be byte sized") return token.add_word(sdindex, words[0].val()) sdindex += 2 elif (words[0].type() == "modreg"): if (size == 0): token.add_bits(0, 2, 0xf, 0x8) else: token.add_bits(0, 2, 0xf, 0x9) token.add_byte(sdindex, words[0].val()) sdindex += 1 elif (words[0].type() in ["var", "arg"]): if (size == 0): token.add_bits(0, 2, 0xf, 0xc) else: if (not special): token.add_bits(0, 2, 0xf, 0xd) elif (special == "time"): token.add_bits(0, 2, 0xf, 0xe) else: err.report_error("Source for lcd moves must be byte sized") return if (words[0].type() == "arg"): token.add_byte(sdindex, words[0].num()) else: token.add_byte(sdindex, 0) token.add_vname(sdindex, size, words[0].val()) sdindex += 1 # if this is a time chkpt then the destination must be in 8bit space if (special == "time"): size = 0 # destination if (words[1].type() == "modreg"): if (special): err.report_error("Destination for lcd and time moves can NOT be mod/reg") return token.add_bits(0, 0, 0x3, 0x0) token.add_byte(sdindex, words[1].val()) sdindex += 1 elif (words[1].type() in ["var", "arg"]): if (size == 0): if (special != "lcd"): token.add_bits(0, 0, 0x3, 0x1) else: token.add_bits(0, 0, 0x3, 0x3) else: if (special): err.report_error("Desination for lcd and time moves can not be in word variables") return token.add_bits(0, 0, 0x3, 0x2) if (words[1].type() == "arg"): token.add_byte(sdindex, words[1].num()) else: token.add_byte(sdindex, 0) if (special == "lcd"): token.add_vname(sdindex, 2, words[1].val()) else: token.add_vname(sdindex, size, words[1].val()) sdindex += 1 logging_utils.dump_object(token, "move") token.finish(token_stream)
def test(): global token_stream global err test_simp = ["incb %acc", "movb 12,@lil_count", "decw 1001/2", " # a comment line", " addb $12 #do some adding", "movb $'a', %acc", "branch :label1", "decw", "mulw 44", "subb $1000", "subw $-3000", "movb $0, @big_count", "movw @last_reading, @store_reading"] test_jump = ["brne :f1", "bra $-1", "ret", ":f1", "dbnz :f2", "dsnz $10", "suba $10", ":f2"] test_stack = ["pushb $32", "pushw @count", "popb %acc", "popw 0x39", "pushw 43"] test_data = ["DATA home, 0", "DATB *, 0, 20, 'a'", ":start", "DATW intensity, *, *, -20", 'DATA buffer, *, 32, "This is an \"interesting\" string"'] test_spec = ["LIMITS -1, -1, -1, 0, 0", "LIMITS 30, 10, 64, 0, 200", "RESERVA 0, 16", "RESERVB 31,1", "RESERVW 0, 1"] test_device = ["DEVICE bad, 1", "DEVICE motor, 0", "DEVICE motor 13", "DEVICE motor 1 **", "DEVICE digin, 1", "DEVICE motor 2, left_wheel", "DEVICE motor 4 right_wheel", "DEVICE digout, 5", "DEVICE analogin 6"] test_begin_end = ["BEGIN WTF", "BEGIN PROGRAM 1", "BEGIN CONFIG", "BEGIN EVENT 34, 43,44", "END PROGRAM CONFIG 0 0", "BEGIN CONFIG 0,0", "BEGIN PROGRAM", "BEGIN EVENT %acc 0xfe 20/16"] test_other = ["stop 1", "COMMS", "COMMS 1 2", "FINISH 2", ":start1", ":start2", "stop", "FINISH", "COMMS 1024", "COMMS 400/16", "COMMS 0x400"] test_prog1 = ["COMMS 0x400", "LIMITS 20, 10, 64, 0, 200", 'RESERVB 0, 3', 'RESERVB 6, 2', 'RESERVW 0, 2', 'RESERVW 4,1', 'RESERVA 0, 5', "BEGIN CONFIG 0,0", "BEGIN PROGRAM", "DATB count *", "DATB buffer *, 10", "DATW temps *, 5", 'DATA message * * "This is fun but long - will it work?"', "movb 5, @count", ":b1", "movb @count, %acc", "cmpb 0", "bre :f1", "decb @count", "bra :b1", ":f1", "movb 0, %acc", "END PROGRAM", "END CONFIG", "FINISH"] test_prog1 = ["COMMS 0x400", "LIMITS 200, 10, 64, 0, 200", 'RESERVB 0, 3', 'RESERVB 6, 2', 'RESERVW 0, 2', 'RESERVW 4,1', 'RESERVA 0, 5', 'DEVICE motor 1', 'DEVICE digin 2', "BEGIN CONFIG 0,0", "BEGIN MAIN", "DATB count *", "DATB buffer *, 10", "DATW temps *, 5", 'DATA message * * "This is fun but long - will it work?"', '::top', 'DATB *, 0, 200', "movb $5, @count", ":b1", "movb @count, %acc", "cmpb 0", "bre :f1", "decb @count", "bra :b1", ":f1", "movb 0, %acc", 'bra ::top', "END MAIN", "BEGIN EVENT %2C 1 1", ":f1", 'movw $-150, @temps', 'brne :f1', 'INSERT BINARY email.sig', 'bra :f1', 'END EVENT', "END CONFIG", "FINISH"] test_prog2 = ['BEGIN FIRMWARE 0, 0, 0', 'BINB 0x10 20/16 255', 'BINB "Copyright"', 'INSERT BINARY email.sig', 'END FIRMWARE', 'FINISH'] test_new_bad = ['bitset', 'bitset 3', 'bitset 3 2', 'bitset 29, f3'] # Bads test_new_good = ['BEGIN CONFIG 0,0', 'BEGIN MAIN', 'bitset 3 f3', 'bitset 0 ff', 'END MAIN', 'END CONFIG', 'FINISH'] logging.info("Starting test") err = logging_utils.Error_reporter() hl_parser.set_err_reporter(err) #err.set_exit_on_error(False) #err.set_throw_on_error(False) token_stream = tokens.Token_stream(err) token_stream.clear() test_lines = [] #test_lines.extend(test_simp) #test_lines.extend(test_jump) #test_lines.extend(test_stack) #test_lines.extend(test_data) #test_lines.extend(test_spec) #test_lines.extend(test_device) #test_lines.extend(test_begin_end) #test_lines.extend(test_other) #test_lines.extend(test_prog2) test_lines.extend(test_new_good) for t in test_lines: assem_line(t) token_stream.dump_tokens() logging_utils.dump_object(token_stream, "Token_stream") token_analysis = tokens.Token_analyser(token_stream, err) token_analysis.map_all_variables() token_analysis.dump_variable_map() token_analysis.fixup_jumps() token_analysis.fixup_sections() # Add section headers including lengths token_analysis.fixup_jumps() # Fixup globals which may change because of section headers token_analysis.fixup_crcs() # Finally the crcs -- nothing will change now token_stream.dump_tokens() logging_utils.dump_object(token_analysis, "Token_analyser")