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

@ -157,7 +157,7 @@ typedef enum spv_operand_type_t {
SPV_OPERAND_TYPE_NONE = 0,
SPV_OPERAND_TYPE_ID,
SPV_OPERAND_TYPE_RESULT_ID,
SPV_OPERAND_TYPE_LITERAL, // Either a literal number or literal string
SPV_OPERAND_TYPE_LITERAL, // Either a literal number or literal string
SPV_OPERAND_TYPE_LITERAL_NUMBER,
SPV_OPERAND_TYPE_LITERAL_STRING,
SPV_OPERAND_TYPE_SOURCE_LANGUAGE,
@ -274,15 +274,15 @@ typedef struct spv_header_t {
typedef struct spv_opcode_desc_t {
const char *name;
const Op opcode;
const uint32_t flags; // Bitfield of spv_opcode_flags_t
const uint32_t capabilities; // spv_language_capabilities_t
const uint32_t flags; // Bitfield of spv_opcode_flags_t
const uint32_t capabilities; // spv_language_capabilities_t
// operandTypes[0..numTypes-1] describe logical operands for the instruction.
// The operand types include result id and result-type id, followed by
// the types of arguments.
uint16_t numTypes;
spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger?
const bool hasResult; // Does the instruction have a result ID operand?
const bool hasType; // Does the instruction have a type ID operand?
const bool hasResult; // Does the instruction have a result ID operand?
const bool hasType; // Does the instruction have a type ID operand?
// The operand class for each logical argument. This does *not* include
// the result Id or type ID. The list is terminated by SPV_OPERAND_TYPE_NONE.
const OperandClass operandClass[16];
@ -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

@ -173,7 +173,7 @@ spv_result_t spvTextWordGet(const spv_text text,
case '\t':
case '\n':
if (escaping || quoting) break;
// Fall through.
// Fall through.
case '\0': { // NOTE: End of word found!
word.assign(text->str + startPosition->index,
(size_t)(endPosition->index - startPosition->index));
@ -201,11 +201,10 @@ bool spvStartsWithOp(const spv_text text, const spv_position position) {
return ('O' == ch0 && 'p' == ch1 && ('A' <= ch2 && ch2 <= 'Z'));
}
} // anonymous namespace
} // 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;
@ -303,22 +302,22 @@ spv_result_t spvTextToLiteral(const char *textValue, spv_literal_t *pLiteral) {
break;
default:
isString = true;
index = len; // break out of the loop too.
index = len; // break out of the loop too.
break;
}
}
pLiteral->type = spv_literal_type_t(99);
if (isString || numPeriods > 1 || (isSigned && len==1)) {
if (isString || numPeriods > 1 || (isSigned && len == 1)) {
// TODO(dneto): Allow escaping.
if (len < 2 || textValue[0] != '"' || textValue[len - 1] != '"')
return SPV_FAILED_MATCH;
pLiteral->type = SPV_LITERAL_TYPE_STRING;
// Need room for the null-terminator.
if (len >= sizeof(pLiteral->value.str)) return SPV_ERROR_OUT_OF_MEMORY;
strncpy(pLiteral->value.str, textValue+1, len-2);
pLiteral->value.str[len-2] = 0;
strncpy(pLiteral->value.str, textValue + 1, len - 2);
pLiteral->value.str[len - 2] = 0;
} else if (numPeriods == 1) {
double d = std::strtod(textValue, nullptr);
float f = (float)d;
@ -358,7 +357,7 @@ spv_result_t spvTextEncodeOperand(
const spv_operand_type_t type, const char *textValue,
const spv_operand_table operandTable, const spv_ext_inst_table extInstTable,
spv_named_id_table namedIdTable, spv_instruction_t *pInst,
spv_operand_pattern_t* pExpectedOperands, uint32_t *pBound,
spv_operand_pattern_t *pExpectedOperands, uint32_t *pBound,
const spv_position position, spv_diagnostic *pDiagnostic) {
// NOTE: Handle immediate int in the stream
if ('!' == textValue[0]) {
@ -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;
@ -773,7 +770,7 @@ spv_result_t spvTextToBinaryInternal(const spv_text text,
return SPV_SUCCESS;
}
} // anonymous namespace
} // anonymous namespace
spv_result_t spvTextToBinary(const char *input_text,
const uint64_t input_text_size,

View File

@ -29,7 +29,7 @@
namespace {
using test_fixture::TextToBinaryTest;
using test_fixture::TextToBinaryTest;
TEST_F(TextToBinaryTest, Whitespace) {
SetText(R"(

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,8 +81,9 @@ TEST(TextToBinary, Default) {
spv_binary binary;
spv_diagnostic diagnostic = nullptr;
spv_result_t error = spvTextToBinary(textStr, strlen(textStr), opcodeTable, operandTable,
extInstTable, &binary, &diagnostic);
spv_result_t error =
spvTextToBinary(textStr, strlen(textStr), opcodeTable, operandTable,
extInstTable, &binary, &diagnostic);
if (error) {
spvDiagnosticPrint(diagnostic);
@ -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,
@ -340,7 +343,7 @@ TEST_F(TextToBinaryTest, GoodSwitch) {
)");
// Minimal check: The OpSwitch opcode word is correct.
EXPECT_EQ(int(spv::OpSwitch) || (7<<16) , code[14]);
EXPECT_EQ(int(spv::OpSwitch) || (7 << 16), code[14]);
}
TEST_F(TextToBinaryTest, GoodSwitchZeroCasesOneDefault) {
@ -353,7 +356,7 @@ TEST_F(TextToBinaryTest, GoodSwitchZeroCasesOneDefault) {
)");
// Minimal check: The OpSwitch opcode word is correct.
EXPECT_EQ(int(spv::OpSwitch) || (3<<16) , code[10]);
EXPECT_EQ(int(spv::OpSwitch) || (3 << 16), code[10]);
}
TEST_F(TextToBinaryTest, BadSwitchTruncatedCase) {
@ -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

@ -52,22 +52,23 @@ class ValidateID : public ::testing::Test {
spv_binary binary;
};
#define CHECK(str, expected) \
spv_diagnostic diagnostic; \
spv_result_t error = spvTextToBinary(str, strlen(str), opcodeTable, operandTable, \
extInstTable, &binary, &diagnostic); \
if (error) { \
spvDiagnosticPrint(diagnostic); \
spvDiagnosticDestroy(diagnostic); \
ASSERT_EQ(SPV_SUCCESS, error); \
} \
spv_result_t result = \
spvValidate(binary, opcodeTable, operandTable, extInstTable, \
SPV_VALIDATE_ID_BIT, &diagnostic); \
if (SPV_SUCCESS != result) { \
spvDiagnosticPrint(diagnostic); \
spvDiagnosticDestroy(diagnostic); \
} \
#define CHECK(str, expected) \
spv_diagnostic diagnostic; \
spv_result_t error = \
spvTextToBinary(str, strlen(str), opcodeTable, operandTable, \
extInstTable, &binary, &diagnostic); \
if (error) { \
spvDiagnosticPrint(diagnostic); \
spvDiagnosticDestroy(diagnostic); \
ASSERT_EQ(SPV_SUCCESS, error); \
} \
spv_result_t result = \
spvValidate(binary, opcodeTable, operandTable, extInstTable, \
SPV_VALIDATE_ID_BIT, &diagnostic); \
if (SPV_SUCCESS != result) { \
spvDiagnosticPrint(diagnostic); \
spvDiagnosticDestroy(diagnostic); \
} \
ASSERT_EQ(expected, result);
// TODO: OpUndef
@ -103,7 +104,7 @@ TEST_F(ValidateID, OpMemberNameMemberBad) {
}
TEST_F(ValidateID, OpLineGood) {
// TODO(dneto): OpLine changed after Rev31. It no longer has a first argument.
// TODO(dneto): OpLine changed after Rev31. It no longer has a first argument.
// The following is the Rev31 form.
const char *spirv = R"(
%1 = OpString "/path/to/source.file"
@ -114,7 +115,7 @@ TEST_F(ValidateID, OpLineGood) {
CHECK(spirv, SPV_SUCCESS);
}
TEST_F(ValidateID, OpLineFileBad) {
// TODO(dneto): OpLine changed after Rev31. It no longer has a first argument.
// TODO(dneto): OpLine changed after Rev31. It no longer has a first argument.
// The following is the Rev31 form.
const char *spirv = R"(
OpLine %4 %2 0 0