From a33a9ff72253f8b61e95167ce6179f349a50890a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sat, 22 Feb 2014 13:11:33 -0500 Subject: [PATCH] nitg: extract toolchain methods into a new ToolChain class MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- src/abstract_compiler.nit | 60 +++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/src/abstract_compiler.nit b/src/abstract_compiler.nit index c8454e5..f900351 100644 --- a/src/abstract_compiler.nit +++ b/src/abstract_compiler.nit @@ -68,6 +68,29 @@ redef class ToolContext end redef class ModelBuilder + redef init(model, toolcontext) + do + if toolcontext.opt_no_stacktrace.value and toolcontext.opt_stacktrace.value then + print "Cannot use --nit-stacktrace when --no-stacktrace is activated" + exit(1) + end + + super + end + + # The compilation directory + var compile_dir: String + + # Simple indirection to `Toolchain::write_and_make` + protected fun write_and_make(compiler: AbstractCompiler) + do + var toolchain = new MakefileToolchain(toolcontext) + compile_dir = toolchain.compile_dir + toolchain.write_and_make compiler + end +end + +class MakefileToolchain # The list of directories to search for included C headers (-I for C compilers) # The list is initially set with : # * the toolcontext --cc-path option @@ -75,11 +98,17 @@ redef class ModelBuilder # * some heuristics including the NIT_DIR environment variable and the progname of the process # Path can be added (or removed) by the client var cc_paths = new Array[String] + var toolcontext: ToolContext - redef init(model, toolcontext) + fun compile_dir: String do - super + var compile_dir = toolcontext.opt_compile_dir.value + if compile_dir == null then compile_dir = ".nit_compile" + return compile_dir + end + protected fun gather_cc_paths + do # Look for the the Nit clib path var path_env = "NIT_DIR".environ if not path_env.is_empty then @@ -94,11 +123,6 @@ redef class ModelBuilder toolcontext.error(null, "Cannot determine the nit clib path. define envvar NIT_DIR.") end - if toolcontext.opt_no_stacktrace.value and toolcontext.opt_stacktrace.value then - print "Cannot use --nit-stacktrace when --no-stacktrace is activated" - exit(1) - end - # Add user defined cc_paths cc_paths.append(toolcontext.opt_cc_path.value) @@ -106,18 +130,14 @@ redef class ModelBuilder if not path_env.is_empty then cc_paths.append(path_env.split_with(':')) end - - var compile_dir = toolcontext.opt_compile_dir.value - if compile_dir == null then compile_dir = ".nit_compile" - self.compile_dir = compile_dir end - # The compilation directory - var compile_dir: String - - protected fun write_and_make(compiler: AbstractCompiler) + fun write_and_make(compiler: AbstractCompiler) do + gather_cc_paths + var mainmodule = compiler.mainmodule + var compile_dir = compile_dir # Generate the .h and .c files # A single C file regroups many compiled rumtime functions @@ -161,8 +181,9 @@ redef class ModelBuilder compiler.files_to_copy.add "{cc_paths.first}/gc_chooser.h" # FFI - for m in compiler.mainmodule.in_importation.greaters do if mmodule2nmodule.keys.has(m) then - var amodule = mmodule2nmodule[m] + var m2m = toolcontext.modelbuilder.mmodule2nmodule + for m in compiler.mainmodule.in_importation.greaters do if m2m.keys.has(m) then + var amodule = m2m[m] if m.uses_ffi or amodule.uses_legacy_ni then compiler.finalize_ffi_for_module(amodule) end @@ -258,8 +279,9 @@ redef class ModelBuilder end var linker_options = new HashSet[String] - for m in mainmodule.in_importation.greaters do if mmodule2nmodule.keys.has(m) then - var amod = mmodule2nmodule[m] + var m2m = toolcontext.modelbuilder.mmodule2nmodule + for m in mainmodule.in_importation.greaters do if m2m.keys.has(m) then + var amod = m2m[m] linker_options.add(amod.c_linker_options) end -- 1.7.9.5