Skip to content

Commit e0bb073

Browse files
authored
Merge pull request #478 from p0tat0ba11/lab6
[LAB6] 313560008
2 parents dfbe8cb + 192ccf8 commit e0bb073

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

lab6/llvm-pass.so.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,21 @@ PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1515
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
1616

1717
for (auto &F : M) {
18-
errs() << "func: " << F.getName() << "\n";
18+
if(F.getName() == "main") {
19+
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
20+
21+
// call debug
22+
Builder.CreateCall(debug_func, debug_arg);
23+
24+
Argument *argc = F.getArg(0);
25+
argc->replaceAllUsesWith(debug_arg);
26+
27+
Argument *argv = F.getArg(1);
28+
Value *argv_ptr = Builder.CreateGEP(Builder.getInt8PtrTy(), argv, ConstantInt::get(Int32Ty, 1));
29+
Value *newStr = Builder.CreateGlobalStringPtr("hayaku... motohayaku!");
30+
31+
Builder.CreateStore(newStr, argv_ptr);
32+
}
1933

2034
}
2135
return PreservedAnalyses::none();

0 commit comments

Comments
 (0)