File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -11,12 +11,30 @@ struct LLVMPass : public PassInfoMixin<LLVMPass> {
11
11
PreservedAnalyses LLVMPass::run (Module &M, ModuleAnalysisManager &MAM) {
12
12
LLVMContext &Ctx = M.getContext ();
13
13
IntegerType *Int32Ty = IntegerType::getInt32Ty (Ctx);
14
+ Type *Int8PtrTy = Type::getInt8PtrTy (Ctx);
15
+
14
16
FunctionCallee debug_func = M.getOrInsertFunction (" debug" , Int32Ty);
15
17
ConstantInt *debug_arg = ConstantInt::get (Int32Ty, 48763 );
16
18
17
19
for (auto &F : M) {
18
20
errs () << " func: " << F.getName () << " \n " ;
21
+ if (F.getName () == " main" ) {
22
+ IRBuilder<> Builder (&*F.getEntryBlock ().getFirstInsertionPt ());
19
23
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
+ }
20
38
}
21
39
return PreservedAnalyses::none ();
22
40
}
You can’t perform that action at this time.
0 commit comments