Пример #1
0
// Fuzz implements go-fuzz interface.
func Fuzz(data []byte) int {
	_, errs, _ := g8.CompileSingle("test.g", string(data), false)
	if len(errs) > 0 {
		return 0
	}
	return 1
}
Пример #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)
		}
	}
}