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

daisytuner / sdfglib / 15334392758

29 May 2025 09:56PM UTC coverage: 58.324% (-0.01%) from 58.336%
15334392758

push

github

web-flow
Merge pull request #42 from daisytuner/alignment

removes alignment from declarations

7 of 17 new or added lines in 3 files covered. (41.18%)

1 existing line in 1 file now uncovered.

7939 of 13612 relevant lines covered (58.32%)

110.86 hits per line

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

29.28
/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::Int128:
352
            return "__int128";
×
353
        case types::PrimitiveType::UInt8:
354
            return "char";
3✔
355
        case types::PrimitiveType::UInt16:
356
            return "unsigned short";
1✔
357
        case types::PrimitiveType::UInt32:
358
            return "unsigned int";
1✔
359
        case types::PrimitiveType::UInt64:
360
            return "unsigned long long";
1✔
361
        case types::PrimitiveType::UInt128:
362
            return "unsigned __int128";
×
363
        case types::PrimitiveType::Half:
364
            return "__fp16";
×
365
        case types::PrimitiveType::BFloat:
366
            return "__bf16";
×
367
        case types::PrimitiveType::Float:
368
            return "float";
5✔
369
        case types::PrimitiveType::Double:
370
            return "double";
1✔
371
        case types::PrimitiveType::X86_FP80:
372
            return "__float80";
×
373
        case types::PrimitiveType::FP128:
374
            return "__float128";
×
375
        case types::PrimitiveType::PPC_FP128:
376
            return "__float128";
×
377
    }
378

379
    throw std::runtime_error("Unknown primitive type");
×
380
};
35✔
381

382
std::string CLanguageExtension::declaration(const std::string& name, const types::IType& type,
38✔
383
                                            bool use_initializer) {
384
    std::stringstream val;
38✔
385

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

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

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

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

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

468
    return val.str();
5✔
469
};
5✔
470

