Skip to content

Commit

Permalink
refactor plugin system
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-kenzel committed Jul 5, 2023
1 parent 54f4e34 commit 2217abb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions src/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,10 @@ const thorin::Def* FnDecl::emit(Emitter& emitter) const {
} else if (auto import_attr = attrs->find("import")) {
if (auto name_attr = import_attr->find("name"))
cont->set_name(name_attr->as<LiteralAttr>()->lit.as_string());
if (auto depends_attr = import_attr->find("depends")) {
auto depends = depends_attr->as<PathAttr>();
depends->path.emit(emitter)->as<thorin::Continuation>();
}
if (auto cc_attr = import_attr->find("cc")) {
auto cc = cc_attr->as<LiteralAttr>()->lit.as_string();
if (cc == "device") {
Expand All @@ -1687,14 +1691,11 @@ const thorin::Def* FnDecl::emit(Emitter& emitter) const {
} else if (cc == "thorin")
cont->set_intrinsic();
else if (cc == "plugin")
cont->attributes().intrinsic = thorin::Intrinsic::Plugin;
// any depends are guaranteed to be emitted earlier
emitter.world.link_plugin_intrinsic(cont);
else if (cc == "builtin")
emitter.builtin(*this, cont);
}
if (auto depends_attr = import_attr->find("depends")) {
auto depends = depends_attr->as<PathAttr>();
cont->attributes().depends = depends->path.emit(emitter)->as<thorin::Continuation>();
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ int main(int argc, char** argv) {
world.set(opts.log_level);
world.set(std::make_shared<thorin::Stream>(std::cerr));

for (auto plugin_to_load : opts.plugin_files) {
world.register_plugin(plugin_to_load.c_str());
}

ast::ModDecl program;
bool success = compile(
opts.files, file_data,
Expand All @@ -322,10 +326,6 @@ int main(int argc, char** argv) {
if (!success)
return EXIT_FAILURE;

for (auto plugin_to_load : opts.plugin_files) {
world.register_plugin(plugin_to_load);
}

if (opts.opt_level == 1)
world.cleanup();
if (opts.emit_c_int) {
Expand Down

0 comments on commit 2217abb

Please sign in to comment.