func runImage(bs []byte, dasm bool, n int) { if dasm { err := dasm8.DumpImage(bytes.NewReader(bs), os.Stdout) if err != nil { fmt.Println(err) } } if len(bs) == 0 { fmt.Println("(the image is empty)") return } m := arch8.NewMachine(new(arch8.Config)) if err := m.LoadImageBytes(bs); err != nil { fmt.Println(err) return } ncycle, exp := m.Run(n) fmt.Printf("(%d cycles)\n", ncycle) if exp != nil { if !arch8.IsHalt(exp) { fmt.Println(exp) err := arch8.FprintStack(os.Stdout, m, exp) if err != nil { fmt.Println(err) } } } else { fmt.Println("(end of time)") } }
func run(bs []byte) (int, error) { // create a single core machine m := arch8.NewMachine(uint32(*memSize), 1) secs, err := e8.Read(bytes.NewReader(bs)) if err != nil { return 0, err } if err := m.LoadSections(secs); err != nil { return 0, err } if *bootArg > math.MaxUint32 { log.Fatalf("boot arg(%d) is too large", *bootArg) } if err := m.WriteWord(arch8.AddrBootArg, uint32(*bootArg)); err != nil { return 0, err } if *romRoot != "" { m.MountROM(*romRoot) } if *randSeed != 0 { m.RandSeed(*randSeed) } ret, exp := m.Run(*ncycle) if *printStatus { m.PrintCoreStatus() } if !arch8.IsHalt(exp) { fmt.Println(exp) err := arch8.FprintStack(os.Stdout, m, exp) if err != nil { log.Fatal(err) } } if exp == nil { return ret, nil } return ret, exp }
func run(bs []byte) (int, error) { // create a single core machine m := arch8.NewMachine(&arch8.Config{ MemSize: uint32(*memSize), RandSeed: *randSeed, }) if err := m.LoadImageBytes(bs); err != nil { return 0, err } ret, exp := m.Run(*ncycle) if *printStatus { m.PrintCoreStatus() } if exp == nil { return ret, nil } return ret, exp }
func run(bs []byte) (int, error) { if *bootArg > math.MaxUint32 { log.Fatalf("boot arg(%d) is too large", *bootArg) } // create a single core machine m := arch8.NewMachine(&arch8.Config{ MemSize: uint32(*memSize), ROM: *romRoot, RandSeed: *randSeed, BootArg: uint32(*bootArg), }) secs, err := e8.Read(bytes.NewReader(bs)) if err != nil { return 0, err } if err := m.LoadSections(secs); err != nil { return 0, err } ret, exp := m.Run(*ncycle) if *printStatus { m.PrintCoreStatus() } if !arch8.IsHalt(exp) { fmt.Println(exp) err := arch8.FprintStack(os.Stdout, m, exp) if err != nil { log.Fatal(err) } } if exp == nil { return ret, nil } return ret, exp }
func runTests( log lex8.Logger, tests map[string]uint32, img []byte, opt *Options, ) { logln := func(s string) { if opt.LogLine == nil { fmt.Println(s) } else { opt.LogLine(s) } } // TODO(h8liu): this reporting should go with JSON for better formatting. report := func( name string, ncycle int, pass bool, m *arch8.Machine, err error, ) { if pass { if opt.Verbose { logln(fmt.Sprintf( " - %s: passed (%s)", name, cycleStr(ncycle), )) } return } if err == nil { err = errTimeOut } lex8.LogError(log, fmt.Errorf("%s failed: got %s", name, err)) if opt.Verbose { logln(fmt.Sprintf( " - %s: FAILED (%s, got %s)", name, cycleStr(ncycle), err, )) // TODO(h8liu): this is too ugly here... excep, ok := err.(*arch8.CoreExcep) if !arch8.IsHalt(err) && ok { stackTrace := new(bytes.Buffer) arch8.FprintStack(stackTrace, m, excep) logln(stackTrace.String()) } } } var testNames []string for name := range tests { testNames = append(testNames, name) } sort.Strings(testNames) for _, test := range testNames { arg := tests[test] m := arch8.NewMachine(&arch8.Config{ BootArg: arg, }) if err := m.LoadImageBytes(img); err != nil { report(test, 0, false, m, err) continue } var err error n, excep := m.Run(opt.TestCycles) if excep == nil { err = errTimeOut } else { err = excep } if strings.HasPrefix(test, "TestBad") { report(test, n, arch8.IsPanic(err), m, err) } else { report(test, n, arch8.IsHalt(err), m, err) } } }