|
@ -103,7 +103,7 @@ func NewTargetMachine(config *compileopts.Config) (llvm.TargetMachine, error) { |
|
|
// violation. Eventually, this Compile function should only compile a single
|
|
|
// violation. Eventually, this Compile function should only compile a single
|
|
|
// package and not the whole program, and loading of the program (including CGo
|
|
|
// package and not the whole program, and loading of the program (including CGo
|
|
|
// processing) should be moved outside the compiler package.
|
|
|
// processing) should be moved outside the compiler package.
|
|
|
func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Config) (llvm.Module, []string, []error) { |
|
|
func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Config) (mod llvm.Module, extrafiles []string, extraldflags []string, errors []error) { |
|
|
c := &compilerContext{ |
|
|
c := &compilerContext{ |
|
|
Config: config, |
|
|
Config: config, |
|
|
difiles: make(map[string]llvm.Metadata), |
|
|
difiles: make(map[string]llvm.Metadata), |
|
@ -148,7 +148,7 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con |
|
|
|
|
|
|
|
|
wd, err := os.Getwd() |
|
|
wd, err := os.Getwd() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return c.mod, nil, []error{err} |
|
|
return c.mod, nil, nil, []error{err} |
|
|
} |
|
|
} |
|
|
lprogram := &loader.Program{ |
|
|
lprogram := &loader.Program{ |
|
|
Build: &build.Context{ |
|
|
Build: &build.Context{ |
|
@ -211,14 +211,14 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con |
|
|
if strings.HasSuffix(pkgName, ".go") { |
|
|
if strings.HasSuffix(pkgName, ".go") { |
|
|
_, err = lprogram.ImportFile(pkgName) |
|
|
_, err = lprogram.ImportFile(pkgName) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return c.mod, nil, []error{err} |
|
|
return c.mod, nil, nil, []error{err} |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
_, err = lprogram.Import(pkgName, wd, token.Position{ |
|
|
_, err = lprogram.Import(pkgName, wd, token.Position{ |
|
|
Filename: "build command-line-arguments", |
|
|
Filename: "build command-line-arguments", |
|
|
}) |
|
|
}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return c.mod, nil, []error{err} |
|
|
return c.mod, nil, nil, []error{err} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -226,12 +226,12 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con |
|
|
Filename: "build default import", |
|
|
Filename: "build default import", |
|
|
}) |
|
|
}) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return c.mod, nil, []error{err} |
|
|
return c.mod, nil, nil, []error{err} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = lprogram.Parse(c.TestConfig.CompileTestBinary) |
|
|
err = lprogram.Parse(c.TestConfig.CompileTestBinary) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return c.mod, nil, []error{err} |
|
|
return c.mod, nil, nil, []error{err} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
c.ir = ir.NewProgram(lprogram, pkgName) |
|
|
c.ir = ir.NewProgram(lprogram, pkgName) |
|
@ -239,7 +239,7 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con |
|
|
// Run a simple dead code elimination pass.
|
|
|
// Run a simple dead code elimination pass.
|
|
|
err = c.ir.SimpleDCE() |
|
|
err = c.ir.SimpleDCE() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return c.mod, nil, []error{err} |
|
|
return c.mod, nil, nil, []error{err} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Initialize debug information.
|
|
|
// Initialize debug information.
|
|
@ -383,7 +383,7 @@ func Compile(pkgName string, machine llvm.TargetMachine, config *compileopts.Con |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return c.mod, extraFiles, c.diagnostics |
|
|
return c.mod, extraFiles, lprogram.LDFlags, c.diagnostics |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// getLLVMRuntimeType obtains a named type from the runtime package and returns
|
|
|
// getLLVMRuntimeType obtains a named type from the runtime package and returns
|
|
|