Esempio n. 1
0
func parsePkg(pinfo *build8.PkgInfo) (map[string]*ast.File, []*lex8.Error) {
	var parseErrs []*lex8.Error
	asts := make(map[string]*ast.File)
	for name, src := range pinfo.Src {
		f, es := parse.File(src.Path, src)
		if es != nil {
			parseErrs = append(parseErrs, es...)
		}
		asts[name] = f
	}
	if len(parseErrs) > 0 {
		return nil, parseErrs
	}

	return asts, nil
}
Esempio n. 2
0
func main() {
	bare := flag.Bool("bare", false, "parse as bare function")
	parseAST := flag.Bool("parse", false, "parse only and print out the ast")
	ir := flag.Bool("ir", false, "prints out the IR")
	dasm := flag.Bool("d", false, "deassemble the image")
	ncycle := flag.Int("n", 100000, "maximum number of cycles")

	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)
			ast.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, es := parse.File(fname, bytes.NewBuffer(input))
			printErrs(es)
			ast.FprintFile(os.Stdout, f)
		} else {
			bs, es, irLog := g8.CompileSingleFile(fname, string(input))
			printErrs(es)
			printIRLog(irLog, *ir)
			runImage(bs, *dasm, *ncycle)
		}
	}
}