#ifndef __ARGUMENT__HELPERS__HPP
#define __ARGUMENT__HELPERS__HPP

#include <llvm/Function.h>

namespace llvm
{
  class Argument;
  class CallInst;
  class Function;
  class Use;
}


/*!
  Determine the _real_ number of arguments for the given function.
  Functions which return structs by value are transformed (by llvm)
  into void functions with an extra OUT parameter; this function
  subtracts one from their argument count if that is the case for @fn.
 */
unsigned realNumArgs(const llvm::Function * fn);
unsigned realArgno(const llvm::Argument * arg);

/*!
  This is similar to realNumArgs; unless the function being called
  is REALLY void, the first operand is a return value (this includes
  the case where a returned struct is transformed into an OUT
  parameter).

  This function merely returns the index at which to start examining
  REAL parameters.
 */
unsigned operandStart(const llvm::CallInst * ci);
llvm::Use* operandStartIter(llvm::CallInst * ci);
const llvm::Use* operandStartIter(const llvm::CallInst * ci);

/*!
  Helpers to retrieve an iterator to the first *REAL* argument of a function
 */
llvm::Function::const_arg_iterator firstArgument(const llvm::Function & F);
llvm::Function::arg_iterator firstArgument(llvm::Function & F);

#endif // __ARGUMENT__HELPERS__HPP
