Home | History | Annotate | Download | only in AndroidBitcode
      1 /*
      2  * Copyright 2012, The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *     http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef BCC_ABC_EXPAND_VAARG_H
     18 #define BCC_ABC_EXPAND_VAARG_H
     19 
     20 #include "bcc/AndroidBitcode/ABCExpandVAArgPass.h"
     21 
     22 #include <llvm/Instructions.h>
     23 #include <llvm/Support/InstIterator.h>
     24 
     25 namespace bcc {
     26 
     27 char ABCExpandVAArgPass::ID = 0;
     28 
     29 bool ABCExpandVAArgPass::runOnFunction(llvm::Function &pFunc) {
     30   bool changed = false;
     31 
     32   mContext = &pFunc.getContext();
     33 
     34   // process va_arg inst
     35   for (llvm::inst_iterator inst = llvm::inst_begin(pFunc),
     36           inst_end = llvm::inst_end(pFunc); inst != inst_end; inst++) {
     37     if (inst->getOpcode() == llvm::Instruction::VAArg) {
     38       llvm::Value *v = expandVAArg(&*inst);
     39       inst->replaceAllUsesWith(v);
     40       inst->eraseFromParent();
     41       changed = true;
     42       continue;
     43     }
     44   }
     45   return changed;
     46 }
     47 
     48 } // end bcc namespace
     49 
     50 #endif // BCC_ABC_EXPAND_VAARG_H
     51