compile: add a way to choose generated output format
authorJean-Sebastien Gelinas <calestar@gmail.com>
Thu, 3 Dec 2009 20:30:22 +0000 (15:30 -0500)
committerJean Privat <jean@pryen.org>
Mon, 11 Jan 2010 21:52:34 +0000 (16:52 -0500)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiling/compiling.nit
src/nitc.nit

index 230f943..9b75317 100644 (file)
@@ -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
index 5a876be..232c404 100644 (file)
@@ -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