MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
print.cpp
Go to the documentation of this file.
1#include "mim/util/print.h"
2
3namespace mim {
4
5std::ostream& print(std::ostream& os, const char* s) {
6 while (*s) {
7 auto next = s + 1;
8
9 switch (*s) {
10 case '{':
11 if (detail::match2nd(os, next, s, '{')) continue;
12 while (*s && *s != '}') s++;
13 assert(*s != '}' && "invalid format string for 'streamf': missing argument(s)");
14 fe::unreachable();
15 break;
16 case '}':
17 if (detail::match2nd(os, next, s, '}')) continue;
18 assert(false && "unmatched/unescaped closing brace '}' in format string");
19 fe::unreachable();
20 default: os << *s++;
21 }
22 }
23 return os;
24}
25
26namespace detail {
27
28bool match2nd(std::ostream& os, const char* next, const char*& s, const char c) {
29 if (*next == c) {
30 os << c;
31 s += 2;
32 return true;
33 }
34 return false;
35}
36
37} // namespace detail
38
39} // namespace mim
Definition cfg.h:11
std::ostream & print(std::ostream &os, const char *s)
Base case.
Definition print.cpp:5