Example #1
0
func compilePackage(fset *token.FileSet, files map[string]*ast.File) (*llgo.Module, error) {
	// make a package (resolve all identifiers)
	pkg, err := ast.NewPackage(fset, files, types.GcImport, types.Universe)
	if err != nil {
		report(err)
		return nil, err
	}

	exprTypes, err := types.Check(fset, pkg)
	if err != nil {
		report(err)
		return nil, err
	}

	if *dumpast {
		ast.Fprint(os.Stderr, fset, pkg, nil)
		os.Exit(0)
	}

	compiler := llgo.NewCompiler()
	compiler.SetTraceEnabled(*trace)
	compiler.SetTargetArch(*arch)
	compiler.SetTargetOs(*os_)
	return compiler.Compile(fset, pkg, exprTypes)
}
Example #2
0
func initCompiler() (llgo.Compiler, error) {
	opts := llgo.CompilerOptions{TargetTriple: computeTriple()}
	if *trace {
		opts.Logger = log.New(os.Stderr, "", 0)
	}
	return llgo.NewCompiler(opts)
}
Example #3
0
File: llgo.go Project: pcc/llgo
func initCompiler() (llgo.Compiler, error) {
	opts := llgo.CompilerOptions{TargetTriple: computeTriple()}
	if *trace || os.Getenv("LLGO_TRACE") == "1" {
		opts.Logger = log.New(os.Stderr, "", 0)
	}
	if os.Getenv("LLGO_ORDERED_COMPILATION") == "1" {
		opts.OrderedCompilation = true
	}
	opts.GenerateDebug = *generateDebug
	return llgo.NewCompiler(opts)
}
Example #4
0
File: llgo.go Project: kisielk/llgo
var importpath = flag.String(
	"importpath", "",
	"Package import path of the source being compiled")

var version = flag.Bool(
	"version", false,
	"Display version information and exit")

var os_ = flag.String("os", runtime.GOOS, "Set the target OS")
var arch = flag.String("arch", runtime.GOARCH, "Set the target architecture")
var printTriple = flag.Bool("print-triple", false, "Print out target triple and exit")
var compileOnly = flag.Bool("c", false, "Compile only, don't link")
var outputFile = flag.String("o", "-", "Output filename")

var exitCode = 0
var compiler = llgo.NewCompiler()

func report(err error) {
	scanner.PrintError(os.Stderr, err)
	exitCode = 2
}

func parseFile(fset *token.FileSet, filename string) *ast.File {
	// parse entire file
	mode := parser.DeclarationErrors | parser.ParseComments
	//if *allErrors {
	//    mode |= parser.SpuriousErrors
	//}
	//if *printTrace {
	//    mode |= parser.Trace
	//}