summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-04 03:30:17 +0000
committerChris Lattner <sabre@nondot.org>2007-05-04 03:30:17 +0000
commitfee5a3752afb3b94715c55fad007fe33ac974650 (patch)
tree87e19a7916fdf90e2344c03315bfe550f873dfff /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parentfc5b61941993bfc54c34f90551a9f0ef1378ca63 (diff)
downloadbcm5719-llvm-fee5a3752afb3b94715c55fad007fe33ac974650.tar.gz
bcm5719-llvm-fee5a3752afb3b94715c55fad007fe33ac974650.zip
add support for reading the param attrs block
llvm-svn: 36731
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
index 8d148ceb805..ca372d663e2 100644
--- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -17,6 +17,7 @@
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/Module.h"
+#include "llvm/ParameterAttributes.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
@@ -26,6 +27,9 @@ BitcodeReader::~BitcodeReader() {
delete Buffer;
}
+//===----------------------------------------------------------------------===//
+// Helper functions to implement forward reference resolution, etc.
+//===----------------------------------------------------------------------===//
/// ConvertToString - Convert a string from a record into an std::string, return
/// true on failure.
@@ -173,6 +177,67 @@ const Type *BitcodeReader::getTypeByID(unsigned ID, bool isTypeTable) {
return TypeList.back().get();
}
+//===----------------------------------------------------------------------===//
+// Functions for parsing blocks from the bitcode file
+//===----------------------------------------------------------------------===//
+
+bool BitcodeReader::ParseParamAttrBlock() {
+ if (Stream.EnterSubBlock())
+ return Error("Malformed block record");
+
+ if (!ParamAttrs.empty())
+ return Error("Multiple PARAMATTR blocks found!");
+
+ SmallVector<uint64_t, 64> Record;
+
+ ParamAttrsVector Attrs;
+
+ // Read all the records.
+ while (1) {
+ unsigned Code = Stream.ReadCode();
+ if (Code == bitc::END_BLOCK) {
+ if (Stream.ReadBlockEnd())
+ return Error("Error at end of PARAMATTR block");
+ return false;
+ }
+
+ if (Code == bitc::ENTER_SUBBLOCK) {
+ // No known subblocks, always skip them.
+ Stream.ReadSubBlockID();
+ if (Stream.SkipBlock())
+ return Error("Malformed block record");
+ continue;
+ }
+
+ if (Code == bitc::DEFINE_ABBREV) {
+ Stream.ReadAbbrevRecord();
+ continue;
+ }
+
+ // Read a record.
+ Record.clear();
+ switch (Stream.ReadRecord(Code, Record)) {
+ default: // Default behavior: ignore.
+ break;
+ case bitc::PARAMATTR_CODE_ENTRY: { // ENTRY: [paramidx0, attr0, ...]
+ if (Record.size() & 1)
+ return Error("Invalid ENTRY record");
+
+ ParamAttrsWithIndex PAWI;
+ for (unsigned i = 0, e = Record.size(); i != e; i += 2) {
+ PAWI.index = Record[i];
+ PAWI.attrs = Record[i+1];
+ Attrs.push_back(PAWI);
+ }
+ ParamAttrs.push_back(ParamAttrsList::get(Attrs));
+ Attrs.clear();
+ break;
+ }
+ }
+ }
+}
+
+
bool BitcodeReader::ParseTypeTable() {
if (Stream.EnterSubBlock())
return Error("Malformed block record");
@@ -742,6 +807,10 @@ bool BitcodeReader::ParseModule(const std::string &ModuleID) {
if (Stream.SkipBlock())
return Error("Malformed block record");
break;
+ case bitc::PARAMATTR_BLOCK_ID:
+ if (ParseParamAttrBlock())
+ return true;
+ break;
case bitc::TYPE_BLOCK_ID:
if (ParseTypeTable())
return true;
OpenPOWER on IntegriCloud