main: compile C source files in packages
TODO: C++ etc. files
Этот коммит содержится в:
родитель
e10d05c74f
коммит
dea660b21c
3 изменённых файлов: 28 добавлений и 5 удалений
|
@ -149,6 +149,10 @@ func NewCompiler(pkgName string, config Config) (*Compiler, error) {
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Compiler) Packages() []*loader.Package {
|
||||||
|
return c.ir.LoaderProgram.Sorted()
|
||||||
|
}
|
||||||
|
|
||||||
// Return the LLVM module. Only valid after a successful compile.
|
// Return the LLVM module. Only valid after a successful compile.
|
||||||
func (c *Compiler) Module() llvm.Module {
|
func (c *Compiler) Module() llvm.Module {
|
||||||
return c.mod
|
return c.mod
|
||||||
|
|
2
ir/ir.go
2
ir/ir.go
|
@ -19,6 +19,7 @@ import (
|
||||||
// results.
|
// results.
|
||||||
type Program struct {
|
type Program struct {
|
||||||
Program *ssa.Program
|
Program *ssa.Program
|
||||||
|
LoaderProgram *loader.Program
|
||||||
mainPkg *ssa.Package
|
mainPkg *ssa.Package
|
||||||
Functions []*Function
|
Functions []*Function
|
||||||
functionMap map[*ssa.Function]*Function
|
functionMap map[*ssa.Function]*Function
|
||||||
|
@ -173,6 +174,7 @@ func NewProgram(lprogram *loader.Program, mainPath string) *Program {
|
||||||
|
|
||||||
p := &Program{
|
p := &Program{
|
||||||
Program: program,
|
Program: program,
|
||||||
|
LoaderProgram: lprogram,
|
||||||
mainPkg: mainPkg,
|
mainPkg: mainPkg,
|
||||||
functionMap: make(map[*ssa.Function]*Function),
|
functionMap: make(map[*ssa.Function]*Function),
|
||||||
globalMap: make(map[*ssa.Global]*Global),
|
globalMap: make(map[*ssa.Global]*Global),
|
||||||
|
|
17
main.go
17
main.go
|
@ -192,6 +192,23 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
|
||||||
ldflags = append(ldflags, outpath)
|
ldflags = append(ldflags, outpath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Compile C files in packages.
|
||||||
|
for i, pkg := range c.Packages() {
|
||||||
|
for _, file := range pkg.CFiles {
|
||||||
|
path := filepath.Join(pkg.Package.Dir, file)
|
||||||
|
outpath := filepath.Join(dir, "pkg"+strconv.Itoa(i)+"-"+file+".o")
|
||||||
|
cmd := exec.Command(spec.Compiler, append(spec.CFlags, "-c", "-o", outpath, path)...)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
cmd.Dir = sourceDir()
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ldflags = append(ldflags, outpath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Link the object files together.
|
// Link the object files together.
|
||||||
cmd := exec.Command(spec.Linker, ldflags...)
|
cmd := exec.Command(spec.Linker, ldflags...)
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче