OLD | NEW |
---|---|
1 //===- NaClBitcodeReader.cpp ----------------------------------------------===// | 1 //===- NaClBitcodeReader.cpp ----------------------------------------------===// |
2 // Internal NaClBitcodeReader implementation | 2 // Internal NaClBitcodeReader implementation |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 | 10 |
(...skipping 1832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1843 | 1843 |
1844 Value *Cond = getValue(Record, 1, NextValueNo); | 1844 Value *Cond = getValue(Record, 1, NextValueNo); |
1845 BasicBlock *Default = getBasicBlock(Record[2]); | 1845 BasicBlock *Default = getBasicBlock(Record[2]); |
1846 if (OpTy == 0 || Cond == 0 || Default == 0) | 1846 if (OpTy == 0 || Cond == 0 || Default == 0) |
1847 return Error(InvalidRecord, "Invalid SWITCH record"); | 1847 return Error(InvalidRecord, "Invalid SWITCH record"); |
1848 | 1848 |
1849 Cond = ConvertOpToScalar(Cond, CurBBNo); | 1849 Cond = ConvertOpToScalar(Cond, CurBBNo); |
1850 // TODO(kschimpf): Deal with values that are too large for NumCases. | 1850 // TODO(kschimpf): Deal with values that are too large for NumCases. |
1851 size_t NumCases = Record[3]; | 1851 size_t NumCases = Record[3]; |
1852 | 1852 |
1853 SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases); | 1853 std::unique_ptr<SwitchInst> SI( |
1854 SwitchInst::Create(Cond, Default, NumCases)); | |
1854 | 1855 |
1855 size_t CurIdx = 4; | 1856 size_t CurIdx = 4; |
1856 for (size_t i = 0; i != NumCases; ++i) { | 1857 for (size_t i = 0; i != NumCases; ++i) { |
1857 // The PNaCl bitcode format has vestigial support for case | 1858 // The PNaCl bitcode format has vestigial support for case |
1858 // ranges, but we no longer support reading them because | 1859 // ranges, but we no longer support reading them because |
1859 // no-one produced them. | 1860 // no-one produced them. |
1860 // See https://code.google.com/p/nativeclient/issues/detail?id=3758 | 1861 // See https://code.google.com/p/nativeclient/issues/detail?id=3758 |
1861 if (CurIdx + 3 >= Record.size()) | 1862 if (CurIdx + 3 >= Record.size()) |
1862 return Error(InvalidRecord, | 1863 return Error(InvalidRecord, |
1863 "Incomplete case entry in SWITCH record"); | 1864 "Incomplete case entry in SWITCH record"); |
1864 uint64_t NumItems = Record[CurIdx++]; | 1865 uint64_t NumItems = Record[CurIdx++]; |
1865 bool isSingleNumber = Record[CurIdx++]; | 1866 bool isSingleNumber = Record[CurIdx++]; |
1866 if (NumItems != 1 || !isSingleNumber) | 1867 if (NumItems != 1 || !isSingleNumber) |
1867 return Error(InvalidRecord, | 1868 return Error(InvalidRecord, |
1868 "Case ranges are not supported in PNaCl bitcode"); | 1869 "Case ranges are not supported in PNaCl bitcode"); |
1869 | 1870 |
1870 APInt CaseValue(ValueBitWidth, | 1871 APInt CaseValue(ValueBitWidth, |
1871 NaClDecodeSignRotatedValue(Record[CurIdx++])); | 1872 NaClDecodeSignRotatedValue(Record[CurIdx++])); |
1872 BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]); | 1873 BasicBlock *DestBB = getBasicBlock(Record[CurIdx++]); |
1874 if (DestBB == nullptr) | |
1875 return Error(InvalidValue, "Invalid branch in SWITCH case"); | |
1873 SI->addCase(ConstantInt::get(Context, CaseValue), DestBB); | 1876 SI->addCase(ConstantInt::get(Context, CaseValue), DestBB); |
1874 } | 1877 } |
1875 I = SI; | 1878 I = SI.release(); |
JF
2015/08/20 16:24:00
At this point it's probably better to do the chang
Karl
2015/08/20 18:30:51
Acknowledged.
| |
1876 break; | 1879 break; |
1877 } | 1880 } |
1878 case naclbitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE | 1881 case naclbitc::FUNC_CODE_INST_UNREACHABLE: // UNREACHABLE |
1879 I = new UnreachableInst(Context); | 1882 I = new UnreachableInst(Context); |
1880 break; | 1883 break; |
1881 case naclbitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...] | 1884 case naclbitc::FUNC_CODE_INST_PHI: { // PHI: [ty, val0,bb0, ...] |
1882 if (Record.size() < 1 || ((Record.size()-1)&1)) | 1885 if (Record.size() < 1 || ((Record.size()-1)&1)) |
1883 return Error(InvalidRecord, "Invalid PHI record"); | 1886 return Error(InvalidRecord, "Invalid PHI record"); |
1884 Type *Ty = getTypeByID(Record[0]); | 1887 Type *Ty = getTypeByID(Record[0]); |
1885 if (!Ty) return Error(InvalidType, "Invalid PHI record"); | 1888 if (!Ty) return Error(InvalidType, "Invalid PHI record"); |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2353 if (std::error_code EC = M->materializeAllPermanently()) { | 2356 if (std::error_code EC = M->materializeAllPermanently()) { |
2354 delete M; | 2357 delete M; |
2355 return EC; | 2358 return EC; |
2356 } | 2359 } |
2357 | 2360 |
2358 // TODO: Restore the use-lists to the in-memory state when the bitcode was | 2361 // TODO: Restore the use-lists to the in-memory state when the bitcode was |
2359 // written. We must defer until the Module has been fully materialized. | 2362 // written. We must defer until the Module has been fully materialized. |
2360 | 2363 |
2361 return M; | 2364 return M; |
2362 } | 2365 } |
OLD | NEW |