Skip to content

Commit

Permalink
Merge pull request #958 from GaijinEntertainment/jit_ast_typedecl
Browse files Browse the repository at this point in the history
typeinfo(ast_typedecl) supported
  • Loading branch information
borisbat authored Feb 10, 2024
2 parents 828a876 + bfe274e commit b2931cf
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/daScript/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,7 @@ namespace das
AnnotationArgumentList options;
CodeOfPolicies policies;
vector<tuple<Module *,string,string,bool,LineInfo>> allRequireDecl;
das_hash_map<uint64_t,TypeDecl *> astTypeInfo;
};

// module parsing routines
Expand Down
1 change: 1 addition & 0 deletions include/daScript/simulate/aot_builtin_jit.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace das {
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 ();
Expand Down
2 changes: 1 addition & 1 deletion include/daScript/simulate/bind_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ public:\
// Use this if `das_enum_name` contains symbols that are not valid in C++ identifiers
#define DAS_BASE_BIND_ENUM_SAFE(enum_name, das_enum_name, safe_enum_name, ...) \
DAS_BASE_BIND_ENUM_BOTH(DAS_BIND_ENUM_QUALIFIED_HELPER, enum_name, das_enum_name, Enumeration##safe_enum_name, __VA_ARGS__)\
DAS_BASE_BIND_ENUM_FACTORY(enum_name, #das_enum_name)
DAS_BASE_BIND_ENUM_FACTORY(enum_name, #das_enum_name)
2 changes: 1 addition & 1 deletion modules/dasLLVM
1 change: 1 addition & 0 deletions src/ast/ast_simulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2914,6 +2914,7 @@ namespace das
bool Program::simulate ( Context & context, TextWriter & logs, StackAllocator * sharedStack ) {
auto time0 = ref_time_ticks();
isSimulating = true;
astTypeInfo.clear(); // this is to be filled via typeinfo(ast_typedecl and such)
auto disableInit = options.getBoolOption("no_init", policies.no_init);
context.thisProgram = this;
context.breakOnException |= policies.debugger;
Expand Down
18 changes: 17 additions & 1 deletion src/builtin/module_builtin_ast_annotations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,24 @@ namespace das {
virtual TypeDeclPtr getAstType ( ModuleLibrary & lib, const ExpressionPtr &, string & ) override {
return typeFactory<smart_ptr<TypeDecl>>::make(lib);
}
virtual SimNode * simluate ( Context * context, const ExpressionPtr & expr, string & ) override {
virtual SimNode * simluate ( Context * context, const ExpressionPtr & expr, string & error ) override {

if ( !context->thisProgram->isCompilingMacros && !context->thisProgram->folding && !daScriptEnvironment::bound->g_isInAot ) {
if ( !context->thisProgram->options.getBoolOption("rtti",context->thisProgram->policies.rtti) ) {
error = "ast_typedecl requires `options rtti` or rtti to be enabled in policies";
return nullptr;
}
}
auto exprTypeInfo = static_pointer_cast<ExprTypeInfo>(expr);
auto tName = exprTypeInfo->typeexpr->getMangledName();
auto hashValue = hash_blockz64((uint8_t *)tName.c_str());
if ( auto oldType = context->thisProgram->astTypeInfo[hashValue] ) {
if ( !oldType->isSameType(*exprTypeInfo->typeexpr,RefMatters::yes,ConstMatters::yes,TemporaryMatters::yes,AllowSubstitute::no,false,false) ) {
error = "internal compiler error. type name collision in ast_typedecl. " + oldType->describe() + " vs " + exprTypeInfo->typeexpr->describe();
return nullptr;
}
}
context->thisProgram->astTypeInfo[hashValue] = exprTypeInfo->typeexpr.get();
char * descr = context->code->allocateName(exprTypeInfo->typeexpr->getMangledName());
return context->code->makeNode<SimNode_AstGetTypeDecl>(expr->at, exprTypeInfo->typeexpr, descr);
}
Expand Down
14 changes: 14 additions & 0 deletions src/builtin/module_jit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,17 @@ extern "C" {
void jit_initialize_fileinfo ( void * dummy ) {
*(FileInfo*)dummy = FileInfo{};
}

void * jit_ast_typedecl ( uint64_t hash, Context * context, LineInfoArg * at ) {
if ( !context->thisProgram ) context->throw_error_at(at, "can't get ast_typeinfo, no program. is 'options rtti' missing?");
auto ti = context->thisProgram->astTypeInfo.find(hash);
if ( ti==context->thisProgram->astTypeInfo.end() ) {
context->throw_error_at(at, "can't find ast_typeinfo for hash %llx", hash);
}
auto info = ti->second;
info->addRef();
return (void*) info;
}
}

void *das_get_jit_exception() { return (void *)&jit_exception; }
Expand Down Expand Up @@ -287,6 +298,7 @@ extern "C" {
void *das_get_jit_debug_exit() { return (void *)&jit_debug_exit; }
void *das_get_jit_debug_line() { return (void *)&jit_debug_line; }
void *das_get_jit_initialize_fileinfo () { return (void*)&jit_initialize_fileinfo; }
void *das_get_jit_ast_typedecl () { return (void*)&jit_ast_typedecl; }

template <typename KeyType>
int32_t jit_table_at ( Table * tab, KeyType key, int32_t valueTypeSize, Context * context ) {
Expand Down Expand Up @@ -495,6 +507,8 @@ extern "C" {
SideEffects::none, "das_get_jit_iterator_next");
addExtern<DAS_BIND_FUN(das_get_jit_iterator_close)>(*this, lib, "get_jit_iterator_close",
SideEffects::none, "das_get_jit_iterator_close");
addExtern<DAS_BIND_FUN(das_get_jit_ast_typedecl)>(*this, lib, "get_jit_ast_typedecl",
SideEffects::none, "das_get_jit_ast_typedecl");
addExtern<DAS_BIND_FUN(das_get_builtin_function_address)>(*this, lib, "get_builtin_function_address",
SideEffects::none, "das_get_builtin_function_address")
->args({"fn","context","at"});
Expand Down

0 comments on commit b2931cf

Please sign in to comment.