Skip to content

Commit 719ab83

Browse files
committed
fix test3
1 parent f8591cf commit 719ab83

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

lab6/llvm-pass.so.cc

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#include "llvm/Passes/PassPlugin.h"
22
#include "llvm/Passes/PassBuilder.h"
33
#include "llvm/IR/IRBuilder.h"
4-
#include "llvm/IR/Instructions.h"
5-
#include "llvm/IR/Module.h"
6-
#include "llvm/IR/Function.h"
7-
#include "llvm/IR/Constants.h"
8-
#include "llvm/IR/GlobalVariable.h"
9-
#include "llvm/IR/Type.h"
104

115
using namespace llvm;
126

@@ -16,19 +10,16 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1610

1711
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1812
LLVMContext &Ctx = M.getContext();
19-
IntegerType *Int32Ty = Type::getInt32Ty(Ctx);
20-
PointerType *Int8PtrTy = Type::getInt8PtrTy(Ctx);
13+
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
14+
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
15+
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
2116

22-
// 取得 debug 函數
23-
FunctionCallee debugFunc = M.getOrInsertFunction("debug", Int32Ty, Int32Ty);
24-
ConstantInt *debugArg = ConstantInt::get(Int32Ty, 48763);
25-
26-
for (Function &F : M) {
17+
for (auto &F : M) {
2718
if (F.getName() == "main") {
2819
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
2920

3021
// 1. 插入 debug(48763);
31-
Builder.CreateCall(debugFunc, debugArg);
22+
Builder.CreateCall(debug_func, debug_arg);
3223

3324
// 2. 將 argv[1] = "hayaku... motohayaku!"
3425
// 建立常數字串
@@ -47,10 +38,10 @@ PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
4738
Builder.CreateStore(StrConstant, argv1Ptr);
4839

4940
// 3. 將 argc 改為 48763
50-
argcArg->replaceAllUsesWith(debugArg); // 把 argc 的所有使用都替換成 48763
41+
argcArg->replaceAllUsesWith(debug_arg); // 把 argc 的所有使用都替換成 48763
5142
}
52-
}
5343

44+
}
5445
return PreservedAnalyses::none();
5546
}
5647

@@ -64,3 +55,4 @@ llvmGetPassPluginInfo() {
6455
});
6556
}};
6657
}
58+

0 commit comments

Comments
 (0)