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), \
reinterpret_cast<CalleePtrTy>(&Subzero_::callee), \ STR(callee), \
} \ argc, \
, &caller, \
&Subzero_::caller, \
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), \
reinterpret_cast<CalleePtrTy>(&callee), \ argc, \
reinterpret_cast<CalleePtrTy>(&Subzero_::callee) \ &caller, \
} \ reinterpret_cast<CalleePtrTy>(&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,14 +45,15 @@ STATISTIC(NumStreamFetches, "Number of calls to Data stream fetch"); ...@@ -45,14 +45,15 @@ STATISTIC(NumStreamFetches, "Number of calls to Data stream fetch");
namespace llvm { namespace llvm {
DataStreamer::~DataStreamer() {} DataStreamer::~DataStreamer() {}
} } // namespace llvm
namespace { namespace {
// Very simple stream backed by a file. Mostly useful for stdin and debugging; // Very simple stream backed by a file. Mostly useful for stdin and debugging;
// 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);
......
...@@ -9,6 +9,5 @@ ...@@ -9,6 +9,5 @@
#include "llvm/Support/MemoryObject.h" #include "llvm/Support/MemoryObject.h"
using namespace llvm; using namespace llvm;
MemoryObject::~MemoryObject() { MemoryObject::~MemoryObject() {}
}
...@@ -13,30 +13,26 @@ ...@@ -13,30 +13,26 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#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;
const bool NaClBitCodeAbbrevOp::HasValueArray[] = { const bool NaClBitCodeAbbrevOp::HasValueArray[] = {
true, // Literal true, // Literal
true, // Fixed true, // Fixed
true, // VBR true, // VBR
false, // Array false, // Array
false // Char6 false // Char6
}; };
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>
...@@ -28,24 +28,24 @@ namespace { ...@@ -28,24 +28,24 @@ namespace {
// The name for each ID tag. // The name for each ID tag.
static const char *TagName[] = { static const char *TagName[] = {
"Invalid", // kInvalid "Invalid", // kInvalid
"PNaCl Version", // kPNaClVersion "PNaCl Version", // kPNaClVersion
"Align bitcode records" // kAlignBitcodeRecords "Align bitcode records" // kAlignBitcodeRecords
}; };
// The name for each field type. // The name for each field type.
static const char *FieldTypeName[] = { static const char *FieldTypeName[] = {
"uint8[]", // kBufferType "uint8[]", // kBufferType
"uint32", // kUInt32Type "uint32", // kUInt32Type
"flag", // kFlagType "flag", // kFlagType
"unknown" // kUnknownType "unknown" // kUnknownType
}; };
// The type associated with each ID tag. // The type associated with each ID tag.
static const NaClBitcodeHeaderField::FieldType ExpectedType[] = { static const NaClBitcodeHeaderField::FieldType ExpectedType[] = {
NaClBitcodeHeaderField::kUnknownType, // kInvalid NaClBitcodeHeaderField::kUnknownType, // kInvalid
NaClBitcodeHeaderField::kUInt32Type, // kPNaClVersion NaClBitcodeHeaderField::kUInt32Type, // kPNaClVersion
NaClBitcodeHeaderField::kFlagType // kAlignBitcodeRecords NaClBitcodeHeaderField::kFlagType // kAlignBitcodeRecords
}; };
} // end of anonymous namespace } // end of anonymous namespace
...@@ -59,10 +59,10 @@ const char *NaClBitcodeHeaderField::TypeName(FieldType FType) { ...@@ -59,10 +59,10 @@ const char *NaClBitcodeHeaderField::TypeName(FieldType FType) {
} }
NaClBitcodeHeaderField::NaClBitcodeHeaderField() NaClBitcodeHeaderField::NaClBitcodeHeaderField()
: ID(kInvalid), FType(kBufferType), Len(0), Data(0) {} : ID(kInvalid), FType(kBufferType), Len(0), Data(0) {}
NaClBitcodeHeaderField::NaClBitcodeHeaderField(Tag MyID) NaClBitcodeHeaderField::NaClBitcodeHeaderField(Tag MyID)
: ID(MyID), FType(kFlagType), Len(0), Data(0) { : ID(MyID), FType(kFlagType), Len(0), Data(0) {
assert(MyID <= kTag_MAX); assert(MyID <= kTag_MAX);
} }
...@@ -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 ||
...@@ -182,7 +182,7 @@ bool NaClBitcodeHeader::ReadPrefix(const unsigned char *BufPtr, ...@@ -182,7 +182,7 @@ bool NaClBitcodeHeader::ReadPrefix(const unsigned char *BufPtr,
UnsupportedMessage = "Invalid PNaCl bitcode header"; UnsupportedMessage = "Invalid PNaCl bitcode header";
if (isBitcode(BufPtr, BufEnd)) { if (isBitcode(BufPtr, BufEnd)) {
UnsupportedMessage += " (to run in Chrome, bitcode files must be " UnsupportedMessage += " (to run in Chrome, bitcode files must be "
"finalized using pnacl-finalize)"; "finalized using pnacl-finalize)";
} }
return true; return true;
} }
...@@ -192,9 +192,9 @@ bool NaClBitcodeHeader::ReadPrefix(const unsigned char *BufPtr, ...@@ -192,9 +192,9 @@ bool NaClBitcodeHeader::ReadPrefix(const unsigned char *BufPtr,
if (BufPtr + WordSize > BufEnd) if (BufPtr + WordSize > BufEnd)
return UnsupportedError("Bitcode read failure"); return UnsupportedError("Bitcode read failure");
NumFields = static_cast<unsigned>(BufPtr[0]) | NumFields = static_cast<unsigned>(BufPtr[0]) |
(static_cast<unsigned>(BufPtr[1]) << 8); (static_cast<unsigned>(BufPtr[1]) << 8);
NumBytes = static_cast<unsigned>(BufPtr[2]) | NumBytes = static_cast<unsigned>(BufPtr[2]) |
(static_cast<unsigned>(BufPtr[3]) << 8); (static_cast<unsigned>(BufPtr[3]) << 8);
BufPtr += WordSize; BufPtr += WordSize;
return false; return false;
} }
...@@ -245,9 +245,8 @@ bool NaClBitcodeHeader::Read(MemoryObject *Bytes) { ...@@ -245,9 +245,8 @@ 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)
return UnsupportedError("Bitcode read failure"); return UnsupportedError("Bitcode read failure");
......
...@@ -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,9 +84,9 @@ NaClBitcodeParser::~NaClBitcodeParser() { ...@@ -86,9 +84,9 @@ 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)
report_fatal_error("Unable to continue"); report_fatal_error("Unable to continue");
...@@ -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
//===- 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
...@@ -25,7 +25,7 @@ namespace naclbitc { ...@@ -25,7 +25,7 @@ namespace naclbitc {
// record codes for user-defined blocks. // record codes for user-defined blocks.
enum SpecialBlockCodes { enum SpecialBlockCodes {
BLK_CODE_ENTER = 65535, BLK_CODE_ENTER = 65535,
BLK_CODE_EXIT = 65534, BLK_CODE_EXIT = 65534,
BLK_CODE_DEFINE_ABBREV = 65533, BLK_CODE_DEFINE_ABBREV = 65533,
BLK_CODE_HEADER = 65532 BLK_CODE_HEADER = 65532
}; };
...@@ -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
......
...@@ -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
...@@ -48,8 +48,8 @@ public: ...@@ -48,8 +48,8 @@ public:
private: 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