8
8
#include < llvm/Support/raw_ostream.h>
9
9
10
10
namespace {
11
- llvm::LLVMContext TheContext;
12
- llvm::Module TheModule (" -" , TheContext);
13
11
14
- llvm::Function *buildFunctionDecl (const llvm::json::Object *O) {
12
+ llvm::Function *buildFunctionDecl (llvm::LLVMContext &TheContext,
13
+ llvm::Module &TheModule,
14
+ const llvm::json::Object *O) {
15
15
// First, check for an existing function from a previous declaration.
16
16
auto TheName = O->get (" name" )->getAsString ()->str ();
17
17
llvm::Function *TheFunction = TheModule.getFunction (TheName);
@@ -44,7 +44,9 @@ llvm::Function *buildFunctionDecl(const llvm::json::Object *O) {
44
44
return nullptr ;
45
45
}
46
46
47
- void buildTranslationUnitDecl (const llvm::json::Object *O) {
47
+ void buildTranslationUnitDecl (llvm::LLVMContext &TheContext,
48
+ llvm::Module &TheModule,
49
+ const llvm::json::Object *O) {
48
50
if (O == nullptr )
49
51
return ;
50
52
if (auto kind = O->get (" kind" )->getAsString ()) {
@@ -57,14 +59,16 @@ void buildTranslationUnitDecl(const llvm::json::Object *O) {
57
59
if (auto P = it.getAsObject ())
58
60
if (auto kind = P->get (" kind" )->getAsString ()) {
59
61
if (*kind == " FunctionDecl" )
60
- buildFunctionDecl (P);
62
+ buildFunctionDecl (TheContext, TheModule, P);
61
63
}
62
64
}
63
65
} // namespace
64
66
65
67
int main () {
68
+ llvm::LLVMContext TheContext;
69
+ llvm::Module TheModule (" -" , TheContext);
66
70
auto llvmin = llvm::MemoryBuffer::getFileOrSTDIN (" -" );
67
71
auto json = llvm::json::parse (llvmin.get ()->getBuffer ());
68
- buildTranslationUnitDecl (json->getAsObject ());
72
+ buildTranslationUnitDecl (TheContext, TheModule, json->getAsObject ());
69
73
TheModule.print (llvm::outs (), nullptr );
70
74
}
0 commit comments