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

daisytuner / sdfglib / 16779684622

06 Aug 2025 02:21PM UTC coverage: 64.3% (-1.0%) from 65.266%
16779684622

push

github

web-flow
Merge pull request #172 from daisytuner/opaque-pointers

Opaque pointers, typed memlets, untyped tasklet connectors

330 of 462 new or added lines in 38 files covered. (71.43%)

382 existing lines in 30 files now uncovered.

8865 of 13787 relevant lines covered (64.3%)

116.73 hits per line

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

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

18
bool CStyleBaseCodeGenerator::generate() {
9✔
19
    this->dispatch_includes();
9✔
20
    this->dispatch_structures();
9✔
21
    this->dispatch_globals();
9✔
22
    this->dispatch_schedule();
9✔
23
    return true;
9✔
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;
×
54
    if (capture_args_results_) {
×
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 (!instrumentation_plan_.is_empty()) {
×
68
        ofs_source << "__daisy_instrumentation_t* __daisy_instrumentation_ctx = __daisy_instrumentation_init();"
×
69
                   << std::endl;
×
UNCOV
70
    }
×
71

72
    if (capturePlan) {
×
73
        this->emit_arg_captures(ofs_source, *capturePlan, false);
×
UNCOV
74
    }
×
75

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

UNCOV
81
    ofs_source << this->main_stream_.str() << std::endl;
×
82

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

88
    if (capturePlan) {
×
89
        this->emit_arg_captures(ofs_source, *capturePlan, true);
×
UNCOV
90
    }
×
91

92
    if (!instrumentation_plan_.is_empty()) {
×
93
        ofs_source << "__daisy_instrumentation_finalize(__daisy_instrumentation_ctx);" << std::endl;
×
UNCOV
94
    }
×
95

96
    ofs_source << "}" << std::endl;
×
UNCOV
97
}
×
98

99
void CStyleBaseCodeGenerator::
100
    emit_arg_captures(std::ostream& ofs_source, const std::vector<CaptureVarPlan>& plan, bool after) {
2✔
101
    std::string name = sdfg_.name();
2✔
102

103
    if (!after) {
2✔
104
        ofs_source << "const bool __daisy_cap_en = __daisy_capture_enter(__capture_ctx);" << std::endl;
1✔
105
    }
1✔
106

107
    const auto& args = sdfg_.arguments();
2✔
108
    const auto& exts = sdfg_.externals();
2✔
109

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

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

114
    for (auto& varPlan : plan) {
9✔
115
        auto argIdx = varPlan.arg_idx;
7✔
116
        auto argName = varPlan.is_external ? exts[argIdx - args.size()] : args[argIdx];
7✔
117

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

158
    if (after) {
2✔
159
        ofs_source << "\t__daisy_capture_end(__capture_ctx);" << std::endl;
1✔
160
    }
1✔
161

162
    ofs_source << "}" << std::endl;
2✔
163
}
2✔
164

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