1.1 --- a/translator.py Mon Feb 20 18:50:16 2017 +0100
1.2 +++ b/translator.py Tue Feb 21 00:20:43 2017 +0100
1.3 @@ -20,7 +20,8 @@
1.4 """
1.5
1.6 from common import CommonModule, CommonOutput, InstructionSequence, \
1.7 - first, get_builtin_class, init_item, predefined_constants
1.8 + first, get_builtin_class, init_item, is_newer, \
1.9 + predefined_constants
1.10 from encoders import encode_access_instruction, \
1.11 encode_function_pointer, encode_literal_constant, \
1.12 encode_literal_instantiator, encode_instantiator_pointer, \
1.13 @@ -45,22 +46,33 @@
1.14 self.deducer = deducer
1.15 self.optimiser = optimiser
1.16 self.output = output
1.17 - self.modules = {}
1.18
1.19 def to_output(self):
1.20 +
1.21 + "Write a program to the configured output directory."
1.22 +
1.23 + # Make a directory for the final sources.
1.24 +
1.25 output = join(self.output, "src")
1.26
1.27 if not exists(output):
1.28 makedirs(output)
1.29
1.30 + # Clean the output directory of irrelevant data.
1.31 +
1.32 self.check_output()
1.33
1.34 for module in self.importer.modules.values():
1.35 + output_filename = join(output, "%s.c" % module.name)
1.36 +
1.37 + # Do not generate modules in the native package. They are provided
1.38 + # by native functionality source files.
1.39 +
1.40 parts = module.name.split(".")
1.41 - if parts[0] != "native":
1.42 +
1.43 + if parts[0] != "native" and is_newer(module.filename, output_filename):
1.44 tm = TranslatedModule(module.name, self.importer, self.deducer, self.optimiser)
1.45 - tm.translate(module.filename, join(output, "%s.c" % module.name))
1.46 - self.modules[module.name] = tm
1.47 + tm.translate(module.filename, output_filename)
1.48
1.49 # Classes representing intermediate translation results.
1.50