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

daisytuner / sdfglib / 18186882603

02 Oct 2025 07:52AM UTC coverage: 61.116% (+0.05%) from 61.068%
18186882603

Pull #258

github

web-flow
Merge 0fbf718f8 into a12f62888
Pull Request #258: adds macro for debug prints

0 of 16 new or added lines in 5 files covered. (0.0%)

10 existing lines in 2 files now uncovered.

9569 of 15657 relevant lines covered (61.12%)

111.31 hits per line

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

45.54
/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(
13✔
9
    StructuredSDFG& sdfg,
10
    InstrumentationPlan& instrumentation_plan,
11
    bool capture_args_results,
12
    const std::pair<std::filesystem::path, std::filesystem::path>* output_and_header_paths
13
)
14
    : CodeGenerator(sdfg, instrumentation_plan, capture_args_results, output_and_header_paths) {
13✔
15
    if (sdfg.type() != FunctionType_CPU) {
13✔
16
        throw std::runtime_error("CStyleBaseCodeGenerator can only be used for CPU SDFGs");
×
17
    }
18
};
13✔
19

20
bool CStyleBaseCodeGenerator::generate() {
7✔
21
    this->dispatch_includes();
7✔
22
    this->dispatch_structures();
7✔
23
    this->dispatch_globals();
7✔
24
    this->dispatch_schedule();
7✔
25
    return true;
7✔
26
};
27

28
bool CStyleBaseCodeGenerator::as_source(const std::filesystem::path& header_path, const std::filesystem::path& source_path) {
×
29
    std::ofstream ofs_header(header_path, std::ofstream::out | std::ofstream::trunc);
×
30
    if (!ofs_header.is_open()) {
×
31
        return false;
×
32
    }
33

34
    std::ofstream ofs_source(source_path, std::ofstream::out | std::ofstream::trunc);
×
35
    if (!ofs_source.is_open()) {
×
36
        return false;
×
37
    }
38

39
    ofs_header << "#pragma once" << std::endl;
×
40
    ofs_header << this->includes_stream_.str() << std::endl;
×
41
    ofs_header << this->classes_stream_.str() << std::endl;
×
42
    ofs_header.close();
×
43

44
    ofs_source << "#include \"" << header_path.filename().string() << "\"" << std::endl;
×
45
    ofs_source << this->globals_stream_.str() << std::endl;
×
46

47
    append_function_source(ofs_source);
×
48

49
    ofs_source.close();
×
50

51
    return true;
×
52
}
×
53

54
void CStyleBaseCodeGenerator::append_function_source(std::ofstream& ofs_source) {
×
55
    std::unique_ptr<std::vector<CaptureVarPlan>> capturePlan;
×
56
    if (capture_args_results_) {
×
57
        capturePlan = create_capture_plans();
×
58
        if (capturePlan) {
×
59
            this->emit_capture_context_init(ofs_source);
×
60
        } else {
×
NEW
61
            DEBUG_PRINTLN("Cannot capture all args for SDFG '" << sdfg_.name() << "'. Skipping capture instrumentation!");
×
62
        }
63
    }
×
64

65
    ofs_source << this->function_definition() << std::endl;
×
66
    ofs_source << "{" << std::endl;
×
67

68
    if (capturePlan) {
×
69
        this->emit_arg_captures(ofs_source, *capturePlan, false);
×
70
    }
×
71

72
    auto init_once = library_snippet_factory_.find(CODE_SNIPPET_INIT_ONCE);
×
73
    if (init_once != library_snippet_factory_.snippets().end()) {
×
74
        ofs_source << init_once->second.stream().str() << std::endl;
×
75
    }
×
76

77
    ofs_source << this->main_stream_.str() << std::endl;
×
78

79
    auto deinit_once = library_snippet_factory_.find(CODE_SNIPPET_DEINIT_ONCE);
×
80
    if (deinit_once != library_snippet_factory_.snippets().end()) {
×
81
        ofs_source << deinit_once->second.stream().str() << std::endl;
×
82
    }
×
83

84
    if (capturePlan) {
×
85
        this->emit_arg_captures(ofs_source, *capturePlan, true);
×
86
    }
×
87

88
    ofs_source << "}" << std::endl;
×
89
}
×
90

