From 3d1b50ef5a361d84f9f7d9f5ffb0ade5deed3623 Mon Sep 17 00:00:00 2001 From: Vipul Cariappa Date: Mon, 5 Aug 2024 09:58:56 +0530 Subject: [PATCH] skip python_bind ASR pass when using C backend --- src/bin/lpython.cpp | 1 + src/libasr/pass/python_bind.cpp | 11 ++++++++++- src/libasr/utils.h | 1 + 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bin/lpython.cpp b/src/bin/lpython.cpp index 5b08a1c9ed..971184baba 100644 --- a/src/bin/lpython.cpp +++ b/src/bin/lpython.cpp @@ -321,6 +321,7 @@ int emit_c(const std::string &infile, pass_manager.use_default_passes(true); compiler_options.po.always_run = true; compiler_options.po.run_fun = "f"; + compiler_options.po.c_backend = true; pass_manager.apply_passes(al, asr, compiler_options.po, diagnostics); diff --git a/src/libasr/pass/python_bind.cpp b/src/libasr/pass/python_bind.cpp index a56bffc53c..4174657b9e 100644 --- a/src/libasr/pass/python_bind.cpp +++ b/src/libasr/pass/python_bind.cpp @@ -361,7 +361,16 @@ void generate_body(Allocator &al, ASR::Function_t &f, SymbolTable &parent_scope) ASRUtils::get_FunctionType(f)->m_deftype = ASR::deftypeType::Implementation; } -void pass_python_bind(Allocator &al, ASR::TranslationUnit_t &unit, const PassOptions &/*pass_options*/) { +void pass_python_bind(Allocator &al, ASR::TranslationUnit_t &unit, const PassOptions &pass_options) { + if (pass_options.c_backend) { + // FIXME: C backend supports arrays, it is used in bindpy_02 to bindpy_04 tests. + // This pass currently does not handle any aggregate types. + // Once we include support for aggregate types, we should remove this check, and + // remove the `c_backend` variable from PassOptions. + // We will also need to remove the special handling of BindPython ABI in C + // backend as it would be handled by this ASR pass. + return; + } bool bindpython_used = false; for (auto &item : unit.m_symtab->get_scope()) { if (ASR::is_a(*item.second)) { diff --git a/src/libasr/utils.h b/src/libasr/utils.h index 9ff8b0f963..f035b1365d 100644 --- a/src/libasr/utils.h +++ b/src/libasr/utils.h @@ -59,6 +59,7 @@ struct PassOptions { bool tree = false; bool with_intrinsic_mods = false; bool c_mangling = false; + bool c_backend = false; }; struct CompilerOptions {