X-Git-Url: http://nitlanguage.org diff --git a/src/compiling/compiling.nit b/src/compiling/compiling.nit index 59503a7..a063ca5 100644 --- a/src/compiling/compiling.nit +++ b/src/compiling/compiling.nit @@ -26,7 +26,7 @@ redef class MMSrcModule # 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 - meth compile_prog_to_c(tc: ToolContext) + fun compile_prog_to_c(tc: ToolContext) do for m in mhe.greaters_and_self do assert m isa MMSrcModule @@ -35,32 +35,32 @@ redef class MMSrcModule var ga = global_analysis(tc) - tc.base_dir.mkdir + tc.compdir.mkdir var files = new Array[String] var includes = new ArraySet[String] files.add("$CLIBDIR/nit_main.c") for m in mhe.greaters_and_self do assert m isa MMSrcModule - files.add("{tc.base_dir}/{m.name}.{tc.ext_prefix}_sep.c") + files.add("{tc.compdir}/{m.name}._sep.c") m.compile_separate_module(tc, ga) var native_name = m.filename.strip_extension(".nit") if (native_name + "_nit.h").file_exists then includes.add("-I {native_name.dirname}") end - native_name.append("_nit.c") + native_name += "_nit.c" if native_name.file_exists then files.add(native_name) end - files.add("{tc.base_dir}/{name}.{tc.ext_prefix}_tables.c") + files.add("{tc.compdir}/{name}._tables.c") compile_main(tc, ga) - var fn = "{tc.base_dir}/{name}.{tc.ext_prefix}_build.sh" + var fn = "{tc.compdir}/{name}._build.sh" var f = new OFStream.open(fn) f.write("#!/bin/sh\n") f.write("# This shell script is generated by NIT to compile the program {name}.\n") f.write("CLIBDIR=\"{tc.clibdir}\"\n") - f.write("{tc.bindir}/gccx -d {tc.base_dir} -I $CLIBDIR {includes.join(" ")}") + f.write("{tc.bindir}/gccx -d {tc.compdir} -I $CLIBDIR {includes.join(" ")}") if tc.output_file != null then f.write(" -o {tc.output_file}") else if tc.ext_prefix.is_empty then @@ -78,46 +78,42 @@ redef class MMSrcModule end # Compile the main file - private meth compile_main(tc: ToolContext, ga: GlobalAnalysis) + private fun compile_main(tc: ToolContext, ga: GlobalAnalysis) do - var v = new CompilerVisitor(self) - v.tc = tc - v.global_analysis = ga + var v = new GlobalCompilerVisitor(self, tc, ga) v.add_decl("#include ") compile_tables_to_c(v) compile_main_part(v) - var f = new OFStream.open("{tc.base_dir}/{name}.{tc.ext_prefix}_tables.c") + var f = new OFStream.open("{tc.compdir}/{name}._tables.c") f.write("/* This C file is generated by NIT to compile program {name}. */\n") for m in mhe.greaters_and_self do - f.write("#include \"{m.name}.{tc.ext_prefix}_sep.h\"\n") + f.write("#include \"{m.name}._sep.h\"\n") end f.write(v.to_s) f.close end # Compile the sep files (of the current module only) - private meth compile_separate_module(tc: ToolContext, ga: GlobalAnalysis) + private fun compile_separate_module(tc: ToolContext, ga: GlobalAnalysis) do - var v = new CompilerVisitor(self) - v.tc = tc - v.global_analysis = ga + var v = new GlobalCompilerVisitor(self, tc, ga) v.add_decl("#include ") var native_name = filename.strip_extension(".nit") - native_name.append("_nit.h") + native_name += ("_nit.h") 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.base_dir}/{name}.{tc.ext_prefix}_sep.h") + var f = new OFStream.open("{tc.compdir}/{name}._sep.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}.{tc.ext_prefix}_sep.h\"\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") f.close - var f = new OFStream.open("{tc.base_dir}/{name}.{tc.ext_prefix}_sep.c") + var 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}.{tc.ext_prefix}_sep.h\"\n") + f.write("#include \"{name}._sep.h\"\n") f.write(v.ctx.instrs.join("\n")) f.write("\n") f.close