@@ -26,6 +26,8 @@ static llvm::cl::opt<std::string> LibName("name", llvm::cl::cat(Category));
26
26
27
27
HeaderManager headerMan;
28
28
29
+ std::string declarations;
30
+ std::string enums;
29
31
30
32
class TreeVisitor : public clang ::RecursiveASTVisitor<TreeVisitor> {
31
33
private:
@@ -57,15 +59,15 @@ class TreeVisitor : public clang::RecursiveASTVisitor<TreeVisitor> {
57
59
params = params.substr (0 , params.size ()-2 );
58
60
}
59
61
60
- llvm::outs () << " \t def " << funcName << " (" << params << " ): " + retType + " = native.extern\n " ;
62
+ declarations += " \t def " + funcName + " (" + params + " ): " + retType + " = native.extern\n " ;
61
63
return true ;
62
64
}
63
65
64
66
virtual bool VisitTypedefDecl (clang::TypedefDecl *tpdef){
65
67
std::string name = tpdef->getName ();
66
68
std::string tpe = typeTranslator.Translate (tpdef->getUnderlyingType ());
67
- llvm::outs () << " \t type " << name << " = " << tpe << " \n " ;
68
- return true ;
69
+ declarations += " \t type " + name + " = " + tpe + " \n " ;
70
+ return true ;
69
71
}
70
72
71
73
virtual bool VisitEnumDecl (clang::EnumDecl *enumdecl){
@@ -79,15 +81,15 @@ class TreeVisitor : public clang::RecursiveASTVisitor<TreeVisitor> {
79
81
}
80
82
81
83
if (name != " " ){
82
- llvm::outs () << " \t type enum_" << name << " = native.CInt\n " ;
84
+ declarations += " \t type enum_" + name + " = native.CInt\n " ;
83
85
}
84
86
85
87
int i = 0 ;
86
88
for (const clang::EnumConstantDecl* en : enumdecl->enumerators ()){
87
89
if (name != " " ){
88
- llvm::outs () << " \t final val enum_" << name << " _" << en->getNameAsString () << " = " << i++ << " \n " ;
90
+ declarations += " \t final val enum_" + name + " _" + en->getNameAsString () + " = " + std::to_string ( i++) + " \n " ;
89
91
} else {
90
- llvm::outs () << " \t final val enum_" << en->getNameAsString () << " = " << i++ << " \n " ;
92
+ declarations += " \t final val enum_" + en->getNameAsString () + " = " + std::to_string ( i++) + " \n " ;
91
93
}
92
94
}
93
95
@@ -113,7 +115,7 @@ class TreeVisitor : public clang::RecursiveASTVisitor<TreeVisitor> {
113
115
maxSize = std::max (maxSize, astContext->getTypeSize (field->getType ()));
114
116
}
115
117
116
- llvm::outs () << " \t type union_" << name << " = native.CArray[Byte, " << intToScalaNat (maxSize) << " ]\n " ;
118
+ declarations += " \t type union_" + name + " = native.CArray[Byte, " + intToScalaNat (maxSize) + " ]\n " ;
117
119
118
120
return true ;
119
121
@@ -136,12 +138,12 @@ class TreeVisitor : public clang::RecursiveASTVisitor<TreeVisitor> {
136
138
}
137
139
138
140
if (counter < SCALA_NATIVE_MAX_STRUCT_FIELDS){
139
- llvm::outs () << " \t type struct_" << name << " = " << " native.CStruct" << counter << " [" << fields << " ]\n " ;
141
+ declarations += " \t type struct_" + name + " = " + " native.CStruct" + std::to_string ( counter) + " [" + fields + " ]\n " ;
140
142
} else {
141
143
// There is no easy way to represent it as a struct in scala native, have to represent it as an array and then
142
144
// Add helpers to help with it's manipulation
143
145
uint64_t size = astContext->getTypeSize (record->getTypeForDecl ());
144
- llvm::outs () << " \t type struct_" << name << " = " << " native.CArray[Byte, " << uint64ToScalaNat (size) << " ]\n " ;
146
+ declarations += " \t type struct_" + name + " = " + " native.CArray[Byte, " + uint64ToScalaNat (size) + " ]\n " ;
145
147
}
146
148
147
149
return true ;
@@ -245,13 +247,19 @@ int main(int argc, const char **argv) {
245
247
return -1 ;
246
248
}
247
249
250
+ declarations = " " ;
251
+ enums = " " ;
252
+
248
253
headerMan.LoadConfig (std::string (" ../llvm/tools/clang/tools/extra/scala-bindgen/nativeHeaders.txt" ));
249
254
255
+
256
+ int result = Tool.run (clang::tooling::newFrontendActionFactory<ExampleFrontendAction>().get ());
257
+
250
258
llvm::outs () << " import scala.scalanative._\n " ;
251
259
llvm::outs () << " import scala.scalanative.native.Nat._\n\n " ;
252
260
llvm::outs () << " @native.link(\" " << lib << " \" )\n " ;
253
261
llvm::outs () << " @native.extern\n object " << lib<< " {\n " ;
254
- int result = Tool. run (clang::tooling::newFrontendActionFactory<ExampleFrontendAction>(). get ()) ;
262
+ llvm::outs () << declarations ;
255
263
llvm::outs () << " }\n " ;
256
264
257
265
return result;
0 commit comments