Пример #1
0
func main() {
	flag.Parse()

	args := flag.Args()
	if len(args) != 1 {
		fmt.Fprintf(os.Stderr, "need exactly one input file\n")
		os.Exit(-1)
	}

	fname := args[0]
	var bs []byte
	if strings.HasSuffix(fname, ".s") {
		f, e := os.Open(fname)
		if e != nil {
			fmt.Fprintf(os.Stderr, "open: %s", e)
			os.Exit(-1)
		}

		var es []*lex8.Error
		if strings.HasSuffix(fname, "_bare.s") {
			bs, es = asm8.BuildBareFunc(fname, f)
		} else {
			bs, es = asm8.BuildSingleFile(fname, f)
		}

		if len(es) > 0 {
			for _, e := range es {
				fmt.Println(e)
			}
			os.Exit(-1)
			return
		}
	} else {
		var e error
		bs, e = ioutil.ReadFile(fname)
		if e != nil {
			fmt.Println(e)
			os.Exit(-1)
			return
		}
	}

	if *doDasm {
		lines := dasm8.Dasm(bs, arch8.InitPC)
		for _, line := range lines {
			fmt.Println(line)
		}
	} else {
		n, e := run(bs)
		fmt.Printf("(%d cycles)\n", n)
		if e != nil {
			fmt.Println(e)
		}
	}
}
Пример #2
0
func runImage(bs []byte, dasm bool, n int) {
	if dasm {
		lines := dasm8.Dasm(bs, arch8.InitPC)
		for _, line := range lines {
			fmt.Println(line)
		}
	}
	if len(bs) == 0 {
		fmt.Println("(the image is empty)")
		return
	}

	ncycle, e := arch8.RunImage(bs, n)
	fmt.Printf("(%d cycles)\n", ncycle)
	if e != nil {
		fmt.Println(e)
	}
}