Run clang-format.

This commit is contained in:
Lei Zhang 2015-09-10 17:07:21 -04:00 committed by David Neto
parent 06efdc59e1
commit e78a7c19ff
9 changed files with 73 additions and 74 deletions

View File

@ -465,8 +465,7 @@ void spvTextDestroy(spv_text text);
/// @param[out] pDiagnostic contains diagnostic on failure
///
/// @return result code
spv_result_t spvBinaryToText(uint32_t* binary,
const uint64_t wordCount,
spv_result_t spvBinaryToText(uint32_t *binary, const uint64_t wordCount,
const uint32_t options,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,

View File

@ -363,13 +363,14 @@ spv_result_t spvBinaryDecodeOpcode(
if (opcodeEntry->numTypes > wordCount &&
!spvOperandIsOptional(opcodeEntry->operandTypes[wordCount])) {
uint16_t numRequired;
for (numRequired = 0; numRequired < opcodeEntry->numTypes &&
!spvOperandIsOptional(opcodeEntry->operandTypes[numRequired]) ; numRequired++ )
for (numRequired = 0;
numRequired < opcodeEntry->numTypes &&
!spvOperandIsOptional(opcodeEntry->operandTypes[numRequired]);
numRequired++)
;
DIAGNOSTIC << "Invalid instruction Op" << opcodeEntry->name
<< " word count '" << wordCount
<< "', expected at least '" << numRequired
<< "'.";
<< " word count '" << wordCount << "', expected at least '"
<< numRequired << "'.";
return SPV_ERROR_INVALID_BINARY;
}
@ -430,8 +431,7 @@ spv_result_t spvBinaryDecodeOpcode(
return SPV_SUCCESS;
}
spv_result_t spvBinaryToText(uint32_t* code,
const uint64_t wordCount,
spv_result_t spvBinaryToText(uint32_t *code, const uint64_t wordCount,
const uint32_t options,
const spv_opcode_table opcodeTable,
const spv_operand_table operandTable,
@ -440,8 +440,8 @@ spv_result_t spvBinaryToText(uint32_t* code,
spv_binary_t binary = {code, wordCount};
spv_position_t position = {};
spvCheck(!binary.code || !binary.wordCount,
DIAGNOSTIC << "Binary stream is empty.";
spvCheck(!binary.code || !binary.wordCount, DIAGNOSTIC
<< "Binary stream is empty.";
return SPV_ERROR_INVALID_BINARY);
spvCheck(!opcodeTable || !operandTable || !extInstTable,
return SPV_ERROR_INVALID_TABLE);

View File

@ -204,8 +204,7 @@ bool spvStartsWithOp(const spv_text text, const spv_position position) {
} // anonymous namespace
// Returns true if a new instruction begins at the given position in text.
bool spvTextIsStartOfNewInst(const spv_text text,
const spv_position position) {
bool spvTextIsStartOfNewInst(const spv_text text, const spv_position position) {
spv_position_t nextPosition = *position;
if (spvTextAdvance(text, &nextPosition)) return false;
if (spvStartsWithOp(text, &nextPosition)) return true;
@ -483,8 +482,7 @@ spv_result_t spvTextEncodeOperand(
case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING: {
size_t len = strlen(textValue);
spvCheck('"' != textValue[0] && '"' != textValue[len - 1],
if (spvOperandIsOptional(type))
return SPV_FAILED_MATCH;
if (spvOperandIsOptional(type)) return SPV_FAILED_MATCH;
DIAGNOSTIC << "Invalid literal string '" << textValue
<< "', expected quotes.";
return SPV_ERROR_INVALID_TEXT;);
@ -635,24 +633,24 @@ spv_result_t spvTextEncodeOpcode(
expectedOperands.pop_front();
// Expand optional tuples lazily.
if (spvExpandOperandSequenceOnce(type, &expectedOperands))
continue;
if (spvExpandOperandSequenceOnce(type, &expectedOperands)) continue;
if (type == SPV_OPERAND_TYPE_RESULT_ID && !result_id.empty()) {
// Handle the <result-id> for value generating instructions.
// We've already consumed it from the text stream. Here
// we inject its words into the instruction.
error = spvTextEncodeOperand(
SPV_OPERAND_TYPE_RESULT_ID, result_id.c_str(), operandTable,
extInstTable, namedIdTable, pInst, nullptr, pBound,
&result_id_position, pDiagnostic);
error = spvTextEncodeOperand(SPV_OPERAND_TYPE_RESULT_ID,
result_id.c_str(), operandTable,
extInstTable, namedIdTable, pInst, nullptr,
pBound, &result_id_position, pDiagnostic);
spvCheck(error, return error);
} else {
// Find the next word.
error = spvTextAdvance(text, position);
if (error == SPV_END_OF_STREAM) {
if (spvOperandIsOptional(type)) {
// This would have been the last potential operand for the instruction,
// This would have been the last potential operand for the
// instruction,
// and we didn't find one. We're finished parsing this instruction.
break;
} else {
@ -676,9 +674,8 @@ spv_result_t spvTextEncodeOpcode(
spvCheck(error, DIAGNOSTIC << "Internal Error"; return error);
error = spvTextEncodeOperand(
type, operandValue.c_str(),
operandTable, extInstTable, namedIdTable, pInst, &expectedOperands,
pBound, position, pDiagnostic);
type, operandValue.c_str(), operandTable, extInstTable, namedIdTable,
pInst, &expectedOperands, pBound, position, pDiagnostic);
if (error == SPV_FAILED_MATCH && spvOperandIsOptional(type))
return SPV_SUCCESS;

View File

@ -28,12 +28,8 @@
namespace {
TEST(Macros, BitShiftInnerParens) {
ASSERT_EQ(65536, SPV_BIT(2 << 3));
}
TEST(Macros, BitShiftInnerParens) { ASSERT_EQ(65536, SPV_BIT(2 << 3)); }
TEST(Macros, BitShiftOuterParens) {
ASSERT_EQ(15, SPV_BIT(4)-1);
}
TEST(Macros, BitShiftOuterParens) { ASSERT_EQ(15, SPV_BIT(4) - 1); }
} // anonymous namespace

View File

@ -114,5 +114,4 @@ INSTANTIATE_TEST_CASE_P(NonMatchableOperandExpansion,
VariableOperandExpansionTest,
::testing::ValuesIn(allOperandTypes()));
} // anonymous namespace

View File

@ -50,7 +50,8 @@ TEST(TextStartsWithOp, NoIfTooFar) {
TEST(TextStartsWithOp, NoRegular) {
spv_position_t startPosition = {};
EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("Fee Fi Fo Fum"), &startPosition));
EXPECT_FALSE(
spvTextIsStartOfNewInst(AutoText("Fee Fi Fo Fum"), &startPosition));
EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("123456"), &startPosition));
EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("123456"), &startPosition));
EXPECT_FALSE(spvTextIsStartOfNewInst(AutoText("OpenCL"), &startPosition));
@ -58,8 +59,10 @@ TEST(TextStartsWithOp, NoRegular) {
TEST(TextStartsWithOp, YesForValueGenerationForm) {
spv_position_t startPosition = {};
EXPECT_TRUE(spvTextIsStartOfNewInst(AutoText("\%foo = OpAdd"), &startPosition));
EXPECT_TRUE(spvTextIsStartOfNewInst(AutoText("\%foo = OpAdd"), &startPosition));
EXPECT_TRUE(
spvTextIsStartOfNewInst(AutoText("\%foo = OpAdd"), &startPosition));
EXPECT_TRUE(
spvTextIsStartOfNewInst(AutoText("\%foo = OpAdd"), &startPosition));
}
TEST(TextStartsWithOp, NoForNearlyValueGeneration) {

View File

@ -81,7 +81,8 @@ TEST(TextToBinary, Default) {
spv_binary binary;
spv_diagnostic diagnostic = nullptr;
spv_result_t error = spvTextToBinary(textStr, strlen(textStr), opcodeTable, operandTable,
spv_result_t error =
spvTextToBinary(textStr, strlen(textStr), opcodeTable, operandTable,
extInstTable, &binary, &diagnostic);
if (error) {
@ -228,14 +229,16 @@ TEST_F(TextToBinaryTest, InvalidTable) {
}
TEST_F(TextToBinaryTest, InvalidPointer) {
SetText("OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
SetText(
"OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
ASSERT_EQ(SPV_ERROR_INVALID_POINTER,
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
extInstTable, nullptr, &diagnostic));
}
TEST_F(TextToBinaryTest, InvalidDiagnostic) {
SetText("OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
SetText(
"OpEntryPoint Kernel 0 \"\"\nOpExecutionMode 0 LocalSizeHint 1 1 1\n");
spv_binary binary;
ASSERT_EQ(SPV_ERROR_INVALID_DIAGNOSTIC,
spvTextToBinary(text.str, text.length, opcodeTable, operandTable,
@ -370,7 +373,8 @@ TEST_F(TextToBinaryTest, BadSwitchTruncatedCase) {
extInstTable, &binary, &diagnostic));
EXPECT_EQ(6, diagnostic->position.line + 1);
EXPECT_EQ(1, diagnostic->position.column + 1);
EXPECT_STREQ("Expected operand, found next instruction instead.", diagnostic->error);
EXPECT_STREQ("Expected operand, found next instruction instead.",
diagnostic->error);
}
using TextToBinaryFloatValueTest = test_fixture::TextToBinaryTestBase<

View File

@ -54,7 +54,8 @@ class ValidateID : public ::testing::Test {
#define CHECK(str, expected) \
spv_diagnostic diagnostic; \
spv_result_t error = spvTextToBinary(str, strlen(str), opcodeTable, operandTable, \
spv_result_t error = \
spvTextToBinary(str, strlen(str), opcodeTable, operandTable, \
extInstTable, &binary, &diagnostic); \
if (error) { \
spvDiagnosticPrint(diagnostic); \