irgen, driver: modify Compiler.Compile to take a FileSet and Files
This change allows clients to generate IR using "files" received from locations
other than the file system. The regular file parser is moved to a new library,
"driver", which is intended to eventually contain much of the logic from
the existing driver.
Differential Revision: http://reviews.llvm.org/D6794
llvm-svn: 225026
diff --git a/llgo/irgen/compiler.go b/llgo/irgen/compiler.go
index f7d1655..de496ff 100644
--- a/llgo/irgen/compiler.go
+++ b/llgo/irgen/compiler.go
@@ -16,6 +16,7 @@
import (
"bytes"
"fmt"
+ "go/ast"
"go/token"
"log"
"sort"
@@ -102,7 +103,7 @@
return compiler, nil
}
-func (c *Compiler) Compile(filenames []string, importpath string) (m *Module, err error) {
+func (c *Compiler) Compile(fset *token.FileSet, astFiles []*ast.File, importpath string) (m *Module, err error) {
target := llvm.NewTargetData(c.dataLayout)
compiler := &compiler{
CompilerOptions: c.opts,
@@ -111,7 +112,7 @@
pnacl: c.pnacl,
llvmtypes: NewLLVMTypeMap(llvm.GlobalContext(), target),
}
- return compiler.compile(filenames, importpath)
+ return compiler.compile(fset, astFiles, importpath)
}
type compiler struct {
@@ -149,7 +150,7 @@
}
}
-func (compiler *compiler) compile(filenames []string, importpath string) (m *Module, err error) {
+func (compiler *compiler) compile(fset *token.FileSet, astFiles []*ast.File, importpath string) (m *Module, err error) {
buildctx, err := llgobuild.ContextFromTriple(compiler.TargetTriple)
if err != nil {
return nil, err
@@ -170,19 +171,13 @@
}
impcfg := &loader.Config{
- Fset: token.NewFileSet(),
+ Fset: fset,
TypeChecker: types.Config{
Import: importer,
Sizes: compiler.llvmtypes,
},
Build: &buildctx.Context,
}
- // Must use parseFiles, so we retain comments;
- // this is important for annotation processing.
- astFiles, err := parseFiles(impcfg.Fset, filenames)
- if err != nil {
- return nil, err
- }
// If no import path is specified, then set the import
// path to be the same as the package's name.
if importpath == "" {