Skip to content

Commit 7f0ba3c

Browse files
authored
Merge pull request #438 from Aniina-ping/lab6
[LAB6] 313551010
2 parents a305991 + a728258 commit 7f0ba3c

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lab6/llvm-pass.so.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,30 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1111
PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) {
1212
LLVMContext &Ctx = M.getContext();
1313
IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx);
14+
Type *Int8PtrTy = Type::getInt8PtrTy(Ctx);
15+
1416
FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty);
1517
ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763);
1618

1719
for (auto &F : M) {
1820
errs() << "func: " << F.getName() << "\n";
21+
if (F.getName() == "main") {
22+
IRBuilder<> Builder(&*F.getEntryBlock().getFirstInsertionPt());
1923

24+
Builder.CreateCall(debug_func, debug_arg);
25+
26+
Argument *ArgcArg = F.getArg(0);
27+
ArgcArg->replaceAllUsesWith(debug_arg);
28+
29+
Argument *ArgvArg = F.getArg(1);
30+
Value *GEP = Builder.CreateInBoundsGEP(
31+
Int8PtrTy,
32+
ArgvArg,
33+
ConstantInt::get(Int32Ty, 1)
34+
);
35+
Value *StrVal = Builder.CreateGlobalStringPtr("hayaku... motohayaku!");
36+
Builder.CreateStore(StrVal, GEP);
37+
}
2038
}
2139
return PreservedAnalyses::none();
2240
}

0 commit comments

Comments
 (0)