package compiling
import compiling_base
-private import compiling_methods
private import compiling_global
-private import syntax
+private import compiling_icode
-redef class MMSrcModule
+redef class MMModule
# Compile the program
# Generate all sep files (_sep.[ch]), the main file (_table.c) and the build file (_build.sh)
# Then execute the build.sh
fun compile_prog_to_c(tc: ToolContext)
do
+ tc.info("Building tables",1)
for m in mhe.greaters_and_self do
- assert m isa MMSrcModule
+ tc.info("Building tables for module: {m.name}",2)
m.local_analysis(tc)
end
+ tc.info("Merging all tables",2)
var ga = global_analysis(tc)
tc.compdir.mkdir
var files = new Array[String]
var includes = new ArraySet[String]
files.add("$CLIBDIR/nit_main.c")
+ files.add("$CLIBDIR/gc.c")
+ files.add("$CLIBDIR/gc_static_objects_list.c")
+ tc.info("Generating C code",1)
for m in mhe.greaters_and_self do
- assert m isa MMSrcModule
files.add("{tc.compdir}/{m.name}._sep.c")
+ tc.info("Generating C code for module: {m.name}",2)
m.compile_separate_module(tc, ga)
- var native_name = m.filename.strip_extension(".nit")
+ var native_name = m.location.file.strip_extension(".nit")
if (native_name + "_nit.h").file_exists then
includes.add("-I {native_name.dirname}")
end
if native_name.file_exists then files.add(native_name)
end
+ tc.info("Generating main, tables and makefile ...",1)
files.add("{tc.compdir}/{name}._tables.c")
compile_main(tc, ga)
f.close
if not tc.no_cc then
+ tc.info("Building",1)
sys.system("sh {fn}")
end
end
do
var v = new GlobalCompilerVisitor(self, tc, ga)
v.add_decl("#include <nit_common.h>")
- var native_name = filename.strip_extension(".nit")
+ var native_name = location.file.strip_extension(".nit")
native_name += ("_nit.h")
if native_name.file_exists then v.add_decl("#include <{native_name.basename("")}>")
declare_class_tables_to_c(v)
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(v.ctx.decls.join("\n"))
- f.write("\n#endif\n")
+ for s in v.ctx.decls do
+ f.write(s)
+ end
+ f.write("#endif\n")
f.close
- var f = new OFStream.open("{tc.compdir}/{name}._sep.c")
+
+ f = new OFStream.open("{tc.compdir}/{name}._sep.c")
f.write("/* This C file is generated by NIT to compile module {name}. */\n")
f.write("#include \"{name}._sep.h\"\n")
- f.write(v.ctx.instrs.join("\n"))
- f.write("\n")
+ for s in v.ctx.instrs do
+ f.write(s)
+ end
f.close
end
end