Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ src/builtin/module_builtin_rtti.cpp
src/builtin/module_builtin_ast.h
src/builtin/module_builtin_uriparser.h
src/builtin/module_builtin_uriparser.cpp
src/builtin/jit_runtime.cpp
src/builtin/module_jit.cpp
src/builtin/module_builtin_fio.cpp
src/builtin/module_builtin_dasbind.cpp
Expand Down
59 changes: 52 additions & 7 deletions daslib/aot_cpp.das
Original file line number Diff line number Diff line change
Expand Up @@ -764,11 +764,17 @@ class public DebugVarCache {
}


// `\?` is `?` to a C compiler and hides the ??-sequences it would otherwise read as trigraphs
def private c_literal(s : string implicit) : string {
return escape(s) |> replace("?", "\\?")
}


def private writeAnnotationArgInit(var sb : StringBuilderWriter; arg : AnnotationArgumentInfo) {
if (arg.basicType == Type.tBool) {
write(sb, "AnnotationArgumentInfo(\"{arg.name}\", {arg.bValue})")
} elif (arg.basicType == Type.tString) {
write(sb, "AnnotationArgumentInfo(\"{arg.name}\", \"{escape(arg.sValue)}\")")
write(sb, "AnnotationArgumentInfo(\"{arg.name}\", \"{c_literal(arg.sValue)}\")")
} elif (arg.basicType == Type.tInt) {
write(sb, "AnnotationArgumentInfo(\"{arg.name}\", {arg.iValue})")
} elif (arg.basicType == Type.tFloat) {
Expand Down Expand Up @@ -855,6 +861,7 @@ class public AotDebugInfoHelper {
def str() {
return build_string() $(var writer) {
verify(info2Name.empty() && info2TypeName.empty())
annInfoNames |> clear()
helper |> debug_helper_iter_structs($(_name, ti) {
write(writer, "extern StructInfo {structInfoName(ti)};\n");
});
Expand Down Expand Up @@ -897,7 +904,6 @@ class public AotDebugInfoHelper {
write(writer, "\}\n\n")
info2Name.clear();
info2TypeName.clear();
annInfoNames |> clear()
}
}

Expand Down Expand Up @@ -2480,7 +2486,8 @@ class public CppAot : AstVisitor {
}
write(*ss, ", {vtype.get_variant_field_offset(field.fieldIndex)}, {field.fieldIndex}>::get(");
} else {
let mod_name = (vtype.structType._module.name.empty() ? "" : string(vtype.structType._module.name) + "::");
let ns = aotModuleName(vtype.structType._module);
let mod_name = (ns |> empty() ? "" : "{ns}::");
write(*ss, ",&{mod_name}{aotStructName(vtype.structType)}::{aotFieldName(string(field.name))}>::get(");
}
}
Expand Down Expand Up @@ -2771,7 +2778,7 @@ class public CppAot : AstVisitor {
write(*ss, "nullptr");
} else {
peek(c.value) $(sv) {
write(*ss, "((char *) \"{escape(sv)}\")");
write(*ss, "((char *) \"{c_literal(sv)}\")");
}
}
return c;
Expand Down Expand Up @@ -4477,6 +4484,41 @@ def private canAotModule(mod : Module?) : bool {
return ok
}

def private markTypeModules(var used : table<Module?>; var seen : table<Structure?>; t : TypeDeclPtr) {
if (t == null) {
return
}
if (t.annotation != null && t.annotation._module != null) {
used |> insert(t.annotation._module)
}
if (t.enumType != null && t.enumType._module != null) {
used |> insert(t.enumType._module)
}
markStructModules(used, seen, t.structType)
markTypeModules(used, seen, t.firstType)
markTypeModules(used, seen, t.secondType)
for (a in t.argTypes) {
markTypeModules(used, seen, a)
}
}


//! A used structure keeps its field types' modules alive: a field of a handled type is the only
//! thing that reaches the module owning it, and dropping that module drops its aot_require include.
def private markStructModules(var used : table<Module?>; var seen : table<Structure?>; st : Structure?) {
if (st == null || (seen |> key_exists(st))) {
return
}
seen |> insert(st)
if (st._module != null) {
used |> insert(st._module)
}
for (fld in st.fields) {
markTypeModules(used, seen, fld._type)
}
}


def private collectUsedModules(program : ProgramPtr) : table<Module?> {
//! Modules owning a function (externs included), struct, enum or handled type the runtime
//! program still reaches.
Expand All @@ -4496,11 +4538,14 @@ def private collectUsedModules(program : ProgramPtr) : table<Module?> {
visit(fn, adapter)
}
}
var seenStructs : table<Structure?>
for (st in keys(utm.useStructs)) {
if (st._module != null) {
used |> insert(st._module)
}
markStructModules(used, seenStructs, st)
}
// a standalone context emits its own module's structures even where nothing reaches them
program.getThisModule |> for_each_structure($(ps) {
markStructModules(used, seenStructs, ps)
})
for (en in keys(utm.useEnums)) {
if (en._module != null) {
used |> insert(en._module)
Expand Down
36 changes: 0 additions & 36 deletions include/daScript/simulate/aot_builtin_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,5 @@ namespace das {
bool das_remove_jit ( const Func func );
bool das_instrument_jit ( void * pfun, const Func func, const LineInfo & info, Context & context );
void * das_instrument_line_info ( const LineInfo & info, Context * context, LineInfoArg * at );
void * das_get_jit_exception ();
void * das_get_jit_call_or_fastcall ();
void * das_get_jit_call_with_cmres ( );
void * das_get_jit_invoke_block ( );
void * das_get_jit_invoke_block_with_cmres ( );
void * das_get_jit_string_builder ();
void * das_get_jit_string_builder_temp ();
void * das_get_jit_get_global_mnh ();
void * das_get_jit_alloc_heap ();
void * das_get_jit_alloc_persistent ();
void * das_get_jit_free_heap ();
void * das_get_jit_free_persistent ();
void * das_get_jit_array_lock ();
void * das_get_jit_array_unlock ();
void * das_get_jit_table_lock ();
void * das_get_jit_table_unlock ();
void * das_get_jit_array_resize ();
void * das_get_jit_table_at ( int32_t baseType, Context * context, LineInfoArg * at );
void * das_get_jit_table_erase ( int32_t baseType, Context * context, LineInfoArg * at );
void * das_get_jit_table_find ( int32_t baseType, Context * context, LineInfoArg * at );
void * das_get_jit_str_cmp ();
void * das_get_jit_str_cat ();
void * das_get_jit_ast_typedecl ();
void * das_get_jit_prologue ();
void * das_get_jit_epilogue ();
void * das_get_jit_make_block ();
void * das_get_jit_ad_by_sid ();
void * das_get_jit_debug ();
void * das_get_jit_iterator_iterate();
void * das_get_jit_iterator_delete();
void * das_get_jit_iterator_close();
void * das_get_jit_iterator_first();
void * das_get_jit_iterator_next();
void * das_get_builtin_function_address ( Function * fn, Context * context, LineInfoArg * at );
void * das_get_jit_debug_enter ();
void * das_get_jit_debug_exit ();
void * das_get_jit_debug_line ();
}
2 changes: 1 addition & 1 deletion include/daScript/simulate/aot_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace das {
DAS_API AotLibrary & getGlobalAotLibrary();
DAS_API void clearGlobalAotLibrary();

// makeAotJitNode builds a SimNode_Jit (defined in module_jit.cpp, where it is visible);
// makeAotJitNode builds a SimNode_Jit (defined in jit_runtime.cpp, where it is visible);
SimNode * makeAotJitNode ( Context & ctx, void * publ );

}
Expand Down
Loading
Loading