• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015, 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 _FRAMEWORKS_COMPILE_SLANG_RS_FOREACH_LOWERING_H
18 #define _FRAMEWORKS_COMPILE_SLANG_RS_FOREACH_LOWERING_H
19 
20 #include "clang/AST/StmtVisitor.h"
21 
22 namespace clang {
23   class ASTContext;
24   class CallExpr;
25   class Expr;
26   class FunctionDecl;
27 }
28 
29 namespace slang {
30 
31 class RSContext;
32 
33 class RSForEachLowering : public clang::StmtVisitor<RSForEachLowering> {
34  public:
35   explicit RSForEachLowering(RSContext* ctxt);
36 
37   // Given a FunctionDecl FD and the target API level, either translates all
38   // rsForEach() and rsForEachWithOptions() calls inside FD into calls to the
39   // low-level rsForEachInternal() API, if FD is not a kernel function itself;
40   // or, in the case where FD is a kernel function, reports a compiler error on
41   // any calls to either kernel launching API function.
42   void handleForEachCalls(clang::FunctionDecl* FD, unsigned int targetAPI);
43 
44   void VisitCallExpr(clang::CallExpr *CE);
45   void VisitStmt(clang::Stmt *S);
46 
47  private:
48   RSContext* mCtxt;
49   clang::ASTContext& mASTCtxt;
50   // A flag, if true, indicating that the visitor is walking inside a kernel
51   // function, in which case any call to rsForEach() or rsForEachWithOptions()
52   // is a compiler error.
53   bool mInsideKernel;
54 
55   const clang::FunctionDecl* matchFunctionDesignator(clang::Expr* expr);
56   const clang::FunctionDecl* matchKernelLaunchCall(clang::CallExpr* CE,
57                                                    int* slot,
58                                                    bool* hasOptions);
59   clang::FunctionDecl* CreateForEachInternalFunctionDecl();
60   clang::Expr* CreateCalleeExprForInternalForEach();
61 };  // RSForEachLowering
62 
63 }  // namespace slang
64 
65 #endif  // _FRAMEWORKS_COMPILE_SLANG_RS_FOREACH_LOWERING_H
66