From 1d6cea8c52068f9b9dd1fb7a847778bfcfd892f6 Mon Sep 17 00:00:00 2001 From: Seth Hall Date: Fri, 27 Jan 2012 22:32:50 -0500 Subject: [PATCH] binpac: Adding int64 and uint64 types to binpac. --- tools/binpac/lib/binpac.h.in | 33 ++++++++++++++++++++++++++++++--- tools/binpac/src/pac_btype.cc | 6 ++++-- tools/binpac/src/pac_main.cc | 5 +++++ tools/binpac/src/pac_parse.yy | 4 ++-- tools/binpac/src/pac_type.def | 2 ++ 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/tools/binpac/lib/binpac.h.in b/tools/binpac/lib/binpac.h.in index c7e8eac515..eaef8e7fcd 100644 --- a/tools/binpac/lib/binpac.h.in +++ b/tools/binpac/lib/binpac.h.in @@ -35,9 +35,11 @@ const int unspecified_byteorder = -1; typedef char int8; typedef short int16; typedef long int32; -typedef unsigned char uint8; -typedef unsigned short uint16; -typedef unsigned int uint32; +typedef long long int64; +typedef unsigned char uint8; +typedef unsigned short uint16; +typedef unsigned int uint32; +typedef unsigned long long uint64; typedef void *nullptr; typedef void *voidptr; typedef uint8 *byteptr; @@ -80,6 +82,31 @@ inline uint32 pac_swap(uint32 x) ((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)) template diff --git a/tools/binpac/src/pac_btype.cc b/tools/binpac/src/pac_btype.cc index a7df6f7bf3..c565932d24 100644 --- a/tools/binpac/src/pac_btype.cc +++ b/tools/binpac/src/pac_btype.cc @@ -11,8 +11,8 @@ Type *BuiltInType::DoClone() const bool BuiltInType::IsNumericType() const { BITType t = bit_type(); - return (t == INT8 || t == INT16 || t == INT32 || - t == UINT8 || t == UINT16 || t == UINT32); + return (t == INT8 || t == INT16 || t == INT32 || t == INT64 || + t == UINT8 || t == UINT16 || t == UINT32 || t == UINT64); } bool BuiltInType::CompatibleBuiltInTypes(BuiltInType *type1, @@ -125,6 +125,8 @@ void BuiltInType::DoGenParseCode(Output* out_cc, Env* env, case UINT16: case INT32: case UINT32: + case INT64: + case UINT64: #if 0 out_cc->println("%s = UnMarshall<%s>(%s, %s);", lvalue(), diff --git a/tools/binpac/src/pac_main.cc b/tools/binpac/src/pac_main.cc index 68405effef..e104a86952 100644 --- a/tools/binpac/src/pac_main.cc +++ b/tools/binpac/src/pac_main.cc @@ -68,9 +68,13 @@ void insert_basictype_defs(Output* out) out->println("typedef char int8;"); out->println("typedef short int16;"); out->println("typedef long int32;"); + out->println("typedef long long int64;"); + out->println("typedef unsigned char uint8;"); out->println("typedef unsigned short uint16;"); out->println("typedef unsigned long uint32;"); + out->println("typedef unsigned long long uint64;"); + out->println(""); out->println("#endif /* pac_type_defs */"); 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 FixByteOrder32(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap32(x))"); + out->println("#define FixByteOrder64(x) (byteorder == HOST_BYTEORDER ? (x) : pac_swap64(x))"); out->println(""); } diff --git a/tools/binpac/src/pac_parse.yy b/tools/binpac/src/pac_parse.yy index 3d7f9a328f..d29e361910 100644 --- a/tools/binpac/src/pac_parse.yy +++ b/tools/binpac/src/pac_parse.yy @@ -6,8 +6,8 @@ %token TOK_RIGHTARROW TOK_DEFAULT TOK_OF %token TOK_PADDING TOK_TO TOK_ALIGN %token TOK_WITHINPUT -%token TOK_INT8 TOK_INT16 TOK_INT32 -%token TOK_UINT8 TOK_UINT16 TOK_UINT32 +%token TOK_INT8 TOK_INT16 TOK_INT32 TOK_INT64 +%token TOK_UINT8 TOK_UINT16 TOK_UINT32 TOK_UINT64 %token TOK_ID TOK_NUMBER TOK_REGEX TOK_STRING %token TOK_BEGIN_RE TOK_END_RE %token TOK_ATTR_ALSO diff --git a/tools/binpac/src/pac_type.def b/tools/binpac/src/pac_type.def index 62939ec671..a34c3547c2 100644 --- a/tools/binpac/src/pac_type.def +++ b/tools/binpac/src/pac_type.def @@ -2,7 +2,9 @@ TYPE_DEF(INT8, "int8", "int8", 1) TYPE_DEF(INT16, "int16", "int16", 2) TYPE_DEF(INT32, "int32", "int32", 4) +TYPE_DEF(INT64, "int64", "int64", 8) TYPE_DEF(UINT8, "uint8", "uint8", 1) TYPE_DEF(UINT16, "uint16", "uint16", 2) TYPE_DEF(UINT32, "uint32", "uint32", 4) +TYPE_DEF(UINT64, "uint64", "uint64", 8) TYPE_DEF(EMPTY, "empty", "", 0)