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
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")
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
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
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
# 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