contrib/jwrapper: write the model to a file next to the Nit module
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 3 Aug 2015 16:33:01 +0000 (12:33 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 5 Aug 2015 01:41:51 +0000 (21:41 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/jwrapper/src/code_generator.nit
contrib/jwrapper/src/jwrapper.nit

index c942ae9..a69414e 100644 (file)
@@ -137,6 +137,17 @@ class CodeGenerator
                file_out.close
        end
 
+       # Serialize `model` to a file next to `file_name`
+       fun write_model_to_file
+       do
+               # Write the model to file next to the Nit module
+               var model_path = file_name.strip_extension + ".jwrapper.bin"
+               var model_stream = model_path.to_path.open_wo
+               var serializer = new BinarySerializer(model_stream)
+               serializer.serialize model
+               model_stream.close
+       end
+
        # License for the header of the generated Nit module
        var license = """
 # This file is part of NIT (http://www.nitlanguage.org).
index fa709c2..99536d6 100644 (file)
@@ -204,12 +204,17 @@ sys.perfs["core hierarchy"].add clock.lapse
 
 if opt_verbose.value > 0 then print "# Generating Nit code"
 
+# Generate the Nit module
 var use_comment = opt_unknown.value == 0
 var use_stub = opt_unknown.value == 1
 var generator = new CodeGenerator(out_file, model, use_comment, use_stub)
 generator.generate
 sys.perfs["code generator"].add clock.lapse
 
+# Write the model to a file, for use by subsequent passes
+generator.write_model_to_file
+sys.perfs["writing model"].add clock.lapse
+
 if opt_verbose.value > 1 then
        print "# Performance Analysis:"
        print sys.perfs