2008-07-15 16:37:14 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package Compilation
|
|
|
|
|
2008-07-29 20:02:49 -06:00
|
|
|
import Utils "utils"
|
2008-07-15 16:37:14 -06:00
|
|
|
import Globals "globals"
|
|
|
|
import Object "object"
|
|
|
|
import Type "type"
|
2008-07-15 20:59:00 -06:00
|
|
|
import Universe "universe"
|
2008-07-15 16:37:14 -06:00
|
|
|
import Scanner "scanner"
|
2008-07-18 18:18:29 -06:00
|
|
|
import AST "ast"
|
2008-07-15 16:37:14 -06:00
|
|
|
import Parser "parser"
|
2008-07-16 18:00:48 -06:00
|
|
|
import Export "export"
|
2008-07-15 16:37:14 -06:00
|
|
|
|
|
|
|
|
|
|
|
export Compile
|
2008-07-17 19:02:10 -06:00
|
|
|
func Compile(file_name string, verbose int) {
|
|
|
|
src, ok := sys.readfile(file_name);
|
2008-07-15 20:59:00 -06:00
|
|
|
if !ok {
|
2008-07-17 19:02:10 -06:00
|
|
|
print "cannot open ", file_name, "\n"
|
2008-07-15 20:59:00 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-17 19:02:10 -06:00
|
|
|
Universe.Init(); // TODO eventually this should be only needed once
|
|
|
|
|
|
|
|
comp := Globals.NewCompilation();
|
2008-07-15 20:59:00 -06:00
|
|
|
|
2008-07-17 19:02:10 -06:00
|
|
|
scanner := new(Scanner.Scanner);
|
|
|
|
scanner.Open(file_name, src);
|
2008-07-15 20:59:00 -06:00
|
|
|
|
2008-07-17 19:02:10 -06:00
|
|
|
parser := new(Parser.Parser);
|
|
|
|
parser.Open(comp, scanner, verbose);
|
|
|
|
|
|
|
|
print "parsing ", file_name, "\n";
|
|
|
|
parser.ParseProgram();
|
|
|
|
if parser.S.nerrors > 0 {
|
|
|
|
return;
|
|
|
|
}
|
2008-07-15 20:59:00 -06:00
|
|
|
|
2008-07-17 19:02:10 -06:00
|
|
|
// export
|
2008-07-18 15:04:21 -06:00
|
|
|
exp := new(Export.Exporter);
|
2008-07-29 20:02:49 -06:00
|
|
|
exp.Export(comp, Utils.FixExt(Utils.BaseName(file_name)));
|
2008-07-15 16:37:14 -06:00
|
|
|
}
|