def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "msp430", "bsp.c3") startercode = io.StringIO(self.startercode) obj = build( base_filename, src, bsp_c3, startercode, "msp430", self.opt_level, io.StringIO(self.arch_mmap), lang=lang, ) flash = obj.get_image("flash") ivect = obj.get_image("vector16") rom = merge_memories(flash, ivect, "rom") rom_data = rom.data assert len(rom_data) % 2 == 0 with open(base_filename + ".bin", "wb") as f: f.write(rom_data) mem_file = base_filename + ".mem" with open(mem_file, "w") as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print("%02x%02x" % (w[1], w[0]), file=f) if has_iverilog() and do_iverilog(): res = run_msp430(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'msp430', 'bsp.c3') startercode = io.StringIO(self.startercode) obj = build(base_filename, src, bsp_c3, startercode, "msp430", self.opt_level, io.StringIO(self.arch_mmap), lang=lang) flash = obj.get_image('flash') ivect = obj.get_image('vector16') rom = merge_memories(flash, ivect, 'rom') rom_data = rom.data assert len(rom_data) % 2 == 0 with open(base_filename + '.bin', 'wb') as f: f.write(rom_data) mem_file = base_filename + '.mem' with open(mem_file, 'w') as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print('%02x%02x' % (w[1], w[0]), file=f) if has_iverilog() and do_iverilog(): res = run_msp430(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'avr', 'bsp.c3') crt0 = relpath('..', 'examples', 'avr', 'glue.asm') mmap = relpath('..', 'examples', 'avr', 'avr.mmap') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='hex', code_image='flash') hexfile = base_filename + '.hex' print(hexfile) if has_avr_emulator() and do_iverilog(): res = run_avr(hexfile) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) obj = build( base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format="bin", elf_format="elf", code_image="flash", ) flash = obj.get_image("flash") data = obj.get_image("ram") rom = merge_memories(flash, data, "rom") rom_data = rom.data filewordsize = 0x8000 datawordlen = len(rom_data) // 4 mem_file = base_filename + ".mem" with open(mem_file, "w") as f: for i in range(filewordsize): if i < datawordlen: w = rom_data[4 * i:4 * i + 4] print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]), file=f) else: print("00000000", file=f) f.close() if has_iverilog() and do_iverilog(): res = run_picorv32(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "avr", "bsp.c3") crt0 = relpath("..", "examples", "avr", "glue.asm") mmap = relpath("..", "examples", "avr", "avr.mmap") build( base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format="hex", code_image="flash", ) hexfile = base_filename + ".hex" print(hexfile) if has_avr_emulator() and do_iverilog(): res = run_avr(hexfile) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) obj = build(base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format='bin', elf_format='elf', code_image='flash') flash = obj.get_image('flash') data = obj.get_image('ram') rom = merge_memories(flash, data, 'rom') rom_data = rom.data filewordsize = 0x8000 datawordlen = len(rom_data) // 4 mem_file = base_filename + '.mem' with open(mem_file, 'w') as f: for i in range(filewordsize): if (i < datawordlen): w = rom_data[4 * i:4 * i + 4] print('%02x%02x%02x%02x' % (w[3], w[2], w[1], w[0]), file=f) else: print('00000000', file=f) f.close() if has_iverilog() and do_iverilog(): res = run_picorv32(mem_file) self.assertEqual(expected_output, res)