binpac: Adding int64 and uint64 types to binpac.

This commit is contained in:
Seth Hall 2012-01-27 22:32:50 -05:00 committed by Tim Wojtulewicz
parent 50f5a913c3
commit 1d6cea8c52
5 changed files with 43 additions and 7 deletions

View file

@ -35,9 +35,11 @@ const int unspecified_byteorder = -1;
typedef char int8; typedef char int8;
typedef short int16; typedef short int16;
typedef long int32; typedef long int32;
typedef long long int64;
typedef unsigned char uint8; typedef unsigned char uint8;
typedef unsigned short uint16; typedef unsigned short uint16;
typedef unsigned int uint32; typedef unsigned int uint32;
typedef unsigned long long uint64;
typedef void *nullptr; typedef void *nullptr;
typedef void *voidptr; typedef void *voidptr;
typedef uint8 *byteptr; typedef uint8 *byteptr;
@ -80,6 +82,31 @@ inline uint32 pac_swap(uint32 x)
((x & 0xff) << 24); ((x & 0xff) << 24);
} }
inline int64 pac_swap(int64 x)
{
return (x >> 56) |
((x & 0xff000000000000) >> 40) |
((x & 0xff0000000000) >> 24) |
((x & 0xff00000000) >> 8) |
((x & 0xff000000) << 8) |
((x & 0xff0000) << 24) |
((x & 0xff00) << 40) |
((x & 0xff) << 56);
}
inline uint64 pac_swap(uint64 x)
{
return (x >> 56) |
((x & 0xff000000000000) >> 40) |
((x & 0xff0000000000) >> 24) |
((x & 0xff00000000) >> 8) |
((x & 0xff000000) << 8) |
((x & 0xff0000) << 24) |
((x & 0xff00) << 40) |
((x & 0xff) << 56);
}
#define FixByteOrder(byteorder, x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap(x)) #define FixByteOrder(byteorder, x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap(x))
template <class T> template <class T>

View file

@ -11,8 +11,8 @@ Type *BuiltInType::DoClone() const
bool BuiltInType::IsNumericType() const bool BuiltInType::IsNumericType() const
{ {
BITType t = bit_type(); BITType t = bit_type();
return (t == INT8 || t == INT16 || t == INT32 || return (t == INT8 || t == INT16 || t == INT32 || t == INT64 ||
t == UINT8 || t == UINT16 || t == UINT32); t == UINT8 || t == UINT16 || t == UINT32 || t == UINT64);
} }
bool BuiltInType::CompatibleBuiltInTypes(BuiltInType *type1, bool BuiltInType::CompatibleBuiltInTypes(BuiltInType *type1,
@ -125,6 +125,8 @@ void BuiltInType::DoGenParseCode(Output* out_cc, Env* env,
case UINT16: case UINT16:
case INT32: case INT32:
case UINT32: case UINT32:
case INT64:
case UINT64:
#if 0 #if 0
out_cc->println("%s = UnMarshall<%s>(%s, %s);", out_cc->println("%s = UnMarshall<%s>(%s, %s);",
lvalue(), lvalue(),

View file

@ -68,9 +68,13 @@ void insert_basictype_defs(Output* out)
out->println("typedef char int8;"); out->println("typedef char int8;");
out->println("typedef short int16;"); out->println("typedef short int16;");
out->println("typedef long int32;"); out->println("typedef long int32;");
out->println("typedef long long int64;");
out->println("typedef unsigned char uint8;"); out->println("typedef unsigned char uint8;");
out->println("typedef unsigned short uint16;"); out->println("typedef unsigned short uint16;");
out->println("typedef unsigned long uint32;"); out->println("typedef unsigned long uint32;");
out->println("typedef unsigned long long uint64;");
out->println(""); out->println("");
out->println("#endif /* pac_type_defs */"); out->println("#endif /* pac_type_defs */");
out->println(""); out->println("");
@ -80,6 +84,7 @@ void insert_byteorder_macros(Output* out)
{ {
out->println("#define FixByteOrder16(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap16(x))"); out->println("#define FixByteOrder16(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap16(x))");
out->println("#define FixByteOrder32(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap32(x))"); out->println("#define FixByteOrder32(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap32(x))");
out->println("#define FixByteOrder64(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap64(x))");
out->println(""); out->println("");
} }

View file

@ -6,8 +6,8 @@
%token TOK_RIGHTARROW TOK_DEFAULT TOK_OF %token TOK_RIGHTARROW TOK_DEFAULT TOK_OF
%token TOK_PADDING TOK_TO TOK_ALIGN %token TOK_PADDING TOK_TO TOK_ALIGN
%token TOK_WITHINPUT %token TOK_WITHINPUT
%token TOK_INT8 TOK_INT16 TOK_INT32 %token TOK_INT8 TOK_INT16 TOK_INT32 TOK_INT64
%token TOK_UINT8 TOK_UINT16 TOK_UINT32 %token TOK_UINT8 TOK_UINT16 TOK_UINT32 TOK_UINT64
%token TOK_ID TOK_NUMBER TOK_REGEX TOK_STRING %token TOK_ID TOK_NUMBER TOK_REGEX TOK_STRING
%token TOK_BEGIN_RE TOK_END_RE %token TOK_BEGIN_RE TOK_END_RE
%token TOK_ATTR_ALSO %token TOK_ATTR_ALSO

View file

@ -2,7 +2,9 @@
TYPE_DEF(INT8, "int8", "int8", 1) TYPE_DEF(INT8, "int8", "int8", 1)
TYPE_DEF(INT16, "int16", "int16", 2) TYPE_DEF(INT16, "int16", "int16", 2)
TYPE_DEF(INT32, "int32", "int32", 4) TYPE_DEF(INT32, "int32", "int32", 4)
TYPE_DEF(INT64, "int64", "int64", 8)
TYPE_DEF(UINT8, "uint8", "uint8", 1) TYPE_DEF(UINT8, "uint8", "uint8", 1)
TYPE_DEF(UINT16, "uint16", "uint16", 2) TYPE_DEF(UINT16, "uint16", "uint16", 2)
TYPE_DEF(UINT32, "uint32", "uint32", 4) TYPE_DEF(UINT32, "uint32", "uint32", 4)
TYPE_DEF(UINT64, "uint64", "uint64", 8)
TYPE_DEF(EMPTY, "empty", "", 0) TYPE_DEF(EMPTY, "empty", "", 0)