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> {
1111PreservedAnalyses 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}
You can’t perform that action at this time.
0 commit comments