• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / docc / 25931355994

15 May 2026 05:18PM UTC coverage: 60.837%. First build
25931355994

Pull #709

github

web-flow
Merge a3c81527d into df89083a8
Pull Request #709: Add support for tenstorrent backend to python front end

12 of 121 new or added lines in 9 files covered. (9.92%)

34996 of 57524 relevant lines covered (60.84%)

11107.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

52.13
/sdfg/src/codegen/code_generators/c_style_base_code_generator.cpp
1

2
#include "sdfg/codegen/code_generators/c_style_base_code_generator.h"
3

4
#include "sdfg/helpers/helpers.h"
5

6
namespace sdfg::codegen {
7

8
CStyleBaseCodeGenerator::CStyleBaseCodeGenerator(
9
    StructuredSDFG& sdfg,
10
    analysis::AnalysisManager& analysis_manager,
11
    InstrumentationPlan& instrumentation_plan,
12
    ArgCapturePlan& arg_capture_plan,
13
    std::shared_ptr<CodeSnippetFactory> library_snippet_factory,
14
    const std::string& externals_prefix
15
)
16
    : CodeGenerator(
19✔
17
          sdfg,
19✔
18
          analysis_manager,
19✔
19
          instrumentation_plan,
19✔
20
          arg_capture_plan,
19✔
21
          std::move(library_snippet_factory),
19✔
22
          externals_prefix
19✔
23
      ) {
19✔
24
    if (sdfg.type() != FunctionType_CPU) {
19✔
25
        throw std::runtime_error("CStyleBaseCodeGenerator can only be used for CPU SDFGs");
×
26
    }
×
27
};
19✔
28

29
bool CStyleBaseCodeGenerator::generate() {
17✔
30
    this->dispatch_includes();
17✔
31
    this->dispatch_structures();
17✔
32
    this->dispatch_globals();
17✔
33
    this->dispatch_schedule();
17✔
34
    return true;
17✔
35
}
17✔
36

37
bool CStyleBaseCodeGenerator::emit_header(PrettyPrinter& out) {
×
38
    out << "#pragma once" << std::endl;
×
39

40
    dispatch_header(out);
×
41
    return true;
×
42
}
×
43

44
void CStyleBaseCodeGenerator::dispatch_header(PrettyPrinter& out) {
×
45
    dispatch_header_includes(out);
×
46
    dispatch_header_structures(out);
×
47
}
×
48

49
void CStyleBaseCodeGenerator::dispatch_includes() { dispatch_header_includes(this->includes_stream_); }
17✔
50

51
void CStyleBaseCodeGenerator::dispatch_structures() { dispatch_header_structures(this->classes_stream_); }
17✔
52

53
bool CStyleBaseCodeGenerator::emit_main_source(std::ostream& out, const std::filesystem::path& header_path) {
×
54
    out << "#include \"" << header_path.filename().string() << "\"" << std::endl;
×
55
    dispatch_globals();
×
56
    dispatch_schedule();
×
57

58
    for (auto& snippet : library_snippet_factory_->globals_snippets()) {
×
59
        out << snippet << std::endl;
×
60
    }
×
NEW
61
    std::vector<std::string> includes;
×
NEW
62
    for (auto* dep : library_snippet_factory_->get_used_lib_dependencies()) {
×
NEW
63
        dep->enumerate_includes(includes);
×
NEW
64
    }
×
NEW
65
    for (auto& include : includes) {
×
NEW
66
        out << "#include <" << include << ">" << std::endl;
×
NEW
67
    }
×
68

69
    out << this->globals_stream_.str() << std::endl;
×
70

71
    append_function_source(out);
×
72
    return true;
×
73
}
×
74

75
bool CStyleBaseCodeGenerator::as_source(const std::filesystem::path& header_path, const std::filesystem::path& source_path) {
1✔
76
    std::ofstream ofs_header(header_path, std::ofstream::out | std::ofstream::trunc);
1✔
77
    if (!ofs_header.is_open()) {
1✔
78
        return false;
×
79
    }
×
80

81
    std::ofstream ofs_source(source_path, std::ofstream::out | std::ofstream::trunc);
1✔
82
    if (!ofs_source.is_open()) {
1✔
83
        return false;
×
84
    }
×
85

86
    ofs_header << "#pragma once" << std::endl;
1✔
87
    ofs_header << this->includes_stream_.str() << std::endl;
1✔
88
    ofs_header << this->classes_stream_.str() << std::endl;
1✔
89
    ofs_header.close();
1✔
90

91
    ofs_source << "#include \"" << header_path.filename().string() << "\"" << std::endl;
1✔
92
    for (auto& snippet : library_snippet_factory_->globals_snippets()) {
1✔
93
        ofs_source << snippet << std::endl;
×
94
    }
×
95
    ofs_source << this->globals_stream_.str() << std::endl;
1✔
96

97
    append_function_source(ofs_source);
1✔
98

99
    ofs_source.close();
1✔
100

101
    return true;
1✔
102
}
1✔
103

104
void CStyleBaseCodeGenerator::append_function_source(std::ostream& ofs_source) {
1✔
105
    std::unique_ptr<std::vector<CaptureVarPlan>> capturePlan;
1✔
106
    if (!arg_capture_plan_.is_empty()) {
1✔
107
        this->emit_capture_context_init(ofs_source);
×
108
    }
×
109

110
    ofs_source << this->function_definition() << std::endl;
1✔
111
    ofs_source << "{" << std::endl;
1✔
112

113
    auto init_once = library_snippet_factory_->find(CODE_SNIPPET_INIT_ONCE);
1✔
114
    if (init_once != library_snippet_factory_->snippets().end()) {
1✔
115
        ofs_source << init_once->second.stream().str() << std::endl;
×
116
    }
×
117

118
    for (auto& snippet : library_snippet_factory_->setup_snippets()) {
1✔
119
        ofs_source << snippet << std::endl;
×
120
    }
×
121

122
    ofs_source << this->main_stream_.str() << std::endl;
1✔
123

124
    for (auto& snippet : library_snippet_factory_->teardown_snippets()) {
1✔
125
        ofs_source << snippet << std::endl;
×
126
    }
×
127

128
    auto deinit_once = library_snippet_factory_->find(CODE_SNIPPET_DEINIT_ONCE);
1✔
129
    if (deinit_once != library_snippet_factory_->snippets().end()) {
1✔
130
        ofs_source << deinit_once->second.stream().str() << std::endl;
×
131
    }
×
132

133
    ofs_source << "}" << std::endl;
1✔
134
}
1✔
135

136
} // namespace sdfg::codegen
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc