Esempio n. 1
0
func (bare bareFunc) Compile(pinfo *build8.PkgInfo, opts *build8.Options) (
	pkg *build8.Package, es []*lex8.Error,
) {
	// parsing
	theFile, e := findTheFile(pinfo)
	if e != nil {
		return nil, lex8.SingleErr(e)
	}
	stmts, es := parse.Stmts(theFile.Path, theFile)
	if es != nil {
		return nil, es
	}

	// building
	b := makeBuilder(pinfo)
	if es = b.Errs(); es != nil {
		return nil, es
	}
	if es := buildBareFunc(b, stmts); es != nil {
		return nil, es
	}
	if es := b.Errs(); es != nil {
		return nil, es
	}

	// logging
	if e := logIr(pinfo, b); e != nil {
		return nil, lex8.SingleErr(e)
	}

	// codegen
	lib, errs := ir.BuildPkg(b.p)
	if errs != nil {
		return nil, errs
	}

	ret := &build8.Package{
		Lang: "g8-barefunc",
		Main: startName,
		Lib:  lib,
	}
	return ret, nil
}
Esempio 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)
		}
	}
}