示例#1
0
文件: main.go 项目: dtcaciuc/llgo
func link(files []string) error {
	tempf, err := ioutil.TempFile("", "llgolink")
	if err != nil {
		return err
	}
	defer os.Remove(tempf.Name())
	defer tempf.Close()

	// TODO? Fix order of modules to be based on package dependency.
	args := append([]string{"-o", tempf.Name()}, files...)
	err = exec.Command(llvmlink, args...).Run()
	if err != nil {
		return err
	}

	module, err := llvm.ParseBitcodeFile(tempf.Name())
	if err != nil {
		return err
	}
	defer module.Dispose()

	f := os.Stdout
	if outfile != "-" {
		f, err = os.Create(outfile)
		if err != nil {
			return err
		}
		defer f.Close()
	}
	return llvm.WriteBitcodeToFile(module, f)
}
示例#2
0
文件: main.go 项目: octabrain/llgo
func link(files []string) error {
	tempf, err := ioutil.TempFile("", "llgolink")
	if err != nil {
		return err
	}
	defer os.Remove(tempf.Name())
	defer tempf.Close()

	args := append([]string{"-o", tempf.Name()}, files...)
	err = exec.Command(llvmlink, args...).Run()
	if err != nil {
		return err
	}

	module, err := llvm.ParseBitcodeFile(tempf.Name())
	if err != nil {
		return err
	}
	defer module.Dispose()

	err = reorderGlobalConstructors(module)
	if err != nil {
		return err
	}

	f := os.Stdout
	if outfile != "-" {
		f, err = os.Create(outfile)
		if err != nil {
			return err
		}
		defer f.Close()
	}
	return llvm.WriteBitcodeToFile(module, f)
}
示例#3
0
func getRuntimeModule() (llvm.Module, error) {
	gofiles, llfiles, err := getRuntimeFiles()
	if err != nil {
		return llvm.Module{}, err
	}

	var runtimeModule *llgo.Module
	runtimeModule, err = compileFiles(testCompiler, gofiles, "runtime")
	if err != nil {
		return llvm.Module{}, err
	}

	if llfiles != nil {
		outfile, err := ioutil.TempFile("", "runtime.ll")
		if err != nil {
			runtimeModule.Dispose()
			return llvm.Module{}, err
		}
		defer func() {
			outfile.Close()
			os.Remove(outfile.Name())
		}()
		err = llvm.WriteBitcodeToFile(runtimeModule.Module, outfile)
		if err != nil {
			runtimeModule.Dispose()
			return llvm.Module{}, err
		}
		runtimeModule.Dispose()
		o := outfile.Name()
		for _, llfile := range llfiles {
			cmd := exec.Command("llvm-link", "-o", o, o, llfile)
			output, err := cmd.CombinedOutput()
			if err != nil {
				err = fmt.Errorf("llvm-link failed: %s", err)
				fmt.Fprintf(os.Stderr, string(output))
				return llvm.Module{}, err
			}
		}
		runtimeModule.Module, err = llvm.ParseBitcodeFile(o)
		if err != nil {
			return llvm.Module{}, err
		}
	}

	return runtimeModule.Module, nil
}