1#pragma once
2
3#include "taichi/util/lang_util.h"
4#include "taichi/common/core.h"
5#include <fstream>
6#include <sstream>
7#include <cstdlib>
8#include <iomanip>
9
10namespace taichi::lang {
11namespace cccp {
12
13inline std::string cc_data_type_name(DataType dt) {
14 return "Ti_" + data_type_name(dt);
15}
16
17inline std::string cc_atomic_op_type_symbol(AtomicOpType op) {
18 switch (op) {
19 case AtomicOpType::add:
20 return "+";
21 case AtomicOpType::sub:
22 return "-";
23 case AtomicOpType::bit_or:
24 return "|";
25 case AtomicOpType::bit_xor:
26 return "^";
27 case AtomicOpType::bit_and:
28 return "&";
29 case AtomicOpType::max:
30 return "max";
31 case AtomicOpType::min:
32 return "min";
33 default:
34 TI_ERROR("Unsupported AtomicOpType={} on C backend",
35 atomic_op_type_name(op));
36 }
37}
38
39inline bool cc_is_binary_op_infix(BinaryOpType op) {
40 switch (op) {
41 case BinaryOpType::max:
42 case BinaryOpType::min:
43 case BinaryOpType::atan2:
44 case BinaryOpType::pow:
45 return false;
46 default:
47 return true;
48 }
49}
50inline bool cc_is_unary_op_infix(UnaryOpType op) {
51 switch (op) {
52 case UnaryOpType::neg:
53 case UnaryOpType::bit_not:
54 case UnaryOpType::logic_not:
55 return true;
56 default:
57 return false;
58 }
59}
60
61// TODO: move this to lang_util.h:
62inline std::string unary_op_type_symbol(UnaryOpType op) {
63 switch (op) {
64 case UnaryOpType::neg:
65 return "-";
66 case UnaryOpType::bit_not:
67 return "~";
68 case UnaryOpType::logic_not:
69 return "!";
70 default:
71 return unary_op_type_name(op);
72 }
73}
74
75template <typename... Args>
76inline int execute(std::string fmt, Args &&...args) {
77 auto cmd = fmt::format(fmt, std::forward<Args>(args)...);
78 TI_TRACE("Executing command: {}", cmd);
79 int ret = std::system(cmd.c_str());
80 TI_TRACE("Command exit status: {}", ret);
81 return ret;
82}
83
84} // namespace cccp
85} // namespace taichi::lang
86