Skip to content

Commit 7fe662d

Browse files
committed
do not use global var
1 parent 457fc96 commit 7fe662d

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ cmake -G Ninja \\
1111
-DCMAKE_CXX_COMPILER=clang++ \\
1212
-DCMAKE_CXX_STANDARD=17 \\
1313
-DCMAKE_INSTALL_PREFIX=\$2 \\
14-
-DCMAKE_PREFIX_PATH="$(/usr/lib/llvm-17/bin/llvm-config --cmakedir)" \\
14+
-DCMAKE_PREFIX_PATH="$(llvm-config --cmakedir)" \\
1515
-DCPACK_SOURCE_IGNORE_FILES=".git/;tester/third_party/" \\
1616
-S \$1 \\
1717
-B \$2/build
@@ -35,7 +35,7 @@ apt-get update -y
3535
apt-get upgrade -y
3636
apt-get install -y --no-install-recommends \
3737
libantlr4-runtime-dev default-jre-headless pkg-config uuid-dev flex bison \
38-
clang llvm-17-dev zlib1g-dev libzstd-dev lld python3 cmake ninja-build git
38+
clang llvm-dev zlib1g-dev libzstd-dev lld python3 cmake ninja-build git
3939
apt-get autoremove -y
4040
apt-get clean -y
4141
rm -rf /var/lib/apt/lists/*

generator/main.cc

+10-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
#include <llvm/Support/raw_ostream.h>
99

1010
namespace {
11-
llvm::LLVMContext TheContext;
12-
llvm::Module TheModule("-", TheContext);
1311

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) {
1515
// First, check for an existing function from a previous declaration.
1616
auto TheName = O->get("name")->getAsString()->str();
1717
llvm::Function *TheFunction = TheModule.getFunction(TheName);
@@ -44,7 +44,9 @@ llvm::Function *buildFunctionDecl(const llvm::json::Object *O) {
4444
return nullptr;
4545
}
4646

47-
void buildTranslationUnitDecl(const llvm::json::Object *O) {
47+
void buildTranslationUnitDecl(llvm::LLVMContext &TheContext,
48+
llvm::Module &TheModule,
49+
const llvm::json::Object *O) {
4850
if (O == nullptr)
4951
return;
5052
if (auto kind = O->get("kind")->getAsString()) {
@@ -57,14 +59,16 @@ void buildTranslationUnitDecl(const llvm::json::Object *O) {
5759
if (auto P = it.getAsObject())
5860
if (auto kind = P->get("kind")->getAsString()) {
5961
if (*kind == "FunctionDecl")
60-
buildFunctionDecl(P);
62+
buildFunctionDecl(TheContext, TheModule, P);
6163
}
6264
}
6365
} // namespace
6466

6567
int main() {
68+
llvm::LLVMContext TheContext;
69+
llvm::Module TheModule("-", TheContext);
6670
auto llvmin = llvm::MemoryBuffer::getFileOrSTDIN("-");
6771
auto json = llvm::json::parse(llvmin.get()->getBuffer());
68-
buildTranslationUnitDecl(json->getAsObject());
72+
buildTranslationUnitDecl(TheContext, TheModule, json->getAsObject());
6973
TheModule.print(llvm::outs(), nullptr);
7074
}

0 commit comments

Comments
 (0)