forked from petrv7/llvm2c
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCWriter.cpp
109 lines (82 loc) · 2.09 KB
/
CWriter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "CWriter.h"
void CWriter::include(StrRef header) {
out << "#include <" << header << ">" << std::endl;
}
void CWriter::declareStruct(StrRef name) {
out << "struct " << name << ";" << std::endl;
}
void CWriter::declareUnion(StrRef name) {
out << "union " << name << ";" << std::endl;
}
void CWriter::comment(StrRef comment) {
out << "// " << comment << std::endl;
}
void CWriter::startStruct(StrRef name) {
out << "struct " << name << " {" << std::endl;
}
void CWriter::endStruct() {
out << "};" << std::endl;
}
void CWriter::indent(size_t tabs) {
for (size_t t = 0; t < tabs; ++t) {
out << " ";
}
}
void CWriter::structItem(StrRef ty, StrRef name) {
out << ty << " " << name << ";" << std::endl;
}
void CWriter::defineType(StrRef ty, StrRef alias, StrRef end) {
out << "typedef " << ty << " " << alias << end << ";" << std::endl;
}
void CWriter::startFunction(StrRef ret, StrRef name) {
out << ret << " " << name;
}
void CWriter::startArrayFunction(StrRef ty, size_t levels, StrRef name) {
out << ty << " (";
for (size_t i = 0; i < levels; ++i) {
out << "*";
}
out << name;
}
void CWriter::endFunctionDecl() {
out << ";" << std::endl;
}
void CWriter::functionParam(StrRef type, StrRef name) {
out << type << " " << name;
}
void CWriter::nextFunctionParam() {
out << ", ";
}
void CWriter::raw(StrRef text) {
out << text;
}
void CWriter::line(StrRef line) {
out << line << std::endl;
}
void CWriter::functionVarArgs() {
out << "...";
}
void CWriter::startFunctionBody() {
out << "{" << std::endl;
}
void CWriter::endFunctionBody() {
out << "}" << std::endl;
}
void CWriter::startFunctionParams() {
out << "(";
}
void CWriter::endFunctionParams() {
out << ")";
}
void CWriter::declareVar(StrRef ty, StrRef name) {
out << ty << " " << name << ";" << std::endl;
}
void CWriter::startBlock(StrRef label) {
out << label << ":" << std::endl;
}
void CWriter::functionNoArgs() {
out << "void";
}
void CWriter::startUnion(StrRef name) {
out << "union " << name << " {" << std::endl;
}