Merge: doc: fixed some typos and other misc. corrections
[nit.git] / src / nitc.nit
index 5c65f1f..83f9de3 100644 (file)
@@ -1,6 +1,6 @@
 # This file is part of NIT ( http://www.nitlanguage.org ).
 #
-# Copyright 2008 Jean Privat <jean@pryen.org>
+# Copyright 2012 Jean Privat <jean@pryen.org>
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Nit compiler main module
-package nitc
+# A Nit compiler
+module nitc
 
-import abstracttool
-private import compiling
+import frontend::code_gen
+import compiler
+import transform
 
-# The main class of the nitcompiler program
-class NitCompiler
-special AbstractCompiler
-       readable attr _opt_output: OptionString = new OptionString("Output file", "-o", "--output")
-       readable attr _opt_boost: OptionBool = new OptionBool("Optimize compilation", "-O", "--boost")
-       readable attr _opt_no_cc: OptionBool = new OptionBool("Do not invoke C compiler", "--no_cc")
-       readable attr _opt_global: OptionBool = new OptionBool("Use global compilation", "--global")
-       readable attr _opt_clibdir: OptionString = new OptionString("NIT C library directory", "--clibdir")
-       readable attr _opt_bindir: OptionString = new OptionString("NIT tools directory", "--bindir")
-       readable attr _opt_compdir: OptionString = new OptionString("Intermediate compilation directory", "--compdir")
-       readable attr _opt_extension_prefix: OptionString = new OptionString("Append prefix to file extension", "-p", "--extension-prefix")
-
-       init
+redef class ToolContext
+       redef fun process_options(args)
        do
                super
-               option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_global, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix)
-       end
-
-       redef meth process_options
-       do
-               super
-               output_file = opt_output.value
-               boost = opt_boost.value
-               no_cc = opt_no_cc.value
-               ext_prefix = opt_extension_prefix.value
-               if ext_prefix == null then ext_prefix = ""
-               global = opt_global.value
-               compdir = opt_compdir.value
-               if compdir == null then
-                       var dir = once ("NIT_COMPDIR".to_symbol).environ
-                       if not dir.is_empty then 
-                               compdir = dir
-                       end
-                       if compdir == null then
-                               compdir = ".nit_compile"
-                       end
-               end
-               compdir += ext_prefix
-
-               clibdir = opt_clibdir.value
-               if clibdir == null then
-                       var dir = once ("NIT_DIR".to_symbol).environ
-                       if dir.is_empty then 
-                               var dir = "{sys.program_name.dirname}/../lib"
-                               if dir.file_exists then clibdir = dir
-                       else
-                               dir = "{dir}/lib"
-                               if dir.file_exists then clibdir = dir
-                       end
-                       if clibdir == null then
-                               error("Error: Cannot locate NIT C library directory. Uses --clibdir or envvar NIT_DIR.")
-                               exit(1)
-                       end
-               end
-               bindir = opt_bindir.value
 
-               if bindir == null then
-                       var dir = once ("NIT_DIR".to_symbol).environ
-                       if dir.is_empty then 
-                               var dir = "{sys.program_name.dirname}/../bin"
-                               if dir.file_exists then bindir = dir
-                       else
-                               dir = "{dir}/bin"
-                               if dir.file_exists then bindir = dir
-                       end
-                       if bindir == null then
-                               error("Error: Cannot locate NIT tools directory. Uses --bindir or envvar NIT_DIR.")
-                               exit(1)
-                       end
+               var sum = opt_global.value.to_i + opt_separate.value.to_i + opt_erasure.value.to_i
+               if sum > 1 then
+                       print "Options --global, --separate and --erasure are exclusive"
+                       exit(1)
+               else if sum == 0 then
+                       # --separate by default
+                       opt_separate.value = true
                end
        end
-
-       redef meth perform_work(mods)
-       do
-               for mod in mods do
-                       assert mod isa MMSrcModule
-                       mod.compile_prog_to_c(self)
-               end
-
-       end
 end
-
-var c = new NitCompiler
-c.exec_cmd_line