blob: 3cbd589c100e0bbefd93af0974af42b9cf3b309f [file] [log] [blame]
Zonr Changc383a502010-10-12 01:52:08 +08001/*
2 * Copyright 2010, 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
Stephen Hinese639eb52010-11-08 19:27:20 -080017#ifndef _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ // NOLINT
18#define _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080019
20#include "slang.h"
21
Zonr Changcf6af6a2010-10-12 12:38:51 +080022#include <list>
Zonr Changcf6af6a2010-10-12 12:38:51 +080023#include <string>
Stephen Hinese639eb52010-11-08 19:27:20 -080024#include <utility>
25#include <vector>
Zonr Changcf6af6a2010-10-12 12:38:51 +080026
Zonr Chang641558f2010-10-12 21:07:06 +080027#include "llvm/ADT/StringMap.h"
28
Zonr Changcf6af6a2010-10-12 12:38:51 +080029#include "slang_rs_reflect_utils.h"
30
Stephen Hinesfcda2352010-10-19 16:49:32 -070031namespace clang {
32 class FunctionDecl;
33}
34
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080035namespace slang {
36 class RSContext;
Zonr Chang641558f2010-10-12 21:07:06 +080037 class RSExportRecordType;
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080038
39class SlangRS : public Slang {
40 private:
41 // Context for RenderScript
42 RSContext *mRSContext;
43
44 bool mAllowRSPrefix;
45
Zonr Chang641558f2010-10-12 21:07:06 +080046 // Custom diagnostic identifiers
47 unsigned mDiagErrorInvalidOutputDepParameter;
48 unsigned mDiagErrorODR;
49
50 // FIXME: Should be std::list<RSExportable *> here. But currently we only
51 // check ODR on record type.
52 //
53 // ReflectedDefinitions maps record type name to a pair:
54 // <its RSExportRecordType instance,
55 // the first file contains this record type definition>
56 typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy;
57 typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
58 ReflectedDefinitionListTy ReflectedDefinitions;
59
Zonr Changcf6af6a2010-10-12 12:38:51 +080060 // The package name that's really applied will be filled in RealPackageName.
61 bool reflectToJava(const std::string &OutputPathBase,
62 const std::string &OutputPackageName,
63 std::string *RealPackageName);
64
65 bool generateBitcodeAccessor(const std::string &OutputPathBase,
66 const std::string &PackageName);
67
Zonr Change86245a2010-10-12 21:42:13 +080068 // CurInputFile is the pointer to a char array holding the input filename
69 // and is valid before compile() ends.
70 bool checkODR(const char *CurInputFile);
Zonr Chang641558f2010-10-12 21:07:06 +080071
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080072 protected:
73 virtual void initDiagnostic();
74 virtual void initPreprocessor();
75 virtual void initASTContext();
76
77 virtual clang::ASTConsumer
78 *createBackend(const clang::CodeGenOptions& CodeGenOpts,
79 llvm::raw_ostream *OS,
80 Slang::OutputType OT);
81
82
83 public:
Zonr Chang592a9542010-10-07 20:03:58 +080084 static bool IsRSHeaderFile(const char *File);
Stephen Hinesfcda2352010-10-19 16:49:32 -070085 // FIXME: Determine whether a function is in RS header (i.e., one of the RS
86 // built-in APIs) should only need its names (we need a "list" of RS
87 // built-in APIs).
88 static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD,
89 const clang::SourceManager &SourceMgr);
Zonr Chang592a9542010-10-07 20:03:58 +080090
Zonr Chang641558f2010-10-12 21:07:06 +080091 SlangRS();
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080092
Zonr Changcf6af6a2010-10-12 12:38:51 +080093 // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if
94 // all given input files are successfully compiled without errors.
95 //
96 // @IOFiles - List of pairs of <input file path, output file path>.
97 //
98 // @DepFiles - List of pairs of <output dep. file path, dependent bitcode
99 // target>. If @OutputDep is true, this parameter must be given
100 // with the same number of pairs given in @IOFiles.
101 //
Zonr Chang641558f2010-10-12 21:07:06 +0800102 // @IncludePaths - User-defined include paths.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800103 //
104 // @AdditionalDepTargets - User-defined files added to the dependencies.
105 //
106 // @OutputType - See Slang::OutputType.
107 //
108 // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp.
109 //
110 // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'.
111 //
Zonr Chang641558f2010-10-12 21:07:06 +0800112 // @OutputDep - true if output dependecies file for each input file.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800113 //
114 // @JavaReflectionPathBase - The path base for storing reflection files.
115 //
116 // @JavaReflectionPackageName - The package name given by user in command
117 // line. This may override the package name
118 // specified in the .rs using #pragma.
119 //
120 bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles,
121 const std::list<std::pair<const char*, const char*> > &DepFiles,
122 const std::vector<std::string> &IncludePaths,
123 const std::vector<std::string> &AdditionalDepTargets,
124 Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage,
125 bool AllowRSPrefix, bool OutputDep,
126 const std::string &JavaReflectionPathBase,
127 const std::string &JavaReflectionPackageName);
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800128
Zonr Chang641558f2010-10-12 21:07:06 +0800129 virtual void reset();
130
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800131 virtual ~SlangRS();
132};
133}
134
Stephen Hinese639eb52010-11-08 19:27:20 -0800135#endif // _FRAMEWORKS_COMPILE_SLANG_SLANG_RS_H_ NOLINT