Skip to content

Commit 0d4fd28

Browse files
authored
Merge pull request #454 from NienTL/lab6
[LAB6] 313551135
2 parents 7a7bb33 + 93e8307 commit 0d4fd28

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lab6/llvm-pass.so.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1616

1717
for (auto &F : M) {
1818
errs() << "func: " << F.getName() << "\n";
19+
if(F.getName()=="main"){
20+
BasicBlock &entryBlock = F.getEntryBlock();
21+
IRBuilder<> builder(&*entryBlock.getFirstInsertionPt());
22+
23+
builder.CreateCall(debug_func, debug_arg);
24+
25+
// 把所有用到 argc 的地方 全部替換成48763
26+
ConstantInt *main_argc = ConstantInt::get(Int32Ty, 48763);
27+
Argument *argcArg = F.getArg(0);
28+
argcArg->replaceAllUsesWith(main_argc);
29+
30+
31+
Argument *argvArg = F.getArg(1);
32+
Value *str = builder.CreateGlobalStringPtr("hayaku... motohayaku!");
33+
Type *argvElementType = argvArg->getType()->getPointerElementType();
34+
ConstantInt *offset = ConstantInt::get(Int32Ty, 1);
35+
Value *ptrToArgv1 = builder.CreateInBoundsGEP(argvElementType, argvArg, offset);
36+
builder.CreateStore(str, ptrToArgv1);
37+
}
1938

2039
}
2140
return PreservedAnalyses::none();

0 commit comments

Comments
 (0)