end
redef class ModelBuilder
- fun run_separate_erasure_compiler(mainmodule: MModule, runtime_type_analysis: RapidTypeAnalysis)
+ fun run_separate_erasure_compiler(mainmodule: MModule, runtime_type_analysis: nullable RapidTypeAnalysis)
do
var time0 = get_time
- self.toolcontext.info("*** COMPILING TO C ***", 1)
+ self.toolcontext.info("*** GENERATING C ***", 1)
var compiler = new SeparateErasureCompiler(mainmodule, self, runtime_type_analysis)
compiler.compile_header
# compile class structures
+ self.toolcontext.info("Property coloring", 2)
compiler.new_file("{mainmodule.name}.tables")
compiler.do_property_coloring
for m in mainmodule.in_importation.greaters do
# compile methods
for m in mainmodule.in_importation.greaters do
+ self.toolcontext.info("Generate C for module {m}", 2)
compiler.new_file("{m.name}.sep")
compiler.compile_module_to_c(m)
end
compiler.display_stats
+ var time1 = get_time
+ self.toolcontext.info("*** END GENERATING C: {time1-time0} ***", 2)
write_and_make(compiler)
end
end
private var class_layout: nullable Layout[MClass]
protected var vt_layout: nullable Layout[MVirtualTypeProp]
- init(mainmodule: MModule, mmbuilder: ModelBuilder, runtime_type_analysis: RapidTypeAnalysis) do
+ init(mainmodule: MModule, mmbuilder: ModelBuilder, runtime_type_analysis: nullable RapidTypeAnalysis) do
super
var mclasses = new HashSet[MClass].from(mmbuilder.model.mclasses)
var layout_builder: TypingLayoutBuilder[MClass]
+ var class_colorer = new MClassColorer(mainmodule)
if modelbuilder.toolcontext.opt_phmod_typing.value then
layout_builder = new MClassHasher(new PHModOperator, mainmodule)
+ class_colorer.build_layout(mclasses)
else if modelbuilder.toolcontext.opt_phand_typing.value then
layout_builder = new MClassHasher(new PHAndOperator, mainmodule)
+ class_colorer.build_layout(mclasses)
else if modelbuilder.toolcontext.opt_bm_typing.value then
layout_builder = new MClassBMizer(mainmodule)
+ class_colorer.build_layout(mclasses)
else
- layout_builder = new MClassColorer(mainmodule)
+ layout_builder = class_colorer
end
self.class_layout = layout_builder.build_layout(mclasses)
self.class_tables = self.build_class_typing_tables(mclasses)
+ # lookup vt to build layout with
+ var vts = new HashMap[MClass, Set[MVirtualTypeProp]]
+ for mclass in mclasses do
+ vts[mclass] = new HashSet[MVirtualTypeProp]
+ for mprop in self.mainmodule.properties(mclass) do
+ if mprop isa MVirtualTypeProp then
+ vts[mclass].add(mprop)
+ end
+ end
+ end
+
# vt coloration
- var vt_coloring = new MVirtualTypePropColorer(mainmodule)
- var vt_layout = vt_coloring.build_layout(mclasses)
+ var vt_coloring = new MPropertyColorer[MVirtualTypeProp](mainmodule, class_colorer)
+ var vt_layout = vt_coloring.build_layout(vts)
self.vt_tables = build_vt_tables(mclasses, vt_layout)
self.vt_layout = vt_layout
end
for mclass in mclasses do
var table = new Array[nullable MPropDef]
# first, fill table from parents by reverse linearization order
- var parents = self.mainmodule.super_mclasses(mclass)
- var lin = self.mainmodule.reverse_linearize_mclasses(parents)
- for parent in lin do
+ var parents = new Array[MClass]
+ if mainmodule.flatten_mclass_hierarchy.has(mclass) then
+ parents = mclass.in_hierarchy(mainmodule).greaters.to_a
+ self.mainmodule.linearize_mclasses(parents)
+ end
+ for parent in parents do
+ if parent == mclass then continue
for mproperty in self.mainmodule.properties(parent) do
if not mproperty isa MVirtualTypeProp then continue
var color = layout.pos[mproperty]
var layout = self.class_layout
for mclass in mclasses do
var table = new Array[nullable MClass]
- var supers = new HashSet[MClass]
- supers.add_all(self.mainmodule.super_mclasses(mclass))
- supers.add(mclass)
+ var supers = new Array[MClass]
+ if mainmodule.flatten_mclass_hierarchy.has(mclass) then
+ supers = mclass.in_hierarchy(mainmodule).greaters.to_a
+ end
for sup in supers do
var color: Int
if layout isa PHLayout[MClass, MClass] then
do
var mtype = mclass.intro.bound_mtype
var c_name = mclass.c_name
+ var c_instance_name = mclass.c_instance_name
var vft = self.method_tables[mclass]
var attrs = self.attr_tables[mclass]
v.add_decl("\};")
if mtype.ctype != "val*" then
- #Build instance struct
- self.header.add_decl("struct instance_{c_name} \{")
- self.header.add_decl("const struct class *class;")
- self.header.add_decl("{mtype.ctype} value;")
- self.header.add_decl("\};")
+ if mtype.mclass.name == "Pointer" or mtype.mclass.kind != extern_kind then
+ #Build instance struct
+ self.header.add_decl("struct instance_{c_instance_name} \{")
+ self.header.add_decl("const struct class *class;")
+ self.header.add_decl("{mtype.ctype} value;")
+ self.header.add_decl("\};")
+ end
#Build BOX
- self.header.add_decl("val* BOX_{c_name}({mtype.ctype});")
+ self.provide_declaration("BOX_{c_name}", "val* BOX_{c_name}({mtype.ctype});")
v.add_decl("/* allocate {mtype} */")
v.add_decl("val* BOX_{mtype.c_name}({mtype.ctype} value) \{")
- v.add("struct instance_{c_name}*res = nit_alloc(sizeof(struct instance_{c_name}));")
+ v.add("struct instance_{c_instance_name}*res = nit_alloc(sizeof(struct instance_{c_instance_name}));")
v.require_declaration("class_{c_name}")
v.add("res->class = &class_{c_name};")
v.add("res->value = value;")
self.generate_init_attr(v, res, mtype)
v.add("return {res};")
v.add("\}")
-
- generate_check_init_instance(mtype)
end
private fun build_class_vts_table(mclass: MClass): Bool do
self.add("{nat} = NEW_{nclass.c_name}({array.length});")
for i in [0..array.length[ do
var r = self.autobox(array[i], self.object_type)
- self.add("((struct instance_{nclass.c_name}*){nat})->values[{i}] = (val*) {r};")
+ self.add("((struct instance_{nclass.c_instance_name}*){nat})->values[{i}] = (val*) {r};")
end
var length = self.int_instance(array.length)
self.send(self.get_property("with_native", arraytype), [res, nat, length])
- self.check_init_instance(res, arraytype)
self.add("\}")
return res
end