2008-07-10 19:46:30 -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 main
|
|
|
|
|
|
|
|
import Build "build"
|
2008-07-30 18:36:03 -06:00
|
|
|
import Globals "globals"
|
2008-07-15 20:59:00 -06:00
|
|
|
import Compilation "compilation"
|
2008-07-10 19:46:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
func PrintHelp() {
|
2008-08-11 22:20:42 -06:00
|
|
|
print(
|
2008-08-07 20:32:22 -06:00
|
|
|
"go (" + Build.time + ")\n" +
|
|
|
|
"usage:\n" +
|
|
|
|
" go { flag } { file }\n" +
|
|
|
|
" -d debug mode, additional self tests and prints\n" +
|
2008-08-11 10:45:40 -06:00
|
|
|
" -o file explicit object file\n" +
|
2008-08-07 20:32:22 -06:00
|
|
|
" -r recursively update imported packages in current directory\n" +
|
|
|
|
" -p print package interface\n" +
|
|
|
|
" -v [0 .. 3] verbosity level\n" +
|
|
|
|
" -6g 6g compatibility mode\n" +
|
2008-08-11 22:20:42 -06:00
|
|
|
" -token_chan use token channel to scan and parse in parallel\n"
|
|
|
|
);
|
2008-08-07 20:32:22 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var argno int = 1;
|
|
|
|
func Next() string {
|
|
|
|
arg := "";
|
2009-01-16 15:58:14 -07:00
|
|
|
if argno < len(sys.Args) {
|
|
|
|
arg = sys.Args[argno];
|
2008-08-07 20:32:22 -06:00
|
|
|
argno++;
|
|
|
|
}
|
|
|
|
return arg;
|
2008-07-10 19:46:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
2008-08-07 20:32:22 -06:00
|
|
|
arg := Next();
|
2008-12-19 04:05:37 -07:00
|
|
|
|
2008-08-07 20:32:22 -06:00
|
|
|
if arg == "" {
|
2008-07-10 19:46:30 -06:00
|
|
|
PrintHelp();
|
2008-08-07 20:32:22 -06:00
|
|
|
return;
|
2008-07-10 19:46:30 -06:00
|
|
|
}
|
2008-08-07 20:32:22 -06:00
|
|
|
|
2008-07-30 18:36:03 -06:00
|
|
|
// collect flags and files
|
2009-01-06 17:26:45 -07:00
|
|
|
flags := new(Globals.Flags);
|
2008-07-30 18:36:03 -06:00
|
|
|
files := Globals.NewList();
|
2008-08-07 20:32:22 -06:00
|
|
|
for arg != "" {
|
|
|
|
switch arg {
|
2008-07-30 18:36:03 -06:00
|
|
|
case "-d": flags.debug = true;
|
2008-08-11 10:45:40 -06:00
|
|
|
case "-o": flags.object_file = Next();
|
2008-08-11 22:20:42 -06:00
|
|
|
print("note: -o flag ignored at the moment\n");
|
2008-08-07 20:32:22 -06:00
|
|
|
case "-r": flags.update_packages = true;
|
|
|
|
case "-p": flags.print_interface = true;
|
|
|
|
case "-v":
|
|
|
|
arg = Next();
|
|
|
|
switch arg {
|
|
|
|
case "0", "1", "2", "3":
|
|
|
|
flags.verbosity = uint(arg[0] - '0');
|
|
|
|
default:
|
|
|
|
// anything else is considered the next argument
|
|
|
|
flags.verbosity = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2008-07-30 22:26:15 -06:00
|
|
|
case "-6g": flags.sixg = true;
|
2008-08-07 20:32:22 -06:00
|
|
|
case "-token_chan": flags.token_chan = true;
|
2008-07-30 18:36:03 -06:00
|
|
|
default: files.AddStr(arg);
|
2008-07-10 19:46:30 -06:00
|
|
|
}
|
2008-08-07 20:32:22 -06:00
|
|
|
arg = Next();
|
2008-07-30 18:36:03 -06:00
|
|
|
}
|
2008-12-19 04:05:37 -07:00
|
|
|
|
2008-08-11 10:45:40 -06:00
|
|
|
// setup environment
|
2009-01-06 17:26:45 -07:00
|
|
|
env := new(Globals.Environment);
|
|
|
|
env.Error = &Compilation.Error;
|
2008-08-11 10:45:40 -06:00
|
|
|
env.Import = &Compilation.Import;
|
|
|
|
env.Export = &Compilation.Export;
|
|
|
|
env.Compile = &Compilation.Compile;
|
2008-12-19 04:05:37 -07:00
|
|
|
|
2008-07-30 18:36:03 -06:00
|
|
|
// compile files
|
|
|
|
for p := files.first; p != nil; p = p.next {
|
2008-08-11 19:44:41 -06:00
|
|
|
// setup compilation
|
2009-01-06 17:26:45 -07:00
|
|
|
comp := new(Globals.Compilation);
|
2008-08-11 19:44:41 -06:00
|
|
|
comp.flags = flags;
|
|
|
|
comp.env = env;
|
2008-12-19 04:05:37 -07:00
|
|
|
|
2008-08-11 19:44:41 -06:00
|
|
|
// compile
|
|
|
|
Compilation.Compile(comp, p.str);
|
2008-07-10 19:46:30 -06:00
|
|
|
}
|
|
|
|
}
|