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

daisytuner / sdfglib / 15238327410

25 May 2025 01:21PM UTC coverage: 60.381% (+0.04%) from 60.342%
15238327410

Pull #32

github

web-flow
Merge 979e5bb69 into 337a208bc
Pull Request #32: Test formatting

297 of 456 new or added lines in 52 files covered. (65.13%)

19 existing lines in 15 files now uncovered.

8268 of 13693 relevant lines covered (60.38%)

99.82 hits per line

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

30.11
/src/codegen/language_extensions/c_language_extension.cpp
1
#include "sdfg/codegen/language_extensions/c_language_extension.h"
2

3
#include "sdfg/codegen/utils.h"
4
#include "sdfg/data_flow/tasklet.h"
5

6
namespace sdfg {
7
namespace codegen {
8

9
constexpr const char* code_to_string(data_flow::TaskletCode c) {
2✔
10
    switch (c) {
2✔
11
        case data_flow::TaskletCode::assign:
12
            return "=";
×
13
        case data_flow::TaskletCode::neg:
14
            return "-";
×
15
        case data_flow::TaskletCode::add:
16
            return "+";
2✔
17
        case data_flow::TaskletCode::sub:
18
            return "-";
×
19
        case data_flow::TaskletCode::mul:
20
            return "*";
×
21
        case data_flow::TaskletCode::div:
22
            return "/";
×
23
        case data_flow::TaskletCode::fma:
24
            return "__daisy_fma";
×
25
        case data_flow::TaskletCode::mod:
26
            return "%";
×
27
        case data_flow::TaskletCode::max:
28
            return "__daisy_max";
×
29
        case data_flow::TaskletCode::min:
30
            return "__daisy_min";
×
31
        case data_flow::TaskletCode::minnum:
32
            return "minnum";
×
33
        case data_flow::TaskletCode::maxnum:
34
            return "maxnum";
×
35
        case data_flow::TaskletCode::minimum:
36
            return "minimum";
×
37
        case data_flow::TaskletCode::maximum:
38
            return "maximum";
×
39
        case data_flow::TaskletCode::trunc:
40
            return "trunc";
×
41
        case data_flow::TaskletCode::logical_and:
42
            return "&&";
×
43
        case data_flow::TaskletCode::logical_or:
44
            return "||";
×
45
        case data_flow::TaskletCode::bitwise_and:
46
            return "&";
×
47
        case data_flow::TaskletCode::bitwise_or:
48
            return "|";
×
49
        case data_flow::TaskletCode::bitwise_xor:
50
            return "^";
×
51
        case data_flow::TaskletCode::bitwise_not:
52
            return "~";
×
53
        case data_flow::TaskletCode::shift_left:
54
            return "<<";
×
55
        case data_flow::TaskletCode::shift_right:
56
            return ">>";
×
57
        case data_flow::TaskletCode::olt:
58
            return "<";
×
59
        case data_flow::TaskletCode::ole:
60
            return "<=";
×
61
        case data_flow::TaskletCode::oeq:
62
            return "==";
×
63
        case data_flow::TaskletCode::one:
64
            return "!=";
×
65
        case data_flow::TaskletCode::oge:
66
            return ">=";
×
67
        case data_flow::TaskletCode::ogt:
68
            return ">";
×
69
        case data_flow::TaskletCode::ord:
70
            return "==";
×
71
        case data_flow::TaskletCode::ult:
72
            return "<";
×
73
        case data_flow::TaskletCode::ule:
74
            return "<=";
×
75
        case data_flow::TaskletCode::ueq:
76
            return "==";
×
77
        case data_flow::TaskletCode::une:
78
            return "!=";
×
79
        case data_flow::TaskletCode::uge:
80
            return ">=";
×
81
        case data_flow::TaskletCode::ugt:
82
            return ">";
×
83
        case data_flow::TaskletCode::uno:
84
            return "!=";
×
85
        case data_flow::TaskletCode::abs:
86
            return "abs";
×
87
        case data_flow::TaskletCode::acos:
88
            return "acos";
×
89
        case data_flow::TaskletCode::acosf:
90
            return "acosf";
×
91
        case data_flow::TaskletCode::acosl:
92
            return "acosl";
×
93
        case data_flow::TaskletCode::acosh:
94
            return "acosh";
×
95
        case data_flow::TaskletCode::acoshf:
96
            return "acoshf";
×
97
        case data_flow::TaskletCode::acoshl:
98
            return "acoshl";
×
99
        case data_flow::TaskletCode::asin:
100
            return "asin";
×
101
        case data_flow::TaskletCode::asinf:
102
            return "asinf";
×
103
        case data_flow::TaskletCode::asinl:
104
            return "asinl";
×
105
        case data_flow::TaskletCode::asinh:
106
            return "asinh";
×
107
        case data_flow::TaskletCode::asinhf:
108
            return "asinhf";
×
109
        case data_flow::TaskletCode::asinhl:
110
            return "asinhl";
×
111
        case data_flow::TaskletCode::atan:
112
            return "atan";
×
113
        case data_flow::TaskletCode::atanf:
114
            return "atanf";
×
115
        case data_flow::TaskletCode::atanl:
116
            return "atanl";
×
117
        case data_flow::TaskletCode::atan2:
118
            return "atan2";
×
119
        case data_flow::TaskletCode::atan2f:
120
            return "atan2f";
×
121
        case data_flow::TaskletCode::atan2l:
122
            return "atan2l";
×
123
        case data_flow::TaskletCode::atanh:
124
            return "atanh";
×
125
        case data_flow::TaskletCode::atanhf:
126
            return "atanhf";
×
127
        case data_flow::TaskletCode::atanhl:
128
            return "atanhl";
×
129
        case data_flow::TaskletCode::cabs:
130
            return "cabs";
×
131
        case data_flow::TaskletCode::cabsf:
132
            return "cabsf";
×
133
        case data_flow::TaskletCode::cabsl:
134
            return "cabsl";
×
135
        case data_flow::TaskletCode::ceil:
136
            return "ceil";
×
137
        case data_flow::TaskletCode::ceilf:
138
            return "ceilf";
×
139
        case data_flow::TaskletCode::ceill:
140
            return "ceill";
×
141
        case data_flow::TaskletCode::copysign:
142
            return "copysign";
×
143
        case data_flow::TaskletCode::copysignf:
144
            return "copysignf";
×
145
        case data_flow::TaskletCode::copysignl:
146
            return "copysignl";
×
147
        case data_flow::TaskletCode::cos:
148
            return "cos";
×
149
        case data_flow::TaskletCode::cosf:
150
            return "cosf";
×
151
        case data_flow::TaskletCode::cosl:
152
            return "cosl";
×
153
        case data_flow::TaskletCode::cosh:
154
            return "cosh";
×
155
        case data_flow::TaskletCode::coshf:
156
            return "coshf";
×
157
        case data_flow::TaskletCode::coshl:
158
            return "coshl";
×
159
        case data_flow::TaskletCode::cbrt:
160
            return "cbrt";
×
161
        case data_flow::TaskletCode::cbrtf:
162
            return "cbrtf";
×
163
        case data_flow::TaskletCode::cbrtl:
164
            return "cbrtl";
×
165
        case data_flow::TaskletCode::exp10:
166
            return "exp10";
×
167
        case data_flow::TaskletCode::exp10f:
168
            return "exp10f";
×
169
        case data_flow::TaskletCode::exp10l:
170
            return "exp10l";
×
171
        case data_flow::TaskletCode::exp2:
172
            return "exp2";
×
173
        case data_flow::TaskletCode::exp2f:
174
            return "exp2f";
×
175
        case data_flow::TaskletCode::exp2l:
176
            return "exp2l";
×
177
        case data_flow::TaskletCode::exp:
178
            return "exp";
×
179
        case data_flow::TaskletCode::expf:
180
            return "expf";
×
181
        case data_flow::TaskletCode::expl:
182
            return "expl";
×
183
        case data_flow::TaskletCode::expm1:
184
            return "expm1";
×
185
        case data_flow::TaskletCode::expm1f:
186
            return "expm1f";
×
187
        case data_flow::TaskletCode::expm1l:
188
            return "expm1l";
×
189
        case data_flow::TaskletCode::fabs:
190
            return "fabs";
×
191
        case data_flow::TaskletCode::fabsf:
192
            return "fabsf";
×
193
        case data_flow::TaskletCode::fabsl:
194
            return "fabsl";
×
195
        case data_flow::TaskletCode::floor:
196
            return "floor";
×
197
        case data_flow::TaskletCode::floorf:
198
            return "floorf";
×
199
        case data_flow::TaskletCode::floorl:
200
            return "floorl";
×
201
        case data_flow::TaskletCode::fls:
202
            return "fls";
×
203
        case data_flow::TaskletCode::flsl:
204
            return "flsl";
×
205
        case data_flow::TaskletCode::fmax:
206
            return "fmax";
×
207
        case data_flow::TaskletCode::fmaxf:
208
            return "fmaxf";
×
209
        case data_flow::TaskletCode::fmaxl:
210
            return "fmaxl";
×
211
        case data_flow::TaskletCode::fmin:
212
            return "fmin";
×
213
        case data_flow::TaskletCode::fminf:
214
            return "fminf";
×
215
        case data_flow::TaskletCode::fminl:
216
            return "fminl";
×
217
        case data_flow::TaskletCode::fmod:
218
            return "fmod";
×
219
        case data_flow::TaskletCode::fmodf:
220
            return "fmodf";
×
221
        case data_flow::TaskletCode::fmodl:
222
            return "fmodl";
×
223
        case data_flow::TaskletCode::frexp:
224
            return "frexp";
×
225
        case data_flow::TaskletCode::frexpf:
226
            return "frexpf";
×
227
        case data_flow::TaskletCode::frexpl:
228
            return "frexpl";
×
229
        case data_flow::TaskletCode::labs:
230
            return "labs";
×
231
        case data_flow::TaskletCode::ldexp:
232
            return "ldexp";
×
233
        case data_flow::TaskletCode::ldexpf:
234
            return "ldexpf";
×
235
        case data_flow::TaskletCode::ldexpl:
236
            return "ldexpl";
×
237
        case data_flow::TaskletCode::log10:
238
            return "log10";
×
239
        case data_flow::TaskletCode::log10f:
240
            return "log10f";
×
241
        case data_flow::TaskletCode::log10l:
242
            return "log10l";
×
243
        case data_flow::TaskletCode::log2:
244
            return "log2";
×
245
        case data_flow::TaskletCode::log2f:
246
            return "log2f";
×
247
        case data_flow::TaskletCode::log2l:
248
            return "log2l";
×
249
        case data_flow::TaskletCode::log:
250
            return "log";
×
251
        case data_flow::TaskletCode::logf:
252
            return "logf";
×
253
        case data_flow::TaskletCode::logl:
254
            return "logl";
×
255
        case data_flow::TaskletCode::logb:
256
            return "logb";
×
257
        case data_flow::TaskletCode::logbf:
258
            return "logbf";
×
259
        case data_flow::TaskletCode::logbl:
260
            return "logbl";
×
261
        case data_flow::TaskletCode::log1p:
262
            return "log1p";
×
263
        case data_flow::TaskletCode::log1pf:
264
            return "log1pf";
×
265
        case data_flow::TaskletCode::log1pl:
266
            return "log1pl";
×
267
        case data_flow::TaskletCode::modf:
268
            return "modf";
×
269
        case data_flow::TaskletCode::modff:
270
            return "modff";
×
271
        case data_flow::TaskletCode::modfl:
272
            return "modfl";
×
273
        case data_flow::TaskletCode::nearbyint:
274
            return "nearbyint";
×
275
        case data_flow::TaskletCode::nearbyintf:
276
            return "nearbyintf";
×
277
        case data_flow::TaskletCode::nearbyintl:
278
            return "nearbyintl";
×
279
        case data_flow::TaskletCode::pow:
280
            return "pow";
×
281
        case data_flow::TaskletCode::powf:
282
            return "powf";
×
283
        case data_flow::TaskletCode::powl:
284
            return "powl";
×
285
        case data_flow::TaskletCode::rint:
286
            return "rint";
×
287
        case data_flow::TaskletCode::rintf:
288
            return "rintf";
×
289
        case data_flow::TaskletCode::rintl:
290
            return "rintl";
×
291
        case data_flow::TaskletCode::round:
292
            return "round";
×
293
        case data_flow::TaskletCode::roundf:
294
            return "roundf";
×
295
        case data_flow::TaskletCode::roundl:
296
            return "roundl";
×
297
        case data_flow::TaskletCode::roundeven:
298
            return "roundeven";
×
299
        case data_flow::TaskletCode::roundevenf:
300
            return "roundevenf";
×
301
        case data_flow::TaskletCode::roundevenl:
302
            return "roundevenl";
×
303
        case data_flow::TaskletCode::sin:
304
            return "sin";
×
305
        case data_flow::TaskletCode::sinf:
306
            return "sinf";
×
307
        case data_flow::TaskletCode::sinl:
308
            return "sinl";
×
309
        case data_flow::TaskletCode::sinh:
310
            return "sinh";
×
311
        case data_flow::TaskletCode::sinhf:
312
            return "sinhf";
×
313
        case data_flow::TaskletCode::sinhl:
314
            return "sinhl";
×
315
        case data_flow::TaskletCode::sqrt:
316
            return "sqrt";
×
317
        case data_flow::TaskletCode::sqrtf:
318
            return "sqrtf";
×
319
        case data_flow::TaskletCode::sqrtl:
320
            return "sqrtl";
×
321
        case data_flow::TaskletCode::tan:
322
            return "tan";
×
323
        case data_flow::TaskletCode::tanf:
324
            return "tanf";
×
325
        case data_flow::TaskletCode::tanl:
326
            return "tanl";
×
327
        case data_flow::TaskletCode::tanh:
328
            return "tanh";
×
329
        case data_flow::TaskletCode::tanhf:
330
            return "tanhf";
×
331
        case data_flow::TaskletCode::tanhl:
332
            return "tanhl";
×
333
    };
334
    throw std::invalid_argument("Invalid tasklet code");
×
335
};
2✔
336

337
std::string CLanguageExtension::primitive_type(const types::PrimitiveType prim_type) {
35✔
338
    switch (prim_type) {
35✔
339
        case types::PrimitiveType::Void:
340
            return "void";
1✔
341
        case types::PrimitiveType::Bool:
342
            return "bool";
1✔
343
        case types::PrimitiveType::Int8:
344
            return "signed char";
1✔
345
        case types::PrimitiveType::Int16:
346
            return "short";
1✔
347
        case types::PrimitiveType::Int32:
348
            return "int";
18✔
349
        case types::PrimitiveType::Int64:
350
            return "long long";
1✔
351
        case types::PrimitiveType::UInt8:
352
            return "char";
3✔
353
        case types::PrimitiveType::UInt16:
354
            return "unsigned short";
1✔
355
        case types::PrimitiveType::UInt32:
356
            return "unsigned int";
1✔
357
        case types::PrimitiveType::UInt64:
358
            return "unsigned long long";
1✔
359
        case types::PrimitiveType::Half:
360
            return "__fp16";
×
361
        case types::PrimitiveType::BFloat:
362
            return "__bf16";
×
363
        case types::PrimitiveType::Float:
364
            return "float";
5✔
365
        case types::PrimitiveType::Double:
366
            return "double";
1✔
367
        case types::PrimitiveType::X86_FP80:
368
            return "__float80";
×
369
        case types::PrimitiveType::FP128:
370
            return "__float128";
×
371
        case types::PrimitiveType::PPC_FP128:
372
            return "__float128";
×
373
    }
374

375
    throw std::runtime_error("Unknown primitive type");
×
376
};
35✔
377

378
std::string CLanguageExtension::declaration(const std::string& name, const types::IType& type,
38✔
379
                                            bool use_initializer) {
380
    std::stringstream val;
38✔
381

382
    if (auto scalar_type = dynamic_cast<const types::Scalar*>(&type)) {
38✔
383
        val << primitive_type(scalar_type->primitive_type());
23✔
384
        val << " ";
23✔
385
        val << name;
23✔
386
    } else if (auto array_type = dynamic_cast<const types::Array*>(&type)) {
38✔
387
        auto& element_type = array_type->element_type();
3✔
388
        val << declaration(name + "[" + this->expression(array_type->num_elements()) + "]",
3✔
389
                           element_type);
3✔
390
        if (array_type->alignment() > 1) {
3✔
391
            val << " __attribute__((aligned(" << array_type->alignment() << ")))";
×
392
        }
×
393
    } else if (auto pointer_type = dynamic_cast<const types::Pointer*>(&type)) {
15✔
394
        auto& pointee_type = pointer_type->pointee_type();
8✔
395
        val << declaration("(*" + name + ")", pointee_type);
8✔
396
    } else if (auto ref_type = dynamic_cast<const Reference*>(&type)) {
12✔
397
        val << declaration("&" + name, ref_type->reference_type());
×
398
    } else if (auto structure_type = dynamic_cast<const types::Structure*>(&type)) {
4✔
399
        val << structure_type->name();
4✔
400
        val << " ";
4✔
401
        val << name;
4✔
402
    } else if (auto function_type = dynamic_cast<const types::Function*>(&type)) {
4✔
403
        val << declaration("", function_type->return_type());
×
404
        val << " ";
×
405
        val << name;
×
406
        val << "(";
×
407
        for (size_t i = 0; i < function_type->num_params(); ++i) {
×
408
            val << declaration("", function_type->param_type(symbolic::integer(i)));
×
409
            if (i < function_type->num_params() - 1) {
×
410
                val << ", ";
×
411
            }
×
412
        }
×
413
        if (function_type->is_var_arg()) {
×
414
            if (function_type->num_params() > 0) {
×
415
                val << ", ";
×
416
            }
×
417
            val << "...";
×
418
        }
×
419
        val << ")";
×
420
    } else {
×
421
        throw std::runtime_error("Unknown declaration type");
×
422
    }
423

424
    if (use_initializer && !type.initializer().empty()) {
38✔
425
        val << " = " << type.initializer();
×
426
    }
×
427

428
    return val.str();
38✔
429
};
38✔
430

431
std::string CLanguageExtension::allocation(const std::string& name, const types::IType& type) {
5✔
432
    std::stringstream val;
5✔
433

434
    if (dynamic_cast<const types::Scalar*>(&type)) {
5✔
435
        val << declaration(name, type);
1✔
436
    } else if (auto array_type = dynamic_cast<const types::Array*>(&type)) {
5✔
437
        val << declaration(name + "[" + this->expression(array_type->num_elements()) + "]",
2✔
438
                           array_type->element_type());
1✔
439
    } else if (auto pointer_type = dynamic_cast<const types::Pointer*>(&type)) {
4✔
440
        val << declaration(name, type);
2✔
441
        val << " = (" << declaration("", type) << ") ";
2✔
442
        val << "malloc(";
2✔
443
        if (auto array_type = dynamic_cast<const types::Array*>(&pointer_type->pointee_type())) {
2✔
444
            val << this->expression(array_type->num_elements());
×
445
        } else {
×
446
            val << "1";
2✔
447
        }
448
        val << " * sizeof(";
2✔
449
        val << declaration("", pointer_type->pointee_type());
2✔
450
        val << "))";
2✔
451
    } else if (dynamic_cast<const types::Structure*>(&type)) {
3✔
452
        val << declaration(name, type);
1✔
453
    } else {
1✔
454
        throw std::runtime_error("Unknown allocation type");
×
455
    }
456

457
    return val.str();
5✔
458
};
5✔
459

460
std::string CLanguageExtension::deallocation(const std::string& name, const types::IType& type) {
5✔
461
    std::stringstream val;
5✔
462

463
    if (dynamic_cast<const types::Scalar*>(&type)) {
5✔
464
        // Do nothing
465
    } else if (dynamic_cast<const types::Array*>(&type)) {
5✔
466
        // Do nothing
467
    } else if (dynamic_cast<const types::Pointer*>(&type)) {
4✔
468
        val << "free(" << name << ")";
2✔
469
    } else if (dynamic_cast<const types::Structure*>(&type)) {
3✔
470
        // Do nothing
471
    } else {
1✔
472
        throw std::runtime_error("Unknown deallocation type");
×
473
    }
474

475
    return val.str();
5✔
476
};
5✔
477

478
std::string CLanguageExtension::type_cast(const std::string& name, const types::IType& type) {
1✔
479
    std::stringstream val;
1✔
480

481
    val << "(";
1✔
482
    val << declaration("", type);
1✔
483
    val << ") ";
1✔
484
    val << name;
1✔
485

486
    return val.str();
1✔
487
};
1✔
488

489
std::string CLanguageExtension::subset(const Function& function, const types::IType& type,
9✔
490
                                       const data_flow::Subset& sub) {
491
    if (sub.empty()) {
9✔
492
        return "";
1✔
493
    }
494

495
    if (dynamic_cast<const types::Scalar*>(&type)) {
8✔
496
        return "";
6✔
497
    } else if (auto array_type = dynamic_cast<const types::Array*>(&type)) {
2✔
498
        std::string subset_str = "[" + this->expression(sub.at(0)) + "]";
1✔
499

500
        if (sub.size() > 1) {
1✔
501
            data_flow::Subset element_subset(sub.begin() + 1, sub.end());
×
502
            auto& element_type = array_type->element_type();
×
503
            return subset_str + subset(function, element_type, element_subset);
×
504
        } else {
×
505
            return subset_str;
1✔
506
        }
507
    } else if (auto pointer_type = dynamic_cast<const types::Pointer*>(&type)) {
2✔
508
        std::string subset_str = "[" + this->expression(sub.at(0)) + "]";
×
509

510
        data_flow::Subset element_subset(sub.begin() + 1, sub.end());
×
511
        auto& pointee_type = pointer_type->pointee_type();
×
512
        return subset_str + subset(function, pointee_type, element_subset);
×
513
    } else if (auto structure_type = dynamic_cast<const types::Structure*>(&type)) {
1✔
514
        auto& definition = function.structure(structure_type->name());
1✔
515

516
        std::string subset_str = ".member_" + this->expression(sub.at(0));
1✔
517
        if (sub.size() > 1) {
1✔
518
            auto member = SymEngine::rcp_dynamic_cast<const SymEngine::Integer>(sub.at(0));
×
519
            auto& member_type = definition.member_type(member);
×
520
            data_flow::Subset element_subset(sub.begin() + 1, sub.end());
×
521
            return subset_str + subset(function, member_type, element_subset);
×
522
        } else {
×
523
            return subset_str;
1✔
524
        }
525
    }
1✔
526

527
    throw std::invalid_argument("Invalid subset type");
×
528
};
9✔
529

530
std::string CLanguageExtension::expression(const symbolic::Expression& expr) {
29✔
531
    CSymbolicPrinter printer;
29✔
532
    return printer.apply(expr);
29✔
533
};
29✔
534

535
std::string CLanguageExtension::tasklet(const data_flow::Tasklet& tasklet) {
2✔
536
    std::string op = code_to_string(tasklet.code());
2✔
537
    std::vector<std::string> arguments;
2✔
538
    for (size_t i = 0; i < tasklet.inputs().size(); ++i) {
6✔
539
        std::string arg = tasklet.input(i).first;
4✔
540
        if (!tasklet.needs_connector(i)) {
4✔
541
            if (arg != "NAN" && arg != "INFINITY") {
×
542
                if (tasklet.input(i).second.primitive_type() == types::PrimitiveType::Float) {
×
543
                    arg += "f";
×
544
                }
×
545
            }
×
546
        }
×
547
        arguments.push_back(arg);
4✔
548
    }
4✔
549

550
    if (tasklet.code() == data_flow::TaskletCode::assign) {
2✔
551
        return arguments.at(0);
×
552
    } else if (data_flow::is_infix(tasklet.code())) {
2✔
553
        switch (data_flow::arity(tasklet.code())) {
2✔
554
            case 1:
555
                return op + arguments.at(0);
×
556
            case 2:
557
                return arguments.at(0) + " " + op + " " + arguments.at(1);
2✔
558
            default:
559
                throw std::runtime_error("Unsupported arity");
×
560
        }
561
    } else {
562
        return op + "(" + helpers::join(arguments, ", ") + ")";
×
563
    }
564
};
2✔
565

566
std::string CLanguageExtension::library_node(const data_flow::LibraryNode& libnode) {
×
567
    data_flow::LibraryNodeType lib_node_type = libnode.call();
×
568
    switch (lib_node_type) {
×
569
        default:
570
            throw std::runtime_error("Unsupported library node type");
×
571
    }
572
}
×
573

574
void CSymbolicPrinter::bvisit(const SymEngine::Infty& x) {
×
575
    if (x.is_negative_infinity())
×
576
        str_ = "-INFINITY";
×
577
    else if (x.is_positive_infinity())
×
578
        str_ = "INFINITY";
×
579
};
×
580

581
void CSymbolicPrinter::bvisit(const SymEngine::BooleanAtom& x) {
11✔
582
    str_ = x.get_val() ? "true" : "false";
11✔
583
};
11✔
584

585
void CSymbolicPrinter::bvisit(const SymEngine::Symbol& x) {
7✔
586
    if (symbolic::is_nullptr(symbolic::symbol(x.get_name()))) {
7✔
587
        str_ = "NULL";
×
588
        return;
×
589
    } else if (symbolic::is_memory_address(symbolic::symbol(x.get_name()))) {
7✔
590
        // symbol of form reinterpret_cast<T*>(0x1234)
591
        str_ = x.get_name();
×
592
        return;
×
593
    }
594
    str_ = x.get_name();
7✔
595
};
7✔
596

597
void CSymbolicPrinter::bvisit(const SymEngine::And& x) {
×
598
    std::ostringstream s;
×
599
    auto container = x.get_container();
×
600
    s << apply(*container.begin());
×
601
    for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
602
        s << " && " << apply(*it);
×
603
    }
×
604
    str_ = parenthesize(s.str());
×
605
};
×
606

607
void CSymbolicPrinter::bvisit(const SymEngine::Or& x) {
×
608
    std::ostringstream s;
×
609
    auto container = x.get_container();
×
610
    s << apply(*container.begin());
×
611
    for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
612
        s << " || " << apply(*it);
×
613
    }
×
614
    str_ = parenthesize(s.str());
×
615
};
×
616

