Example #1
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 #2
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 #3
0
func main() {
	llvm.InitializeAllTargets()
	llvm.InitializeAllTargetMCs()
	llvm.InitializeAllTargetInfos()
	flag.Parse()

	if *version {
		displayVersion()
	}

	if *printTriple {
		fmt.Println(computeTriple())
		os.Exit(0)
	}

	opts := llgo.CompilerOptions{}
	opts.TargetTriple = computeTriple()
	if *trace {
		opts.Logger = log.New(os.Stderr, "", 0)
	}

	compiler, err := initCompiler()
	if err != nil {
		fmt.Fprintf(os.Stderr, "initCompiler failed: %s\n", err)
		os.Exit(1)
	}
	defer compiler.Dispose()

	module, err := compileFiles(compiler, flag.Args(), *importpath)
	if err == nil {
		defer module.Dispose()
		if exitCode == 0 {
			if *dump {
				module.Dump()
			} else {
				err := writeObjectFile(module)
				if err != nil {
					fmt.Println(err)
				}
			}
		}
	} else {
		report(err)
	}
	os.Exit(exitCode)
}