From: Alexandre Terrasa Date: Sat, 8 Dec 2012 05:19:11 +0000 (-0500) Subject: nitg-s: option --use-naive-coloring now affects FT, VT and livegen fabrics coloring X-Git-Tag: v0.6~178^2~12 X-Git-Url: http://nitlanguage.org nitg-s: option --use-naive-coloring now affects FT, VT and livegen fabrics coloring Signed-off-by: Alexandre Terrasa --- diff --git a/src/coloring.nit b/src/coloring.nit index 4e4805d..b8c26d1 100644 --- a/src/coloring.nit +++ b/src/coloring.nit @@ -774,6 +774,25 @@ class VTColoring init(class_coloring: ClassColoring) do end end +class NaiveVTColoring + super VTColoring + + init(class_coloring: ClassColoring) do end + + redef fun colorize: Map[MPROP, Int] do + var mclasses = new HashSet[MClass] + mclasses.add_all(self.class_coloring.core) + mclasses.add_all(self.class_coloring.crown) + var min_color = 0 + + for mclass in mclasses do + min_color = max_color(min_color, mclasses) + colorize_elements(self.properties(mclass), min_color) + end + return self.coloration_result + end +end + # MParameterType coloring class FTColoring private var class_coloring: ClassColoring @@ -896,6 +915,25 @@ class FTColoring end end +class NaiveFTColoring + super FTColoring + + init(class_coloring: ClassColoring) do end + + redef fun colorize: Map[MParameterType, Int] do + var mclasses = new HashSet[MClass] + mclasses.add_all(self.class_coloring.core) + mclasses.add_all(self.class_coloring.crown) + var min_color = 0 + + for mclass in mclasses do + min_color = max_color(min_color, mclasses) + colorize_elements(self.fts(mclass), min_color) + end + return self.coloration_result + end +end + # Live Entries coloring class LiveEntryColoring @@ -1050,6 +1088,21 @@ class LiveEntryColoring private fun conflicts_graph: Map[MType, Set[MType]] do return conflicts_graph_cache.as(not null) end +class NaiveLiveEntryColoring + super LiveEntryColoring + + init do end + + redef fun colorize_elements(elements: Collection[MType]) do + var color = 0 + for element in elements do + coloration_result[element] = color + color += 1 + end + end +end + + # Utils # An ordered set diff --git a/src/separate_compiler.nit b/src/separate_compiler.nit index 3b20717..b75cab2 100644 --- a/src/separate_compiler.nit +++ b/src/separate_compiler.nit @@ -222,8 +222,14 @@ class SeparateCompiler self.class_coloring = new NaiveClassColoring(mainmodule) self.class_coloring.colorize(modelbuilder.model.mclasses) end + # vt coloration - var vt_coloring = new VTColoring(class_coloring) + var vt_coloring + if modelbuilder.toolcontext.opt_use_naive_coloring.value then + vt_coloring = new NaiveVTColoring(self.class_coloring) + else + vt_coloring = new VTColoring(self.class_coloring) + end self.vt_colors = vt_coloring.colorize self.vt_tables = vt_coloring.build_property_tables self.compile_color_consts(self.vt_colors) @@ -254,6 +260,7 @@ class SeparateCompiler else mclass_type = mtype.as(MClassType) end + # add virtual types to mtypes for vt in self.vt_tables[mclass_type.mclass] do if vt != null then @@ -278,13 +285,23 @@ class SeparateCompiler end # fts coloration for non-erased compilation - var ft_coloring = new FTColoring(class_coloring) + var ft_coloring + if modelbuilder.toolcontext.opt_use_naive_coloring.value then + ft_coloring = new NaiveFTColoring(self.class_coloring) + else + ft_coloring = new FTColoring(self.class_coloring) + end self.ft_colors = ft_coloring.colorize self.ft_tables = ft_coloring.build_ft_tables self.compile_color_consts(self.ft_colors.as(not null)) # colorize live entries - var entries_coloring = new LiveEntryColoring + var entries_coloring + if modelbuilder.toolcontext.opt_use_naive_coloring.value then + entries_coloring = new NaiveLiveEntryColoring + else + entries_coloring = new LiveEntryColoring + end self.livetypes_colors = entries_coloring.colorize(mtypes) self.livetypes_tables = entries_coloring.build_livetype_tables(mtypes) self.livetypes_tables_sizes = entries_coloring.livetypes_tables_sizes