617
void CSymbolicPrinter::bvisit(const SymEngine::Not& x) {
×
618
    str_ = "!" + apply(x.get_arg());
×
619
    str_ = parenthesize(str_);
×
620
};
×
621

622
void CSymbolicPrinter::bvisit(const SymEngine::Equality& x) {
1✔
623
    str_ = apply(x.get_args()[0]) + " == " + apply(x.get_args()[1]);
1✔
624
    str_ = parenthesize(str_);
1✔
625
};
1✔
626

627
void CSymbolicPrinter::bvisit(const SymEngine::Unequality& x) {
1✔
628
    str_ = apply(x.get_args()[0]) + " != " + apply(x.get_args()[1]);
1✔
629
    str_ = parenthesize(str_);
1✔
630
};
1✔
631

632
void CSymbolicPrinter::bvisit(const SymEngine::Min& x) {
×
633
    std::ostringstream s;
×
634
    auto container = x.get_args();
×
635
    if (container.size() == 1) {
×
636
        s << apply(*container.begin());
×
637
    } else {
×
638
        s << "__daisy_min(";
×
639
        s << apply(*container.begin());
×
640

641
        // Recursively apply __daisy_min to the arguments
642
        SymEngine::vec_basic subargs;
×
643
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
644
            subargs.push_back(*it);
×
645
        }
×
646
        auto submin = SymEngine::min(subargs);
×
647
        s << ", " << apply(submin);
×
648

649
        s << ")";
×
650
    }
