1
0
mirror of https://github.com/golang/go synced 2024-10-01 16:18:32 -06:00
go/usr/gri/gosrc/compilation.go

45 lines
955 B
Go
Raw Normal View History

// 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
import Utils "utils"
import Globals "globals"
import Object "object"
import Type "type"
2008-07-15 20:59:00 -06:00
import Universe "universe"
import Scanner "scanner"
import AST "ast"
import Parser "parser"
import Export "export"
import Printer "printer"
export Compile
func Compile(comp *Globals.Compilation, file_name string) {
src, ok := sys.readfile(file_name);
2008-07-15 20:59:00 -06:00
if !ok {
print "cannot open ", file_name, "\n"
2008-07-15 20:59:00 -06:00
return;
}
scanner := new(Scanner.Scanner);
scanner.Open(file_name, src);
2008-07-15 20:59:00 -06:00
parser := new(Parser.Parser);
parser.Open(comp, scanner);
print "parsing ", file_name, "\n";
parser.ParseProgram();
if parser.S.nerrors > 0 {
return;
}
2008-07-15 20:59:00 -06:00
// export
if comp.flags.semantic_checks {
Printer.PrintObject(comp, comp.pkgs[0].obj, false);
Export.Export(comp, file_name);
}
}