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

daisytuner / sdfglib / 18715841342

22 Oct 2025 12:16PM UTC coverage: 61.619% (+0.01%) from 61.607%
18715841342

push

github

web-flow
Merge pull request #295 from daisytuner/arg-capture-exts-functions

fixes argIdx mismatch to vector of externals

6 of 7 new or added lines in 1 file covered. (85.71%)

1 existing line in 1 file now uncovered.

9469 of 15367 relevant lines covered (61.62%)

92.35 hits per line

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

50.45
/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(
21✔
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
    const std::string& externals_prefix
14
)
15
    : CodeGenerator(sdfg, instrumentation_plan, capture_args_results, output_and_header_paths, externals_prefix) {
21✔
16
    if (sdfg.type() != FunctionType_CPU) {
21✔
17
        throw std::runtime_error("CStyleBaseCodeGenerator can only be used for CPU SDFGs");
×
18
    }
19
};
21✔
20

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

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

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

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

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

48
    append_function_source(ofs_source);
×
49

50
    ofs_source.close();
×
51

52
    return true;
×
53
}
×
54

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

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

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

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

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

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

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

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

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

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

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

103
    // filter externals by removing functions
104
    std::vector<std::string> filtered_exts;
2✔
105
    for (const auto& ext_name : exts) {
5✔
106
        if (sdfg_.type(ext_name).type_id() != types::TypeID::Function) {
3✔
107
            filtered_exts.push_back(ext_name);
3✔
108
        }
3✔
109
    }
110

111
    ofs_source << "if (__daisy_cap_en) {" << std::endl;
2✔
112

113
    auto afterBoolStr = after ? "true" : "false";
2✔
114

115
    for (auto& varPlan : plan) {
9✔
116
        auto argIdx = varPlan.arg_idx;
7✔
117
        std::string argName;
7✔
118
        if (varPlan.is_external) {
7✔
119
            argName = filtered_exts[argIdx - args.size()];
3✔
120
            argName = this->externals_prefix_ + argName;
3✔
121
        } else {
3✔
122
            argName = args[argIdx];
4✔
123
        }
124

125
        if ((!after && varPlan.capture_input) || (after && varPlan.capture_output)) {
7✔
126
            switch (varPlan.type) {
5✔
127
                case CaptureVarType::CapRaw: {
128
                    ofs_source << "\t__daisy_capture_raw(" << "__capture_ctx, " << argIdx << ", " << "&" << argName
2✔
129
                               << ", " << "sizeof(" << argName << "), " << varPlan.inner_type << ", " << afterBoolStr
2✔
130
                               << ");" << std::endl;
2✔
131
                    break;
2✔
132
                }
133
                case CaptureVarType::Cap1D: {
134
                    ofs_source << "\t__daisy_capture_1d(" << "__capture_ctx, " << argIdx << ", " << argName << ", "
2✔
135
                               << "sizeof(" << language_extension().primitive_type(varPlan.inner_type) << "), "
1✔
136
                               << varPlan.inner_type << ", " << language_extension().expression(varPlan.dim1) << ", "
1✔
137
                               << afterBoolStr << ");" << std::endl;
1✔
138
                    break;
1✔
139
                }
140
                case CaptureVarType::Cap2D: {
141
                    ofs_source << "\t__daisy_capture_2d(" << "__capture_ctx, " << argIdx << ", " << argName << ", "
4✔
142
                               << "sizeof(" << language_extension().primitive_type(varPlan.inner_type) << "), "
2✔
143
                               << varPlan.inner_type << ", " << language_extension().expression(varPlan.dim1) << ", "
2✔
144
                               << language_extension().expression(varPlan.dim2) << ", " << afterBoolStr << ");"
2✔
145
                               << std::endl;
2✔
146
                    break;
2✔
147
                }
148
                case CaptureVarType::Cap3D: {
149
                    ofs_source << "\t__daisy_capture_3d(" << "__capture_ctx, " << argIdx << ", " << argName << ", "
×
150
                               << "sizeof(" << language_extension().primitive_type(varPlan.inner_type) << "), "
×
151
                               << varPlan.inner_type << ", " << language_extension().expression(varPlan.dim1) << ", "
×
152
                               << language_extension().expression(varPlan.dim2) << ", "
×
153
                               << language_extension().expression(varPlan.dim3) << ", " << afterBoolStr << ");"
×
154
                               << std::endl;
×
155
                    break;
×
156
                }
157
                default: {
NEW
158
                    DEBUG_PRINTLN(
×
159
                        "Unknown capture type " << static_cast<int>(varPlan.type) << " for arg " << argIdx << " at "
160
                                                << (after ? "result" : "input") << " time"
161
                    );
UNCOV
162
                    break;
×
163
                }
164
            }
165
        }
5✔
166
    }
7✔
167

168
    if (after) {
2✔
169
        ofs_source << "\t__daisy_capture_end(__capture_ctx);" << std::endl;
1✔
170
    }
1✔
171

172
    ofs_source << "}" << std::endl;
2✔
173
}
2✔
174

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