91
void CStyleBaseCodeGenerator::
92
    emit_arg_captures(std::ostream& ofs_source, const std::vector<CaptureVarPlan>& plan, bool after) {
2✔
93
    std::string name = sdfg_.name();
2✔
94

95
    if (!after) {
2✔
96
        ofs_source << "const bool __daisy_cap_en = __daisy_capture_enter(__capture_ctx);" << std::endl;
1✔
97
    }
1✔
98

99
    const auto& args = sdfg_.arguments();
2✔
100
    const auto& exts = sdfg_.externals();
2✔
101

102
    ofs_source << "if (__daisy_cap_en) {" << std::endl;
2✔
103

104
    auto afterBoolStr = after ? "true" : "false";
2✔
105

106
    for (auto& varPlan : plan) {
9✔
107
        auto argIdx = varPlan.arg_idx;
7✔
108
        auto argName = varPlan.is_external ? exts[argIdx - args.size()] : args[argIdx];
7✔
109

110
        if ((!after && varPlan.capture_input) || (after && varPlan.capture_output)) {
7✔
111
            switch (varPlan.type) {
5✔
112
                case CaptureVarType::CapRaw: {
113
                    ofs_source << "\t__daisy_capture_raw(" << "__capture_ctx, " << argIdx << ", " << "&" << argName
2✔
114
                               << ", " << "sizeof(" << argName << "), " << varPlan.inner_type << ", " << afterBoolStr
2✔
115
                               << ");" << std::endl;
2✔
116
                    break;
2✔
117
                }
118
                case CaptureVarType::Cap1D: {
119
                    ofs_source << "\t__daisy_capture_1d(" << "__capture_ctx, " << argIdx << ", " << argName << ", "
2✔
120
                               << "sizeof(" << language_extension().primitive_type(varPlan.inner_type) << "), "
1✔
121
                               << varPlan.inner_type << ", " << language_extension().expression(varPlan.dim1) << ", "
1✔
122
                               << afterBoolStr << ");" << std::endl;
1✔
123
                    break;
1✔
124
                }
125
                case CaptureVarType::Cap2D: {
126
                    ofs_source << "\t__daisy_capture_2d(" << "__capture_ctx, " << argIdx << ", " << argName << ", "
4✔
127
                               << "sizeof(" << language_extension().primitive_type(varPlan.inner_type) << "), "
2✔
128
                               << varPlan.inner_type << ", " << language_extension().expression(varPlan.dim1) << ", "
2✔
129
                               << language_extension().expression(varPlan.dim2) << ", " << afterBoolStr << ");"
2✔
130
                               << std::endl;
2✔
131
                    break;
2✔
132
                }
133
                case CaptureVarType::Cap3D: {
134
                    ofs_source << "\t__daisy_capture_3d(" << "__capture_ctx, " << argIdx << ", " << argName << ", "
×
135
                               << "sizeof(" << language_extension().primitive_type(varPlan.inner_type) << "), "
×
136
                               << varPlan.inner_type << ", " << language_extension().expression(varPlan.dim1) << ", "
×
137
                               << language_extension().expression(varPlan.dim2) << ", "
×
138
                               << language_extension().expression(varPlan.dim3) << ", " << afterBoolStr << ");"
×
139
                               << std::endl;
×
140
                    break;
×
141
                }
142
                default: {
NEW
143
                    DEBUG_PRINTLN("Unknown capture type " << static_cast<int>(varPlan.type) << " for arg " << argIdx
×
144
                              << " at " << (after ? "result" : "input") << " time");
UNCOV
145
                    break;
×
146
                }
147
            }
148
        }
5✔
149
    }
7✔
150

151
    if (after) {
2✔
152
        ofs_source << "\t__daisy_capture_end(__capture_ctx);" << std::endl;
1✔
153
    }
1✔
154

155
    ofs_source << "}" << std::endl;
2✔
156
}
2✔
157

158
} // 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