File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
#include < iostream>
2
+ #include < fstream>
2
3
#include < memory>
3
4
4
5
#include < libasr/asr.h>
655
656
#include <string.h>
656
657
#include <lfortran_intrinsics.h>
657
658
659
+ #ifndef ASSERT
658
660
#define ASSERT(cond) \
659
661
{ \
660
662
if (!(cond)) { \
665
667
exit(1); \
666
668
} \
667
669
}
670
+ #endif
671
+
672
+ #ifndef ASSERT_MSG
668
673
#define ASSERT_MSG(cond, msg) \
669
674
{ \
670
675
if (!(cond)) { \
677
682
exit(1); \
678
683
} \
679
684
}
685
+ #endif
680
686
681
687
)" ;
682
688
807
813
}
808
814
src = to_include + head + array_types_decls + unit_src +
809
815
ds_funcs_defined + util_funcs_defined;
816
+ if (!emit_headers.empty ()) {
817
+ std::string to_includes_1 = " " ;
818
+ for (auto &s: headers) {
819
+ to_includes_1 += " #include <" + s + " >\n " ;
820
+ }
821
+ for (auto &f_name: emit_headers) {
822
+ std::ofstream out_file;
823
+ std::string out_src = to_includes_1 + head + f_name.second ;
824
+ std::string ifdefs = f_name.first .substr (0 , f_name.first .length () - 2 );
825
+ std::transform (ifdefs.begin (), ifdefs.end (), ifdefs.begin (), ::toupper);
826
+ ifdefs += " _H" ;
827
+ out_src = " #ifndef " + ifdefs + " \n #define " + ifdefs + " \n\n " + out_src;
828
+ out_src += " \n\n #endif\n " ;
829
+ out_file.open (f_name.first );
830
+ out_file << out_src;
831
+ out_file.close ();
832
+ }
833
+ }
810
834
}
811
835
812
836
void visit_Module (const ASR::Module_t &x) {
Original file line number Diff line number Diff line change @@ -104,6 +104,7 @@ class BaseCCPPVisitor : public ASR::BaseVisitor<Struct>
104
104
std::map<uint64_t , SymbolInfo> sym_info;
105
105
std::map<uint64_t , std::string> const_var_names;
106
106
std::map<int32_t , std::string> gotoid2name;
107
+ std::map<std::string, std::string> emit_headers;
107
108
108
109
// Output configuration:
109
110
// Use std::string or char*
@@ -622,6 +623,15 @@ R"(#include <stdio.h>
622
623
}
623
624
sub += " \n " ;
624
625
src = sub;
626
+ if (f_type->m_abi == ASR::abiType::BindC
627
+ && f_type->m_deftype == ASR::deftypeType::Implementation) {
628
+ if (x.m_c_header ) {
629
+ std::string header_name = std::string (x.m_c_header );
630
+ user_headers.insert (header_name);
631
+ emit_headers[header_name]+= " \n " + src;
632
+ src = " " ;
633
+ }
634
+ }
625
635
current_scope = current_scope_copy;
626
636
}
627
637
You can’t perform that action at this time.
0 commit comments