Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
do not use global var
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-kan committed Nov 27, 2024
1 parent 457fc96 commit 7fe662d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cmake -G Ninja \\
-DCMAKE_CXX_COMPILER=clang++ \\
-DCMAKE_CXX_STANDARD=17 \\
-DCMAKE_INSTALL_PREFIX=\$2 \\
-DCMAKE_PREFIX_PATH="$(/usr/lib/llvm-17/bin/llvm-config --cmakedir)" \\
-DCMAKE_PREFIX_PATH="$(llvm-config --cmakedir)" \\
-DCPACK_SOURCE_IGNORE_FILES=".git/;tester/third_party/" \\
-S \$1 \\
-B \$2/build
Expand All @@ -35,7 +35,7 @@ apt-get update -y
apt-get upgrade -y
apt-get install -y --no-install-recommends \
libantlr4-runtime-dev default-jre-headless pkg-config uuid-dev flex bison \
clang llvm-17-dev zlib1g-dev libzstd-dev lld python3 cmake ninja-build git
clang llvm-dev zlib1g-dev libzstd-dev lld python3 cmake ninja-build git
apt-get autoremove -y
apt-get clean -y
rm -rf /var/lib/apt/lists/*
Expand Down
16 changes: 10 additions & 6 deletions generator/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
#include <llvm/Support/raw_ostream.h>

namespace {
llvm::LLVMContext TheContext;
llvm::Module TheModule("-", TheContext);

llvm::Function *buildFunctionDecl(const llvm::json::Object *O) {
llvm::Function *buildFunctionDecl(llvm::LLVMContext &TheContext,
llvm::Module &TheModule,
const llvm::json::Object *O) {
// First, check for an existing function from a previous declaration.
auto TheName = O->get("name")->getAsString()->str();
llvm::Function *TheFunction = TheModule.getFunction(TheName);
Expand Down Expand Up @@ -44,7 +44,9 @@ llvm::Function *buildFunctionDecl(const llvm::json::Object *O) {
return nullptr;
}

void buildTranslationUnitDecl(const llvm::json::Object *O) {
void buildTranslationUnitDecl(llvm::LLVMContext &TheContext,
llvm::Module &TheModule,
const llvm::json::Object *O) {
if (O == nullptr)
return;
if (auto kind = O->get("kind")->getAsString()) {
Expand All @@ -57,14 +59,16 @@ void buildTranslationUnitDecl(const llvm::json::Object *O) {
if (auto P = it.getAsObject())
if (auto kind = P->get("kind")->getAsString()) {
if (*kind == "FunctionDecl")
buildFunctionDecl(P);
buildFunctionDecl(TheContext, TheModule, P);
}
}
} // namespace

int main() {
llvm::LLVMContext TheContext;
llvm::Module TheModule("-", TheContext);
auto llvmin = llvm::MemoryBuffer::getFileOrSTDIN("-");
auto json = llvm::json::parse(llvmin.get()->getBuffer());
buildTranslationUnitDecl(json->getAsObject());
buildTranslationUnitDecl(TheContext, TheModule, json->getAsObject());
TheModule.print(llvm::outs(), nullptr);
}

0 comments on commit 7fe662d

Please sign in to comment.