From a4d43b8256204a5690d28fdbacfe011ab8c4e423 Mon Sep 17 00:00:00 2001 From: Jean-Sebastien Gelinas Date: Thu, 3 Dec 2009 15:30:22 -0500 Subject: [PATCH] compile: add a way to choose generated output format Signed-off-by: Jean-Sebastien Gelinas Signed-off-by: Jean Privat --- src/compiling/compiling.nit | 15 ++++++++++++++- src/nitc.nit | 6 ++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/compiling/compiling.nit b/src/compiling/compiling.nit index 230f943..9b75317 100644 --- a/src/compiling/compiling.nit +++ b/src/compiling/compiling.nit @@ -23,7 +23,20 @@ private import compiling_global private import compiling_icode redef class Program - # Compile the program + # The type of code generation to use + readable writable var _output_format: String = "none" + + # Compile the program depending on the output format + fun compile_prog + do + if output_format == "none" then + # Nothing to do + else if output_format == "C" then + compile_prog_to_c + end + end + + # Compile the program to C # Generate all files (_sep.[ch] or _glob.[ch]), the main file (_table.c) and the build file (_build.sh) # Then execute the build.sh fun compile_prog_to_c diff --git a/src/nitc.nit b/src/nitc.nit index 5a876be..232c404 100644 --- a/src/nitc.nit +++ b/src/nitc.nit @@ -41,11 +41,12 @@ special AbstractCompiler readable var _opt_compdir: OptionString = new OptionString("Intermediate compilation directory", "--compdir") readable var _opt_extension_prefix: OptionString = new OptionString("Append prefix to file extension", "-p", "--extension-prefix") readable var _opt_dump: OptionBool = new OptionBool("Dump intermediate code", "--dump") + readable var _opt_output_format: OptionEnum = new OptionEnum(["none", "C"], "The type of code we want to be generated", 1, "--output-format") init do super("nitc") - option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_global, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix, opt_dump, opt_global_no_STF_opt, opt_global_no_DMR_opt, opt_global_callgraph, opt_global_no_inline_get_set, opt_global_no_RFIMA, opt_global_no_out_of_init_get_test_opt) + option_context.add_option(opt_output, opt_boost, opt_no_cc, opt_global, opt_clibdir, opt_bindir, opt_compdir, opt_extension_prefix, opt_dump, opt_global_no_STF_opt, opt_global_no_DMR_opt, opt_global_callgraph, opt_global_no_inline_get_set, opt_global_no_RFIMA, opt_global_no_out_of_init_get_test_opt, opt_output_format) end redef fun process_options @@ -138,6 +139,7 @@ special AbstractCompiler end for mod in mods do var p = new Program(mod, self) + p.output_format = opt_output_format.value_name p.compute_main_method p.generate_allocation_iroutines if global then @@ -150,7 +152,7 @@ special AbstractCompiler end end p.do_table_computation - p.compile_prog_to_c + p.compile_prog end end end -- 1.7.9.5