471
std::string CLanguageExtension::deallocation(const std::string& name, const types::IType& type) {
5✔
472
    std::stringstream val;
5✔
473

474
    if (dynamic_cast<const types::Scalar*>(&type)) {
5✔
475
        // Do nothing
476
    } else if (dynamic_cast<const types::Array*>(&type)) {
5✔
477
        // Do nothing
478
    } else if (dynamic_cast<const types::Pointer*>(&type)) {
4✔
479
        val << "free(" << name << ")";
2✔
480
    } else if (dynamic_cast<const types::Structure*>(&type)) {
3✔
481
        // Do nothing
482
    } else {
1✔
483
        throw std::runtime_error("Unknown deallocation type");
×
484
    }
485

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

489
std::string CLanguageExtension::type_cast(const std::string& name, const types::IType& type) {
1✔
490
    std::stringstream val;
1✔
491

492
    val << "(";
1✔
493
    val << declaration("", type);
1✔
494
    val << ") ";
1✔
495
    val << name;
1✔
496

497
    return val.str();
1✔
498
};
1✔
499

500
std::string CLanguageExtension::subset(const Function& function, const types::IType& type,
9✔
501
                                       const data_flow::Subset& sub) {
502
    if (sub.empty()) {
9✔
503
        return "";
7✔
504
    }
505

506
    if (dynamic_cast<const types::Scalar*>(&type)) {
2✔
507
        return "";
×
508
    } else if (auto array_type = dynamic_cast<const types::Array*>(&type)) {
2✔
509
        std::string subset_str = "[" + this->expression(sub.at(0)) + "]";
1✔
510

511
        if (sub.size() > 1) {
1✔
512
            data_flow::Subset element_subset(sub.begin() + 1, sub.end());
×
513
            auto& element_type = array_type->element_type();
×
514
            return subset_str + subset(function, element_type, element_subset);
×
515
        } else {
×
516
            return subset_str;
1✔
517
        }
518
    } else if (auto pointer_type = dynamic_cast<const types::Pointer*>(&type)) {
2✔
519
        std::string subset_str = "[" + this->expression(sub.at(0)) + "]";
×
520

521
        data_flow::Subset element_subset(sub.begin() + 1, sub.end());
×
522
        auto& pointee_type = pointer_type->pointee_type();
×
523
        return subset_str + subset(function, pointee_type, element_subset);
×
524
    } else if (auto structure_type = dynamic_cast<const types::Structure*>(&type)) {
1✔
525
        auto& definition = function.structure(structure_type->name());
1✔
526

527
        std::string subset_str = ".member_" + this->expression(sub.at(0));
1✔
528
        if (sub.size() > 1) {
1✔
529
            auto member = SymEngine::rcp_dynamic_cast<const SymEngine::Integer>(sub.at(0));
×
530
            auto& member_type = definition.member_type(member);
×
531
            data_flow::Subset element_subset(sub.begin() + 1, sub.end());
×
532
            return subset_str + subset(function, member_type, element_subset);
×
533
        } else {
×
534
            return subset_str;
1✔
535
        }
536
    }
1✔
537

538
    throw std::invalid_argument("Invalid subset type");
×
539
};
9✔
540

541
std::string CLanguageExtension::expression(const symbolic::Expression& expr) {
28✔
542
    CSymbolicPrinter printer;
28✔
543
    return printer.apply(expr);
28✔
544
};
28✔
545

546
std::string CLanguageExtension::tasklet(const data_flow::Tasklet& tasklet) {
2✔
547
    std::string op = code_to_string(tasklet.code());
2✔
548
    std::vector<std::string> arguments;
2✔
549
    for (size_t i = 0; i < tasklet.inputs().size(); ++i) {
6✔
550
        std::string arg = tasklet.input(i).first;
4✔
551
        if (!tasklet.needs_connector(i)) {
4✔
552
            if (arg != "NAN" && arg != "INFINITY") {
×
553
                if (tasklet.input(i).second.primitive_type() == types::PrimitiveType::Float) {
×
554
                    arg += "f";
×
555
                }
×
556
            }
×
557
        }
×
558
        arguments.push_back(arg);
4✔
559
    }
4✔
560

561
    if (tasklet.code() == data_flow::TaskletCode::assign) {
2✔
562
        return arguments.at(0);
×
563
    } else if (data_flow::is_infix(tasklet.code())) {
2✔
564
        switch (data_flow::arity(tasklet.code())) {
2✔
565
            case 1:
566
                return op + arguments.at(0);
×
567
            case 2:
568
                return arguments.at(0) + " " + op + " " + arguments.at(1);
2✔
569
            default:
570
                throw std::runtime_error("Unsupported arity");
×
571
        }
572
    } else {
573
        return op + "(" + helpers::join(arguments, ", ") + ")";
×
574
    }
575
};
2✔
576

577
std::string CLanguageExtension::library_node(const data_flow::LibraryNode& libnode) {
×
578
    data_flow::LibraryNodeType lib_node_type = libnode.call();
×
579
    switch (lib_node_type) {
×
580
        default:
581
            throw std::runtime_error("Unsupported library node type");
×
582
    }
583
}
×
584

585
void CSymbolicPrinter::bvisit(const SymEngine::Infty& x) {
×
586
    if (x.is_negative_infinity())
×
587
        str_ = "-INFINITY";
×
588
    else if (x.is_positive_infinity())
×
589
        str_ = "INFINITY";
×
590
};
×
591

592
void CSymbolicPrinter::bvisit(const SymEngine::BooleanAtom& x) {
11✔
593
    str_ = x.get_val() ? "true" : "false";
11✔
594
};
11✔
595

596
void CSymbolicPrinter::bvisit(const SymEngine::Symbol& x) {
7✔
597
    if (symbolic::is_nullptr(symbolic::symbol(x.get_name()))) {
7✔
598
        str_ = "NULL";
×
599
        return;
×
600
    } else if (symbolic::is_memory_address(symbolic::symbol(x.get_name()))) {
7✔
601
        // symbol of form reinterpret_cast<T*>(0x1234)
602
        str_ = x.get_name();
×
603
        return;
×
604
    }
605
    str_ = x.get_name();
7✔
606
};
7✔
607

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

618
void CSymbolicPrinter::bvisit(const SymEngine::Or& x) {
×
619
    std::ostringstream s;
×
620
    auto container = x.get_container();
×
621
    s << apply(*container.begin());
×
622
    for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
623
        s << " || " << apply(*it);
×
624
    }
×
625
    str_ = parenthesize(s.str());
×
626
};
×
627

