@@ -11,27 +11,12 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
1111PreservedAnalyses LLVMPass::run (Module &M, ModuleAnalysisManager &MAM ) {
1212 LLVMContext &Ctx = M.getContext ();
1313 IntegerType *Int32Ty = IntegerType::getInt32Ty (Ctx);
14- // Prepare debug function and argument
1514 FunctionCallee debug_func = M.getOrInsertFunction (" debug" , Int32Ty);
1615 ConstantInt *debug_arg = ConstantInt::get (Int32Ty, 48763 );
1716
1817 for (auto &F : M) {
19- if (F.getName () == " main" ) {
20- // 1. Invoke debug function with the first argument is 48763 in main function.
21- IRBuilder<> Builder (&*F.getEntryBlock ().getFirstInsertionPt ());
22- Builder.CreateCall (debug_func, {debug_arg});
23-
24- // 2. Modify argv[1] to a custom string
25- Argument *argv_arg = F.getArg (1 );
26- Value *index = ConstantInt::get (Int32Ty, 1 );
27- Value *argv_ptr = Builder.CreateInBoundsGEP (Builder.getInt8PtrTy (), argv_arg, index);
28- Value *custom_str = Builder.CreateGlobalStringPtr (" hayaku... motohayaku!" );
29- Builder.CreateStore (custom_str, argv_ptr);
30-
31- // 3. Replace all uses of argc with the debug ID = 48763
32- Argument *argc_arg = F.getArg (0 );
33- argc_arg->replaceAllUsesWith (debug_arg);
34- }
18+ errs () << " func: " << F.getName () << " \n " ;
19+
3520 }
3621 return PreservedAnalyses::none ();
3722}
0 commit comments