blob: f50077e1085805a31917f311e749deba8d3539f0 [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
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080017#ifndef _SLANG_COMPILER_SLANG_RS_HPP
18#define _SLANG_COMPILER_SLANG_RS_HPP
19
20#include "slang.h"
21
Zonr Changcf6af6a2010-10-12 12:38:51 +080022#include <list>
23#include <vector>
24#include <string>
25
Zonr Chang641558f2010-10-12 21:07:06 +080026#include "llvm/ADT/StringMap.h"
27
Zonr Changcf6af6a2010-10-12 12:38:51 +080028#include "slang_rs_reflect_utils.h"
29
Stephen Hinesfcda2352010-10-19 16:49:32 -070030namespace clang {
31 class FunctionDecl;
32}
33
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080034namespace slang {
35 class RSContext;
Zonr Chang641558f2010-10-12 21:07:06 +080036 class RSExportRecordType;
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080037
38class SlangRS : public Slang {
39 private:
40 // Context for RenderScript
41 RSContext *mRSContext;
42
43 bool mAllowRSPrefix;
44
Zonr Chang641558f2010-10-12 21:07:06 +080045 // Custom diagnostic identifiers
46 unsigned mDiagErrorInvalidOutputDepParameter;
47 unsigned mDiagErrorODR;
48
49 // FIXME: Should be std::list<RSExportable *> here. But currently we only
50 // check ODR on record type.
51 //
52 // ReflectedDefinitions maps record type name to a pair:
53 // <its RSExportRecordType instance,
54 // the first file contains this record type definition>
55 typedef std::pair<RSExportRecordType*, const char*> ReflectedDefinitionTy;
56 typedef llvm::StringMap<ReflectedDefinitionTy> ReflectedDefinitionListTy;
57 ReflectedDefinitionListTy ReflectedDefinitions;
58
Zonr Changcf6af6a2010-10-12 12:38:51 +080059 // The package name that's really applied will be filled in RealPackageName.
60 bool reflectToJava(const std::string &OutputPathBase,
61 const std::string &OutputPackageName,
62 std::string *RealPackageName);
63
64 bool generateBitcodeAccessor(const std::string &OutputPathBase,
65 const std::string &PackageName);
66
Zonr Change86245a2010-10-12 21:42:13 +080067 // CurInputFile is the pointer to a char array holding the input filename
68 // and is valid before compile() ends.
69 bool checkODR(const char *CurInputFile);
Zonr Chang641558f2010-10-12 21:07:06 +080070
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080071 protected:
72 virtual void initDiagnostic();
73 virtual void initPreprocessor();
74 virtual void initASTContext();
75
76 virtual clang::ASTConsumer
77 *createBackend(const clang::CodeGenOptions& CodeGenOpts,
78 llvm::raw_ostream *OS,
79 Slang::OutputType OT);
80
81
82 public:
Zonr Chang592a9542010-10-07 20:03:58 +080083 static bool IsRSHeaderFile(const char *File);
Stephen Hinesfcda2352010-10-19 16:49:32 -070084 // FIXME: Determine whether a function is in RS header (i.e., one of the RS
85 // built-in APIs) should only need its names (we need a "list" of RS
86 // built-in APIs).
87 static bool IsFunctionInRSHeaderFile(const clang::FunctionDecl *FD,
88 const clang::SourceManager &SourceMgr);
Zonr Chang592a9542010-10-07 20:03:58 +080089
Zonr Chang641558f2010-10-12 21:07:06 +080090 SlangRS();
Zonr Chang3a9ca1f2010-10-06 17:52:56 +080091
Zonr Changcf6af6a2010-10-12 12:38:51 +080092 // Compile bunch of RS files given in the llvm-rs-cc arguments. Return true if
93 // all given input files are successfully compiled without errors.
94 //
95 // @IOFiles - List of pairs of <input file path, output file path>.
96 //
97 // @DepFiles - List of pairs of <output dep. file path, dependent bitcode
98 // target>. If @OutputDep is true, this parameter must be given
99 // with the same number of pairs given in @IOFiles.
100 //
Zonr Chang641558f2010-10-12 21:07:06 +0800101 // @IncludePaths - User-defined include paths.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800102 //
103 // @AdditionalDepTargets - User-defined files added to the dependencies.
104 //
105 // @OutputType - See Slang::OutputType.
106 //
107 // @BitcodeStorage - See BitCodeStorageType in slang_rs_reflect_util.cpp.
108 //
109 // @AllowRSPrefix - true to allow user-defined function prefixed with 'rs'.
110 //
Zonr Chang641558f2010-10-12 21:07:06 +0800111 // @OutputDep - true if output dependecies file for each input file.
Zonr Changcf6af6a2010-10-12 12:38:51 +0800112 //
113 // @JavaReflectionPathBase - The path base for storing reflection files.
114 //
115 // @JavaReflectionPackageName - The package name given by user in command
116 // line. This may override the package name
117 // specified in the .rs using #pragma.
118 //
119 bool compile(const std::list<std::pair<const char*, const char*> > &IOFiles,
120 const std::list<std::pair<const char*, const char*> > &DepFiles,
121 const std::vector<std::string> &IncludePaths,
122 const std::vector<std::string> &AdditionalDepTargets,
123 Slang::OutputType OutputType, BitCodeStorageType BitcodeStorage,
124 bool AllowRSPrefix, bool OutputDep,
125 const std::string &JavaReflectionPathBase,
126 const std::string &JavaReflectionPackageName);
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800127
Zonr Chang641558f2010-10-12 21:07:06 +0800128 virtual void reset();
129
Zonr Chang3a9ca1f2010-10-06 17:52:56 +0800130 virtual ~SlangRS();
131};
132}
133
134#endif // _SLANG_COMPILER_SLANG_RS_HPP