nitg: Added PNaCl support for Nit
[nit.git] / src / nitg.nit
index 3d2b868..7feafb2 100644 (file)
 module nitg
 
 import modelbuilder
-import exprbuilder
+import frontend
+import transform
 import rapid_type_analysis
 import global_compiler
+import separate_erasure_compiler
+import separate_compiler
+import android_platform
+import compiler_ffi
+import pnacl_platform
 
 # Create a tool context to handle options and paths
 var toolcontext = new ToolContext
+
+# Create a new option for --global
+var opt_global = new OptionBool("Use global compilation", "--global")
+toolcontext.option_context.add_option(opt_global)
+
+var opt_mixins = new OptionArray("Additionals module to min-in", "-m")
+toolcontext.option_context.add_option(opt_mixins)
+
+toolcontext.tooldescription = "Usage: nitg [OPTION]... file.nit\nCompiles Nit programs."
+
 # We do not add other options, so process them now!
-toolcontext.process_options
+toolcontext.process_options(args)
 
 # We need a model to collect stufs
 var model = new Model
@@ -33,21 +49,39 @@ var model = new Model
 var modelbuilder = new ModelBuilder(model, toolcontext)
 
 var arguments = toolcontext.option_context.rest
-if arguments.is_empty then
-       toolcontext.option_context.usage
-       return
+if arguments.length > 1 then
+       print "Too much arguments: {arguments.join(" ")}"
+       print toolcontext.tooldescription
+       exit 1
 end
 var progname = arguments.first
 
 # Here we load an process all modules passed on the command line
-var mmodules = modelbuilder.parse_and_build([progname])
+var mmodules = modelbuilder.parse([progname])
+mmodules.add_all modelbuilder.parse(opt_mixins.value)
+
 if mmodules.is_empty then return
-modelbuilder.full_propdef_semantic_analysis
+modelbuilder.run_phases
 
-if toolcontext.opt_only_metamodel.value then exit(0)
+var mainmodule
+if mmodules.length == 1 then
+       mainmodule = mmodules.first
+else
+       mainmodule = new MModule(model, null, mmodules.first.name, mmodules.first.location)
+       mainmodule.set_imported_mmodules(mmodules)
+end
+
+var platform = mainmodule.target_platform
+if platform != null and not platform.supports_libunwind then
+       if toolcontext.opt_stacktrace.value == null then toolcontext.opt_stacktrace.value = "none" # default is none
+end
 
-# Here we launch the interpreter on the main module
-assert mmodules.length == 1
-var mainmodule = mmodules.first
-var analysis = modelbuilder.do_rapid_type_analysis(mainmodule)
-modelbuilder.run_global_compiler(mainmodule, analysis)
+if toolcontext.opt_erasure.value then
+       modelbuilder.run_separate_erasure_compiler(mainmodule, null)
+else if opt_global.value then
+       var analysis = modelbuilder.do_rapid_type_analysis(mainmodule)
+       modelbuilder.run_global_compiler(mainmodule, analysis)
+else
+       var analysis = modelbuilder.do_rapid_type_analysis(mainmodule)
+       modelbuilder.run_separate_compiler(mainmodule, analysis)
+end