Add code for emitting call arguments (not used yet).
authorAnders Carlsson <andersca@mac.com>
Wed, 8 Apr 2009 20:47:54 +0000 (20:47 +0000)
committerAnders Carlsson <andersca@mac.com>
Wed, 8 Apr 2009 20:47:54 +0000 (20:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68639 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGCall.cpp
lib/CodeGen/CodeGenFunction.h

index e3f824fc7428cddfb78d905b7011a32f3d1922e5..2edf3bd104a163d3de386914941cb38b28dc3fa1 100644 (file)
@@ -1929,6 +1929,42 @@ void CodeGenFunction::EmitFunctionEpilog(const CGFunctionInfo &FI,
   }
 }
 
+RValue CodeGenFunction::EmitCallArg(const Expr *E, QualType ArgType) {
+  return EmitAnyExprToTemp(E);
+}
+
+void CodeGenFunction::EmitCallArgs(CallArgList& Args, 
+                                   const FunctionProtoType *FPT,
+                                   CallExpr::const_arg_iterator ArgBeg,
+                                   CallExpr::const_arg_iterator ArgEnd) {
+  CallExpr::const_arg_iterator Arg = ArgBeg;
+  
+  // First, use the function argument types.
+  if (FPT) {
+    for (FunctionProtoType::arg_type_iterator I = FPT->arg_type_begin(),
+         E = FPT->arg_type_end(); I != E; ++I, ++Arg) {
+      assert(getContext().getCanonicalType(I->getNonReferenceType()).
+             getTypePtr() == 
+             getContext().getCanonicalType(Arg->getType()).getTypePtr() && 
+             "type mismatch in call argument!");
+      
+      QualType ArgType = *I;
+      Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType), 
+                                    ArgType));
+    }
+    
+    assert(Arg == ArgEnd || FPT->isVariadic() && 
+           "Extra arguments in non-variadic function!");
+  }
+  
+  // If we still have any arguments, emit them using the type of the argument.
+  for (; Arg != ArgEnd; ++Arg) {
+    QualType ArgType = Arg->getType();
+    Args.push_back(std::make_pair(EmitCallArg(*Arg, ArgType),
+                                  ArgType));
+  }
+}
+
 RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
                                  llvm::Value *Callee, 
                                  const CallArgList &CallArgs,
index 96db4a45c77a2a683be299b18980e53c33bc060d..39ba5eb1e799d62785cb1860d6aa77daba375523 100644 (file)
@@ -798,6 +798,17 @@ private:
   /// current cleanup scope.
   void AddBranchFixup(llvm::BranchInst *BI);
 
+  /// EmitCallArg - Emit a single call argument.
+  RValue EmitCallArg(const Expr *E, QualType ArgType);
+  
+  /// EmitCallArgs - Emit call arguments for a function.
+  /// FIXME: It should be possible to generalize this and pass a generic
+  /// "argument type container" type instead of the FunctionProtoType. This way
+  /// it can work on Objective-C methods as well.
+  void EmitCallArgs(CallArgList& args, const FunctionProtoType *FPT,
+                    CallExpr::const_arg_iterator ArgBeg,
+                    CallExpr::const_arg_iterator ArgEnd);
+
 };
 }  // end namespace CodeGen
 }  // end namespace clang