Exemplo n.º 1
0
Arquivo: main.go Projeto: Xslxy/e8vm
func main() {
	flag.Parse()

	args := flag.Args()
	if len(args) != 1 {
		exit(errors.New("need exactly one input input file"))
	}
	fname := args[0]
	input, e := ioutil.ReadFile(fname)
	if e != nil {
		exit(e)
	}

	if *bare {
		bs, es, irLog := g8.CompileBareFunc(fname, string(input))
		printErrs(es)
		printIRLog(irLog, *ir)
		runImage(bs, *dasm, *ncycle)
	} else {
		bs, es, irLog := g8.CompileAndTestSingle(
			fname, string(input), *golike, *ncycleTest,
		)
		printErrs(es)
		printIRLog(irLog, *ir)
		runImage(bs, *dasm, *ncycle)
	}
}
Exemplo n.º 2
0
func main() {
	flag.Parse()

	args := flag.Args()
	if len(args) != 1 {
		exit(errors.New("need exactly one input input file"))
	}
	fname := args[0]
	input, e := ioutil.ReadFile(fname)
	if e != nil {
		exit(e)
	}

	if *bare {
		if *parseAST {
			stmts, es := parse.Stmts(fname, bytes.NewBuffer(input))
			printErrs(es)
			gfmt.FprintStmts(os.Stdout, stmts)
		} else {
			bs, es, irLog := g8.CompileBareFunc(fname, string(input))
			printErrs(es)
			printIRLog(irLog, *ir)
			runImage(bs, *dasm, *ncycle)
		}
	} else {
		if *parseAST {
			f, rec, es := parse.File(fname, bytes.NewBuffer(input), true)
			printErrs(es)
			gfmt.FprintFile(os.Stdout, f, rec)
		} else {
			bs, es, irLog := g8.CompileSingle(fname, string(input), *golike)
			printErrs(es)
			printIRLog(irLog, *ir)
			runImage(bs, *dasm, *ncycle)
		}
	}
}