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

daisytuner / sdfglib / 18088490311

29 Sep 2025 06:54AM UTC coverage: 61.292% (-0.02%) from 61.307%
18088490311

Pull #249

github

web-flow
Merge 1125ac1f8 into 9f4a4bef7
Pull Request #249: adds arg capture types

7 of 12 new or added lines in 5 files covered. (58.33%)

1 existing line in 1 file now uncovered.

9567 of 15609 relevant lines covered (61.29%)

111.65 hits per line

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

42.99
/src/codegen/code_generators/c_style_base_code_generator.cpp
1

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

4
namespace sdfg::codegen {
5

6
CStyleBaseCodeGenerator::CStyleBaseCodeGenerator(
13✔
7
    StructuredSDFG& sdfg,
8
    InstrumentationPlan& instrumentation_plan,
9
    ArgCaptureType arg_capture_type,
10
    const std::pair<std::filesystem::path, std::filesystem::path>* output_and_header_paths
11
)
12
    : CodeGenerator(sdfg, instrumentation_plan, arg_capture_type, output_and_header_paths) {
13✔
13
    if (sdfg.type() != FunctionType_CPU) {
13✔
14
        throw std::runtime_error("CStyleBaseCodeGenerator can only be used for CPU SDFGs");
×
15
    }
16
};
13✔
17

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

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

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

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

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

45
    append_function_source(ofs_source);
×
46

47
    ofs_source.close();
×
48

49
    return true;
×
50
}
×
51

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

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

67
    if (capturePlan) {
×
NEW
68
        ofs_source << "\tstatic bool __daisy_cap_once = false;" << std::endl;
×
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);
×
NEW
86
        if (arg_capture_type_ == ArgCaptureType::ARG_CAPTURE_ONCE) {
×
NEW
87
            ofs_source << "\t__daisy_cap_once = true;" << std::endl;
×
NEW
88
        }
×
UNCOV
89
    }
×
90

91
    ofs_source << "}" << std::endl;
×
92
}
×
93

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

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

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

105
    ofs_source << "if (__daisy_cap_en && !__daisy_cap_once) {" << std::endl;
2✔
106

107
    auto afterBoolStr = after ? "true" : "false";
2✔
108

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

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

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

157
    ofs_source << "}" << std::endl;
2✔
158
}
2✔
159

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