628
void CSymbolicPrinter::bvisit(const SymEngine::Not& x) {
×
629
    str_ = "!" + apply(x.get_arg());
×
630
    str_ = parenthesize(str_);
×
631
};
×
632

633
void CSymbolicPrinter::bvisit(const SymEngine::Equality& x) {
1✔
634
    str_ = apply(x.get_args()[0]) + " == " + apply(x.get_args()[1]);
1✔
635
    str_ = parenthesize(str_);
1✔
636
};
1✔
637

638
void CSymbolicPrinter::bvisit(const SymEngine::Unequality& x) {
1✔
639
    str_ = apply(x.get_args()[0]) + " != " + apply(x.get_args()[1]);
1✔
640
    str_ = parenthesize(str_);
1✔
641
};
1✔
642

643
void CSymbolicPrinter::bvisit(const SymEngine::Min& x) {
×
644
    std::ostringstream s;
×
645
    auto container = x.get_args();
×
646
    if (container.size() == 1) {
×
647
        s << apply(*container.begin());
×
648
    } else {
×
649
        s << "__daisy_min(";
×
650
        s << apply(*container.begin());
×
651

652
        // Recursively apply __daisy_min to the arguments
653
        SymEngine::vec_basic subargs;
×
654
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
655
            subargs.push_back(*it);
×
656
        }
×
657
        auto submin = SymEngine::min(subargs);
×
658
        s << ", " << apply(submin);
×
659

660
        s << ")";
×
661
    }
×
662

663
    str_ = s.str();
×
664
};
×
665

666
void CSymbolicPrinter::bvisit(const SymEngine::Max& x) {
×
667
    std::ostringstream s;
×
668
    auto container = x.get_args();
×
669
    if (container.size() == 1) {
×
670
        s << apply(*container.begin());
×
671
    } else {
×
672
        s << "__daisy_max(";
×
673
        s << apply(*container.begin());
×
674

675
        // Recursively apply __daisy_max to the arguments
676
        SymEngine::vec_basic subargs;
×
677
        for (auto it = ++(container.begin()); it != container.end(); ++it) {
×
678
            subargs.push_back(*it);
×
679
        }
×
680
        auto submax = SymEngine::max(subargs);
×
681
        s << ", " << apply(submax);
×
682

683
        s << ")";
×
684
    }
×
685

686
    str_ = s.str();
×
687
};
×
688

689
void CSymbolicPrinter::_print_pow(std::ostringstream& o,
×
690
                                  const SymEngine::RCP<const SymEngine::Basic>& a,
691
                                  const SymEngine::RCP<const SymEngine::Basic>& b) {
692
    if (SymEngine::eq(*a, *SymEngine::E)) {
×
693
        o << "exp(" << apply(b) << ")";
×
694
    } else if (SymEngine::eq(*b, *SymEngine::rational(1, 2))) {
×
695
        o << "sqrt(" << apply(a) << ")";
×
696
    } else if (SymEngine::eq(*b, *SymEngine::rational(1, 3))) {
×
697
        o << "cbrt(" << apply(a) << ")";
×
698
    } else if (SymEngine::eq(*b, *SymEngine::integer(2))) {
×
699
        o << apply(a) + " * " + apply(a);
×
700
    } else {
×
701
        o << "pow(" << apply(a) << ", " << apply(b) << ")";
×
702
    }
703
};
×
704

705
}  // namespace codegen
706
}  // 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

© 2025 Coveralls, Inc