]> git.proxmox.com Git - rustc.git/blob - src/binaryen/src/pretty_printing.h
New upstream version 1.23.0+dfsg1
[rustc.git] / src / binaryen / src / pretty_printing.h
1 /*
2 * Copyright 2015 WebAssembly Community Group participants
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 //
18 // Pretty printing helpers
19 //
20
21 #ifndef wasm_pretty_printing_h
22 #define wasm_pretty_printing_h
23
24 #include <ostream>
25
26 #include "support/colors.h"
27
28 inline std::ostream &doIndent(std::ostream &o, unsigned indent) {
29 for (unsigned i = 0; i < indent; i++) {
30 o << " ";
31 }
32 return o;
33 }
34
35 inline std::ostream &prepareMajorColor(std::ostream &o) {
36 Colors::red(o);
37 Colors::bold(o);
38 return o;
39 }
40
41 inline std::ostream &prepareColor(std::ostream &o) {
42 Colors::magenta(o);
43 Colors::bold(o);
44 return o;
45 }
46
47 inline std::ostream &prepareMinorColor(std::ostream &o) {
48 Colors::orange(o);
49 return o;
50 }
51
52 inline std::ostream &restoreNormalColor(std::ostream &o) {
53 Colors::normal(o);
54 return o;
55 }
56
57 inline std::ostream& printText(std::ostream &o, const char *str) {
58 o << '"';
59 Colors::green(o);
60 o << str;
61 Colors::normal(o);
62 return o << '"';
63 }
64
65 inline std::ostream& printOpening(std::ostream &o, const char *str, bool major=false) {
66 o << '(';
67 major ? prepareMajorColor(o) : prepareColor(o);
68 o << str;
69 restoreNormalColor(o);
70 return o;
71 }
72
73 inline std::ostream& printMinorOpening(std::ostream &o, const char *str) {
74 o << '(';
75 prepareMinorColor(o);
76 o << str;
77 restoreNormalColor(o);
78 return o;
79 }
80
81 #endif // wasm_pretty_printing_h