Exemplo n.º 1
0
//---------------------------------------------------------------------------
void TransformWCR::CheckParmVarDecls(FunctionDecl *FD, StmtVector &Body,
                                     StmtVector &WCR) {
  // If some function parameters are modified in the function body,
  // they should be saved in some temporal variables.
  for (unsigned i = 0, e = FD->getNumParams(); i < e; ++i) {
    ParmVarDecl *PD = FD->getParamDecl(i);
    if (PD->isModified()) {
      SourceLocation SL;

      // T __cl_parm_PD;
      VarDecl *VD = NewVarDeclForParameter(PD);
      VD->setInit(NULL);
      Body.push_back(NewDeclStmt(VD));

      // __cl_parm_PD = PD;
      DeclRefExpr *Init_LHS = new (ASTCtx) DeclRefExpr(VD, VD->getType(),
                                                       VK_RValue, SL);
      DeclRefExpr *Init_RHS = new (ASTCtx) DeclRefExpr(PD, PD->getType(),
                                                       VK_RValue, SL);
      Expr *InitExpr = new (ASTCtx) BinaryOperator(Init_LHS, Init_RHS,
          BO_Assign, PD->getType(), VK_RValue, OK_Ordinary, SL);
      Body.push_back(InitExpr);

      // PD = __cl_parm_PD;
      DeclRefExpr *LHS = new (ASTCtx) DeclRefExpr(PD, PD->getType(),
                                                  VK_RValue, SL);
      DeclRefExpr *RHS = new (ASTCtx) DeclRefExpr(VD, VD->getType(),
                                                  VK_RValue, SL);
      Expr *RestoreExpr = new (ASTCtx) BinaryOperator(LHS, RHS, BO_Assign,
          PD->getType(), VK_RValue, OK_Ordinary, SL);
      WCR.push_back(RestoreExpr);
    }
  }
}