123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- #include "bcinfo/BitcodeWrapper.h"
- #include "llvm/Support/raw_ostream.h"
- #include "BitWriter_2_9/ReaderWriter_2_9.h"
- #include "BitWriter_2_9_func/ReaderWriter_2_9_func.h"
- #include "BitWriter_3_2/ReaderWriter_3_2.h"
- #include "slang_assert.h"
- #include "slang_bitcode_gen.h"
- #include "slang_version.h"
- #include "llvm/Bitcode/ReaderWriter.h"
- namespace slang {
- void writeBitcode(llvm::raw_ostream &Out,
- const llvm::Module &M,
- uint32_t TargetAPI,
- uint32_t OptimizationLevel,
- bool GenerateDebugInfo) {
- std::string BitcodeStr;
- llvm::raw_string_ostream Bitcode(BitcodeStr);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (GenerateDebugInfo) {
- llvm::WriteBitcodeToFile(&M, Bitcode);
- } else {
-
- switch (TargetAPI) {
- case SLANG_HC_TARGET_API:
- case SLANG_HC_MR1_TARGET_API:
- case SLANG_HC_MR2_TARGET_API: {
-
- llvm_2_9::WriteBitcodeToFile(&M, Bitcode);
- break;
- }
- case SLANG_ICS_TARGET_API:
- case SLANG_ICS_MR1_TARGET_API: {
-
- llvm_2_9_func::WriteBitcodeToFile(&M, Bitcode);
- break;
- }
- default: {
- if (TargetAPI != SLANG_DEVELOPMENT_TARGET_API &&
- (TargetAPI < SLANG_MINIMUM_TARGET_API ||
- TargetAPI > SLANG_MAXIMUM_TARGET_API)) {
- slangAssert(false && "Invalid target API value");
- }
-
-
- llvm_3_2::WriteBitcodeToFile(&M, Bitcode);
- break;
- }
- }
- }
- const uint32_t CompilerVersion = SlangVersion::CURRENT;
-
- bcinfo::AndroidBitcodeWrapper Wrapper;
- size_t ActualWrapperLen = bcinfo::writeAndroidBitcodeWrapper(
- &Wrapper, Bitcode.str().length(), TargetAPI,
- CompilerVersion, OptimizationLevel);
- slangAssert(ActualWrapperLen > 0);
-
- Out.write(reinterpret_cast<char*>(&Wrapper), ActualWrapperLen);
- Out << Bitcode.str();
- }
- }
|