Commit ca8a16ef by Antonio Maiorano

Subzero: clang-format crosstest, pnacl-llvm, runtime, and unittest

Formatted using: find ${DIR} -iname "*.cc" -o -iname "*.h" -o -iname "*.hpp" -o -iname "*.cpp" -o -iname "*.inl" | xargs ${CLANG_FORMAT} -i -style=file Bug: b/144825072 Change-Id: Ie6ebd83f85dc11a044dec4514a1e81edbbd4ed21 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/50169Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarAntonio Maiorano <amaiorano@google.com> Kokoro-Result: kokoro <noreply+kokoro@google.com>
parent debdfa2a
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
* (fixed length buffers, variable length buffers, etc.) * (fixed length buffers, variable length buffers, etc.)
*/ */
#include <stdint.h> /* cstdint requires -std=c++0x or higher */
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <stdint.h> /* cstdint requires -std=c++0x or higher */
#include "mem_intrin.h" #include "mem_intrin.h"
#include "xdefs.h" #include "xdefs.h"
......
/* crosstest.py --test=mem_intrin.cpp --driver=mem_intrin_main.cpp \ /* crosstest.py --test=mem_intrin.cpp --driver=mem_intrin_main.cpp \
--prefix=Subzero_ --output=mem_intrin */ --prefix=Subzero_ --output=mem_intrin */
#include <stdint.h> /* cstdint requires -std=c++0x or higher */
#include <cstdio> #include <cstdio>
#include <stdint.h> /* cstdint requires -std=c++0x or higher */
#include "mem_intrin.h" #include "mem_intrin.h"
#include "xdefs.h" #include "xdefs.h"
......
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include <stdint.h>
#include "test_arith.def" #include "test_arith.def"
#include "xdefs.h" #include "xdefs.h"
#include <stdint.h>
#include "vectors.h" #include "vectors.h"
......
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
#include <stdint.h> #include <stdint.h>
#include <climits> // CHAR_BIT
#include <limits>
#include <cfloat> #include <cfloat>
#include <climits> // CHAR_BIT
#include <cmath> // fmodf #include <cmath> // fmodf
#include <cstring> // memcmp #include <cstring> // memcmp
#include <iostream> #include <iostream>
#include <limits>
// Include test_arith.h twice - once normally, and once within the // Include test_arith.h twice - once normally, and once within the
// Subzero_ namespace, corresponding to the llc and Subzero translated // Subzero_ namespace, corresponding to the llc and Subzero translated
...@@ -66,22 +66,26 @@ void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -66,22 +66,26 @@ void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
bool ExcludeDivExceptions; // for divide related tests bool ExcludeDivExceptions; // for divide related tests
} Funcs[] = { } Funcs[] = {
#define X(inst, op, isdiv, isshift) \ #define X(inst, op, isdiv, isshift) \
{ STR(inst), test##inst, Subzero_::test##inst, NULL, NULL, isdiv } \ {STR(inst), test##inst, Subzero_::test##inst, NULL, NULL, isdiv},
,
UINTOP_TABLE UINTOP_TABLE
#undef X #undef X
#define X(inst, op, isdiv, isshift) \ #define X(inst, op, isdiv, isshift) \
{ STR(inst), NULL, NULL, test##inst, Subzero_::test##inst, isdiv } \ {STR(inst), NULL, NULL, test##inst, Subzero_::test##inst, isdiv},
,
SINTOP_TABLE SINTOP_TABLE
#undef X #undef X
#define X(mult_by) \ #define X(mult_by) \
{ \ {"Mult-By-" STR(mult_by), \
"Mult-By-" STR(mult_by), testMultiplyBy##mult_by, \ testMultiplyBy##mult_by, \
Subzero_::testMultiplyBy##mult_by, NULL, NULL, false \ Subzero_::testMultiplyBy##mult_by, \
} \ NULL, \
, {"Mult-By-Neg-" STR(mult_by), testMultiplyByNeg##mult_by, \ NULL, \
Subzero_::testMultiplyByNeg##mult_by, NULL, NULL, false}, false}, \
{"Mult-By-Neg-" STR(mult_by), \
testMultiplyByNeg##mult_by, \
Subzero_::testMultiplyByNeg##mult_by, \
NULL, \
NULL, \
false},
MULIMM_TABLE}; MULIMM_TABLE};
#undef X #undef X
const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
...@@ -187,13 +191,11 @@ void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -187,13 +191,11 @@ void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
bool MaskShiftOperations; // for shift related tests bool MaskShiftOperations; // for shift related tests
} Funcs[] = { } Funcs[] = {
#define X(inst, op, isdiv, isshift) \ #define X(inst, op, isdiv, isshift) \
{ STR(inst), test##inst, Subzero_::test##inst, NULL, NULL, isdiv, isshift } \ {STR(inst), test##inst, Subzero_::test##inst, NULL, NULL, isdiv, isshift},
,
UINTOP_TABLE UINTOP_TABLE
#undef X #undef X
#define X(inst, op, isdiv, isshift) \ #define X(inst, op, isdiv, isshift) \
{ STR(inst), NULL, NULL, test##inst, Subzero_::test##inst, isdiv, isshift } \ {STR(inst), NULL, NULL, test##inst, Subzero_::test##inst, isdiv, isshift},
,
SINTOP_TABLE SINTOP_TABLE
#undef X #undef X
}; };
...@@ -256,8 +258,7 @@ void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -256,8 +258,7 @@ void testsFp(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncType FuncSz; FuncType FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(inst, op, func) \ #define X(inst, op, func) \
{ STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \ {STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst},
,
FPOP_TABLE FPOP_TABLE
#undef X #undef X
}; };
...@@ -327,8 +328,7 @@ void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -327,8 +328,7 @@ void testsVecFp(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncType FuncSz; FuncType FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(inst, op, func) \ #define X(inst, op, func) \
{ STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst } \ {STR(inst), (FuncType)test##inst, (FuncType)Subzero_::test##inst},
,
FPOP_TABLE FPOP_TABLE
#undef X #undef X
}; };
......
...@@ -29,19 +29,56 @@ namespace Subzero_ { ...@@ -29,19 +29,56 @@ namespace Subzero_ {
#include "test_bitmanip.h" #include "test_bitmanip.h"
} }
volatile uint64 Values[] = { volatile uint64 Values[] = {0,
0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, 1,
0xfffe, 0xffff, 0xc0de, 0xabcd, 0xdcba, 0x007fffff /*Max subnormal + */, 0x7e,
0x00800000 /*Min+ */, 0x7f7fffff /*Max+ */, 0x7f800000 /*+Inf*/, 0x7f,
0xff800000 /*-Inf*/, 0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, 0x7ffffffe, 0x80,
0x7fffffff, 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x12345678, 0x81,
0xabcd1234, 0x1234dcba, 0x100000000ll, 0x100000001ll, 0x123456789abcdef1ll, 0xfe,
0x987654321ab1fedcll, 0x000fffffffffffffll /*Max subnormal + */, 0xff,
0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */, 0x7ffe,
0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/, 0x7fff,
0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/, 0x8000,
0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, 0x8001,
0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll}; 0xfffe,
0xffff,
0xc0de,
0xabcd,
0xdcba,
0x007fffff /*Max subnormal + */,
0x00800000 /*Min+ */,
0x7f7fffff /*Max+ */,
0x7f800000 /*+Inf*/,
0xff800000 /*-Inf*/,
0x7fa00000 /*SNaN*/,
0x7fc00000 /*QNaN*/,
0x7ffffffe,
0x7fffffff,
0x80000000,
0x80000001,
0xfffffffe,
0xffffffff,
0x12345678,
0xabcd1234,
0x1234dcba,
0x100000000ll,
0x100000001ll,
0x123456789abcdef1ll,
0x987654321ab1fedcll,
0x000fffffffffffffll /*Max subnormal + */,
0x0010000000000000ll /*Min+ */,
0x7fefffffffffffffll /*Max+ */,
0x7ff0000000000000ll /*+Inf*/,
0xfff0000000000000ll /*-Inf*/,
0x7ff0000000000001ll /*SNaN*/,
0x7ff8000000000000ll /*QNaN*/,
0x7ffffffffffffffell,
0x7fffffffffffffffll,
0x8000000000000000ll,
0x8000000000000001ll,
0xfffffffffffffffell,
0xffffffffffffffffll};
const static size_t NumValues = sizeof(Values) / sizeof(*Values); const static size_t NumValues = sizeof(Values) / sizeof(*Values);
...@@ -54,8 +91,8 @@ void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -54,8 +91,8 @@ void testBitManip(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncType FuncSz; FuncType FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(inst) \ #define X(inst) \
{ STR(inst), test_##inst, Subzero_::test_##inst } \ {STR(inst), test_##inst, Subzero_::test_##inst}, \
, {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \ {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \
{STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst}, {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
BMI_OPS BMI_OPS
#undef X #undef X
......
...@@ -50,9 +50,8 @@ void caller_vlvilvfvdviv(void) { ...@@ -50,9 +50,8 @@ void caller_vlvilvfvdviv(void) {
int arg11 = 26; int arg11 = 26;
v4f32 arg12 = {27, 28, 29, 30}; v4f32 arg12 = {27, 28, 29, 30};
CALL_AS_TYPE(callee_vlvilvfvdviv_Ty, Callee)(arg1, arg2, arg3, arg4, arg5, CALL_AS_TYPE(callee_vlvilvfvdviv_Ty, Callee)
arg6, arg7, arg8, arg9, arg10, (arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, arg11, arg12);
arg11, arg12);
} }
#define HANDLE_ARG(ARGNUM) \ #define HANDLE_ARG(ARGNUM) \
......
...@@ -72,19 +72,21 @@ void testCaller(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -72,19 +72,21 @@ void testCaller(size_t &TotalTests, size_t &Passes, size_t &Failures) {
#ifdef MIPS32 #ifdef MIPS32
#define X(caller, callee, argc) \ #define X(caller, callee, argc) \
{ \ { \
STR(caller), STR(callee), argc, &caller, &Subzero_::caller, \ STR(caller), \
STR(callee), \
argc, \
&caller, \
&Subzero_::caller, \
reinterpret_cast<CalleePtrTy>(&Subzero_::callee), \ reinterpret_cast<CalleePtrTy>(&Subzero_::callee), \
} \ },
,
TEST_FUNC_TABLE TEST_FUNC_TABLE
#undef X #undef X
#else #else
#define X(caller, callee, argc) \ #define X(caller, callee, argc) \
{ \ { \
STR(caller), STR(callee), argc, &caller, &Subzero_::caller, \ STR(caller), STR(callee), argc, \
reinterpret_cast<CalleePtrTy>(&callee), \ &caller, &Subzero_::caller, reinterpret_cast<CalleePtrTy>(&callee), \
} \ },
,
TEST_FUNC_TABLE TEST_FUNC_TABLE
#undef X #undef X
#endif #endif
...@@ -130,12 +132,12 @@ void testCallee(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -130,12 +132,12 @@ void testCallee(size_t &TotalTests, size_t &Passes, size_t &Failures) {
CalleePtrTy Callee, Subzero_Callee; CalleePtrTy Callee, Subzero_Callee;
} Funcs[] = { } Funcs[] = {
#define X(caller, callee, argc) \ #define X(caller, callee, argc) \
{ \ {STR(caller), \
STR(caller), STR(callee), argc, &caller, \ STR(callee), \
argc, \
&caller, \
reinterpret_cast<CalleePtrTy>(&callee), \ reinterpret_cast<CalleePtrTy>(&callee), \
reinterpret_cast<CalleePtrTy>(&Subzero_::callee) \ reinterpret_cast<CalleePtrTy>(&Subzero_::callee)},
} \
,
TEST_FUNC_TABLE TEST_FUNC_TABLE
#undef X #undef X
}; };
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
// This aims to test all the conversion bitcode instructions across // This aims to test all the conversion bitcode instructions across
// all PNaCl primitive data types. // all PNaCl primitive data types.
#include <stdint.h>
#include "test_cast.h" #include "test_cast.h"
#include "xdefs.h" #include "xdefs.h"
#include <stdint.h>
template <typename FromType, typename ToType> template <typename FromType, typename ToType>
ToType __attribute__((noinline)) cast(FromType a) { ToType __attribute__((noinline)) cast(FromType a) {
......
...@@ -179,20 +179,64 @@ int main(int argc, char *argv[]) { ...@@ -179,20 +179,64 @@ int main(int argc, char *argv[]) {
0x80000000, 0x80000001, 0xfffffffe, 0xffffffff}; 0x80000000, 0x80000001, 0xfffffffe, 0xffffffff};
static const size_t NumValsSi32 = sizeof(ValsSi32) / sizeof(*ValsSi32); static const size_t NumValsSi32 = sizeof(ValsSi32) / sizeof(*ValsSi32);
volatile uint64 ValsUi64[] = { volatile uint64 ValsUi64[] = {0,
0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, 1,
0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001, 0x7e,
0xfffffffe, 0xffffffff, 0x100000000ull, 0x100000001ull, 0x7f,
0x7ffffffffffffffeull, 0x7fffffffffffffffull, 0x8000000000000000ull, 0x80,
0x8000000000000001ull, 0xfffffffffffffffeull, 0xffffffffffffffffull}; 0x81,
0xfe,
0xff,
0x7ffe,
0x7fff,
0x8000,
0x8001,
0xfffe,
0xffff,
0x7ffffffe,
0x7fffffff,
0x80000000,
0x80000001,
0xfffffffe,
0xffffffff,
0x100000000ull,
0x100000001ull,
0x7ffffffffffffffeull,
0x7fffffffffffffffull,
0x8000000000000000ull,
0x8000000000000001ull,
0xfffffffffffffffeull,
0xffffffffffffffffull};
static const size_t NumValsUi64 = sizeof(ValsUi64) / sizeof(*ValsUi64); static const size_t NumValsUi64 = sizeof(ValsUi64) / sizeof(*ValsUi64);
volatile int64 ValsSi64[] = { volatile int64 ValsSi64[] = {0,
0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, 1,
0xfffe, 0xffff, 0x7ffffffe, 0x7fffffff, 0x80000000, 0x80000001, 0x7e,
0xfffffffe, 0xffffffff, 0x100000000ll, 0x100000001ll, 0x7f,
0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, 0x80,
0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll}; 0x81,
0xfe,
0xff,
0x7ffe,
0x7fff,
0x8000,
0x8001,
0xfffe,
0xffff,
0x7ffffffe,
0x7fffffff,
0x80000000,
0x80000001,
0xfffffffe,
0xffffffff,
0x100000000ll,
0x100000001ll,
0x7ffffffffffffffell,
0x7fffffffffffffffll,
0x8000000000000000ll,
0x8000000000000001ll,
0xfffffffffffffffell,
0xffffffffffffffffll};
static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64); static const size_t NumValsSi64 = sizeof(ValsSi64) / sizeof(*ValsSi64);
static const double NegInf = -1.0 / 0.0; static const double NegInf = -1.0 / 0.0;
......
...@@ -20,9 +20,9 @@ ...@@ -20,9 +20,9 @@
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>
#include "vectors.h"
#include "test_arith.def" #include "test_arith.def"
#include "test_fcmp.def" #include "test_fcmp.def"
#include "vectors.h"
#define X(cmp) \ #define X(cmp) \
extern "C" bool fcmp##cmp##Float(float a, float b); \ extern "C" bool fcmp##cmp##Float(float a, float b); \
...@@ -79,13 +79,11 @@ void testsScalar(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -79,13 +79,11 @@ void testsScalar(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncTypeDoubleSelect FuncDoubleSelectLlc; FuncTypeDoubleSelect FuncDoubleSelectLlc;
} Funcs[] = { } Funcs[] = {
#define X(cmp) \ #define X(cmp) \
{ \ {"fcmp" STR(cmp), Subzero_fcmp##cmp##Float, \
"fcmp" STR(cmp), Subzero_fcmp##cmp##Float, fcmp##cmp##Float, \ fcmp##cmp##Float, Subzero_fcmp##cmp##Double, \
Subzero_fcmp##cmp##Double, fcmp##cmp##Double, \ fcmp##cmp##Double, Subzero_fcmpSelect##cmp##Float, \
Subzero_fcmpSelect##cmp##Float, fcmpSelect##cmp##Float, \ fcmpSelect##cmp##Float, Subzero_fcmpSelect##cmp##Double, \
Subzero_fcmpSelect##cmp##Double, fcmpSelect##cmp##Double \ fcmpSelect##cmp##Double},
} \
,
FCMP_TABLE FCMP_TABLE
#undef X #undef X
}; };
...@@ -164,9 +162,7 @@ void testsVector(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -164,9 +162,7 @@ void testsVector(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncTypeVector FuncVectorSz; FuncTypeVector FuncVectorSz;
FuncTypeVector FuncVectorLlc; FuncTypeVector FuncVectorLlc;
} Funcs[] = { } Funcs[] = {
#define X(cmp) \ #define X(cmp) {"fcmp" STR(cmp), Subzero_fcmp##cmp##Vector, fcmp##cmp##Vector},
{ "fcmp" STR(cmp), Subzero_fcmp##cmp##Vector, fcmp##cmp##Vector } \
,
FCMP_TABLE FCMP_TABLE
#undef X #undef X
}; };
......
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include <stdint.h>
#include <cstdlib> #include <cstdlib>
#include <stdint.h>
#include "test_global.h" #include "test_global.h"
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
/* crosstest.py --test=test_global.cpp \ /* crosstest.py --test=test_global.cpp \
--driver=test_global_main.cpp --prefix=Subzero_ --output=test_global */ --driver=test_global_main.cpp --prefix=Subzero_ --output=test_global */
#include <stdint.h>
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <stdint.h>
#include "test_global.h" #include "test_global.h"
namespace Subzero_ { namespace Subzero_ {
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include <climits> // CHAR_BIT #include <climits> // CHAR_BIT
#include <cstring> // memcmp, memset #include <cstring> // memcmp, memset
#include <stdint.h>
#include <iostream> #include <iostream>
#include <stdint.h>
// Include test_icmp.h twice - once normally, and once within the // Include test_icmp.h twice - once normally, and once within the
// Subzero_ namespace, corresponding to the llc and Subzero translated // Subzero_ namespace, corresponding to the llc and Subzero translated
...@@ -49,19 +49,13 @@ void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -49,19 +49,13 @@ void testsInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncTypeUnsigned FuncSz; FuncTypeUnsigned FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(cmp, op) \ #define X(cmp, op) \
{ \ {STR(cmp), (FuncTypeUnsigned)icmp##cmp, \
STR(cmp), (FuncTypeUnsigned)icmp##cmp, \ (FuncTypeUnsigned)Subzero_::icmp##cmp},
(FuncTypeUnsigned)Subzero_::icmp##cmp \
} \
,
ICMP_U_TABLE ICMP_U_TABLE
#undef X #undef X
#define X(cmp, op) \ #define X(cmp, op) \
{ \ {STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \
STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp},
(FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \
} \
,
ICMP_S_TABLE ICMP_S_TABLE
#undef X #undef X
}; };
...@@ -132,19 +126,13 @@ void testsIntWithZero(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -132,19 +126,13 @@ void testsIntWithZero(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncTypeUnsigned FuncSz; FuncTypeUnsigned FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(cmp, op) \ #define X(cmp, op) \
{ \ {STR(cmp), (FuncTypeUnsigned)icmp_zero##cmp, \
STR(cmp), (FuncTypeUnsigned)icmp_zero##cmp, \ (FuncTypeUnsigned)Subzero_::icmp_zero##cmp},
(FuncTypeUnsigned)Subzero_::icmp_zero##cmp \
} \
,
ICMP_U_TABLE ICMP_U_TABLE
#undef X #undef X
#define X(cmp, op) \ #define X(cmp, op) \
{ \ {STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp_zero##cmp, \
STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp_zero##cmp, \ (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp_zero##cmp},
(FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp_zero##cmp \
} \
,
ICMP_S_TABLE ICMP_S_TABLE
#undef X #undef X
}; };
...@@ -210,19 +198,13 @@ void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -210,19 +198,13 @@ void testsVecInt(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncTypeUnsigned FuncSz; FuncTypeUnsigned FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(cmp, op) \ #define X(cmp, op) \
{ \ {STR(cmp), (FuncTypeUnsigned)icmp##cmp, \
STR(cmp), (FuncTypeUnsigned)icmp##cmp, \ (FuncTypeUnsigned)Subzero_::icmp##cmp},
(FuncTypeUnsigned)Subzero_::icmp##cmp \
} \
,
ICMP_U_TABLE ICMP_U_TABLE
#undef X #undef X
#define X(cmp, op) \ #define X(cmp, op) \
{ \ {STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \
STR(cmp), (FuncTypeUnsigned)(FuncTypeSigned)icmp##cmp, \ (FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp},
(FuncTypeUnsigned)(FuncTypeSigned)Subzero_::icmp##cmp \
} \
,
ICMP_S_TABLE ICMP_S_TABLE
#undef X #undef X
}; };
...@@ -283,8 +265,7 @@ void testsVecI1(size_t &TotalTests, size_t &Passes, size_t &Failures) { ...@@ -283,8 +265,7 @@ void testsVecI1(size_t &TotalTests, size_t &Passes, size_t &Failures) {
FuncType FuncSz; FuncType FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(cmp, op) \ #define X(cmp, op) \
{ STR(cmp), (FuncType)icmpi1##cmp, (FuncType)Subzero_::icmpi1##cmp } \ {STR(cmp), (FuncType)icmpi1##cmp, (FuncType)Subzero_::icmpi1##cmp},
,
ICMP_U_TABLE ICMP_S_TABLE}; ICMP_U_TABLE ICMP_S_TABLE};
const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs); const static size_t NumFuncs = sizeof(Funcs) / sizeof(*Funcs);
const static size_t NumElements = Vectors<T>::NumElements; const static size_t NumElements = Vectors<T>::NumElements;
......
...@@ -33,18 +33,48 @@ namespace Subzero_ { ...@@ -33,18 +33,48 @@ namespace Subzero_ {
#include "test_sync_atomic.h" #include "test_sync_atomic.h"
} }
volatile uint64 Values[] = { volatile uint64 Values[] = {0,
0, 1, 0x7e, 0x7f, 0x80, 0x81, 0xfe, 0xff, 0x7ffe, 0x7fff, 0x8000, 0x8001, 1,
0xfffe, 0xffff, 0x007fffff /*Max subnormal + */, 0x00800000 /*Min+ */, 0x7e,
0x7f7fffff /*Max+ */, 0x7f800000 /*+Inf*/, 0xff800000 /*-Inf*/, 0x7f,
0x7fa00000 /*SNaN*/, 0x7fc00000 /*QNaN*/, 0x7ffffffe, 0x7fffffff, 0x80,
0x80000000, 0x80000001, 0xfffffffe, 0xffffffff, 0x100000000ll, 0x81,
0x100000001ll, 0x000fffffffffffffll /*Max subnormal + */, 0xfe,
0x0010000000000000ll /*Min+ */, 0x7fefffffffffffffll /*Max+ */, 0xff,
0x7ff0000000000000ll /*+Inf*/, 0xfff0000000000000ll /*-Inf*/, 0x7ffe,
0x7ff0000000000001ll /*SNaN*/, 0x7ff8000000000000ll /*QNaN*/, 0x7fff,
0x7ffffffffffffffell, 0x7fffffffffffffffll, 0x8000000000000000ll, 0x8000,
0x8000000000000001ll, 0xfffffffffffffffell, 0xffffffffffffffffll}; 0x8001,
0xfffe,
0xffff,
0x007fffff /*Max subnormal + */,
0x00800000 /*Min+ */,
0x7f7fffff /*Max+ */,
0x7f800000 /*+Inf*/,
0xff800000 /*-Inf*/,
0x7fa00000 /*SNaN*/,
0x7fc00000 /*QNaN*/,
0x7ffffffe,
0x7fffffff,
0x80000000,
0x80000001,
0xfffffffe,
0xffffffff,
0x100000000ll,
0x100000001ll,
0x000fffffffffffffll /*Max subnormal + */,
0x0010000000000000ll /*Min+ */,
0x7fefffffffffffffll /*Max+ */,
0x7ff0000000000000ll /*+Inf*/,
0xfff0000000000000ll /*-Inf*/,
0x7ff0000000000001ll /*SNaN*/,
0x7ff8000000000000ll /*QNaN*/,
0x7ffffffffffffffell,
0x7fffffffffffffffll,
0x8000000000000000ll,
0x8000000000000001ll,
0xfffffffffffffffell,
0xffffffffffffffffll};
const static size_t NumValues = sizeof(Values) / sizeof(*Values); const static size_t NumValues = sizeof(Values) / sizeof(*Values);
...@@ -65,8 +95,8 @@ void testAtomicRMW(volatile Type *AtomicLoc, size_t &TotalTests, size_t &Passes, ...@@ -65,8 +95,8 @@ void testAtomicRMW(volatile Type *AtomicLoc, size_t &TotalTests, size_t &Passes,
FuncType FuncSz; FuncType FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(inst) \ #define X(inst) \
{ STR(inst), test_##inst, Subzero_::test_##inst } \ {STR(inst), test_##inst, Subzero_::test_##inst}, \
, {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \ {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, \
{STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst}, {STR(inst) "_const", test_const_##inst, Subzero_::test_const_##inst},
RMWOP_TABLE RMWOP_TABLE
#undef X #undef X
...@@ -186,8 +216,8 @@ void testAtomicRMWThreads(volatile Type *AtomicLoc, size_t &TotalTests, ...@@ -186,8 +216,8 @@ void testAtomicRMWThreads(volatile Type *AtomicLoc, size_t &TotalTests,
FuncType FuncSz; FuncType FuncSz;
} Funcs[] = { } Funcs[] = {
#define X(inst) \ #define X(inst) \
{ STR(inst), test_##inst, Subzero_::test_##inst } \ {STR(inst), test_##inst, Subzero_::test_##inst}, \
, {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst}, {STR(inst) "_alloca", test_alloca_##inst, Subzero_::test_alloca_##inst},
RMWOP_TABLE RMWOP_TABLE
#undef X #undef X
}; };
......
...@@ -44,18 +44,23 @@ template <typename T> struct VectorOps; ...@@ -44,18 +44,23 @@ template <typename T> struct VectorOps;
TY(NAME) Subzero_shufflevector_##NAME(TY(NAME), TY(NAME), uint32_t); \ TY(NAME) Subzero_shufflevector_##NAME(TY(NAME), TY(NAME), uint32_t); \
uint32_t shufflevector_count_##NAME(); \ uint32_t shufflevector_count_##NAME(); \
} \ } \
TY(NAME) (*FIELD(NAME, insertelement))(TY(NAME), CASTTY(NAME), int32_t) = \ TY(NAME) \
(*FIELD(NAME, insertelement))(TY(NAME), CASTTY(NAME), int32_t) = \
&insertelement_##NAME; \ &insertelement_##NAME; \
TY(NAME) (*FIELD(NAME, Subzero_insertelement))( \ TY(NAME) \
TY(NAME), CASTTY(NAME), int32_t) = &Subzero_insertelement_##NAME; \ (*FIELD(NAME, Subzero_insertelement))(TY(NAME), CASTTY(NAME), int32_t) = \
CASTTY(NAME) (*FIELD(NAME, extractelement))(TY(NAME), int32_t) = \ &Subzero_insertelement_##NAME; \
&extractelement_##NAME; \ CASTTY(NAME) \
CASTTY(NAME) (*FIELD(NAME, Subzero_extractelement))(TY(NAME), int32_t) = \ (*FIELD(NAME, extractelement))(TY(NAME), int32_t) = &extractelement_##NAME; \
CASTTY(NAME) \
(*FIELD(NAME, Subzero_extractelement))(TY(NAME), int32_t) = \
&Subzero_extractelement_##NAME; \ &Subzero_extractelement_##NAME; \
TY(NAME) (*FIELD(NAME, shufflevector))(TY(NAME), TY(NAME), uint32_t) = \ TY(NAME) \
(*FIELD(NAME, shufflevector))(TY(NAME), TY(NAME), uint32_t) = \
&shufflevector_##NAME; \ &shufflevector_##NAME; \
TY(NAME) (*FIELD(NAME, Subzero_shufflevector))( \ TY(NAME) \
TY(NAME), TY(NAME), uint32_t) = &Subzero_shufflevector_##NAME; \ (*FIELD(NAME, Subzero_shufflevector))(TY(NAME), TY(NAME), uint32_t) = \
&Subzero_shufflevector_##NAME; \
uint32_t (*FIELD(NAME, shufflevector_count))() = &shufflevector_count_##NAME; uint32_t (*FIELD(NAME, shufflevector_count))() = &shufflevector_count_##NAME;
#define X(ty, eltty, castty) DECLARE_VECTOR_OPS(ty) #define X(ty, eltty, castty) DECLARE_VECTOR_OPS(ty)
......
...@@ -16,9 +16,9 @@ ...@@ -16,9 +16,9 @@
#ifndef VECTORS_H #ifndef VECTORS_H
#define VECTORS_H #define VECTORS_H
#include <sstream>
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <sstream>
// The driver and the test program may be compiled by different // The driver and the test program may be compiled by different
// versions of clang, with different standard libraries that have // versions of clang, with different standard libraries that have
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/DataStream.h" #include "llvm/Support/DataStream.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/Program.h" #include "llvm/Support/Program.h"
#include <string> #include <string>
...@@ -45,7 +45,7 @@ STATISTIC(NumStreamFetches, "Number of calls to Data stream fetch"); ...@@ -45,7 +45,7 @@ STATISTIC(NumStreamFetches, "Number of calls to Data stream fetch");
namespace llvm { namespace llvm {
DataStreamer::~DataStreamer() {} DataStreamer::~DataStreamer() {}
} } // namespace llvm
namespace { namespace {
...@@ -53,6 +53,7 @@ namespace { ...@@ -53,6 +53,7 @@ namespace {
// actual file access is probably still best done with mmap. // actual file access is probably still best done with mmap.
class DataFileStreamer : public DataStreamer { class DataFileStreamer : public DataStreamer {
int Fd; int Fd;
public: public:
DataFileStreamer() : Fd(0) {} DataFileStreamer() : Fd(0) {}
~DataFileStreamer() override { close(Fd); } ~DataFileStreamer() override { close(Fd); }
...@@ -72,14 +73,14 @@ public: ...@@ -72,14 +73,14 @@ public:
} }
}; };
} } // namespace
std::unique_ptr<DataStreamer> std::unique_ptr<DataStreamer>
llvm::getDataFileStreamer(const std::string &Filename, std::string *StrError) { llvm::getDataFileStreamer(const std::string &Filename, std::string *StrError) {
std::unique_ptr<DataFileStreamer> s = make_unique<DataFileStreamer>(); std::unique_ptr<DataFileStreamer> s = make_unique<DataFileStreamer>();
if (std::error_code e = s->OpenFile(Filename)) { if (std::error_code e = s->OpenFile(Filename)) {
*StrError = std::string("Could not open ") + Filename + ": " + *StrError =
e.message() + "\n"; std::string("Could not open ") + Filename + ": " + e.message() + "\n";
return nullptr; return nullptr;
} }
return std::move(s); return std::move(s);
......
...@@ -10,5 +10,4 @@ ...@@ -10,5 +10,4 @@
#include "llvm/Support/MemoryObject.h" #include "llvm/Support/MemoryObject.h"
using namespace llvm; using namespace llvm;
MemoryObject::~MemoryObject() { MemoryObject::~MemoryObject() {}
}
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Bitcode/NaCl/NaClBitCodes.h" #include "llvm/Bitcode/NaCl/NaClBitCodes.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm; using namespace llvm;
...@@ -27,16 +27,12 @@ const bool NaClBitCodeAbbrevOp::HasValueArray[] = { ...@@ -27,16 +27,12 @@ const bool NaClBitCodeAbbrevOp::HasValueArray[] = {
}; };
const char *NaClBitCodeAbbrevOp::EncodingNameArray[] = { const char *NaClBitCodeAbbrevOp::EncodingNameArray[] = {
"Literal", "Literal", "Fixed", "VBR", "Array", "Char6"};
"Fixed",
"VBR",
"Array",
"Char6"
};
NaClBitCodeAbbrevOp::NaClBitCodeAbbrevOp(Encoding E, uint64_t Data) NaClBitCodeAbbrevOp::NaClBitCodeAbbrevOp(Encoding E, uint64_t Data)
: Enc(E), Val(Data) { : Enc(E), Val(Data) {
if (isValid(E, Data)) return; if (isValid(E, Data))
return;
std::string Buffer; std::string Buffer;
raw_string_ostream StrBuf(Buffer); raw_string_ostream StrBuf(Buffer);
StrBuf << "Invalid NaClBitCodeAbbrevOp(" << E << ", " << Data << ")"; StrBuf << "Invalid NaClBitCodeAbbrevOp(" << E << ", " << Data << ")";
...@@ -57,7 +53,7 @@ bool NaClBitCodeAbbrevOp::isValid(Encoding E, uint64_t Val) { ...@@ -57,7 +53,7 @@ bool NaClBitCodeAbbrevOp::isValid(Encoding E, uint64_t Val) {
llvm_unreachable("unhandled abbreviation"); llvm_unreachable("unhandled abbreviation");
} }
void NaClBitCodeAbbrevOp::Print(raw_ostream& Stream) const { void NaClBitCodeAbbrevOp::Print(raw_ostream &Stream) const {
if (Enc == Literal) { if (Enc == Literal) {
Stream << getValue(); Stream << getValue();
return; return;
...@@ -69,11 +65,11 @@ void NaClBitCodeAbbrevOp::Print(raw_ostream& Stream) const { ...@@ -69,11 +65,11 @@ void NaClBitCodeAbbrevOp::Print(raw_ostream& Stream) const {
} }
static void PrintExpression(raw_ostream &Stream, static void PrintExpression(raw_ostream &Stream,
const NaClBitCodeAbbrev *Abbrev, const NaClBitCodeAbbrev *Abbrev, unsigned &Index) {
unsigned &Index) {
// Bail out early, in case we are incrementally building the // Bail out early, in case we are incrementally building the
// expression and the argument is not available yet. // expression and the argument is not available yet.
if (Index >= Abbrev->getNumOperandInfos()) return; if (Index >= Abbrev->getNumOperandInfos())
return;
const NaClBitCodeAbbrevOp &Op = Abbrev->getOperandInfo(Index); const NaClBitCodeAbbrevOp &Op = Abbrev->getOperandInfo(Index);
Op.Print(Stream); Op.Print(Stream);
...@@ -81,7 +77,8 @@ static void PrintExpression(raw_ostream &Stream, ...@@ -81,7 +77,8 @@ static void PrintExpression(raw_ostream &Stream,
Stream << "("; Stream << "(";
for (unsigned i = 0; i < NumArgs; ++i) { for (unsigned i = 0; i < NumArgs; ++i) {
++Index; ++Index;
if (i > 0) Stream << ","; if (i > 0)
Stream << ",";
PrintExpression(Stream, Abbrev, Index); PrintExpression(Stream, Abbrev, Index);
} }
Stream << ")"; Stream << ")";
...@@ -91,11 +88,13 @@ static void PrintExpression(raw_ostream &Stream, ...@@ -91,11 +88,13 @@ static void PrintExpression(raw_ostream &Stream,
void NaClBitCodeAbbrev::Print(raw_ostream &Stream, bool AddNewLine) const { void NaClBitCodeAbbrev::Print(raw_ostream &Stream, bool AddNewLine) const {
Stream << "["; Stream << "[";
for (unsigned i = 0; i < getNumOperandInfos(); ++i) { for (unsigned i = 0; i < getNumOperandInfos(); ++i) {
if (i > 0) Stream << ", "; if (i > 0)
Stream << ", ";
PrintExpression(Stream, this, i); PrintExpression(Stream, this, i);
} }
Stream << "]"; Stream << "]";
if (AddNewLine) Stream << "\n"; if (AddNewLine)
Stream << "\n";
} }
NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const { NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const {
...@@ -106,9 +105,9 @@ NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const { ...@@ -106,9 +105,9 @@ NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const {
// is to remove unnecessary operands appearing immediately before an // is to remove unnecessary operands appearing immediately before an
// array operator. That is, apply the simplification: // array operator. That is, apply the simplification:
// Op Array(Op) -> Array(Op) // Op Array(Op) -> Array(Op)
assert(!Op.isArrayOp() || i == OperandList.size()-2); assert(!Op.isArrayOp() || i == OperandList.size() - 2);
while (Op.isArrayOp() && !Abbrev->OperandList.empty() && while (Op.isArrayOp() && !Abbrev->OperandList.empty() &&
Abbrev->OperandList.back() == OperandList[i+1]) { Abbrev->OperandList.back() == OperandList[i + 1]) {
Abbrev->OperandList.pop_back(); Abbrev->OperandList.pop_back();
} }
Abbrev->OperandList.push_back(Op); Abbrev->OperandList.push_back(Op);
...@@ -120,7 +119,8 @@ bool NaClBitCodeAbbrev::isValid() const { ...@@ -120,7 +119,8 @@ bool NaClBitCodeAbbrev::isValid() const {
// Verify that an array op appears can only appear if it is the // Verify that an array op appears can only appear if it is the
// second to last element. // second to last element.
unsigned NumOperands = getNumOperandInfos(); unsigned NumOperands = getNumOperandInfos();
if (NumOperands == 0) return false; if (NumOperands == 0)
return false;
for (unsigned i = 0; i < NumOperands; ++i) { for (unsigned i = 0; i < NumOperands; ++i) {
const NaClBitCodeAbbrevOp &Op = getOperandInfo(i); const NaClBitCodeAbbrevOp &Op = getOperandInfo(i);
if (Op.isArrayOp() && i + 2 != NumOperands) if (Op.isArrayOp() && i + 2 != NumOperands)
......
...@@ -13,8 +13,7 @@ ...@@ -13,8 +13,7 @@
namespace llvm { namespace llvm {
namespace naclbitc { namespace naclbitc {
bool DecodeCastOpcode(uint64_t NaClOpcode, bool DecodeCastOpcode(uint64_t NaClOpcode, Instruction::CastOps &LLVMOpcode) {
Instruction::CastOps &LLVMOpcode) {
switch (NaClOpcode) { switch (NaClOpcode) {
default: default:
LLVMOpcode = Instruction::BitCast; LLVMOpcode = Instruction::BitCast;
...@@ -223,6 +222,5 @@ bool DecodeIcmpPredicate(uint64_t NaClPredicate, ...@@ -223,6 +222,5 @@ bool DecodeIcmpPredicate(uint64_t NaClPredicate,
} }
} }
} // namespace naclbitc
} } // namespace llvm
}
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include "llvm/Bitcode/ReaderWriter.h" #include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Support/ErrorHandling.h" #include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Format.h" #include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/StreamingMemoryObject.h" #include "llvm/Support/StreamingMemoryObject.h"
#include "llvm/Support/raw_ostream.h"
#include <cstring> #include <cstring>
#include <iomanip> #include <iomanip>
...@@ -94,7 +94,7 @@ NaClBitcodeHeaderField::NaClBitcodeHeaderField(Tag MyID, size_t MyLen, ...@@ -94,7 +94,7 @@ NaClBitcodeHeaderField::NaClBitcodeHeaderField(Tag MyID, size_t MyLen,
bool NaClBitcodeHeaderField::Write(uint8_t *Buf, size_t BufLen) const { bool NaClBitcodeHeaderField::Write(uint8_t *Buf, size_t BufLen) const {
size_t FieldsLen = kTagLenSize + Len; size_t FieldsLen = kTagLenSize + Len;
size_t PadLen = (WordSize - (FieldsLen & (WordSize-1))) & (WordSize-1); size_t PadLen = (WordSize - (FieldsLen & (WordSize - 1))) & (WordSize - 1);
// Ensure buffer is large enough and that length can be represented // Ensure buffer is large enough and that length can be represented
// in 32 bits // in 32 bits
if (BufLen < FieldsLen + PadLen || if (BufLen < FieldsLen + PadLen ||
...@@ -245,8 +245,7 @@ bool NaClBitcodeHeader::Read(MemoryObject *Bytes) { ...@@ -245,8 +245,7 @@ bool NaClBitcodeHeader::Read(MemoryObject *Bytes) {
} }
// Then read the rest, starting after the 2 * WordSize of the prefix. // Then read the rest, starting after the 2 * WordSize of the prefix.
uint8_t *Header = new uint8_t[NumBytes]; uint8_t *Header = new uint8_t[NumBytes];
bool failed = bool failed = Bytes->readBytes(Header, NumBytes, 2 * WordSize) != NumBytes ||
Bytes->readBytes(Header, NumBytes, 2 * WordSize) != NumBytes ||
ReadFields(Header, Header + NumBytes, NumFields, NumBytes); ReadFields(Header, Header + NumBytes, NumFields, NumBytes);
delete[] Header; delete[] Header;
if (failed) if (failed)
......
...@@ -14,19 +14,20 @@ using namespace llvm; ...@@ -14,19 +14,20 @@ using namespace llvm;
void NaClBitcodeRecordData::Print(raw_ostream &os) const { void NaClBitcodeRecordData::Print(raw_ostream &os) const {
os << "[" << Code; os << "[" << Code;
for (NaClRecordVector::const_iterator for (NaClRecordVector::const_iterator Iter = Values.begin(),
Iter = Values.begin(), IterEnd = Values.end(); IterEnd = Values.end();
Iter != IterEnd; ++Iter) { Iter != IterEnd; ++Iter) {
os << ", " << *Iter; os << ", " << *Iter;
} }
os << "]"; os << "]";
} }
void NaClBitcodeRecord::Print(raw_ostream& os) const { void NaClBitcodeRecord::Print(raw_ostream &os) const {
Block.Print(os); Block.Print(os);
os << ", Code " << Data.Code << ", EntryID " << Entry.ID << ", <"; os << ", Code " << Data.Code << ", EntryID " << Entry.ID << ", <";
for (unsigned i = 0, e = Data.Values.size(); i != e; ++i) { for (unsigned i = 0, e = Data.Values.size(); i != e; ++i) {
if (i > 0) os << " "; if (i > 0)
os << " ";
os << Data.Values[i]; os << Data.Values[i];
} }
os << ">"; os << ">";
...@@ -34,11 +35,8 @@ void NaClBitcodeRecord::Print(raw_ostream& os) const { ...@@ -34,11 +35,8 @@ void NaClBitcodeRecord::Print(raw_ostream& os) const {
NaClBitcodeBlock::NaClBitcodeBlock(unsigned BlockID, NaClBitcodeBlock::NaClBitcodeBlock(unsigned BlockID,
const NaClBitcodeRecord &Record) const NaClBitcodeRecord &Record)
: NaClBitcodeData(Record), : NaClBitcodeData(Record), BlockID(BlockID),
BlockID(BlockID), EnclosingBlock(&Record.GetBlock()), LocalStartBit(Record.GetStartBit()) {}
EnclosingBlock(&Record.GetBlock()),
LocalStartBit(Record.GetStartBit())
{}
void NaClBitcodeBlock::Print(raw_ostream &os) const { void NaClBitcodeBlock::Print(raw_ostream &os) const {
os << "Block " << BlockID; os << "Block " << BlockID;
...@@ -69,8 +67,8 @@ void NaClBitcodeParserListener::EndBlockInfoBlock() { ...@@ -69,8 +67,8 @@ void NaClBitcodeParserListener::EndBlockInfoBlock() {
Parser->ExitBlock(); Parser->ExitBlock();
} }
void NaClBitcodeParserListener:: void NaClBitcodeParserListener::ProcessAbbreviation(NaClBitCodeAbbrev *Abbrev,
ProcessAbbreviation(NaClBitCodeAbbrev *Abbrev, bool IsLocal) { bool IsLocal) {
Parser->Record.SetStartBit(StartBit); Parser->Record.SetStartBit(StartBit);
Parser->Record.Entry.Kind = NaClBitstreamEntry::Record; Parser->Record.Entry.Kind = NaClBitstreamEntry::Record;
Parser->Record.Entry.ID = naclbitc::DEFINE_ABBREV; Parser->Record.Entry.ID = naclbitc::DEFINE_ABBREV;
...@@ -86,8 +84,8 @@ NaClBitcodeParser::~NaClBitcodeParser() { ...@@ -86,8 +84,8 @@ NaClBitcodeParser::~NaClBitcodeParser() {
} }
} }
bool NaClBitcodeParser::ErrorAt( bool NaClBitcodeParser::ErrorAt(naclbitc::ErrorLevel Level,
naclbitc::ErrorLevel Level, uint64_t BitPosition, uint64_t BitPosition,
const std::string &Message) { const std::string &Message) {
naclbitc::ErrorAt(*ErrStream, Level, BitPosition) << Message << "\n"; naclbitc::ErrorAt(*ErrStream, Level, BitPosition) << Message << "\n";
if (Level == naclbitc::Fatal) if (Level == naclbitc::Fatal)
...@@ -108,7 +106,8 @@ bool NaClBitcodeParser::ParseBlockInfoInternal() { ...@@ -108,7 +106,8 @@ bool NaClBitcodeParser::ParseBlockInfoInternal() {
// BLOCKINFO is a special part of the stream. Let the bitstream // BLOCKINFO is a special part of the stream. Let the bitstream
// reader process this block. // reader process this block.
bool Result = Record.GetCursor().ReadBlockInfoBlock(Listener); bool Result = Record.GetCursor().ReadBlockInfoBlock(Listener);
if (Result) return Error("Malformed BlockInfoBlock"); if (Result)
return Error("Malformed BlockInfoBlock");
return Result; return Result;
} }
...@@ -136,7 +135,8 @@ bool NaClBitcodeParser::ParseBlockInternal() { ...@@ -136,7 +135,8 @@ bool NaClBitcodeParser::ParseBlockInternal() {
return false; return false;
} }
case NaClBitstreamEntry::SubBlock: { case NaClBitstreamEntry::SubBlock: {
if (ParseBlock(Record.GetEntryID())) return true; if (ParseBlock(Record.GetEntryID()))
return true;
break; break;
} }
case NaClBitstreamEntry::Record: case NaClBitstreamEntry::Record:
...@@ -145,7 +145,8 @@ bool NaClBitcodeParser::ParseBlockInternal() { ...@@ -145,7 +145,8 @@ bool NaClBitcodeParser::ParseBlockInternal() {
// Since this abbreviation is local, the listener doesn't // Since this abbreviation is local, the listener doesn't
// have the start bit set (it is only set when processing // have the start bit set (it is only set when processing
// the BlockInfo block). Fix this by setting it here. // the BlockInfo block). Fix this by setting it here.
if (Listener) Listener->StartBit = Record.GetStartBit(); if (Listener)
Listener->StartBit = Record.GetStartBit();
Record.GetCursor().ReadAbbrevRecord(true, Listener); Record.GetCursor().ReadAbbrevRecord(true, Listener);
} else { } else {
// Read in a record. // Read in a record.
......
...@@ -17,14 +17,12 @@ namespace { ...@@ -17,14 +17,12 @@ namespace {
class RawMemoryObject : public MemoryObject { class RawMemoryObject : public MemoryObject {
public: public:
RawMemoryObject(const unsigned char *Start, const unsigned char *End) : RawMemoryObject(const unsigned char *Start, const unsigned char *End)
FirstChar(Start), LastChar(End) { : FirstChar(Start), LastChar(End) {
assert(LastChar >= FirstChar && "Invalid start/end range"); assert(LastChar >= FirstChar && "Invalid start/end range");
} }
uint64_t getExtent() const override { uint64_t getExtent() const override { return LastChar - FirstChar; }
return LastChar - FirstChar;
}
uint64_t readBytes(uint8_t *Buf, uint64_t Size, uint64_t readBytes(uint8_t *Buf, uint64_t Size,
uint64_t Address) const override; uint64_t Address) const override;
const uint8_t *getPointer(uint64_t address, uint64_t size) const override; const uint8_t *getPointer(uint64_t address, uint64_t size) const override;
...@@ -33,8 +31,8 @@ public: ...@@ -33,8 +31,8 @@ public:
} }
private: private:
const uint8_t* const FirstChar; const uint8_t *const FirstChar;
const uint8_t* const LastChar; const uint8_t *const LastChar;
// These are implemented as inline functions here to avoid multiple virtual // These are implemented as inline functions here to avoid multiple virtual
// calls per public function // calls per public function
...@@ -42,8 +40,8 @@ private: ...@@ -42,8 +40,8 @@ private:
return static_cast<std::ptrdiff_t>(address) < LastChar - FirstChar; return static_cast<std::ptrdiff_t>(address) < LastChar - FirstChar;
} }
RawMemoryObject(const RawMemoryObject&) = delete; RawMemoryObject(const RawMemoryObject &) = delete;
void operator=(const RawMemoryObject&) = delete; void operator=(const RawMemoryObject &) = delete;
}; };
uint64_t RawMemoryObject::readBytes(uint8_t *Buf, uint64_t Size, uint64_t RawMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
...@@ -72,15 +70,18 @@ namespace llvm { ...@@ -72,15 +70,18 @@ namespace llvm {
// If the bitcode has a header, then its size is known, and we don't have to // If the bitcode has a header, then its size is known, and we don't have to
// block until we actually want to read it. // block until we actually want to read it.
bool StreamingMemoryObject::isValidAddress(uint64_t address) const { bool StreamingMemoryObject::isValidAddress(uint64_t address) const {
if (ObjectSize && address < ObjectSize) return true; if (ObjectSize && address < ObjectSize)
return true;
return fetchToPos(address); return fetchToPos(address);
} }
uint64_t StreamingMemoryObject::getExtent() const { uint64_t StreamingMemoryObject::getExtent() const {
if (ObjectSize) return ObjectSize; if (ObjectSize)
return ObjectSize;
size_t pos = BytesRead + kChunkSize; size_t pos = BytesRead + kChunkSize;
// keep fetching until we run out of bytes // keep fetching until we run out of bytes
while (fetchToPos(pos)) pos += kChunkSize; while (fetchToPos(pos))
pos += kChunkSize;
return ObjectSize; return ObjectSize;
} }
...@@ -111,7 +112,8 @@ const uint8_t *StreamingMemoryObject::getPointer(uint64_t Address, ...@@ -111,7 +112,8 @@ const uint8_t *StreamingMemoryObject::getPointer(uint64_t Address,
} }
bool StreamingMemoryObject::dropLeadingBytes(size_t s) { bool StreamingMemoryObject::dropLeadingBytes(size_t s) {
if (BytesRead < s) return true; if (BytesRead < s)
return true;
BytesSkipped = s; BytesSkipped = s;
BytesRead -= s; BytesRead -= s;
return false; return false;
...@@ -135,4 +137,4 @@ StreamingMemoryObject::StreamingMemoryObject( ...@@ -135,4 +137,4 @@ StreamingMemoryObject::StreamingMemoryObject(
BytesSkipped(0), ObjectSize(0), EOFReached(false) { BytesSkipped(0), ObjectSize(0), EOFReached(false) {
BytesRead = this->Streamer->GetBytes(&Bytes[0], kChunkSize); BytesRead = this->Streamer->GetBytes(&Bytes[0], kChunkSize);
} }
} } // namespace llvm
...@@ -37,9 +37,9 @@ enum StandardWidths { ...@@ -37,9 +37,9 @@ enum StandardWidths {
MinRecordBitSize = 2 // Minimum number of bits needed to represent a record. MinRecordBitSize = 2 // Minimum number of bits needed to represent a record.
}; };
// The standard abbrev namespace always has a way to exit a block, enter a // The standard abbrev namespace always has a way to exit a block, enter a
// nested block, define abbrevs, and define an unabbreviated record. // nested block, define abbrevs, and define an unabbreviated record.
enum FixedAbbrevIDs { enum FixedAbbrevIDs {
END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode. END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode.
ENTER_SUBBLOCK = 1, ENTER_SUBBLOCK = 1,
...@@ -69,12 +69,12 @@ enum StandardWidths { ...@@ -69,12 +69,12 @@ enum StandardWidths {
FIRST_APPLICATION_ABBREV = 4, FIRST_APPLICATION_ABBREV = 4,
// Defines default values for code length, if no additional selectors // Defines default values for code length, if no additional selectors
// are added. // are added.
DEFAULT_MAX_ABBREV = FIRST_APPLICATION_ABBREV-1 DEFAULT_MAX_ABBREV = FIRST_APPLICATION_ABBREV - 1
}; };
/// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO
/// block, which contains metadata about other blocks in the file. /// block, which contains metadata about other blocks in the file.
enum StandardBlockIDs { enum StandardBlockIDs {
/// BLOCKINFO_BLOCK is used to define metadata about blocks, for example, /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example,
/// standard abbrevs that should be available to all blocks of a specified /// standard abbrevs that should be available to all blocks of a specified
/// ID. /// ID.
...@@ -85,11 +85,11 @@ enum StandardWidths { ...@@ -85,11 +85,11 @@ enum StandardWidths {
// appear in a block). // appear in a block).
TOP_LEVEL_BLOCKID = 7, TOP_LEVEL_BLOCKID = 7,
FIRST_APPLICATION_BLOCKID = 8 FIRST_APPLICATION_BLOCKID = 8
}; };
/// BlockInfoCodes - The blockinfo block contains metadata about user-defined /// BlockInfoCodes - The blockinfo block contains metadata about user-defined
/// blocks. /// blocks.
enum BlockInfoCodes { enum BlockInfoCodes {
// DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd
// block, instead of the BlockInfo block. // block, instead of the BlockInfo block.
...@@ -100,12 +100,12 @@ enum StandardWidths { ...@@ -100,12 +100,12 @@ enum StandardWidths {
// the writer. // the writer.
BLOCKINFO_CODE_BLOCKNAME = 2, // Not used in PNaCl. BLOCKINFO_CODE_BLOCKNAME = 2, // Not used in PNaCl.
BLOCKINFO_CODE_SETRECORDNAME = 3 // Not used in PNaCl. BLOCKINFO_CODE_SETRECORDNAME = 3 // Not used in PNaCl.
}; };
} // End naclbitc namespace } // namespace naclbitc
/// NaClBitCodeAbbrevOp - This describes one or more operands in an abbreviation. /// NaClBitCodeAbbrevOp - This describes one or more operands in an
/// This is actually a union of two different things: /// abbreviation. This is actually a union of two different things:
/// 1. It could be a literal integer value ("the operand is always 17"). /// 1. It could be a literal integer value ("the operand is always 17").
/// 2. It could be an encoding specification ("this operand encoded like so"). /// 2. It could be an encoding specification ("this operand encoded like so").
/// ///
...@@ -129,9 +129,7 @@ public: ...@@ -129,9 +129,7 @@ public:
uint64_t getValue() const { return Val; } uint64_t getValue() const { return Val; }
bool hasValue() const { bool hasValue() const { return hasValue(Enc); }
return hasValue(Enc);
}
static bool hasValue(Encoding E) { static bool hasValue(Encoding E) {
return E <= Encoding_MAX && HasValueArray[E]; return E <= Encoding_MAX && HasValueArray[E];
} }
...@@ -164,28 +162,42 @@ public: ...@@ -164,28 +162,42 @@ public:
/// isChar6 - Return true if this character is legal in the Char6 encoding. /// isChar6 - Return true if this character is legal in the Char6 encoding.
static bool isChar6(char C) { static bool isChar6(char C) {
if (C >= 'a' && C <= 'z') return true; if (C >= 'a' && C <= 'z')
if (C >= 'A' && C <= 'Z') return true; return true;
if (C >= '0' && C <= '9') return true; if (C >= 'A' && C <= 'Z')
if (C == '.' || C == '_') return true; return true;
if (C >= '0' && C <= '9')
return true;
if (C == '.' || C == '_')
return true;
return false; return false;
} }
static unsigned EncodeChar6(char C) { static unsigned EncodeChar6(char C) {
if (C >= 'a' && C <= 'z') return C-'a'; if (C >= 'a' && C <= 'z')
if (C >= 'A' && C <= 'Z') return C-'A'+26; return C - 'a';
if (C >= '0' && C <= '9') return C-'0'+26+26; if (C >= 'A' && C <= 'Z')
if (C == '.') return 62; return C - 'A' + 26;
if (C == '_') return 63; if (C >= '0' && C <= '9')
return C - '0' + 26 + 26;
if (C == '.')
return 62;
if (C == '_')
return 63;
llvm_unreachable("Not a value Char6 character!"); llvm_unreachable("Not a value Char6 character!");
} }
static char DecodeChar6(unsigned V) { static char DecodeChar6(unsigned V) {
assert((V & ~63) == 0 && "Not a Char6 encoded character!"); assert((V & ~63) == 0 && "Not a Char6 encoded character!");
if (V < 26) return V+'a'; if (V < 26)
if (V < 26+26) return V-26+'A'; return V + 'a';
if (V < 26+26+10) return V-26-26+'0'; if (V < 26 + 26)
if (V == 62) return '.'; return V - 26 + 'A';
if (V == 63) return '_'; if (V < 26 + 26 + 10)
return V - 26 - 26 + '0';
if (V == 62)
return '.';
if (V == 63)
return '_';
llvm_unreachable("Not a value Char6 character!"); llvm_unreachable("Not a value Char6 character!");
} }
...@@ -194,7 +206,8 @@ public: ...@@ -194,7 +206,8 @@ public:
int Compare(const NaClBitCodeAbbrevOp &Op) const { int Compare(const NaClBitCodeAbbrevOp &Op) const {
// Compare encoding values. // Compare encoding values.
int EncodingDiff = static_cast<int>(Enc) - static_cast<int>(Op.Enc); int EncodingDiff = static_cast<int>(Enc) - static_cast<int>(Op.Enc);
if (EncodingDiff != 0) return EncodingDiff; if (EncodingDiff != 0)
return EncodingDiff;
// Encodings don't differ, so now base on data associated with the // Encodings don't differ, so now base on data associated with the
// encoding. // encoding.
...@@ -218,7 +231,7 @@ private: ...@@ -218,7 +231,7 @@ private:
}; };
template <> struct isPodLike<NaClBitCodeAbbrevOp> { template <> struct isPodLike<NaClBitCodeAbbrevOp> {
static const bool value=true; static const bool value = true;
}; };
static inline bool operator<(const NaClBitCodeAbbrevOp &Op1, static inline bool operator<(const NaClBitCodeAbbrevOp &Op1,
...@@ -258,11 +271,15 @@ class NaClBitCodeAbbrev { ...@@ -258,11 +271,15 @@ class NaClBitCodeAbbrev {
SmallVector<NaClBitCodeAbbrevOp, 8> OperandList; SmallVector<NaClBitCodeAbbrevOp, 8> OperandList;
unsigned char RefCount; // Number of things using this. unsigned char RefCount; // Number of things using this.
~NaClBitCodeAbbrev() {} ~NaClBitCodeAbbrev() {}
public: public:
NaClBitCodeAbbrev() : RefCount(1) {} NaClBitCodeAbbrev() : RefCount(1) {}
void addRef() { ++RefCount; } void addRef() { ++RefCount; }
void dropRef() { if (--RefCount == 0) delete this; } void dropRef() {
if (--RefCount == 0)
delete this;
}
unsigned getNumOperandInfos() const { unsigned getNumOperandInfos() const {
return static_cast<unsigned>(OperandList.size()); return static_cast<unsigned>(OperandList.size());
...@@ -271,9 +288,7 @@ public: ...@@ -271,9 +288,7 @@ public:
return OperandList[N]; return OperandList[N];
} }
void Add(const NaClBitCodeAbbrevOp &OpInfo) { void Add(const NaClBitCodeAbbrevOp &OpInfo) { OperandList.push_back(OpInfo); }
OperandList.push_back(OpInfo);
}
// Returns a simplified version of the abbreviation. Used // Returns a simplified version of the abbreviation. Used
// to recognize equivalent abbrevations. // to recognize equivalent abbrevations.
...@@ -303,24 +318,25 @@ public: ...@@ -303,24 +318,25 @@ public:
// of fixed length. // of fixed length.
bool IsFixedSize() const { bool IsFixedSize() const {
unsigned Size = getNumOperandInfos(); unsigned Size = getNumOperandInfos();
if (Size < 2) return true; if (Size < 2)
return !OperandList[Size-2].isArrayOp(); return true;
return !OperandList[Size - 2].isArrayOp();
} }
// Returns the smallest record size that will match this // Returns the smallest record size that will match this
// abbreviation. // abbreviation.
size_t GetMinRecordSize() const { size_t GetMinRecordSize() const {
size_t Min = getNumOperandInfos(); size_t Min = getNumOperandInfos();
if (!IsFixedSize()) Min -= 2; if (!IsFixedSize())
Min -= 2;
return Min; return Min;
} }
void Print(raw_ostream &Stream, bool AddNewline=true) const; void Print(raw_ostream &Stream, bool AddNewline = true) const;
NaClBitCodeAbbrev *Copy() const { NaClBitCodeAbbrev *Copy() const {
NaClBitCodeAbbrev *AbbrevCopy = new NaClBitCodeAbbrev(); NaClBitCodeAbbrev *AbbrevCopy = new NaClBitCodeAbbrev();
for (unsigned I = 0, IEnd = getNumOperandInfos(); for (unsigned I = 0, IEnd = getNumOperandInfos(); I != IEnd; ++I) {
I != IEnd; ++I) {
AbbrevCopy->Add(NaClBitCodeAbbrevOp(getOperandInfo(I))); AbbrevCopy->Add(NaClBitCodeAbbrevOp(getOperandInfo(I)));
} }
return AbbrevCopy; return AbbrevCopy;
...@@ -360,8 +376,9 @@ static inline bool operator>(const NaClBitCodeAbbrev &A1, ...@@ -360,8 +376,9 @@ static inline bool operator>(const NaClBitCodeAbbrev &A1,
inline unsigned NaClBitsNeededForValue(unsigned Value) { inline unsigned NaClBitsNeededForValue(unsigned Value) {
// Note: Need to handle case where Value=0xFFFFFFFF as special case, // Note: Need to handle case where Value=0xFFFFFFFF as special case,
// since we can't add 1 to it. // since we can't add 1 to it.
if (Value >= 0x80000000) return 32; if (Value >= 0x80000000)
return Log2_32_Ceil(Value+1); return 32;
return Log2_32_Ceil(Value + 1);
} }
/// \brief Encode a signed value by moving the sign to the LSB for dense /// \brief Encode a signed value by moving the sign to the LSB for dense
...@@ -393,8 +410,7 @@ public: ...@@ -393,8 +410,7 @@ public:
unsigned NumBits; unsigned NumBits;
// Creates a selector range for the given values. // Creates a selector range for the given values.
NaClBitcodeSelectorAbbrev(bool IF, unsigned NB) NaClBitcodeSelectorAbbrev(bool IF, unsigned NB) : IsFixed(IF), NumBits(NB) {}
: IsFixed(IF), NumBits(NB) {}
// Creates a selector range when no abbreviations are defined. // Creates a selector range when no abbreviations are defined.
NaClBitcodeSelectorAbbrev() NaClBitcodeSelectorAbbrev()
...@@ -404,9 +420,8 @@ public: ...@@ -404,9 +420,8 @@ public:
// Creates a selector range to handle fixed abbrevations up to // Creates a selector range to handle fixed abbrevations up to
// the specified value. // the specified value.
explicit NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev) explicit NaClBitcodeSelectorAbbrev(unsigned MaxAbbrev)
: IsFixed(true), : IsFixed(true), NumBits(NaClBitsNeededForValue(MaxAbbrev)) {}
NumBits(NaClBitsNeededForValue(MaxAbbrev)) {}
}; };
} // End llvm namespace } // namespace llvm
#endif #endif
//===- NaClBitcodeDecoders.h -------------------------------------*- C++ -*-===// //===- NaClBitcodeDecoders.h -------------------------------------*- C++
//-*-===//
// Functions used to decode values in PNaCl bitcode files. // Functions used to decode values in PNaCl bitcode files.
// //
// The LLVM Compiler Infrastructure // The LLVM Compiler Infrastructure
...@@ -16,11 +17,11 @@ ...@@ -16,11 +17,11 @@
#ifndef LLVM_BITCODE_NACL_NACLBITCODEDECODERS_H #ifndef LLVM_BITCODE_NACL_NACLBITCODEDECODERS_H
#define LLVM_BITCODE_NACL_NACLBITCODEDECODERS_H #define LLVM_BITCODE_NACL_NACLBITCODEDECODERS_H
#include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h"
#include "llvm/IR/CallingConv.h" #include "llvm/IR/CallingConv.h"
#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalValue.h"
#include "llvm/IR/InstrTypes.h" #include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h" #include "llvm/IR/Instruction.h"
#include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h"
namespace llvm { namespace llvm {
namespace naclbitc { namespace naclbitc {
...@@ -29,8 +30,7 @@ namespace naclbitc { ...@@ -29,8 +30,7 @@ namespace naclbitc {
/// LLVM cast opcode. Returns true if the conversion /// LLVM cast opcode. Returns true if the conversion
/// succeeds. Otherwise sets LLVMOpcode to Instruction::BitCast and /// succeeds. Otherwise sets LLVMOpcode to Instruction::BitCast and
/// returns false. /// returns false.
bool DecodeCastOpcode(uint64_t NaClOpcode, bool DecodeCastOpcode(uint64_t NaClOpcode, Instruction::CastOps &LLVMOpcode);
Instruction::CastOps &LLVMOpcode);
/// Converts the NaCl (bitcode file) linkage type to the corresponding /// Converts the NaCl (bitcode file) linkage type to the corresponding
/// LLVM linkage type. Returns true if the conversion /// LLVM linkage type. Returns true if the conversion
...@@ -68,7 +68,7 @@ bool DecodeFcmpPredicate(uint64_t NaClPredicate, ...@@ -68,7 +68,7 @@ bool DecodeFcmpPredicate(uint64_t NaClPredicate,
bool DecodeIcmpPredicate(uint64_t NaClPredicate, bool DecodeIcmpPredicate(uint64_t NaClPredicate,
CmpInst::Predicate &LLVMPredicate); CmpInst::Predicate &LLVMPredicate);
} } // namespace naclbitc
} } // namespace llvm
#endif #endif
...@@ -49,5 +49,4 @@ static const size_t MaxNaClGlobalVarInits = ...@@ -49,5 +49,4 @@ static const size_t MaxNaClGlobalVarInits =
} // end of namespace llvm } // end of namespace llvm
#endif // LLVM_BITCODE_NACL_NACLBITCODEDEFS_H #endif // LLVM_BITCODE_NACL_NACLBITCODEDEFS_H
...@@ -88,15 +88,11 @@ public: ...@@ -88,15 +88,11 @@ public:
/// \brief Returns string describing ID of field. /// \brief Returns string describing ID of field.
static const char *IDName(Tag ID); static const char *IDName(Tag ID);
const char *IDName() const { const char *IDName() const { return IDName(ID); }
return IDName(ID);
}
/// \brief Returns string describing type of field. /// \brief Returns string describing type of field.
static const char *TypeName(FieldType FType); static const char *TypeName(FieldType FType);
const char *TypeName() const { const char *TypeName() const { return TypeName(FType); }
return TypeName(FType);
}
/// \brief Returns string describing field. /// \brief Returns string describing field.
std::string Contents() const; std::string Contents() const;
...@@ -132,7 +128,8 @@ private: ...@@ -132,7 +128,8 @@ private:
ID = (PossibleID > kTag_MAX ? kInvalid : static_cast<Tag>(PossibleID)); ID = (PossibleID > kTag_MAX ? kInvalid : static_cast<Tag>(PossibleID));
FixedSubfield PossibleFType = Subfield & 0xF; FixedSubfield PossibleFType = Subfield & 0xF;
FType = (PossibleFType > kFieldType_MAX FType = (PossibleFType > kFieldType_MAX
? kUnknownType : static_cast<FieldType>(PossibleFType)); ? kUnknownType
: static_cast<FieldType>(PossibleFType));
} }
// Combined size of the fixed subfields // Combined size of the fixed subfields
const static size_t kTagLenSize = 2 * sizeof(FixedSubfield); const static size_t kTagLenSize = 2 * sizeof(FixedSubfield);
...@@ -182,9 +179,7 @@ public: ...@@ -182,9 +179,7 @@ public:
/// \brief Adds a field to the list of fields in a header. Takes ownership /// \brief Adds a field to the list of fields in a header. Takes ownership
/// of fields added. /// of fields added.
void push_back(NaClBitcodeHeaderField *Field) { void push_back(NaClBitcodeHeaderField *Field) { Fields.push_back(Field); }
Fields.push_back(Field);
}
/// \brief Read the PNaCl bitcode header, The format of the header is: /// \brief Read the PNaCl bitcode header, The format of the header is:
/// ///
...@@ -255,7 +250,6 @@ private: ...@@ -255,7 +250,6 @@ private:
UnsupportedMessage = Message.str(); UnsupportedMessage = Message.str();
return true; return true;
} }
}; };
} // namespace llvm } // namespace llvm
......
...@@ -24,120 +24,117 @@ ...@@ -24,120 +24,117 @@
#include <string> #include <string>
namespace llvm { namespace llvm {
class LLVMContext; class LLVMContext;
class Module; class Module;
class NaClBitcodeHeader; class NaClBitcodeHeader;
class NaClBitstreamWriter; class NaClBitstreamWriter;
class StreamingMemoryObject; class StreamingMemoryObject;
class raw_ostream; class raw_ostream;
/// Defines the data layout used for PNaCl bitcode files. We set the /// Defines the data layout used for PNaCl bitcode files. We set the
/// data layout of the module in the bitcode readers rather than in /// data layout of the module in the bitcode readers rather than in
/// pnacl-llc so that 'opt' will also use the correct data layout if /// pnacl-llc so that 'opt' will also use the correct data layout if
/// it is run on a pexe. /// it is run on a pexe.
extern const char *PNaClDataLayout; extern const char *PNaClDataLayout;
/// Allows (function) local symbol tables (unsupported) in PNaCl bitcode /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode
/// files. /// files.
extern cl::opt<bool> PNaClAllowLocalSymbolTables; extern cl::opt<bool> PNaClAllowLocalSymbolTables;
/// \brief Defines the integer bit size used to model pointers in PNaCl. /// \brief Defines the integer bit size used to model pointers in PNaCl.
static const unsigned PNaClIntPtrTypeBitSize = 32; static const unsigned PNaClIntPtrTypeBitSize = 32;
/// Diagnostic handler that redirects error diagnostics to the given stream. /// Diagnostic handler that redirects error diagnostics to the given stream.
DiagnosticHandlerFunction redirectNaClDiagnosticToStream(raw_ostream &Out); DiagnosticHandlerFunction redirectNaClDiagnosticToStream(raw_ostream &Out);
/// Read the header of the specified bitcode buffer and prepare for lazy /// Read the header of the specified bitcode buffer and prepare for lazy
/// deserialization of function bodies. If successful, this takes ownership /// deserialization of function bodies. If successful, this takes ownership
/// of 'Buffer' (extending its lifetime). On error, this returns an error /// of 'Buffer' (extending its lifetime). On error, this returns an error
/// code and deletes Buffer. /// code and deletes Buffer.
/// ///
/// The AcceptSupportedOnly argument is used to decide which PNaCl versions /// The AcceptSupportedOnly argument is used to decide which PNaCl versions
/// of the PNaCl bitcode to accept. There are three forms: /// of the PNaCl bitcode to accept. There are three forms:
/// 1) Readable and supported. /// 1) Readable and supported.
/// 2) Readable and unsupported. Allows testing of code before becoming /// 2) Readable and unsupported. Allows testing of code before becoming
/// supported, as well as running experiments on the bitcode format. /// supported, as well as running experiments on the bitcode format.
/// 3) Unreadable. /// 3) Unreadable.
/// When AcceptSupportedOnly is true, only form 1 is allowed. When /// When AcceptSupportedOnly is true, only form 1 is allowed. When
/// AcceptSupportedOnly is false, forms 1 and 2 are allowed. /// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
ErrorOr<Module *> getNaClLazyBitcodeModule( ErrorOr<Module *>
std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context, getNaClLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer,
LLVMContext &Context,
DiagnosticHandlerFunction DiagnosticHandler = nullptr, DiagnosticHandlerFunction DiagnosticHandler = nullptr,
bool AcceptSupportedOnly = true); bool AcceptSupportedOnly = true);
/// Read the header of the specified stream and prepare for lazy /// Read the header of the specified stream and prepare for lazy
/// deserialization and streaming of function bodies. On error, /// deserialization and streaming of function bodies. On error,
/// this returns null, and fills in *ErrMsg with an error description /// this returns null, and fills in *ErrMsg with an error description
/// if ErrMsg is non-null. /// if ErrMsg is non-null.
/// ///
/// See getNaClLazyBitcodeModule for an explanation of argument /// See getNaClLazyBitcodeModule for an explanation of argument
/// AcceptSupportedOnly. /// AcceptSupportedOnly.
/// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use /// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use
/// ErrorOr<Module *> API so that all methods have the same interface. /// ErrorOr<Module *> API so that all methods have the same interface.
Module *getNaClStreamedBitcodeModule( Module *getNaClStreamedBitcodeModule(
const std::string &name, StreamingMemoryObject *streamer, const std::string &name, StreamingMemoryObject *streamer,
LLVMContext &Context, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler = nullptr,
DiagnosticHandlerFunction DiagnosticHandler = nullptr,
std::string *ErrMsg = nullptr, bool AcceptSupportedOnly = true); std::string *ErrMsg = nullptr, bool AcceptSupportedOnly = true);
/// Read the bitcode file from a buffer, returning the module. /// Read the bitcode file from a buffer, returning the module.
/// ///
/// See getNaClLazyBitcodeModule for an explanation of argument /// See getNaClLazyBitcodeModule for an explanation of argument
/// AcceptSupportedOnly. /// AcceptSupportedOnly.
ErrorOr<Module *> ErrorOr<Module *>
NaClParseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context, NaClParseBitcodeFile(MemoryBufferRef Buffer, LLVMContext &Context,
DiagnosticHandlerFunction DiagnosticHandler = nullptr, DiagnosticHandlerFunction DiagnosticHandler = nullptr,
bool AcceptSupportedOnly = true); bool AcceptSupportedOnly = true);
/// Read the textual bitcode records in Filename, returning the module. /// Read the textual bitcode records in Filename, returning the module.
/// Note: If Filename is "-", stdin will be read. /// Note: If Filename is "-", stdin will be read.
/// ///
/// TODO(kschimpf) Replace Verbose argument with a DiagnosticHandlerFunction. /// TODO(kschimpf) Replace Verbose argument with a DiagnosticHandlerFunction.
ErrorOr<Module *> parseNaClBitcodeText(const std::string &Filename, ErrorOr<Module *> parseNaClBitcodeText(const std::string &Filename,
LLVMContext &Context, LLVMContext &Context,
raw_ostream *Verbose = nullptr); raw_ostream *Verbose = nullptr);
/// Write the specified module to the specified raw output stream, using /// Write the specified module to the specified raw output stream, using
/// PNaCl wire format. For streams where it matters, the given stream /// PNaCl wire format. For streams where it matters, the given stream
/// should be in "binary" mode. /// should be in "binary" mode.
/// ///
/// The AcceptSupportedOnly argument is used to decide which PNaCl versions /// The AcceptSupportedOnly argument is used to decide which PNaCl versions
/// of the PNaCl bitcode to generate. There are two forms: /// of the PNaCl bitcode to generate. There are two forms:
/// 1) Writable and supported. /// 1) Writable and supported.
/// 2) Writable and unsupported. Allows testing of code before becoming /// 2) Writable and unsupported. Allows testing of code before becoming
/// supported, as well as running experiments on the bitcode format. /// supported, as well as running experiments on the bitcode format.
/// When AcceptSupportedOnly is true, only form 1 is allowed. When /// When AcceptSupportedOnly is true, only form 1 is allowed. When
/// AcceptSupportedOnly is false, forms 1 and 2 are allowed. /// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out, void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out,
bool AcceptSupportedOnly = true); bool AcceptSupportedOnly = true);
/// isNaClBitcode - Return true if the given bytes are the magic bytes for /// isNaClBitcode - Return true if the given bytes are the magic bytes for
/// PNaCl bitcode wire format. /// PNaCl bitcode wire format.
/// ///
inline bool isNaClBitcode(const unsigned char *BufPtr, inline bool isNaClBitcode(const unsigned char *BufPtr,
const unsigned char *BufEnd) { const unsigned char *BufEnd) {
return BufPtr+4 <= BufEnd && return BufPtr + 4 <= BufEnd && BufPtr[0] == 'P' && BufPtr[1] == 'E' &&
BufPtr[0] == 'P' && BufPtr[2] == 'X' && BufPtr[3] == 'E';
BufPtr[1] == 'E' && }
BufPtr[2] == 'X' &&
BufPtr[3] == 'E'; /// NaClWriteHeader - Generate a default header (using the version
} /// number defined by kPNaClVersion) and write to the corresponding
/// bitcode stream.
/// NaClWriteHeader - Generate a default header (using the version void NaClWriteHeader(NaClBitstreamWriter &Stream, bool AcceptSupportedOnly);
/// number defined by kPNaClVersion) and write to the corresponding
/// bitcode stream. // NaClWriteHeader - Write the contents of the bitcode header to the
void NaClWriteHeader(NaClBitstreamWriter &Stream, bool AcceptSupportedOnly); // corresponding bitcode stream.
void NaClWriteHeader(const NaClBitcodeHeader &Header,
// NaClWriteHeader - Write the contents of the bitcode header to the
// corresponding bitcode stream.
void NaClWriteHeader(const NaClBitcodeHeader &Header,
NaClBitstreamWriter &Stream); NaClBitstreamWriter &Stream);
/// NaClObjDump - Read PNaCl bitcode file from input, and print a /// NaClObjDump - Read PNaCl bitcode file from input, and print a
/// textual representation of its contents. NoRecords and NoAssembly /// textual representation of its contents. NoRecords and NoAssembly
/// define what should not be included in the dump. /// define what should not be included in the dump.
bool NaClObjDump(MemoryBufferRef Input, raw_ostream &output, bool NaClObjDump(MemoryBufferRef Input, raw_ostream &output, bool NoRecords,
bool NoRecords, bool NoAssembly); bool NoAssembly);
} // end llvm namespace } // namespace llvm
#endif #endif
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_SUPPORT_DATASTREAM_H #ifndef LLVM_SUPPORT_DATASTREAM_H
#define LLVM_SUPPORT_DATASTREAM_H #define LLVM_SUPPORT_DATASTREAM_H
...@@ -33,6 +32,6 @@ public: ...@@ -33,6 +32,6 @@ public:
std::unique_ptr<DataStreamer> getDataFileStreamer(const std::string &Filename, std::unique_ptr<DataStreamer> getDataFileStreamer(const std::string &Filename,
std::string *Err); std::string *Err);
} } // namespace llvm
#endif // LLVM_SUPPORT_DATASTREAM_H_ #endif // LLVM_SUPPORT_DATASTREAM_H_
...@@ -63,6 +63,6 @@ public: ...@@ -63,6 +63,6 @@ public:
virtual bool isValidAddress(uint64_t address) const = 0; virtual bool isValidAddress(uint64_t address) const = 0;
}; };
} } // namespace llvm
#endif #endif
...@@ -49,7 +49,7 @@ private: ...@@ -49,7 +49,7 @@ private:
mutable std::vector<unsigned char> Bytes; mutable std::vector<unsigned char> Bytes;
std::unique_ptr<DataStreamer> Streamer; std::unique_ptr<DataStreamer> Streamer;
mutable size_t BytesRead; // Bytes read from stream mutable size_t BytesRead; // Bytes read from stream
size_t BytesSkipped;// Bytes skipped at start of stream (e.g. wrapper/header) size_t BytesSkipped; // Bytes skipped at start of stream (e.g. wrapper/header)
mutable size_t ObjectSize; // 0 if unknown, set if wrapper seen or EOF reached mutable size_t ObjectSize; // 0 if unknown, set if wrapper seen or EOF reached
mutable bool EOFReached; mutable bool EOFReached;
...@@ -64,8 +64,8 @@ private: ...@@ -64,8 +64,8 @@ private:
if (EOFReached) if (EOFReached)
return false; return false;
Bytes.resize(BytesRead + BytesSkipped + kChunkSize); Bytes.resize(BytesRead + BytesSkipped + kChunkSize);
size_t bytes = Streamer->GetBytes(&Bytes[BytesRead + BytesSkipped], size_t bytes =
kChunkSize); Streamer->GetBytes(&Bytes[BytesRead + BytesSkipped], kChunkSize);
BytesRead += bytes; BytesRead += bytes;
if (bytes == 0) { // reached EOF/ran out of bytes if (bytes == 0) { // reached EOF/ran out of bytes
if (ObjectSize == 0) if (ObjectSize == 0)
...@@ -76,12 +76,12 @@ private: ...@@ -76,12 +76,12 @@ private:
return !ObjectSize || Pos < ObjectSize; return !ObjectSize || Pos < ObjectSize;
} }
StreamingMemoryObject(const StreamingMemoryObject&) = delete; StreamingMemoryObject(const StreamingMemoryObject &) = delete;
void operator=(const StreamingMemoryObject&) = delete; void operator=(const StreamingMemoryObject &) = delete;
}; };
MemoryObject *getNonStreamedMemoryObject( MemoryObject *getNonStreamedMemoryObject(const unsigned char *Start,
const unsigned char *Start, const unsigned char *End); const unsigned char *End);
} } // namespace llvm
#endif // STREAMINGMEMORYOBJECT_H_ #endif // STREAMINGMEMORYOBJECT_H_
...@@ -26,8 +26,8 @@ ...@@ -26,8 +26,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h>
#include <termios.h> #include <termios.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
// License. See LICENSE.TXT for details. // License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "IceAssemblerX8632.h"
#include "AssemblerX8632/TestUtil.h" #include "AssemblerX8632/TestUtil.h"
#include "IceAssemblerX8632.h"
namespace Ice { namespace Ice {
namespace X8632 { namespace X8632 {
......
...@@ -135,8 +135,8 @@ TEST_F(AssemblerX8632Test, Lea) { ...@@ -135,8 +135,8 @@ TEST_F(AssemblerX8632Test, Lea) {
AssemblerFixup::NoFixup)); \ AssemblerFixup::NoFixup)); \
AssembledTest test = assemble(); \ AssembledTest test = assemble(); \
test.run(); \ test.run(); \
ASSERT_EQ(test.Base() + (Disp), test.Dst()) << TestString << " with Disp " \ ASSERT_EQ(test.Base() + (Disp), test.Dst()) \
<< Disp; \ << TestString << " with Disp " << Disp; \
reset(); \ reset(); \
} while (0) } while (0)
...@@ -620,8 +620,8 @@ TEST_F(AssemblerX8632Test, Arith_most) { ...@@ -620,8 +620,8 @@ TEST_F(AssemblerX8632Test, Arith_most) {
do { \ do { \
TestImplOp(And, Dst, Value0, Src, Value1, int, Size, &); \ TestImplOp(And, Dst, Value0, Src, Value1, int, Size, &); \
TestImplOp(And, Dst, Value0, Src, Value1, uint, Size, &); \ TestImplOp(And, Dst, Value0, Src, Value1, uint, Size, &); \
TestImplOp(Or, Dst, Value0, Src, Value1, int, Size, | ); \ TestImplOp(Or, Dst, Value0, Src, Value1, int, Size, |); \
TestImplOp(Or, Dst, Value0, Src, Value1, uint, Size, | ); \ TestImplOp(Or, Dst, Value0, Src, Value1, uint, Size, |); \
TestImplOp(Xor, Dst, Value0, Src, Value1, int, Size, ^); \ TestImplOp(Xor, Dst, Value0, Src, Value1, int, Size, ^); \
TestImplOp(Xor, Dst, Value0, Src, Value1, uint, Size, ^); \ TestImplOp(Xor, Dst, Value0, Src, Value1, uint, Size, ^); \
TestImplOp(add, Dst, Value0, Src, Value1, int, Size, +); \ TestImplOp(add, Dst, Value0, Src, Value1, int, Size, +); \
...@@ -699,9 +699,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { ...@@ -699,9 +699,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) {
AssembledTest test = assemble(); \ AssembledTest test = assemble(); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ Op(uint64_t(Value1) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \
...@@ -734,9 +733,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { ...@@ -734,9 +733,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) {
test.setDwordTo(T1, V1); \ test.setDwordTo(T1, V1); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ Op(uint64_t(Value1) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \
...@@ -763,9 +761,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { ...@@ -763,9 +761,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) {
AssembledTest test = assemble(); \ AssembledTest test = assemble(); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ Op(uint64_t(Imm) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \
...@@ -798,9 +795,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { ...@@ -798,9 +795,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) {
test.setDwordTo(T1, V1); \ test.setDwordTo(T1, V1); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ Op(uint64_t(Value1) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \
...@@ -829,9 +825,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) { ...@@ -829,9 +825,8 @@ TEST_F(AssemblerX8632Test, Arith_BorrowNCarry) {
test.setDwordTo(T1, V1); \ test.setDwordTo(T1, V1); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ Op(uint64_t(Imm) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \
......
...@@ -318,12 +318,12 @@ protected: ...@@ -318,12 +318,12 @@ protected:
return *reinterpret_cast<Dqword *>(&Ret); \ return *reinterpret_cast<Dqword *>(&Ret); \
} }
DefinePackedComparisonOperator(< ); DefinePackedComparisonOperator(<);
DefinePackedComparisonOperator(<= ); DefinePackedComparisonOperator(<=);
DefinePackedComparisonOperator(> ); DefinePackedComparisonOperator(>);
DefinePackedComparisonOperator(>= ); DefinePackedComparisonOperator(>=);
DefinePackedComparisonOperator(== ); DefinePackedComparisonOperator(==);
DefinePackedComparisonOperator(!= ); DefinePackedComparisonOperator(!=);
#undef DefinePackedComparisonOperator #undef DefinePackedComparisonOperator
...@@ -387,7 +387,7 @@ protected: ...@@ -387,7 +387,7 @@ protected:
DefinePackedArithOperator(/, true, false); DefinePackedArithOperator(/, true, false);
DefinePackedArithOperator(&, true, true); DefinePackedArithOperator(&, true, true);
DefinePackedArithOperator(|, true, true); DefinePackedArithOperator(|, true, true);
DefinePackedArithOperator (^, true, true); DefinePackedArithOperator(^, true, true);
#undef DefinePackedArithOperator #undef DefinePackedArithOperator
...@@ -403,8 +403,8 @@ protected: ...@@ -403,8 +403,8 @@ protected:
return *reinterpret_cast<Dqword *>(&Ret); \ return *reinterpret_cast<Dqword *>(&Ret); \
} }
DefinePackedArithShiftImm(>> ); DefinePackedArithShiftImm(>>);
DefinePackedArithShiftImm(<< ); DefinePackedArithShiftImm(<<);
#undef DefinePackedArithShiftImm #undef DefinePackedArithShiftImm
...@@ -693,8 +693,7 @@ protected: ...@@ -693,8 +693,7 @@ protected:
Dqword contentsOfDqword(uint32_t InitialDword) const { Dqword contentsOfDqword(uint32_t InitialDword) const {
return *reinterpret_cast<Dqword *>( return *reinterpret_cast<Dqword *>(
static_cast<uint8_t *>(ExecutableData) + static_cast<uint8_t *>(ExecutableData) + dwordOffset(InitialDword));
dwordOffset(InitialDword));
} }
template <typename T = uint32_t, typename = typename std::enable_if< template <typename T = uint32_t, typename = typename std::enable_if<
......
...@@ -646,8 +646,8 @@ TEST_F(AssemblerX8664Test, Arith_most) { ...@@ -646,8 +646,8 @@ TEST_F(AssemblerX8664Test, Arith_most) {
do { \ do { \
TestImplOp(And, Dst, Value0, Src, Value1, int, Size, &); \ TestImplOp(And, Dst, Value0, Src, Value1, int, Size, &); \
TestImplOp(And, Dst, Value0, Src, Value1, uint, Size, &); \ TestImplOp(And, Dst, Value0, Src, Value1, uint, Size, &); \
TestImplOp(Or, Dst, Value0, Src, Value1, int, Size, | ); \ TestImplOp(Or, Dst, Value0, Src, Value1, int, Size, |); \
TestImplOp(Or, Dst, Value0, Src, Value1, uint, Size, | ); \ TestImplOp(Or, Dst, Value0, Src, Value1, uint, Size, |); \
TestImplOp(Xor, Dst, Value0, Src, Value1, int, Size, ^); \ TestImplOp(Xor, Dst, Value0, Src, Value1, int, Size, ^); \
TestImplOp(Xor, Dst, Value0, Src, Value1, uint, Size, ^); \ TestImplOp(Xor, Dst, Value0, Src, Value1, uint, Size, ^); \
TestImplOp(add, Dst, Value0, Src, Value1, int, Size, +); \ TestImplOp(add, Dst, Value0, Src, Value1, int, Size, +); \
...@@ -728,9 +728,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) { ...@@ -728,9 +728,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) {
AssembledTest test = assemble(); \ AssembledTest test = assemble(); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ Op(uint64_t(Value1) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \
...@@ -761,9 +760,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) { ...@@ -761,9 +760,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) {
test.setDwordTo(T1, V1); \ test.setDwordTo(T1, V1); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ Op(uint64_t(Value1) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \
...@@ -790,9 +788,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) { ...@@ -790,9 +788,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) {
AssembledTest test = assemble(); \ AssembledTest test = assemble(); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ Op(uint64_t(Imm) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.Dst0()) << TestString << ": 0"; \
...@@ -823,9 +820,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) { ...@@ -823,9 +820,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) {
test.setDwordTo(T1, V1); \ test.setDwordTo(T1, V1); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Value1) & \ Op(uint64_t(Value1) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \
...@@ -854,9 +850,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) { ...@@ -854,9 +850,8 @@ TEST_F(AssemblerX8664Test, Arith_BorrowNCarry) {
test.setDwordTo(T1, V1); \ test.setDwordTo(T1, V1); \
test.run(); \ test.run(); \
\ \
static constexpr uint64_t Result = \ static constexpr uint64_t Result = (uint64_t(Value0) & ResultMask##Size) \
(uint64_t(Value0) & ResultMask##Size)Op(uint64_t(Imm) & \ Op(uint64_t(Imm) & ResultMask##Size); \
ResultMask##Size); \
static constexpr uint32_t Expected0 = Result & Mask##Size; \ static constexpr uint32_t Expected0 = Result & Mask##Size; \
static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \ static constexpr uint32_t Expected1 = (Result >> Size) & Mask##Size; \
ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \ ASSERT_EQ(Expected0, test.contentsOfDword(T0)) << TestString << ": 0"; \
......
...@@ -430,12 +430,12 @@ protected: ...@@ -430,12 +430,12 @@ protected:
return *reinterpret_cast<Dqword *>(&Ret); \ return *reinterpret_cast<Dqword *>(&Ret); \
} }
DefinePackedComparisonOperator(< ); DefinePackedComparisonOperator(<);
DefinePackedComparisonOperator(<= ); DefinePackedComparisonOperator(<=);
DefinePackedComparisonOperator(> ); DefinePackedComparisonOperator(>);
DefinePackedComparisonOperator(>= ); DefinePackedComparisonOperator(>=);
DefinePackedComparisonOperator(== ); DefinePackedComparisonOperator(==);
DefinePackedComparisonOperator(!= ); DefinePackedComparisonOperator(!=);
#undef DefinePackedComparisonOperator #undef DefinePackedComparisonOperator
...@@ -499,7 +499,7 @@ protected: ...@@ -499,7 +499,7 @@ protected:
DefinePackedArithOperator(/, true, false); DefinePackedArithOperator(/, true, false);
DefinePackedArithOperator(&, true, true); DefinePackedArithOperator(&, true, true);
DefinePackedArithOperator(|, true, true); DefinePackedArithOperator(|, true, true);
DefinePackedArithOperator (^, true, true); DefinePackedArithOperator(^, true, true);
#undef DefinePackedArithOperator #undef DefinePackedArithOperator
...@@ -515,8 +515,8 @@ protected: ...@@ -515,8 +515,8 @@ protected:
return *reinterpret_cast<Dqword *>(&Ret); \ return *reinterpret_cast<Dqword *>(&Ret); \
} }
DefinePackedArithShiftImm(>> ); DefinePackedArithShiftImm(>>);
DefinePackedArithShiftImm(<< ); DefinePackedArithShiftImm(<<);
#undef DefinePackedArithShiftImm #undef DefinePackedArithShiftImm
...@@ -879,8 +879,7 @@ protected: ...@@ -879,8 +879,7 @@ protected:
Dqword contentsOfDqword(uint32_t InitialDword) const { Dqword contentsOfDqword(uint32_t InitialDword) const {
return *reinterpret_cast<Dqword *>( return *reinterpret_cast<Dqword *>(
static_cast<uint8_t *>(ExecutableData) + static_cast<uint8_t *>(ExecutableData) + dwordOffset(InitialDword));
dwordOffset(InitialDword));
} }
template <typename T = uint32_t, typename = typename std::enable_if< template <typename T = uint32_t, typename = typename std::enable_if<
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
#include "BitcodeMunge.h" #include "BitcodeMunge.h"
#include "IceCfg.h" #include "IceCfg.h"
#include "IceClFlags.h" #include "IceClFlags.h"
#include "PNaClTranslator.h"
#include "IceTypes.h" #include "IceTypes.h"
#include "PNaClTranslator.h"
namespace IceTest { namespace IceTest {
......
...@@ -24,16 +24,33 @@ namespace { ...@@ -24,16 +24,33 @@ namespace {
static const unsigned NO_LOCAL_ABBREVS = static const unsigned NO_LOCAL_ABBREVS =
NaClBitsNeededForValue(naclbitc::DEFAULT_MAX_ABBREV); NaClBitsNeededForValue(naclbitc::DEFAULT_MAX_ABBREV);
const uint64_t BitcodeRecords[] = { const uint64_t BitcodeRecords[] = {naclbitc::ENTER_SUBBLOCK,
naclbitc::ENTER_SUBBLOCK, naclbitc::BLK_CODE_ENTER, naclbitc::BLK_CODE_ENTER,
naclbitc::MODULE_BLOCK_ID, NO_LOCAL_ABBREVS, Terminator, naclbitc::MODULE_BLOCK_ID,
naclbitc::ENTER_SUBBLOCK, naclbitc::BLK_CODE_ENTER, NO_LOCAL_ABBREVS,
naclbitc::TYPE_BLOCK_ID_NEW, NO_LOCAL_ABBREVS, Terminator, Terminator,
naclbitc::UNABBREV_RECORD, naclbitc::TYPE_CODE_NUMENTRY, 2, Terminator, naclbitc::ENTER_SUBBLOCK,
naclbitc::UNABBREV_RECORD, naclbitc::TYPE_CODE_INTEGER, 32, Terminator, naclbitc::BLK_CODE_ENTER,
naclbitc::UNABBREV_RECORD, naclbitc::TYPE_CODE_FLOAT, Terminator, naclbitc::TYPE_BLOCK_ID_NEW,
naclbitc::END_BLOCK, naclbitc::BLK_CODE_EXIT, Terminator, NO_LOCAL_ABBREVS,
naclbitc::END_BLOCK, naclbitc::BLK_CODE_EXIT, Terminator}; Terminator,
naclbitc::UNABBREV_RECORD,
naclbitc::TYPE_CODE_NUMENTRY,
2,
Terminator,
naclbitc::UNABBREV_RECORD,
naclbitc::TYPE_CODE_INTEGER,
32,
Terminator,
naclbitc::UNABBREV_RECORD,
naclbitc::TYPE_CODE_FLOAT,
Terminator,
naclbitc::END_BLOCK,
naclbitc::BLK_CODE_EXIT,
Terminator,
naclbitc::END_BLOCK,
naclbitc::BLK_CODE_EXIT,
Terminator};
const char *ExpectedDump = const char *ExpectedDump =
" 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, " " 0:0|<65532, 80, 69, 88, 69, 1, 0,|Magic Number: 'PEXE' (80, 69, "
...@@ -75,8 +92,9 @@ TEST(NaClParseTypesTest, BadTypeCountRecord) { ...@@ -75,8 +92,9 @@ TEST(NaClParseTypesTest, BadTypeCountRecord) {
// Index for "count 2;". // Index for "count 2;".
const uint64_t CountRecordIndex = 2; const uint64_t CountRecordIndex = 2;
const uint64_t Edit[] = { const uint64_t Edit[] = {
CountRecordIndex, NaClMungedBitcode::Replace, naclbitc::UNABBREV_RECORD, CountRecordIndex, NaClMungedBitcode::Replace,
naclbitc::TYPE_CODE_NUMENTRY, 18446744073709547964ULL, Terminator}; naclbitc::UNABBREV_RECORD, naclbitc::TYPE_CODE_NUMENTRY,
18446744073709547964ULL, Terminator};
SubzeroBitcodeMunger Munger(ARRAY_TERM(BitcodeRecords)); SubzeroBitcodeMunger Munger(ARRAY_TERM(BitcodeRecords));
Munger.Flags.setGenerateUnitTestMessages(false); Munger.Flags.setGenerateUnitTestMessages(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment