Home | History | Annotate | Download | only in slang
      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   // Emit phony targets for each header dependency, which can avoid make errors
     79   // when the header gets deleted. See -MP option of cc.
     80   bool mEmitPhonyDependency;
     81 
     82   // The output directory for writing dependency files
     83   // (i.e. out/target/common/obj/APPS/.../src/renderscript).
     84   std::string mDependencyOutputDir;
     85 
     86   // User-defined files added to the dependencies (i.e. for adding fake
     87   // dependency files like RenderScript.stamp).
     88   std::vector<std::string> mAdditionalDepTargets;
     89 
     90   bool mShowHelp;     // Show the -help text.
     91   bool mShowVersion;  // Show the -version text.
     92 
     93   // The target API we are generating code for (see slang_version.h).
     94   unsigned int mTargetAPI;
     95 
     96   // Enable emission of debugging symbols.
     97   bool mDebugEmission;
     98 
     99   // The optimization level used in CodeGen, and encoded in emitted bitcode.
    100   llvm::CodeGenOpt::Level mOptimizationLevel;
    101 
    102   // Display verbose information about the compilation on stdout.
    103   bool mVerbose;
    104 
    105   // Display AST.
    106   bool mASTPrint;
    107 
    108   // Emit both 32-bit and 64-bit bitcode (embedded in the reflected sources).
    109   bool mEmit3264;
    110 
    111   RSCCOptions() {
    112     mOutputType = slang::Slang::OT_Bitcode;
    113     mBitWidth = 32;
    114     mBitcodeStorage = slang::BCST_APK_RESOURCE;
    115     mEmitDependency = 0;
    116     mEmitPhonyDependency = 0;
    117     mShowHelp = 0;
    118     mShowVersion = 0;
    119     mTargetAPI = RS_VERSION;
    120     mDebugEmission = 0;
    121     mOptimizationLevel = llvm::CodeGenOpt::Aggressive;
    122     mVerbose = false;
    123     mASTPrint = false;
    124     mEmit3264 = true;
    125   }
    126 };
    127 
    128 /* Return a valid OptTable (useful for dumping help information)
    129  */
    130 llvm::opt::OptTable *createRSCCOptTable();
    131 
    132 /* Parse ArgVector and return a list of Inputs (source files) and Opts
    133  * (options affecting the compilation of those source files).
    134  *
    135  * \param ArgVector - the input arguments to llvm-rs-cc
    136  * \param Inputs - returned list of actual input source filenames
    137  * \param Opts - returned options after command line has been processed
    138  * \param DiagEngine - input for issuing warnings/errors on arguments
    139  */
    140 
    141 bool ParseArguments(const llvm::ArrayRef<const char *> &ArgsIn,
    142                     llvm::SmallVectorImpl<const char *> &Inputs,
    143                     RSCCOptions &Opts, clang::DiagnosticOptions &DiagOpts,
    144                     llvm::StringSaver &StringSaver);
    145 
    146 } // namespace slang
    147 
    148 #endif  // _FRAMEWORKS_COMPILE_SLANG_RS_CC_OPTIONS_H_
    149