diff options
author | Chris Lattner <sabre@nondot.org> | 2001-07-15 00:16:22 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-07-15 00:16:22 +0000 |
commit | d2fdd91c66e5308bf7f5cee9dba0fcda1f50acb8 (patch) | |
tree | 747604bfc8a347d7030142282869b6f7806b796d /include | |
parent | bb1604c9313f36437742f972bef7431030ba3519 (diff) | |
download | external_llvm-d2fdd91c66e5308bf7f5cee9dba0fcda1f50acb8.zip external_llvm-d2fdd91c66e5308bf7f5cee9dba0fcda1f50acb8.tar.gz external_llvm-d2fdd91c66e5308bf7f5cee9dba0fcda1f50acb8.tar.bz2 |
Add support to write and read a fixed amount of raw data
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Bytecode/Primitives.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/include/llvm/Bytecode/Primitives.h b/include/llvm/Bytecode/Primitives.h index f4b232b..e5f93e7 100644 --- a/include/llvm/Bytecode/Primitives.h +++ b/include/llvm/Bytecode/Primitives.h @@ -130,6 +130,24 @@ static inline bool read(const unsigned char *&Buf, const unsigned char *EndBuf, return false; } +static inline bool input_data(const unsigned char *&Buf, + const unsigned char *EndBuf, + void *Ptr, void *End, bool Align = false) { + unsigned char *Start = (unsigned char *)Ptr; + unsigned Amount = (unsigned char *)End - Start; + if (Buf+Amount > EndBuf) return true; +#ifdef LITTLE_ENDIAN + copy(Buf, Buf+Amount, Start); + Buf += Amount; +#else + unsigned char *E = (unsigned char *)End; + while (Ptr != E) + *--E = *Buf++; +#endif + + if (Align) return align32(Buf, EndBuf); + return false; +} //===----------------------------------------------------------------------===// // Writing Primitives @@ -234,4 +252,17 @@ static inline void output(const string &s, vector<unsigned char> &Out, align32(Out); // Make sure we are now aligned... } +static inline void output_data(void *Ptr, void *End, + vector<unsigned char> &Out, bool Align = false) { +#ifdef LITTLE_ENDIAN + Out.insert(Out.end(), (unsigned char*)Ptr, (unsigned char*)End); +#else + unsigned char *E = (unsigned char *)End; + while (Ptr != E) + Out.push_back(*--E); +#endif + + if (Align) align32(Out); +} + #endif |