@@ -11,11 +11,34 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1111PreservedAnalyses LLVMPass::run (Module &M, ModuleAnalysisManager &MAM) {
1212 LLVMContext &Ctx = M.getContext ();
1313 IntegerType *Int32Ty = IntegerType::getInt32Ty (Ctx);
14+ IntegerType *Int64Ty = IntegerType::getInt64Ty (Ctx);
1415 FunctionCallee debug_func = M.getOrInsertFunction (" debug" , Int32Ty);
1516 ConstantInt *debug_arg = ConstantInt::get (Int32Ty, 48763 );
1617
1718 for (auto &F : M) {
18- errs () << " func: " << F.getName () << " \n " ;
19+ if (!F.getName ().equals (" main" ))
20+ continue ;
21+
22+ IRBuilder<> Builder (&*F.getEntryBlock ().getFirstInsertionPt ());
23+ Builder.CreateCall (debug_func, debug_arg);
24+
25+ Argument *Arg1 = F.getArg (1 );
26+ Value *Idx1 = ConstantInt::get (Int64Ty, 1 );
27+ Value *Arg1Ptr = Builder.CreateInBoundsGEP (Type::getInt8PtrTy (Ctx), Arg1, Idx1);
28+
29+ Value *Kirito = Builder.CreateGlobalStringPtr (" hayaku... motohayaku!" , " hayaku" );
30+ Builder.CreateStore (Kirito, Arg1Ptr);
31+
32+ Argument *Arg0 = F.getArg (0 );
33+ for (Instruction &I : instructions (F)) {
34+ if (auto *SI = dyn_cast<StoreInst>(&I)) {
35+ if (SI->getValueOperand () == Arg0) {
36+ IRBuilder<> B (SI->getNextNode ());
37+ B.CreateStore (debug_arg, SI->getPointerOperand ());
38+ break ;
39+ }
40+ }
41+ }
1942
2043 }
2144 return PreservedAnalyses::none ();
0 commit comments