×
651

652
    str_ = s.str();
×
653
};
×
654

655
void CSymbolicPrinter::bvisit(const SymEngine::Max& x) {
×
656
    std::ostringstream s;
×
657
    auto container = x.get_args();
×
658
    if (container.size() == 1) {
×
659
        s << apply(*container.begin());
×
660
    } else {
×
661
        s << "__daisy_max(";
×
662
        s << apply(*container.begin());
×
663

664
        // Recursively apply __daisy_max to the arguments
665
        SymEngine::vec_basic subargs;
×
666
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
667
            subargs.push_back(*it);
×
668
        }
×
669
        auto submax = SymEngine::max(subargs);
×
670
        s << ", " << apply(submax);
×
671

672
        s << ")";
×
673
    }
×
674

675
    str_ = s.str();
×
676
};
×
677

NEW
678
void CSymbolicPrinter::_print_pow(std::ostringstream& o,
×
679
                                  const SymEngine::RCP<const SymEngine::Basic>& a,
680
                                  const SymEngine::RCP<const SymEngine::Basic>& b) {
681
    if (SymEngine::eq(*a, *SymEngine::E)) {
×
682
        o << "exp(" << apply(b) << ")";
×
683
    } else if (SymEngine::eq(*b, *SymEngine::rational(1, 2))) {
×
684
        o << "sqrt(" << apply(a) << ")";
×
685
    } else if (SymEngine::eq(*b, *SymEngine::rational(1, 3))) {
×
686
        o << "cbrt(" << apply(a) << ")";
×
687
    } else if (SymEngine::eq(*b, *SymEngine::integer(2))) {
×
688
        o << apply(a) + " * " + apply(a);
×
689
    } else {
×
690
        o << "pow(" << apply(a) << ", " << apply(b) << ")";
×
691
    }
692
};
×
693

694
}  // namespace codegen
695
}  // namespace sdfg
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