compile: when in global compilation, compile to _glob instead of _sep
authorJean-Sebastien Gelinas <calestar@gmail.com>
Thu, 27 Aug 2009 21:08:25 +0000 (17:08 -0400)
committerJean Privat <jean@pryen.org>
Tue, 1 Sep 2009 18:15:24 +0000 (14:15 -0400)
Signed-off-by: Jean-Sebastien Gelinas <calestar@gmail.com>
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiling/compiling.nit
src/compiling/compiling_global.nit
src/program.nit

index 445fc50..230f943 100644 (file)
@@ -24,7 +24,7 @@ private import compiling_icode
 
 redef class Program
        # Compile the program
-       # Generate all sep files (_sep.[ch]), the main file (_table.c) and the build file (_build.sh)
+       # 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
        do
@@ -37,7 +37,7 @@ redef class Program
                files.add("$CLIBDIR/gc_static_objects_list.c")
                tc.info("Generating C code",1)
                for m in module.mhe.greaters_and_self do
-                       files.add("{tc.compdir}/{m.name}._sep.c")
+                       files.add("{tc.compdir}/{m.name}.{get_file_ending}.c")
                        tc.info("Generating C code for module: {m.name}",2)
                        m.compile_separate_module(self)
                        var native_name = m.location.file.strip_extension(".nit")
@@ -92,7 +92,7 @@ redef class Program
                var f = new OFStream.open("{tc.compdir}/{module.name}._tables.c")
                f.write("/* This C file is generated by NIT to compile program {module.name}. */\n")
                for m in module.mhe.greaters_and_self do
-                       f.write("#include \"{m.name}._sep.h\"\n")
+                       f.write("#include \"{m.name}.{get_file_ending}.h\"\n")
                end
                f.write(v.to_s)
                f.close
@@ -100,7 +100,7 @@ redef class Program
 end
 
 redef class MMModule
-       # Compile the sep files (of the current module only)
+       # Compile the sep or glob files (of the current module only)
        private fun compile_separate_module(program: Program)
        do
                var tc = program.tc
@@ -111,20 +111,20 @@ redef class MMModule
                if native_name.file_exists then v.add_decl("#include <{native_name.basename("")}>")
                declare_class_tables_to_c(v)
                compile_mod_to_c(v)
-               var f = new OFStream.open("{tc.compdir}/{name}._sep.h")
+               var f = new OFStream.open("{tc.compdir}/{name}.{program.get_file_ending}.h")
                f.write("/* This C header file is generated by NIT to compile modules and programs that requires {name}. */\n")
-               f.write("#ifndef {name}_sep\n")
-               f.write("#define {name}_sep\n")
-               for m in mhe.direct_greaters do f.write("#include \"{m.name}._sep.h\"\n")
+               f.write("#ifndef {name}{program.get_file_ending}\n")
+               f.write("#define {name}{program.get_file_ending}\n")
+               for m in mhe.direct_greaters do f.write("#include \"{m.name}.{program.get_file_ending}.h\"\n")
                for s in v.ctx.decls do
                        f.write(s)
                end
                f.write("#endif\n")
                f.close
 
-               f = new OFStream.open("{tc.compdir}/{name}._sep.c")
+               f = new OFStream.open("{tc.compdir}/{name}.{program.get_file_ending}.c")
                f.write("/* This C file is generated by NIT to compile module {name}. */\n")
-               f.write("#include \"{name}._sep.h\"\n")
+               f.write("#include \"{name}.{program.get_file_ending}.h\"\n")
                for s in v.ctx.instrs do
                        f.write(s)
                end
index afe203f..7123ad3 100644 (file)
@@ -64,7 +64,7 @@ redef class Program
 end
 
 redef class MMModule
-       # Declare class table (for _sep.h)
+       # Declare class table (for _sep.h or _glob.h)
        fun declare_class_tables_to_c(v: CompilerVisitor)
        do
                for c in local_classes do
index 98bfb44..f0f2bb2 100644 (file)
@@ -44,6 +44,10 @@ class Program
        # Would be null if there is no main method
        readable var _main_class: nullable MMLocalClass = null
 
+       # When we are using global compilation, we generate _glob files instead
+       # of _sep files so that we do not corrupt separate compilation
+       fun get_file_ending: String do return if tc.global then "_glob" else "_sep"
+
        fun compute_main_method do
                # Check for the 'Sys' class
                var sysname = once "Sys".to_symbol