1 /*
2  * Copyright 2014, 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_CC_OPTIONS_H_  // NOLINT
18 #define _FRAMEWORKS_COMPILE_SLANG_RS_CC_OPTIONS_H_
19 
20 #include "llvm/Option/ArgList.h"
21 #include "llvm/Option/Option.h"
22 #include "llvm/Option/OptTable.h"
23 
24 #include "slang.h"
25 #include "slang_rs_reflect_utils.h"
26 
27 #include <string>
28 #include <vector>
29 
30 namespace llvm {
31 namespace cl {
32 class StringSaver;
33 }
34 namespace opt {
35 class OptTable;
36 }
37 }
38 
39 namespace slang {
40 
41 // Options for the RenderScript compiler llvm-rs-cc
42 class RSCCOptions {
43  public:
44   // User-defined include paths.
45   std::vector<std::string> mIncludePaths;
46 
47   // The output directory for writing the bitcode files
48   // (i.e. out/target/common/obj/APPS/.../src/renderscript/res/raw).
49   std::string mBitcodeOutputDir;
50 
51   // Type of file to emit (bitcode, dependency, ...).
52   slang::Slang::OutputType mOutputType;
53 
54   // Allow user-defined functions prefixed with 'rs'.
55   bool mAllowRSPrefix;
56 
57   // 32-bit or 64-bit target
58   uint32_t mBitWidth;
59 
60   // The path for storing reflected Java source files
61   // (i.e. out/target/common/obj/APPS/.../src/renderscript/src).
62   std::string mJavaReflectionPathBase;
63 
64   // Force package name. This may override the package name specified by a
65   // #pragma in the .rs file.
66   std::string mJavaReflectionPackageName;
67 
68   // Force the RS package name to use. This can override the default value of
69   // "android.renderscript" used for the standard RS APIs.
70   std::string mRSPackageName;
71 
72   // Where to store the generated bitcode (resource, Java source, C++ source).
73   slang::BitCodeStorageType mBitcodeStorage;
74 
75   // Emit output dependency file for each input file.
76   bool mEmitDependency;
77 
78   // The output directory for writing dependency files
79   // (i.e. out/target/common/obj/APPS/.../src/renderscript).
80   std::string mDependencyOutputDir;
81 
82   // User-defined files added to the dependencies (i.e. for adding fake
83   // dependency files like RenderScript.stamp).
84   std::vector<std::string> mAdditionalDepTargets;
85 
86   bool mShowHelp;     // Show the -help text.
87   bool mShowVersion;  // Show the -version text.
88 
89   // The target API we are generating code for (see slang_version.h).
90   unsigned int mTargetAPI;
91 
92   // Enable emission of debugging symbols.
93   bool mDebugEmission;
94 
95   // The optimization level used in CodeGen, and encoded in emitted bitcode.
96   llvm::CodeGenOpt::Level mOptimizationLevel;
97 
98   // Display verbose information about the compilation on stdout.
99   bool mVerbose;
100 
101   // Emit both 32-bit and 64-bit bitcode (embedded in the reflected sources).
102   bool mEmit3264;
103 
RSCCOptions()104   RSCCOptions() {
105     mOutputType = slang::Slang::OT_Bitcode;
106     mBitWidth = 32;
107     mBitcodeStorage = slang::BCST_APK_RESOURCE;
108     mEmitDependency = 0;
109     mShowHelp = 0;
110     mShowVersion = 0;
111     mTargetAPI = RS_VERSION;
112     mDebugEmission = 0;
113     mOptimizationLevel = llvm::CodeGenOpt::Aggressive;
114     mVerbose = false;
115     mEmit3264 = false;
116   }
117 };
118 
119 /* Return a valid OptTable (useful for dumping help information)
120  */
121 llvm::opt::OptTable *createRSCCOptTable();
122 
123 /* Parse ArgVector and return a list of Inputs (source files) and Opts
124  * (options affecting the compilation of those source files).
125  *
126  * \param ArgVector - the input arguments to llvm-rs-cc
127  * \param Inputs - returned list of actual input source filenames
128  * \param Opts - returned options after command line has been processed
129  * \param DiagEngine - input for issuing warnings/errors on arguments
130  */
131 
132 bool ParseArguments(const llvm::ArrayRef<const char *> &ArgsIn,
133                     llvm::SmallVectorImpl<const char *> &Inputs,
134                     RSCCOptions &Opts, clang::DiagnosticOptions &DiagOpts,
135                     llvm::cl::StringSaver &StringSaver);
136 
137 } // namespace slang
138 
139 #endif  // _FRAMEWORKS_COMPILE_SLANG_RS_CC_OPTIONS_H_
140