Run clang-format to enforce Google style globally.

Note that we are more strict than Google style for one aspect:
pointer/reference indicators are adjacent to their types, not
their variables.

find . -name "*.h" -exec clang-format -i {} \;
find . -name "*.cpp" -exec clang-format -i {} \;
This commit is contained in:
Lei Zhang 2015-11-02 09:41:20 -05:00 committed by David Neto
parent 0170752763
commit 1a0334edee
51 changed files with 898 additions and 1124 deletions

View File

@ -1,65 +1,5 @@
--- ---
Language: Cpp Language: Cpp
# BasedOnStyle: Google BasedOnStyle: Google
AccessModifierOffset: -1 DerivePointerAlignment: false
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 80
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: true
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: false
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
SpacesBeforeTrailingComments: 2
Cpp11BracedListStyle: true
Standard: Auto
IndentWidth: 2
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Attach
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
... ...

View File

@ -103,7 +103,8 @@ typedef uint64_t spv_capability_mask_t;
// be a constexpr inline function, but some important versions of MSVC don't // be a constexpr inline function, but some important versions of MSVC don't
// support that yet. Different from SPV_BIT, which doesn't guarantee 64-bit // support that yet. Different from SPV_BIT, which doesn't guarantee 64-bit
// values. // values.
#define SPV_CAPABILITY_AS_MASK(capability) (spv_capability_mask_t(1) << (capability)) #define SPV_CAPABILITY_AS_MASK(capability) \
(spv_capability_mask_t(1) << (capability))
// Enumerations // Enumerations
@ -291,11 +292,11 @@ typedef struct spv_header_t {
uint32_t generator; uint32_t generator;
uint32_t bound; uint32_t bound;
uint32_t schema; // NOTE: Reserved uint32_t schema; // NOTE: Reserved
const uint32_t *instructions; // NOTE: Unfixed pointer to instruciton stream const uint32_t* instructions; // NOTE: Unfixed pointer to instruciton stream
} spv_header_t; } spv_header_t;
typedef struct spv_opcode_desc_t { typedef struct spv_opcode_desc_t {
const char *name; const char* name;
const SpvOp opcode; const SpvOp opcode;
const spv_capability_mask_t const spv_capability_mask_t
capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability) capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability)
@ -313,11 +314,11 @@ typedef struct spv_opcode_desc_t {
typedef struct spv_opcode_table_t { typedef struct spv_opcode_table_t {
const uint32_t count; const uint32_t count;
const spv_opcode_desc_t *entries; const spv_opcode_desc_t* entries;
} spv_opcode_table_t; } spv_opcode_table_t;
typedef struct spv_operand_desc_t { typedef struct spv_operand_desc_t {
const char *name; const char* name;
const uint32_t value; const uint32_t value;
const spv_capability_mask_t const spv_capability_mask_t
capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability) capabilities; // Bitfield of SPV_CAPABILITY_AS_MASK(spv::Capability)
@ -327,16 +328,16 @@ typedef struct spv_operand_desc_t {
typedef struct spv_operand_desc_group_t { typedef struct spv_operand_desc_group_t {
const spv_operand_type_t type; const spv_operand_type_t type;
const uint32_t count; const uint32_t count;
const spv_operand_desc_t *entries; const spv_operand_desc_t* entries;
} spv_operand_desc_group_t; } spv_operand_desc_group_t;
typedef struct spv_operand_table_t { typedef struct spv_operand_table_t {
const uint32_t count; const uint32_t count;
const spv_operand_desc_group_t *types; const spv_operand_desc_group_t* types;
} spv_operand_table_t; } spv_operand_table_t;
typedef struct spv_ext_inst_desc_t { typedef struct spv_ext_inst_desc_t {
const char *name; const char* name;
const uint32_t ext_inst; const uint32_t ext_inst;
const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger? const spv_operand_type_t operandTypes[16]; // TODO: Smaller/larger?
} spv_ext_inst_desc_t; } spv_ext_inst_desc_t;
@ -344,21 +345,21 @@ typedef struct spv_ext_inst_desc_t {
typedef struct spv_ext_inst_group_t { typedef struct spv_ext_inst_group_t {
const spv_ext_inst_type_t type; const spv_ext_inst_type_t type;
const uint32_t count; const uint32_t count;
const spv_ext_inst_desc_t *entries; const spv_ext_inst_desc_t* entries;
} spv_ext_inst_group_t; } spv_ext_inst_group_t;
typedef struct spv_ext_inst_table_t { typedef struct spv_ext_inst_table_t {
const uint32_t count; const uint32_t count;
const spv_ext_inst_group_t *groups; const spv_ext_inst_group_t* groups;
} spv_ext_inst_table_t; } spv_ext_inst_table_t;
typedef struct spv_binary_t { typedef struct spv_binary_t {
uint32_t *code; uint32_t* code;
uint64_t wordCount; uint64_t wordCount;
} spv_binary_t; } spv_binary_t;
typedef struct spv_text_t { typedef struct spv_text_t {
const char *str; const char* str;
uint64_t length; uint64_t length;
} spv_text_t; } spv_text_t;
@ -370,22 +371,22 @@ typedef struct spv_position_t {
typedef struct spv_diagnostic_t { typedef struct spv_diagnostic_t {
spv_position_t position; spv_position_t position;
char *error; char* error;
bool isTextSource; bool isTextSource;
} spv_diagnostic_t; } spv_diagnostic_t;
// Type Definitions // Type Definitions
typedef const spv_opcode_desc_t *spv_opcode_desc; typedef const spv_opcode_desc_t* spv_opcode_desc;
typedef const spv_opcode_table_t *spv_opcode_table; typedef const spv_opcode_table_t* spv_opcode_table;
typedef const spv_operand_desc_t *spv_operand_desc; typedef const spv_operand_desc_t* spv_operand_desc;
typedef const spv_operand_table_t *spv_operand_table; typedef const spv_operand_table_t* spv_operand_table;
typedef const spv_ext_inst_desc_t *spv_ext_inst_desc; typedef const spv_ext_inst_desc_t* spv_ext_inst_desc;
typedef const spv_ext_inst_table_t *spv_ext_inst_table; typedef const spv_ext_inst_table_t* spv_ext_inst_table;
typedef spv_binary_t *spv_binary; typedef spv_binary_t* spv_binary;
typedef spv_text_t *spv_text; typedef spv_text_t* spv_text;
typedef spv_position_t *spv_position; typedef spv_position_t* spv_position;
typedef spv_diagnostic_t *spv_diagnostic; typedef spv_diagnostic_t* spv_diagnostic;
// Platform API // Platform API
@ -396,21 +397,21 @@ typedef spv_diagnostic_t *spv_diagnostic;
/// @param[out] pOpcodeTable table to be populated /// @param[out] pOpcodeTable table to be populated
/// ///
/// @return result code /// @return result code
spv_result_t spvOpcodeTableGet(spv_opcode_table *pOpcodeTable); spv_result_t spvOpcodeTableGet(spv_opcode_table* pOpcodeTable);
/// @brief Populate the operand table /// @brief Populate the operand table
/// ///
/// @param[in] pOperandTable table to be populated /// @param[in] pOperandTable table to be populated
/// ///
/// @return result code /// @return result code
spv_result_t spvOperandTableGet(spv_operand_table *pOperandTable); spv_result_t spvOperandTableGet(spv_operand_table* pOperandTable);
/// @brief Populate the extended instruction table /// @brief Populate the extended instruction table
/// ///
/// @param pTable table to be populated /// @param pTable table to be populated
/// ///
/// @return result code /// @return result code
spv_result_t spvExtInstTableGet(spv_ext_inst_table *pTable); spv_result_t spvExtInstTableGet(spv_ext_inst_table* pTable);
// Text API // Text API
@ -425,11 +426,11 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table *pTable);
/// @param[out] pDiagnostic contains diagnostic on failure /// @param[out] pDiagnostic contains diagnostic on failure
/// ///
/// @return result code /// @return result code
spv_result_t spvTextToBinary(const char *text, const uint64_t length, spv_result_t spvTextToBinary(const char* text, const uint64_t length,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
spv_binary *pBinary, spv_diagnostic *pDiagnostic); spv_binary* pBinary, spv_diagnostic* pDiagnostic);
/// @brief Entry point to covert text form to binary form /// @brief Entry point to covert text form to binary form
/// ///
@ -443,13 +444,13 @@ spv_result_t spvTextToBinary(const char *text, const uint64_t length,
/// @param[out] pDiagnostic contains diagnostic on failure /// @param[out] pDiagnostic contains diagnostic on failure
/// ///
/// @return result code /// @return result code
spv_result_t spvTextWithFormatToBinary(const char *text, const uint64_t length, spv_result_t spvTextWithFormatToBinary(const char* text, const uint64_t length,
spv_assembly_syntax_format_t format, spv_assembly_syntax_format_t format,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
spv_binary *pBinary, spv_binary* pBinary,
spv_diagnostic *pDiagnostic); spv_diagnostic* pDiagnostic);
/// @brief Free an allocated text stream /// @brief Free an allocated text stream
/// ///
@ -472,12 +473,12 @@ void spvTextDestroy(spv_text text);
/// @param[out] pDiagnostic contains diagnostic on failure /// @param[out] pDiagnostic contains diagnostic on failure
/// ///
/// @return result code /// @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 uint32_t options,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
spv_text *pText, spv_diagnostic *pDiagnostic); spv_text* pText, spv_diagnostic* pDiagnostic);
/// @brief Entry point to convert binary to text form /// @brief Entry point to convert binary to text form
/// ///
@ -493,10 +494,10 @@ spv_result_t spvBinaryToText(uint32_t *binary, const uint64_t wordCount,
/// ///
/// @return result code /// @return result code
spv_result_t spvBinaryToTextWithFormat( spv_result_t spvBinaryToTextWithFormat(
uint32_t *binary, const uint64_t wordCount, const uint32_t options, uint32_t* binary, const uint64_t wordCount, const uint32_t options,
const spv_opcode_table opcodeTable, const spv_operand_table operandTable, const spv_opcode_table opcodeTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, spv_assembly_syntax_format_t format, const spv_ext_inst_table extInstTable, spv_assembly_syntax_format_t format,
spv_text *pText, spv_diagnostic *pDiagnostic); spv_text* pText, spv_diagnostic* pDiagnostic);
/// @brief Free a binary stream from memory. /// @brief Free a binary stream from memory.
/// ///
@ -521,7 +522,7 @@ spv_result_t spvValidate(const spv_binary binary,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
const uint32_t options, spv_diagnostic *pDiagnostic); const uint32_t options, spv_diagnostic* pDiagnostic);
// Diagnostic API // Diagnostic API
@ -532,7 +533,7 @@ spv_result_t spvValidate(const spv_binary binary,
/// ///
/// @return the diagnostic object /// @return the diagnostic object
spv_diagnostic spvDiagnosticCreate(const spv_position position, spv_diagnostic spvDiagnosticCreate(const spv_position position,
const char *message); const char* message);
/// @brief Destroy a diagnostic object /// @brief Destroy a diagnostic object
/// ///

3
include/util/bitutils.h Executable file → Normal file
View File

@ -48,8 +48,7 @@ template <typename T, size_t First = 0, size_t Num = 0>
struct SetBits { struct SetBits {
static_assert(First < sizeof(T) * 8, static_assert(First < sizeof(T) * 8,
"Tried to set a bit that is shifted too far."); "Tried to set a bit that is shifted too far.");
const static T get = const static T get = (T(1) << First) | SetBits<T, First + 1, Num - 1>::get;
(T(1) << First) | SetBits<T, First + 1, Num - 1>::get;
}; };
template <typename T, size_t Last> template <typename T, size_t Last>

4
include/util/hex_float.h Executable file → Normal file
View File

@ -68,9 +68,7 @@ class FloatProxy {
// Intentionally non-explicit. This is a proxy type so // Intentionally non-explicit. This is a proxy type so
// implicit conversions allow us to use it more transparently. // implicit conversions allow us to use it more transparently.
FloatProxy(T val) { FloatProxy(T val) { data_ = BitwiseCast<uint_type>(val); }
data_ = BitwiseCast<uint_type>(val);
}
// Intentionally non-explicit. This is a proxy type so // Intentionally non-explicit. This is a proxy type so
// implicit conversions allow us to use it more transparently. // implicit conversions allow us to use it more transparently.

View File

@ -50,11 +50,11 @@ namespace {
/// @return result code /// @return result code
spv_result_t spvTextParseMaskOperand(const spv_operand_table operandTable, spv_result_t spvTextParseMaskOperand(const spv_operand_table operandTable,
const spv_operand_type_t type, const spv_operand_type_t type,
const char *textValue, uint32_t *pValue) { const char* textValue, uint32_t* pValue) {
if (textValue == nullptr) return SPV_ERROR_INVALID_TEXT; if (textValue == nullptr) return SPV_ERROR_INVALID_TEXT;
size_t text_length = strlen(textValue); size_t text_length = strlen(textValue);
if (text_length == 0) return SPV_ERROR_INVALID_TEXT; if (text_length == 0) return SPV_ERROR_INVALID_TEXT;
const char *text_end = textValue + text_length; const char* text_end = textValue + text_length;
// We only support mask expressions in ASCII, so the separator value is a // We only support mask expressions in ASCII, so the separator value is a
// char. // char.
@ -63,8 +63,8 @@ spv_result_t spvTextParseMaskOperand(const spv_operand_table operandTable,
// Accumulate the result by interpreting one word at a time, scanning // Accumulate the result by interpreting one word at a time, scanning
// from left to right. // from left to right.
uint32_t value = 0; uint32_t value = 0;
const char *begin = textValue; // The left end of the current word. const char* begin = textValue; // The left end of the current word.
const char *end = nullptr; // One character past the end of the current word. const char* end = nullptr; // One character past the end of the current word.
do { do {
end = std::find(begin, text_end, separator); end = std::find(begin, text_end, separator);
@ -90,48 +90,48 @@ bool AssemblyGrammar::isValid() const {
return operandTable_ && opcodeTable_ && extInstTable_; return operandTable_ && opcodeTable_ && extInstTable_;
} }
spv_result_t AssemblyGrammar::lookupOpcode(const char *name, spv_result_t AssemblyGrammar::lookupOpcode(const char* name,
spv_opcode_desc *desc) const { spv_opcode_desc* desc) const {
return spvOpcodeTableNameLookup(opcodeTable_, name, desc); return spvOpcodeTableNameLookup(opcodeTable_, name, desc);
} }
spv_result_t AssemblyGrammar::lookupOpcode(SpvOp opcode, spv_result_t AssemblyGrammar::lookupOpcode(SpvOp opcode,
spv_opcode_desc *desc) const { spv_opcode_desc* desc) const {
return spvOpcodeTableValueLookup(opcodeTable_, opcode, desc); return spvOpcodeTableValueLookup(opcodeTable_, opcode, desc);
} }
spv_result_t AssemblyGrammar::lookupOperand(spv_operand_type_t type, spv_result_t AssemblyGrammar::lookupOperand(spv_operand_type_t type,
const char *name, size_t name_len, const char* name, size_t name_len,
spv_operand_desc *desc) const { spv_operand_desc* desc) const {
return spvOperandTableNameLookup(operandTable_, type, name, name_len, desc); return spvOperandTableNameLookup(operandTable_, type, name, name_len, desc);
} }
spv_result_t AssemblyGrammar::lookupOperand(spv_operand_type_t type, spv_result_t AssemblyGrammar::lookupOperand(spv_operand_type_t type,
uint32_t operand, uint32_t operand,
spv_operand_desc *desc) const { spv_operand_desc* desc) const {
return spvOperandTableValueLookup(operandTable_, type, operand, desc); return spvOperandTableValueLookup(operandTable_, type, operand, desc);
} }
spv_result_t AssemblyGrammar::parseMaskOperand(const spv_operand_type_t type, spv_result_t AssemblyGrammar::parseMaskOperand(const spv_operand_type_t type,
const char *textValue, const char* textValue,
uint32_t *pValue) const { uint32_t* pValue) const {
return spvTextParseMaskOperand(operandTable_, type, textValue, pValue); return spvTextParseMaskOperand(operandTable_, type, textValue, pValue);
} }
spv_result_t AssemblyGrammar::lookupExtInst(spv_ext_inst_type_t type, spv_result_t AssemblyGrammar::lookupExtInst(spv_ext_inst_type_t type,
const char *textValue, const char* textValue,
spv_ext_inst_desc *extInst) const { spv_ext_inst_desc* extInst) const {
return spvExtInstTableNameLookup(extInstTable_, type, textValue, extInst); return spvExtInstTableNameLookup(extInstTable_, type, textValue, extInst);
} }
spv_result_t AssemblyGrammar::lookupExtInst(spv_ext_inst_type_t type, spv_result_t AssemblyGrammar::lookupExtInst(spv_ext_inst_type_t type,
uint32_t firstWord, uint32_t firstWord,
spv_ext_inst_desc *extInst) const { spv_ext_inst_desc* extInst) const {
return spvExtInstTableValueLookup(extInstTable_, type, firstWord, extInst); return spvExtInstTableValueLookup(extInstTable_, type, firstWord, extInst);
} }
void AssemblyGrammar::prependOperandTypesForMask( void AssemblyGrammar::prependOperandTypesForMask(
const spv_operand_type_t type, const uint32_t mask, const spv_operand_type_t type, const uint32_t mask,
spv_operand_pattern_t *pattern) const { spv_operand_pattern_t* pattern) const {
spvPrependOperandTypesForMask(operandTable_, type, mask, pattern); spvPrependOperandTypesForMask(operandTable_, type, mask, pattern);
} }
} // namespace libspirv } // namespace libspirv

View File

@ -49,24 +49,24 @@ class AssemblyGrammar {
// Fills in the desc parameter with the information about the opcode // Fills in the desc parameter with the information about the opcode
// of the given name. Returns SPV_SUCCESS if the opcode was found, and // of the given name. Returns SPV_SUCCESS if the opcode was found, and
// SPV_ERROR_INVALID_LOOKUP if the opcode does not exist. // SPV_ERROR_INVALID_LOOKUP if the opcode does not exist.
spv_result_t lookupOpcode(const char *name, spv_opcode_desc *desc) const; spv_result_t lookupOpcode(const char* name, spv_opcode_desc* desc) const;
// Fills in the desc parameter with the information about the opcode // Fills in the desc parameter with the information about the opcode
// of the valid. Returns SPV_SUCCESS if the opcode was found, and // of the valid. Returns SPV_SUCCESS if the opcode was found, and
// SPV_ERROR_INVALID_LOOKUP if the opcode does not exist. // SPV_ERROR_INVALID_LOOKUP if the opcode does not exist.
spv_result_t lookupOpcode(SpvOp opcode, spv_opcode_desc *desc) const; spv_result_t lookupOpcode(SpvOp opcode, spv_opcode_desc* desc) const;
// Fills in the desc parameter with the information about the given // Fills in the desc parameter with the information about the given
// operand. Returns SPV_SUCCESS if the operand was found, and // operand. Returns SPV_SUCCESS if the operand was found, and
// SPV_ERROR_INVALID_LOOKUP otherwise. // SPV_ERROR_INVALID_LOOKUP otherwise.
spv_result_t lookupOperand(spv_operand_type_t type, const char *name, spv_result_t lookupOperand(spv_operand_type_t type, const char* name,
size_t name_len, spv_operand_desc *desc) const; size_t name_len, spv_operand_desc* desc) const;
// Fills in the desc parameter with the information about the given // Fills in the desc parameter with the information about the given
// operand. Returns SPV_SUCCESS if the operand was found, and // operand. Returns SPV_SUCCESS if the operand was found, and
// SPV_ERROR_INVALID_LOOKUP otherwise. // SPV_ERROR_INVALID_LOOKUP otherwise.
spv_result_t lookupOperand(spv_operand_type_t type, uint32_t operand, spv_result_t lookupOperand(spv_operand_type_t type, uint32_t operand,
spv_operand_desc *desc) const; spv_operand_desc* desc) const;
// Parses a mask expression string for the given operand type. // Parses a mask expression string for the given operand type.
// //
@ -78,19 +78,19 @@ class AssemblyGrammar {
// The operand type is defined by the type parameter, and the text to be // The operand type is defined by the type parameter, and the text to be
// parsed is defined by the textValue parameter. // parsed is defined by the textValue parameter.
spv_result_t parseMaskOperand(const spv_operand_type_t type, spv_result_t parseMaskOperand(const spv_operand_type_t type,
const char *textValue, uint32_t *pValue) const; const char* textValue, uint32_t* pValue) const;
// Writes the extended operand with the given type and text to the *extInst // Writes the extended operand with the given type and text to the *extInst
// parameter. // parameter.
// Returns SPV_SUCCESS if the value could be found. // Returns SPV_SUCCESS if the value could be found.
spv_result_t lookupExtInst(spv_ext_inst_type_t type, const char *textValue, spv_result_t lookupExtInst(spv_ext_inst_type_t type, const char* textValue,
spv_ext_inst_desc *extInst) const; spv_ext_inst_desc* extInst) const;
// Writes the extended operand with the given type and first encoded word // Writes the extended operand with the given type and first encoded word
// to the *extInst parameter. // to the *extInst parameter.
// Returns SPV_SUCCESS if the value could be found. // Returns SPV_SUCCESS if the value could be found.
spv_result_t lookupExtInst(spv_ext_inst_type_t type, uint32_t firstWord, spv_result_t lookupExtInst(spv_ext_inst_type_t type, uint32_t firstWord,
spv_ext_inst_desc *extInst) const; spv_ext_inst_desc* extInst) const;
// Inserts the operands expected after the given typed mask onto the front // Inserts the operands expected after the given typed mask onto the front
// of the given pattern. // of the given pattern.
@ -102,7 +102,7 @@ class AssemblyGrammar {
// If a set bit is unknown, then we assume it has no operands. // If a set bit is unknown, then we assume it has no operands.
void prependOperandTypesForMask(const spv_operand_type_t type, void prependOperandTypesForMask(const spv_operand_type_t type,
const uint32_t mask, const uint32_t mask,
spv_operand_pattern_t *pattern) const; spv_operand_pattern_t* pattern) const;
private: private:
const spv_operand_table operandTable_; const spv_operand_table operandTable_;

View File

@ -48,7 +48,7 @@ using type_id_to_type_map = std::unordered_map<uint32_t, libspirv::IdType>;
spv_result_t spvBinaryHeaderGet(const spv_binary binary, spv_result_t spvBinaryHeaderGet(const spv_binary binary,
const spv_endianness_t endian, const spv_endianness_t endian,
spv_header_t *pHeader) { spv_header_t* pHeader) {
if (!binary->code || !binary->wordCount) return SPV_ERROR_INVALID_BINARY; if (!binary->code || !binary->wordCount) return SPV_ERROR_INVALID_BINARY;
if (!pHeader) return SPV_ERROR_INVALID_POINTER; if (!pHeader) return SPV_ERROR_INVALID_POINTER;
@ -72,7 +72,7 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
const uint16_t operandIndex, const uint16_t operandIndex,
const spv_opcode_desc opcodeEntry, const spv_opcode_desc opcodeEntry,
const spv_operand_table operandTable, const spv_operand_table operandTable,
spv_operand_desc *pOperandEntry) { spv_operand_desc* pOperandEntry) {
spv_operand_type_t type; spv_operand_type_t type;
if (operandIndex < opcodeEntry->numTypes) { if (operandIndex < opcodeEntry->numTypes) {
// NOTE: Do operand table lookup to set operandEntry if successful // NOTE: Do operand table lookup to set operandEntry if successful
@ -105,7 +105,6 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
return type; return type;
} }
/// @brief Translate a binary operand to the textual form /// @brief Translate a binary operand to the textual form
/// ///
/// @param[in] opcode of the current instruction /// @param[in] opcode of the current instruction
@ -120,11 +119,11 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
/// ///
/// @return result code /// @return result code
spv_result_t spvBinaryDecodeOperand( spv_result_t spvBinaryDecodeOperand(
const SpvOp opcode, const spv_operand_type_t type, const uint32_t *words, const SpvOp opcode, const spv_operand_type_t type, const uint32_t* words,
uint16_t numWords, const spv_endianness_t endian, const uint32_t options, uint16_t numWords, const spv_endianness_t endian, const uint32_t options,
const libspirv::AssemblyGrammar& grammar, const libspirv::AssemblyGrammar& grammar,
spv_operand_pattern_t *pExpectedOperands, spv_ext_inst_type_t *pExtInstType, spv_operand_pattern_t* pExpectedOperands, spv_ext_inst_type_t* pExtInstType,
out_stream &stream, spv_position position, spv_diagnostic *pDiagnostic) { out_stream& stream, spv_position position, spv_diagnostic* pDiagnostic) {
if (!words || !position) return SPV_ERROR_INVALID_POINTER; if (!words || !position) return SPV_ERROR_INVALID_POINTER;
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC; if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;
@ -190,7 +189,7 @@ spv_result_t spvBinaryDecodeOperand(
} break; } break;
case SPV_OPERAND_TYPE_LITERAL_STRING: case SPV_OPERAND_TYPE_LITERAL_STRING:
case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING: { case SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING: {
const char *string = (const char *)words; const char* string = (const char*)words;
uint64_t stringOperandCount = (strlen(string) / 4) + 1; uint64_t stringOperandCount = (strlen(string) / 4) + 1;
// NOTE: Special case for extended instruction import // NOTE: Special case for extended instruction import
@ -206,7 +205,7 @@ spv_result_t spvBinaryDecodeOperand(
stream.get() << "\""; stream.get() << "\"";
stream.get() << (color ? clr::green() : ""); stream.get() << (color ? clr::green() : "");
for (const char* p = string; *p; ++p) { for (const char* p = string; *p; ++p) {
if(*p == '"' || *p == '\\') { if (*p == '"' || *p == '\\') {
stream.get() << '\\'; stream.get() << '\\';
} }
stream.get() << *p; stream.get() << *p;
@ -239,7 +238,8 @@ spv_result_t spvBinaryDecodeOperand(
if (grammar.lookupOperand(type, spvFixWord(words[0], endian), &entry)) { if (grammar.lookupOperand(type, spvFixWord(words[0], endian), &entry)) {
DIAGNOSTIC << "Invalid " << spvOperandTypeStr(type) << " operand '" DIAGNOSTIC << "Invalid " << spvOperandTypeStr(type) << " operand '"
<< words[0] << "'."; << words[0] << "'.";
return SPV_ERROR_INVALID_TEXT; // TODO(dneto): Surely this is invalid binary. return SPV_ERROR_INVALID_TEXT; // TODO(dneto): Surely this is invalid
// binary.
} }
stream.get() << entry->name; stream.get() << entry->name;
// Prepare to accept operands to this operand, if needed. // Prepare to accept operands to this operand, if needed.
@ -306,8 +306,6 @@ spv_result_t spvBinaryDecodeOperand(
return SPV_SUCCESS; return SPV_SUCCESS;
} }
/// @brief Regsiters the given instruction with the type and id tracking /// @brief Regsiters the given instruction with the type and id tracking
/// tables. /// tables.
/// ///
@ -374,15 +372,12 @@ spv_result_t spvRegisterIdForOpcode(const spv_instruction_t* pInst,
/// @param[out] pDiag return diagnostic on error /// @param[out] pDiag return diagnostic on error
/// ///
/// @return result code /// @return result code
spv_result_t spvBinaryDecodeOpcode(spv_instruction_t* pInst, spv_result_t spvBinaryDecodeOpcode(
const spv_endianness_t endian, spv_instruction_t* pInst, const spv_endianness_t endian,
const uint32_t options, const uint32_t options, const libspirv::AssemblyGrammar& grammar,
const libspirv::AssemblyGrammar& grammar, type_id_to_type_map* type_map, id_to_type_id_map* id_map,
type_id_to_type_map* type_map, spv_assembly_syntax_format_t format, out_stream& stream,
id_to_type_id_map* id_map, spv_position position, spv_diagnostic* pDiagnostic) {
spv_assembly_syntax_format_t format,
out_stream &stream, spv_position position,
spv_diagnostic *pDiagnostic) {
if (!pInst || !position) return SPV_ERROR_INVALID_POINTER; if (!pInst || !position) return SPV_ERROR_INVALID_POINTER;
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC; if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;
@ -479,8 +474,7 @@ spv_result_t spvBinaryDecodeOpcode(spv_instruction_t* pInst,
if (spvBinaryDecodeOperand( if (spvBinaryDecodeOperand(
opcodeEntry->opcode, type, &pInst->words[index], numWords, endian, opcodeEntry->opcode, type, &pInst->words[index], numWords, endian,
options, grammar, &expectedOperands, options, grammar, &expectedOperands, &pInst->extInstType,
&pInst->extInstType,
(isAssigmentFormat && !currentIsResultId ? no_result_id_stream (isAssigmentFormat && !currentIsResultId ? no_result_id_stream
: stream), : stream),
position, pDiagnostic)) { position, pDiagnostic)) {
@ -507,22 +501,22 @@ spv_result_t spvBinaryDecodeOpcode(spv_instruction_t* pInst,
return SPV_SUCCESS; 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 uint32_t options,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
spv_text *pText, spv_diagnostic *pDiagnostic) { spv_text* pText, spv_diagnostic* pDiagnostic) {
return spvBinaryToTextWithFormat( return spvBinaryToTextWithFormat(
code, wordCount, options, opcodeTable, operandTable, extInstTable, code, wordCount, options, opcodeTable, operandTable, extInstTable,
SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT, pText, pDiagnostic); SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT, pText, pDiagnostic);
} }
spv_result_t spvBinaryToTextWithFormat( spv_result_t spvBinaryToTextWithFormat(
uint32_t *code, const uint64_t wordCount, const uint32_t options, uint32_t* code, const uint64_t wordCount, const uint32_t options,
const spv_opcode_table opcodeTable, const spv_operand_table operandTable, const spv_opcode_table opcodeTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, spv_assembly_syntax_format_t format, const spv_ext_inst_table extInstTable, spv_assembly_syntax_format_t format,
spv_text *pText, spv_diagnostic *pDiagnostic) { spv_text* pText, spv_diagnostic* pDiagnostic) {
spv_binary_t binary = {code, wordCount}; spv_binary_t binary = {code, wordCount};
spv_position_t position = {}; spv_position_t position = {};
@ -575,7 +569,7 @@ spv_result_t spvBinaryToTextWithFormat(
stream.get() << clr::reset(); stream.get() << clr::reset();
} }
const uint32_t *words = binary.code; const uint32_t* words = binary.code;
position.index = SPV_INDEX_INSTRUCTION; position.index = SPV_INDEX_INSTRUCTION;
spv_ext_inst_type_t extInstType = SPV_EXT_INST_TYPE_NONE; spv_ext_inst_type_t extInstType = SPV_EXT_INST_TYPE_NONE;
@ -609,7 +603,7 @@ spv_result_t spvBinaryToTextWithFormat(
if (!print) { if (!print) {
size_t length = sstream.str().size(); size_t length = sstream.str().size();
char *str = new char[length + 1]; char* str = new char[length + 1];
if (!str) return SPV_ERROR_OUT_OF_MEMORY; if (!str) return SPV_ERROR_OUT_OF_MEMORY;
strncpy(str, sstream.str().c_str(), length + 1); strncpy(str, sstream.str().c_str(), length + 1);
spv_text text = new spv_text_t(); spv_text text = new spv_text_t();

View File

@ -43,7 +43,7 @@
/// @return result code /// @return result code
spv_result_t spvBinaryHeaderGet(const spv_binary binary, spv_result_t spvBinaryHeaderGet(const spv_binary binary,
const spv_endianness_t endian, const spv_endianness_t endian,
spv_header_t *pHeader); spv_header_t* pHeader);
/// @brief Determine the type of the desired operand /// @brief Determine the type of the desired operand
/// ///
@ -58,5 +58,5 @@ spv_operand_type_t spvBinaryOperandInfo(const uint32_t word,
const uint16_t index, const uint16_t index,
const spv_opcode_desc opcodeEntry, const spv_opcode_desc opcodeEntry,
const spv_operand_table operandTable, const spv_operand_table operandTable,
spv_operand_desc *pOperandEntry); spv_operand_desc* pOperandEntry);
#endif // LIBSPIRV_BINARY_H_ #endif // LIBSPIRV_BINARY_H_

View File

@ -35,7 +35,7 @@
// Diagnostic API // Diagnostic API
spv_diagnostic spvDiagnosticCreate(const spv_position position, spv_diagnostic spvDiagnosticCreate(const spv_position position,
const char *message) { const char* message) {
spv_diagnostic diagnostic = new spv_diagnostic_t; spv_diagnostic diagnostic = new spv_diagnostic_t;
if (!diagnostic) return nullptr; if (!diagnostic) return nullptr;
size_t length = strlen(message) + 1; size_t length = strlen(message) + 1;
@ -80,10 +80,8 @@ spv_result_t spvDiagnosticPrint(const spv_diagnostic diagnostic) {
return SPV_ERROR_INVALID_VALUE; return SPV_ERROR_INVALID_VALUE;
} }
DiagnosticStream::~DiagnosticStream() { DiagnosticStream::~DiagnosticStream() {
if (pDiagnostic_ && error_ != SPV_FAILED_MATCH) { if (pDiagnostic_ && error_ != SPV_FAILED_MATCH) {
*pDiagnostic_ = spvDiagnosticCreate(position_, stream_.str().c_str()); *pDiagnostic_ = spvDiagnosticCreate(position_, stream_.str().c_str());
} }
} }

View File

@ -35,10 +35,10 @@
class diagnostic_helper { class diagnostic_helper {
public: public:
diagnostic_helper(spv_position_t &position, spv_diagnostic *pDiagnostic) diagnostic_helper(spv_position_t& position, spv_diagnostic* pDiagnostic)
: position(&position), pDiagnostic(pDiagnostic) {} : position(&position), pDiagnostic(pDiagnostic) {}
diagnostic_helper(spv_position position, spv_diagnostic *pDiagnostic) diagnostic_helper(spv_position position, spv_diagnostic* pDiagnostic)
: position(position), pDiagnostic(pDiagnostic) {} : position(position), pDiagnostic(pDiagnostic) {}
~diagnostic_helper() { ~diagnostic_helper() {
@ -49,7 +49,7 @@ class diagnostic_helper {
private: private:
spv_position position; spv_position position;
spv_diagnostic *pDiagnostic; spv_diagnostic* pDiagnostic;
}; };
// A DiagnosticStream remembers the current position of the input and an error // A DiagnosticStream remembers the current position of the input and an error
@ -61,11 +61,11 @@ class diagnostic_helper {
// eventually. // eventually.
class DiagnosticStream { class DiagnosticStream {
public: public:
DiagnosticStream(spv_position position, spv_diagnostic *pDiagnostic, DiagnosticStream(spv_position position, spv_diagnostic* pDiagnostic,
spv_result_t error) spv_result_t error)
: position_(position), pDiagnostic_(pDiagnostic), error_(error) {} : position_(position), pDiagnostic_(pDiagnostic), error_(error) {}
DiagnosticStream(DiagnosticStream &&other) DiagnosticStream(DiagnosticStream&& other)
: stream_(other.stream_.str()), : stream_(other.stream_.str()),
position_(other.position_), position_(other.position_),
pDiagnostic_(other.pDiagnostic_), pDiagnostic_(other.pDiagnostic_),
@ -80,7 +80,7 @@ class DiagnosticStream {
// Adds the given value to the diagnostic message to be written. // Adds the given value to the diagnostic message to be written.
template <typename T> template <typename T>
DiagnosticStream &operator<<(const T &val) { DiagnosticStream& operator<<(const T& val) {
stream_ << val; stream_ << val;
return *this; return *this;
} }
@ -91,7 +91,7 @@ class DiagnosticStream {
private: private:
std::stringstream stream_; std::stringstream stream_;
spv_position position_; spv_position position_;
spv_diagnostic *pDiagnostic_; spv_diagnostic* pDiagnostic_;
spv_result_t error_; spv_result_t error_;
}; };

View File

@ -57,7 +57,7 @@ uint64_t spvFixDoubleWord(const uint32_t low, const uint32_t high,
} }
spv_result_t spvBinaryEndianness(const spv_binary binary, spv_result_t spvBinaryEndianness(const spv_binary binary,
spv_endianness_t *pEndian) { spv_endianness_t* pEndian) {
if (!binary->code || !binary->wordCount) return SPV_ERROR_INVALID_BINARY; if (!binary->code || !binary->wordCount) return SPV_ERROR_INVALID_BINARY;
if (!pEndian) return SPV_ERROR_INVALID_POINTER; if (!pEndian) return SPV_ERROR_INVALID_POINTER;

View File

@ -58,6 +58,6 @@ uint64_t spvFixDoubleWord(const uint32_t low, const uint32_t high,
/// ///
/// @return result code /// @return result code
spv_result_t spvBinaryEndianness(const spv_binary binary, spv_result_t spvBinaryEndianness(const spv_binary binary,
spv_endianness_t *pEndian); spv_endianness_t* pEndian);
#endif // LIBSPIRV_ENDIAN_H_ #endif // LIBSPIRV_ENDIAN_H_

View File

@ -97,7 +97,9 @@ static const spv_ext_inst_desc_t glslStd450Entries[] = {
}; };
static const spv_ext_inst_desc_t openclEntries[] = { static const spv_ext_inst_desc_t openclEntries[] = {
#define ExtInst(Name, Opcode, OperandList) {#Name, Opcode, OperandList}, #define ExtInst(Name, Opcode, OperandList) \
{ #Name, Opcode, OperandList } \
,
#define EmptyList \ #define EmptyList \
{} {}
#define List(...) \ #define List(...) \
@ -116,7 +118,7 @@ static const spv_ext_inst_desc_t openclEntries[] = {
#undef OperandVariableIds #undef OperandVariableIds
}; };
spv_result_t spvExtInstTableGet(spv_ext_inst_table *pExtInstTable) { spv_result_t spvExtInstTableGet(spv_ext_inst_table* pExtInstTable) {
if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER; if (!pExtInstTable) return SPV_ERROR_INVALID_POINTER;
static const spv_ext_inst_group_t groups[] = { static const spv_ext_inst_group_t groups[] = {
@ -124,8 +126,7 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table *pExtInstTable) {
sizeof(glslStd450Entries) / sizeof(spv_ext_inst_desc_t), sizeof(glslStd450Entries) / sizeof(spv_ext_inst_desc_t),
glslStd450Entries}, glslStd450Entries},
{SPV_EXT_INST_TYPE_OPENCL_STD, {SPV_EXT_INST_TYPE_OPENCL_STD,
sizeof(openclEntries) / sizeof(spv_ext_inst_desc_t), sizeof(openclEntries) / sizeof(spv_ext_inst_desc_t), openclEntries},
openclEntries},
}; };
static const spv_ext_inst_table_t table = { static const spv_ext_inst_table_t table = {
@ -136,7 +137,7 @@ spv_result_t spvExtInstTableGet(spv_ext_inst_table *pExtInstTable) {
return SPV_SUCCESS; return SPV_SUCCESS;
} }
spv_ext_inst_type_t spvExtInstImportTypeGet(const char *name) { spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name) {
// The names are specified by the respective extension instruction // The names are specified by the respective extension instruction
// specifications. // specifications.
if (!strcmp("GLSL.std.450", name)) { if (!strcmp("GLSL.std.450", name)) {
@ -150,16 +151,16 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char *name) {
spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table, spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table,
const spv_ext_inst_type_t type, const spv_ext_inst_type_t type,
const char *name, const char* name,
spv_ext_inst_desc *pEntry) { spv_ext_inst_desc* pEntry) {
if (!table) return SPV_ERROR_INVALID_TABLE; if (!table) return SPV_ERROR_INVALID_TABLE;
if (!pEntry) return SPV_ERROR_INVALID_POINTER; if (!pEntry) return SPV_ERROR_INVALID_POINTER;
for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) {
auto &group = table->groups[groupIndex]; auto& group = table->groups[groupIndex];
if (type == group.type) { if (type == group.type) {
for (uint32_t index = 0; index < group.count; index++) { for (uint32_t index = 0; index < group.count; index++) {
auto &entry = group.entries[index]; auto& entry = group.entries[index];
if (!strcmp(name, entry.name)) { if (!strcmp(name, entry.name)) {
*pEntry = &table->groups[groupIndex].entries[index]; *pEntry = &table->groups[groupIndex].entries[index];
return SPV_SUCCESS; return SPV_SUCCESS;
@ -174,15 +175,15 @@ spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table,
spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table, spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table,
const spv_ext_inst_type_t type, const spv_ext_inst_type_t type,
const uint32_t value, const uint32_t value,
spv_ext_inst_desc *pEntry) { spv_ext_inst_desc* pEntry) {
if (!table) return SPV_ERROR_INVALID_TABLE; if (!table) return SPV_ERROR_INVALID_TABLE;
if (!pEntry) return SPV_ERROR_INVALID_POINTER; if (!pEntry) return SPV_ERROR_INVALID_POINTER;
for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) { for (uint32_t groupIndex = 0; groupIndex < table->count; groupIndex++) {
auto &group = table->groups[groupIndex]; auto& group = table->groups[groupIndex];
if (type == group.type) { if (type == group.type) {
for (uint32_t index = 0; index < group.count; index++) { for (uint32_t index = 0; index < group.count; index++) {
auto &entry = group.entries[index]; auto& entry = group.entries[index];
if (value == entry.ext_inst) { if (value == entry.ext_inst) {
*pEntry = &table->groups[groupIndex].entries[index]; *pEntry = &table->groups[groupIndex].entries[index];
return SPV_SUCCESS; return SPV_SUCCESS;

View File

@ -34,7 +34,7 @@
/// @param name of the library /// @param name of the library
/// ///
/// @return type of the extended instruction library /// @return type of the extended instruction library
spv_ext_inst_type_t spvExtInstImportTypeGet(const char *name); spv_ext_inst_type_t spvExtInstImportTypeGet(const char* name);
/// @brief Find the extented instruction with value in the table /// @brief Find the extented instruction with value in the table
/// ///
@ -46,8 +46,8 @@ spv_ext_inst_type_t spvExtInstImportTypeGet(const char *name);
/// @return result code /// @return result code
spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table, spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table,
const spv_ext_inst_type_t type, const spv_ext_inst_type_t type,
const char *name, const char* name,
spv_ext_inst_desc *pEntry); spv_ext_inst_desc* pEntry);
/// @brief Find the extented instruction with value in the table /// @brief Find the extented instruction with value in the table
/// ///
@ -60,6 +60,6 @@ spv_result_t spvExtInstTableNameLookup(const spv_ext_inst_table table,
spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table, spv_result_t spvExtInstTableValueLookup(const spv_ext_inst_table table,
const spv_ext_inst_type_t type, const spv_ext_inst_type_t type,
const uint32_t value, const uint32_t value,
spv_ext_inst_desc *pEntry); spv_ext_inst_desc* pEntry);
#endif // LIBSPIRV_EXT_INST_H_ #endif // LIBSPIRV_EXT_INST_H_

View File

@ -44,19 +44,25 @@ namespace {
// TODO(dneto): Some of the macros are quite unreadable. We could make // TODO(dneto): Some of the macros are quite unreadable. We could make
// good use of constexpr functions, but some compilers don't support that yet. // good use of constexpr functions, but some compilers don't support that yet.
spv_opcode_desc_t opcodeTableEntries[] = { spv_opcode_desc_t opcodeTableEntries[] = {
#define EmptyList {} #define EmptyList \
#define List(...) {__VA_ARGS__} {}
#define List(...) \
{ __VA_ARGS__ }
#define Capability(X) SPV_CAPABILITY_AS_MASK(SpvCapability##X) #define Capability(X) SPV_CAPABILITY_AS_MASK(SpvCapability##X)
#define Capability2(X,Y) Capability(X)|Capability(Y) #define Capability2(X, Y) Capability(X) | Capability(Y)
#define SpvCapabilityNone 0 // Needed so Capability(None) still expands to valid syntax. #define SpvCapabilityNone \
#define Instruction(Name,HasResult,HasType,NumLogicalOperands,NumCapabilities,CapabilityRequired,IsVariable,LogicalArgsList) \ 0 // Needed so Capability(None) still expands to valid syntax.
{ #Name, \ #define Instruction(Name, HasResult, HasType, NumLogicalOperands, \
SpvOp##Name, \ NumCapabilities, CapabilityRequired, IsVariable, \
(NumCapabilities) ? (CapabilityRequired) : 0, \ LogicalArgsList) \
0, {}, /* Filled in later. Operand list, including result id and type id, if needed */ \ { \
HasResult, \ #Name, SpvOp##Name, \
HasType, \ (NumCapabilities) ? (CapabilityRequired) : 0, 0, \
LogicalArgsList }, {}, /* Filled in later. Operand list, including \
result id and type id, if needed */ \
HasResult, HasType, LogicalArgsList \
} \
,
#include "opcode.inc" #include "opcode.inc"
#undef EmptyList #undef EmptyList
#undef List #undef List
@ -99,80 +105,117 @@ spv_operand_type_t convertOperandClassToType(SpvOp opcode,
return SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER; return SPV_OPERAND_TYPE_MULTIWORD_LITERAL_NUMBER;
} }
switch(operandClass) { switch (operandClass) {
case OperandNone: return SPV_OPERAND_TYPE_NONE; case OperandNone:
case OperandId: return SPV_OPERAND_TYPE_ID; return SPV_OPERAND_TYPE_NONE;
case OperandOptionalId: return SPV_OPERAND_TYPE_OPTIONAL_ID; case OperandId:
case OperandOptionalImage: return SPV_OPERAND_TYPE_OPTIONAL_IMAGE; return SPV_OPERAND_TYPE_ID;
case OperandVariableIds: return SPV_OPERAND_TYPE_VARIABLE_ID; case OperandOptionalId:
return SPV_OPERAND_TYPE_OPTIONAL_ID;
case OperandOptionalImage:
return SPV_OPERAND_TYPE_OPTIONAL_IMAGE;
case OperandVariableIds:
return SPV_OPERAND_TYPE_VARIABLE_ID;
// The spec only uses OptionalLiteral for an optional literal number. // The spec only uses OptionalLiteral for an optional literal number.
case OperandOptionalLiteral: return SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER; case OperandOptionalLiteral:
case OperandOptionalLiteralString: return SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING; return SPV_OPERAND_TYPE_OPTIONAL_LITERAL_INTEGER;
case OperandOptionalLiteralString:
return SPV_OPERAND_TYPE_OPTIONAL_LITERAL_STRING;
// This is only used for sequences of literal numbers. // This is only used for sequences of literal numbers.
case OperandVariableLiterals: return SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER; case OperandVariableLiterals:
return SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER;
case OperandLiteralNumber: case OperandLiteralNumber:
if (opcode == SpvOpExtInst) { if (opcode == SpvOpExtInst) {
// We use a special operand type for the extension instruction number. // We use a special operand type for the extension instruction number.
// For now, we assume there is only one LiteraNumber argument to OpExtInst, // For now, we assume there is only one LiteraNumber argument to
// and it is the extension instruction argument. // OpExtInst, and it is the extension instruction argument.
// See the ExtInst entry in opcode.inc // See the ExtInst entry in opcode.inc
// TODO(dneto): Use a function to confirm the assumption, and to verify // TODO(dneto): Use a function to confirm the assumption, and to verify
// that the index into the operandClass is 1, as expected. // that the index into the operandClass is 1, as expected.
return SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER; return SPV_OPERAND_TYPE_EXTENSION_INSTRUCTION_NUMBER;
} }
return SPV_OPERAND_TYPE_LITERAL_INTEGER; return SPV_OPERAND_TYPE_LITERAL_INTEGER;
case OperandLiteralString: return SPV_OPERAND_TYPE_LITERAL_STRING; case OperandLiteralString:
case OperandSource: return SPV_OPERAND_TYPE_SOURCE_LANGUAGE; return SPV_OPERAND_TYPE_LITERAL_STRING;
case OperandExecutionModel: return SPV_OPERAND_TYPE_EXECUTION_MODEL; case OperandSource:
case OperandAddressing: return SPV_OPERAND_TYPE_ADDRESSING_MODEL; return SPV_OPERAND_TYPE_SOURCE_LANGUAGE;
case OperandMemory: return SPV_OPERAND_TYPE_MEMORY_MODEL; case OperandExecutionModel:
case OperandExecutionMode: return SPV_OPERAND_TYPE_EXECUTION_MODE; return SPV_OPERAND_TYPE_EXECUTION_MODEL;
case OperandStorage: return SPV_OPERAND_TYPE_STORAGE_CLASS; case OperandAddressing:
case OperandDimensionality: return SPV_OPERAND_TYPE_DIMENSIONALITY; return SPV_OPERAND_TYPE_ADDRESSING_MODEL;
case OperandSamplerAddressingMode: return SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE; case OperandMemory:
case OperandSamplerFilterMode: return SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE; return SPV_OPERAND_TYPE_MEMORY_MODEL;
case OperandSamplerImageFormat: return SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT; case OperandExecutionMode:
return SPV_OPERAND_TYPE_EXECUTION_MODE;
case OperandStorage:
return SPV_OPERAND_TYPE_STORAGE_CLASS;
case OperandDimensionality:
return SPV_OPERAND_TYPE_DIMENSIONALITY;
case OperandSamplerAddressingMode:
return SPV_OPERAND_TYPE_SAMPLER_ADDRESSING_MODE;
case OperandSamplerFilterMode:
return SPV_OPERAND_TYPE_SAMPLER_FILTER_MODE;
case OperandSamplerImageFormat:
return SPV_OPERAND_TYPE_SAMPLER_IMAGE_FORMAT;
case OperandImageChannelOrder: case OperandImageChannelOrder:
// This is only used to describe the value generated by OpImageQueryOrder. // This is only used to describe the value generated by OpImageQueryOrder.
// It is not used as an operand. // It is not used as an operand.
break; break;
case OperandImageChannelDataType: case OperandImageChannelDataType:
// This is only used to describe the value generated by OpImageQueryFormat. // This is only used to describe the value generated by
// It is not used as an operand. // OpImageQueryFormat. It is not used as an operand.
break; break;
case OperandImageOperands: case OperandImageOperands:
// This is not used in opcode.inc. It only exists to generate the // This is not used in opcode.inc. It only exists to generate the
// corresponding spec section. In parsing, image operands meld into the // corresponding spec section. In parsing, image operands meld into the
// OperandOptionalImage case. // OperandOptionalImage case.
break; break;
case OperandFPFastMath: return SPV_OPERAND_TYPE_FP_FAST_MATH_MODE; case OperandFPFastMath:
case OperandFPRoundingMode: return SPV_OPERAND_TYPE_FP_ROUNDING_MODE; return SPV_OPERAND_TYPE_FP_FAST_MATH_MODE;
case OperandLinkageType: return SPV_OPERAND_TYPE_LINKAGE_TYPE; case OperandFPRoundingMode:
case OperandAccessQualifier: return SPV_OPERAND_TYPE_ACCESS_QUALIFIER; return SPV_OPERAND_TYPE_FP_ROUNDING_MODE;
case OperandFuncParamAttr: return SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE; case OperandLinkageType:
case OperandDecoration: return SPV_OPERAND_TYPE_DECORATION; return SPV_OPERAND_TYPE_LINKAGE_TYPE;
case OperandBuiltIn: return SPV_OPERAND_TYPE_BUILT_IN; case OperandAccessQualifier:
case OperandSelect: return SPV_OPERAND_TYPE_SELECTION_CONTROL; return SPV_OPERAND_TYPE_ACCESS_QUALIFIER;
case OperandLoop: return SPV_OPERAND_TYPE_LOOP_CONTROL; case OperandFuncParamAttr:
case OperandFunction: return SPV_OPERAND_TYPE_FUNCTION_CONTROL; return SPV_OPERAND_TYPE_FUNCTION_PARAMETER_ATTRIBUTE;
case OperandMemorySemantics: return SPV_OPERAND_TYPE_MEMORY_SEMANTICS; case OperandDecoration:
return SPV_OPERAND_TYPE_DECORATION;
case OperandBuiltIn:
return SPV_OPERAND_TYPE_BUILT_IN;
case OperandSelect:
return SPV_OPERAND_TYPE_SELECTION_CONTROL;
case OperandLoop:
return SPV_OPERAND_TYPE_LOOP_CONTROL;
case OperandFunction:
return SPV_OPERAND_TYPE_FUNCTION_CONTROL;
case OperandMemorySemantics:
return SPV_OPERAND_TYPE_MEMORY_SEMANTICS;
case OperandMemoryAccess: case OperandMemoryAccess:
// This case does not occur in the table for SPIR-V 0.99 Rev 32. // This case does not occur in the table for SPIR-V 0.99 Rev 32.
// We expect that it will become SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS, // We expect that it will become SPV_OPERAND_TYPE_OPTIONAL_MEMORY_ACCESS,
// and we can remove the special casing above for memory operation // and we can remove the special casing above for memory operation
// instructions. // instructions.
break; break;
case OperandScope: return SPV_OPERAND_TYPE_EXECUTION_SCOPE; case OperandScope:
case OperandGroupOperation: return SPV_OPERAND_TYPE_GROUP_OPERATION; return SPV_OPERAND_TYPE_EXECUTION_SCOPE;
case OperandKernelEnqueueFlags: return SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS; case OperandGroupOperation:
case OperandKernelProfilingInfo: return SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO; return SPV_OPERAND_TYPE_GROUP_OPERATION;
case OperandCapability: return SPV_OPERAND_TYPE_CAPABILITY; case OperandKernelEnqueueFlags:
return SPV_OPERAND_TYPE_KERNEL_ENQ_FLAGS;
case OperandKernelProfilingInfo:
return SPV_OPERAND_TYPE_KERNEL_PROFILING_INFO;
case OperandCapability:
return SPV_OPERAND_TYPE_CAPABILITY;
// Used by GroupMemberDecorate // Used by GroupMemberDecorate
case OperandVariableIdLiteral: return SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER; case OperandVariableIdLiteral:
return SPV_OPERAND_TYPE_VARIABLE_ID_LITERAL_INTEGER;
// Used by Switch // Used by Switch
case OperandVariableLiteralId: return SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID; case OperandVariableLiteralId:
return SPV_OPERAND_TYPE_VARIABLE_LITERAL_INTEGER_ID;
// These exceptional cases shouldn't occur. // These exceptional cases shouldn't occur.
case OperandCount: case OperandCount:
@ -188,7 +231,7 @@ spv_operand_type_t convertOperandClassToType(SpvOp opcode,
// Finish populating the opcodeTableEntries array. // Finish populating the opcodeTableEntries array.
void spvOpcodeTableInitialize() { void spvOpcodeTableInitialize() {
// Compute the operandTypes field for each entry. // Compute the operandTypes field for each entry.
for (auto &opcode : opcodeTableEntries) { for (auto& opcode : opcodeTableEntries) {
opcode.numTypes = 0; opcode.numTypes = 0;
// Type ID always comes first, if present. // Type ID always comes first, if present.
if (opcode.hasType) if (opcode.hasType)
@ -223,7 +266,7 @@ void spvOpcodeTableInitialize() {
opcodeTableInitialized = true; opcodeTableInitialized = true;
} }
const char *spvGeneratorStr(uint32_t generator) { const char* spvGeneratorStr(uint32_t generator) {
switch (generator) { switch (generator) {
case SPV_GENERATOR_KHRONOS: case SPV_GENERATOR_KHRONOS:
return "Khronos"; return "Khronos";
@ -246,7 +289,7 @@ uint32_t spvOpcodeMake(uint16_t wordCount, SpvOp opcode) {
return ((uint32_t)opcode) | (((uint32_t)wordCount) << 16); return ((uint32_t)opcode) | (((uint32_t)wordCount) << 16);
} }
void spvOpcodeSplit(const uint32_t word, uint16_t *pWordCount, SpvOp *pOpcode) { void spvOpcodeSplit(const uint32_t word, uint16_t* pWordCount, SpvOp* pOpcode) {
if (pWordCount) { if (pWordCount) {
*pWordCount = (uint16_t)((0xffff0000 & word) >> 16); *pWordCount = (uint16_t)((0xffff0000 & word) >> 16);
} }
@ -255,7 +298,7 @@ void spvOpcodeSplit(const uint32_t word, uint16_t *pWordCount, SpvOp *pOpcode) {
} }
} }
spv_result_t spvOpcodeTableGet(spv_opcode_table *pInstTable) { spv_result_t spvOpcodeTableGet(spv_opcode_table* pInstTable) {
if (!pInstTable) return SPV_ERROR_INVALID_POINTER; if (!pInstTable) return SPV_ERROR_INVALID_POINTER;
static spv_opcode_table_t table = { static spv_opcode_table_t table = {
@ -272,8 +315,8 @@ spv_result_t spvOpcodeTableGet(spv_opcode_table *pInstTable) {
} }
spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table, spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
const char *name, const char* name,
spv_opcode_desc *pEntry) { spv_opcode_desc* pEntry) {
if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER; if (!name || !pEntry) return SPV_ERROR_INVALID_POINTER;
if (!table) return SPV_ERROR_INVALID_TABLE; if (!table) return SPV_ERROR_INVALID_TABLE;
@ -296,7 +339,7 @@ spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table, spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table,
const SpvOp opcode, const SpvOp opcode,
spv_opcode_desc *pEntry) { spv_opcode_desc* pEntry) {
if (!table) return SPV_ERROR_INVALID_TABLE; if (!table) return SPV_ERROR_INVALID_TABLE;
if (!pEntry) return SPV_ERROR_INVALID_POINTER; if (!pEntry) return SPV_ERROR_INVALID_POINTER;
@ -323,9 +366,9 @@ int32_t spvOpcodeRequiresCapabilities(spv_opcode_desc entry) {
return entry->capabilities != 0; return entry->capabilities != 0;
} }
void spvInstructionCopy(const uint32_t *words, const SpvOp opcode, void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
const uint16_t wordCount, const spv_endianness_t endian, const uint16_t wordCount, const spv_endianness_t endian,
spv_instruction_t *pInst) { spv_instruction_t* pInst) {
pInst->opcode = opcode; pInst->opcode = opcode;
pInst->words.resize(wordCount); pInst->words.resize(wordCount);
for (uint16_t wordIndex = 0; wordIndex < wordCount; ++wordIndex) { for (uint16_t wordIndex = 0; wordIndex < wordCount; ++wordIndex) {
@ -340,9 +383,9 @@ void spvInstructionCopy(const uint32_t *words, const SpvOp opcode,
} }
} }
const char *spvOpcodeString(const SpvOp opcode) { const char* spvOpcodeString(const SpvOp opcode) {
#define CASE(OPCODE) \ #define CASE(OPCODE) \
case Spv##OPCODE: \ case Spv##OPCODE: \
return #OPCODE; return #OPCODE;
switch (opcode) { switch (opcode) {
CASE(OpNop) CASE(OpNop)
@ -651,8 +694,8 @@ int32_t spvOpcodeIsComposite(const SpvOp opcode) {
} }
} }
int32_t spvOpcodeAreTypesEqual(const spv_instruction_t *pTypeInst0, int32_t spvOpcodeAreTypesEqual(const spv_instruction_t* pTypeInst0,
const spv_instruction_t *pTypeInst1) { const spv_instruction_t* pTypeInst1) {
if (pTypeInst0->opcode != pTypeInst1->opcode) return false; if (pTypeInst0->opcode != pTypeInst1->opcode) return false;
if (pTypeInst0->words[1] != pTypeInst1->words[1]) return false; if (pTypeInst0->words[1] != pTypeInst1->words[1]) return false;
return true; return true;
@ -801,8 +844,8 @@ int32_t spvOpcodeIsBasicTypeNullable(SpvOp opcode) {
} }
} }
int32_t spvInstructionIsInBasicBlock(const spv_instruction_t *pFirstInst, int32_t spvInstructionIsInBasicBlock(const spv_instruction_t* pFirstInst,
const spv_instruction_t *pInst) { const spv_instruction_t* pInst) {
while (pFirstInst != pInst) { while (pFirstInst != pInst) {
if (SpvOpFunction == pInst->opcode) break; if (SpvOpFunction == pInst->opcode) break;
pInst--; pInst--;
@ -824,7 +867,7 @@ int32_t spvOpcodeIsValue(SpvOp opcode) {
} }
int32_t spvOpcodeGeneratesType(SpvOp op) { int32_t spvOpcodeGeneratesType(SpvOp op) {
switch(op) { switch (op) {
case SpvOpTypeVoid: case SpvOpTypeVoid:
case SpvOpTypeBool: case SpvOpTypeBool:
case SpvOpTypeInt: case SpvOpTypeInt:

View File

@ -40,7 +40,7 @@
/// @param[in] generator Khronos SPIR-V generator ID /// @param[in] generator Khronos SPIR-V generator ID
/// ///
/// @return string name /// @return string name
const char *spvGeneratorStr(uint32_t generator); const char* spvGeneratorStr(uint32_t generator);
/// @brief Combine word count and Opcode enumerant in single word /// @brief Combine word count and Opcode enumerant in single word
/// ///
@ -55,7 +55,7 @@ uint32_t spvOpcodeMake(uint16_t wordCount, SpvOp opcode);
/// @param[in] word binary opcode to split /// @param[in] word binary opcode to split
/// @param[out] wordCount the returned number of words (optional) /// @param[out] wordCount the returned number of words (optional)
/// @param[out] opcode the returned opcode enumerant (optional) /// @param[out] opcode the returned opcode enumerant (optional)
void spvOpcodeSplit(const uint32_t word, uint16_t *wordCount, SpvOp *opcode); void spvOpcodeSplit(const uint32_t word, uint16_t* wordCount, SpvOp* opcode);
/// @brief Find the named Opcode in the table /// @brief Find the named Opcode in the table
/// ///
@ -65,8 +65,8 @@ void spvOpcodeSplit(const uint32_t word, uint16_t *wordCount, SpvOp *opcode);
/// ///
/// @return result code /// @return result code
spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table, spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
const char *name, const char* name,
spv_opcode_desc *pEntry); spv_opcode_desc* pEntry);
/// @brief Find the opcode ID in the table /// @brief Find the opcode ID in the table
/// ///
@ -77,7 +77,7 @@ spv_result_t spvOpcodeTableNameLookup(const spv_opcode_table table,
/// @return result code /// @return result code
spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table, spv_result_t spvOpcodeTableValueLookup(const spv_opcode_table table,
const SpvOp opcode, const SpvOp opcode,
spv_opcode_desc *pEntry); spv_opcode_desc* pEntry);
/// @brief Get the argument index for the <result-id> operand, if any. /// @brief Get the argument index for the <result-id> operand, if any.
/// ///
@ -107,16 +107,16 @@ int32_t spvOpcodeRequiresCapabilities(spv_opcode_desc entry);
/// @param[in] wordCount the number of words to copy /// @param[in] wordCount the number of words to copy
/// @param[in] endian the endianness of the stream /// @param[in] endian the endianness of the stream
/// @param[out] pInst the returned instruction /// @param[out] pInst the returned instruction
void spvInstructionCopy(const uint32_t *words, const SpvOp opcode, void spvInstructionCopy(const uint32_t* words, const SpvOp opcode,
const uint16_t wordCount, const spv_endianness_t endian, const uint16_t wordCount, const spv_endianness_t endian,
spv_instruction_t *pInst); spv_instruction_t* pInst);
/// @brief Get the string of an OpCode /// @brief Get the string of an OpCode
/// ///
/// @param[in] opcode the opcode /// @param[in] opcode the opcode
/// ///
/// @return the opcode string /// @return the opcode string
const char *spvOpcodeString(const SpvOp opcode); const char* spvOpcodeString(const SpvOp opcode);
/// @brief Determine if the Opcode is a type /// @brief Determine if the Opcode is a type
/// ///
@ -152,8 +152,8 @@ int32_t spvOpcodeIsComposite(const SpvOp opcode);
/// @param[in] pTypeInst1 type definition one /// @param[in] pTypeInst1 type definition one
/// ///
/// @return zero if false, non-zero otherwise /// @return zero if false, non-zero otherwise
int32_t spvOpcodeAreTypesEqual(const spv_instruction_t *pTypeInst0, int32_t spvOpcodeAreTypesEqual(const spv_instruction_t* pTypeInst0,
const spv_instruction_t *pTypeInst1); const spv_instruction_t* pTypeInst1);
/// @brief Determine if the Opcode results in a pointer /// @brief Determine if the Opcode results in a pointer
/// ///
@ -182,8 +182,8 @@ int32_t spvOpcodeIsBasicTypeNullable(SpvOp opcode);
/// @param[in] pInst current instruction /// @param[in] pInst current instruction
/// ///
/// @return zero if false, non-zero otherwise /// @return zero if false, non-zero otherwise
int32_t spvInstructionIsInBasicBlock(const spv_instruction_t *pFirstInst, int32_t spvInstructionIsInBasicBlock(const spv_instruction_t* pFirstInst,
const spv_instruction_t *pInst); const spv_instruction_t* pInst);
/// @brief Determine if the Opcode contains a value /// @brief Determine if the Opcode contains a value
/// ///

View File

@ -30,22 +30,10 @@
#include <string.h> #include <string.h>
static const spv_operand_desc_t sourceLanguageEntries[] = { static const spv_operand_desc_t sourceLanguageEntries[] = {
{"Unknown", {"Unknown", SpvSourceLanguageUnknown, 0, {SPV_OPERAND_TYPE_NONE}},
SpvSourceLanguageUnknown, {"ESSL", SpvSourceLanguageESSL, 0, {SPV_OPERAND_TYPE_NONE}},
0, {"GLSL", SpvSourceLanguageGLSL, 0, {SPV_OPERAND_TYPE_NONE}},
{SPV_OPERAND_TYPE_NONE}}, {"OpenCL", SpvSourceLanguageOpenCL, 0, {SPV_OPERAND_TYPE_NONE}},
{"ESSL",
SpvSourceLanguageESSL,
0,
{SPV_OPERAND_TYPE_NONE}},
{"GLSL",
SpvSourceLanguageGLSL,
0,
{SPV_OPERAND_TYPE_NONE}},
{"OpenCL",
SpvSourceLanguageOpenCL,
0,
{SPV_OPERAND_TYPE_NONE}},
}; };
static const spv_operand_desc_t executionModelEntries[] = { static const spv_operand_desc_t executionModelEntries[] = {
@ -80,10 +68,7 @@ static const spv_operand_desc_t executionModelEntries[] = {
}; };
static const spv_operand_desc_t addressingModelEntries[] = { static const spv_operand_desc_t addressingModelEntries[] = {
{"Logical", {"Logical", SpvAddressingModelLogical, 0, {SPV_OPERAND_TYPE_NONE}},
SpvAddressingModelLogical,
0,
{SPV_OPERAND_TYPE_NONE}},
{"Physical32", {"Physical32",
SpvAddressingModelPhysical32, SpvAddressingModelPhysical32,
SPV_CAPABILITY_AS_MASK(SpvCapabilityAddresses), SPV_CAPABILITY_AS_MASK(SpvCapabilityAddresses),
@ -203,10 +188,7 @@ static const spv_operand_desc_t storageClassEntries[] = {
SpvStorageClassPrivateGlobal, SpvStorageClassPrivateGlobal,
SPV_CAPABILITY_AS_MASK(SpvCapabilityShader), SPV_CAPABILITY_AS_MASK(SpvCapabilityShader),
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"Function", {"Function", SpvStorageClassFunction, 0, {SPV_OPERAND_TYPE_NONE}},
SpvStorageClassFunction,
0,
{SPV_OPERAND_TYPE_NONE}},
{"Generic", {"Generic",
SpvStorageClassGeneric, SpvStorageClassGeneric,
SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel), SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel),
@ -219,10 +201,7 @@ static const spv_operand_desc_t storageClassEntries[] = {
SpvStorageClassAtomicCounter, SpvStorageClassAtomicCounter,
SPV_CAPABILITY_AS_MASK(SpvCapabilityAtomicStorage), SPV_CAPABILITY_AS_MASK(SpvCapabilityAtomicStorage),
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"Image", {"Image", SpvStorageClassImage, 0, {SPV_OPERAND_TYPE_NONE}},
SpvStorageClassImage,
0,
{SPV_OPERAND_TYPE_NONE}},
}; };
static const spv_operand_desc_t dimensionalityEntries[] = { static const spv_operand_desc_t dimensionalityEntries[] = {
@ -341,33 +320,18 @@ static const spv_operand_desc_t samplerImageFormatEntries[] = {
}; };
// All image channel orders depend on the Kernel capability. // All image channel orders depend on the Kernel capability.
#define CASE(NAME) \ #define CASE(NAME) \
{ \ { \
#NAME, SpvImageChannelOrder##NAME, SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel), \ #NAME, SpvImageChannelOrder##NAME, \
{ \ SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel), { \
SPV_OPERAND_TYPE_NONE \ SPV_OPERAND_TYPE_NONE \
} \ } \
} }
static const spv_operand_desc_t imageChannelOrderEntries[] = { static const spv_operand_desc_t imageChannelOrderEntries[] = {
CASE(R), CASE(R), CASE(A), CASE(RG), CASE(RA), CASE(RGB),
CASE(A), CASE(RGBA), CASE(BGRA), CASE(ARGB), CASE(Intensity), CASE(Luminance),
CASE(RG), CASE(Rx), CASE(RGx), CASE(RGBx), CASE(Depth), CASE(DepthStencil),
CASE(RA), CASE(sRGB), CASE(sRGBx), CASE(sRGBA), CASE(sBGRA),
CASE(RGB),
CASE(RGBA),
CASE(BGRA),
CASE(ARGB),
CASE(Intensity),
CASE(Luminance),
CASE(Rx),
CASE(RGx),
CASE(RGBx),
CASE(Depth),
CASE(DepthStencil),
CASE(sRGB),
CASE(sRGBx),
CASE(sRGBA),
CASE(sBGRA),
}; };
#undef CASE #undef CASE
@ -380,22 +344,12 @@ static const spv_operand_desc_t imageChannelOrderEntries[] = {
} \ } \
} }
static const spv_operand_desc_t imageChannelDataTypeEntries[] = { static const spv_operand_desc_t imageChannelDataTypeEntries[] = {
CASE(SnormInt8), CASE(SnormInt8), CASE(SnormInt16), CASE(UnormInt8),
CASE(SnormInt16), CASE(UnormInt16), CASE(UnormShort565), CASE(UnormShort555),
CASE(UnormInt8), CASE(UnormInt101010), CASE(SignedInt8), CASE(SignedInt16),
CASE(UnormInt16), CASE(SignedInt32), CASE(UnsignedInt8), CASE(UnsignedInt16),
CASE(UnormShort565), CASE(UnsignedInt32), CASE(HalfFloat), CASE(Float),
CASE(UnormShort555), CASE(UnormInt24),
CASE(UnormInt101010),
CASE(SignedInt8),
CASE(SignedInt16),
CASE(SignedInt32),
CASE(UnsignedInt8),
CASE(UnsignedInt16),
CASE(UnsignedInt32),
CASE(HalfFloat),
CASE(Float),
CASE(UnormInt24),
}; };
#undef CASE #undef CASE
@ -404,10 +358,8 @@ static const spv_operand_desc_t imageChannelDataTypeEntries[] = {
// Some mask values depend on a capability. // Some mask values depend on a capability.
static const spv_operand_desc_t imageOperandEntries[] = { static const spv_operand_desc_t imageOperandEntries[] = {
// Rev32 and later adds many more enums. // Rev32 and later adds many more enums.
#define CASE(NAME) \ #define CASE(NAME) #NAME, SpvImageOperands##NAME##Mask, 0
#NAME, SpvImageOperands##NAME##Mask, 0 #define CASE_CAP(NAME, CAP) #NAME, SpvImageOperands##NAME##Mask, CAP
#define CASE_CAP(NAME, CAP) \
#NAME, SpvImageOperands##NAME##Mask, CAP
#define ID SPV_OPERAND_TYPE_ID #define ID SPV_OPERAND_TYPE_ID
#define NONE SPV_OPERAND_TYPE_NONE #define NONE SPV_OPERAND_TYPE_NONE
{"None", SpvImageOperandsMaskNone, 0, {NONE}}, {"None", SpvImageOperandsMaskNone, 0, {NONE}},
@ -427,10 +379,7 @@ static const spv_operand_desc_t imageOperandEntries[] = {
}; };
static const spv_operand_desc_t fpFastMathModeEntries[] = { static const spv_operand_desc_t fpFastMathModeEntries[] = {
{"None", {"None", SpvFPFastMathModeMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvFPFastMathModeMaskNone,
0,
{SPV_OPERAND_TYPE_NONE}},
{"NotNaN", {"NotNaN",
SpvFPFastMathModeNotNaNMask, SpvFPFastMathModeNotNaNMask,
SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel), SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel),
@ -612,34 +561,16 @@ static const spv_operand_desc_t decorationEntries[] = {
SpvDecorationInvariant, SpvDecorationInvariant,
SPV_CAPABILITY_AS_MASK(SpvCapabilityShader), SPV_CAPABILITY_AS_MASK(SpvCapabilityShader),
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"Restrict", {"Restrict", SpvDecorationRestrict, 0, {SPV_OPERAND_TYPE_NONE}},
SpvDecorationRestrict, {"Aliased", SpvDecorationAliased, 0, {SPV_OPERAND_TYPE_NONE}},
0, {"Volatile", SpvDecorationVolatile, 0, {SPV_OPERAND_TYPE_NONE}},
{SPV_OPERAND_TYPE_NONE}},
{"Aliased",
SpvDecorationAliased,
0,
{SPV_OPERAND_TYPE_NONE}},
{"Volatile",
SpvDecorationVolatile,
0,
{SPV_OPERAND_TYPE_NONE}},
{"Constant", {"Constant",
SpvDecorationConstant, SpvDecorationConstant,
SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel), SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel),
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"Coherent", {"Coherent", SpvDecorationCoherent, 0, {SPV_OPERAND_TYPE_NONE}},
SpvDecorationCoherent, {"NonWritable", SpvDecorationNonWritable, 0, {SPV_OPERAND_TYPE_NONE}},
0, {"NonReadable", SpvDecorationNonReadable, 0, {SPV_OPERAND_TYPE_NONE}},
{SPV_OPERAND_TYPE_NONE}},
{"NonWritable",
SpvDecorationNonWritable,
0,
{SPV_OPERAND_TYPE_NONE}},
{"NonReadable",
SpvDecorationNonReadable,
0,
{SPV_OPERAND_TYPE_NONE}},
{"Uniform", {"Uniform",
SpvDecorationUniform, SpvDecorationUniform,
SPV_CAPABILITY_AS_MASK(SpvCapabilityShader), SPV_CAPABILITY_AS_MASK(SpvCapabilityShader),
@ -707,8 +638,9 @@ static const spv_operand_desc_t decorationEntries[] = {
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"InputTargetIndex", {"InputTargetIndex",
SpvDecorationInputTargetIndex, SpvDecorationInputTargetIndex,
SPV_CAPABILITY_AS_MASK(SpvCapabilityShader), // TODO(dneto): Should this be SPV_CAPABILITY_AS_MASK(
// SpvCapabilityInputTarget? SpvCapabilityShader), // TODO(dneto): Should this be
// SpvCapabilityInputTarget?
{SPV_OPERAND_TYPE_NONE}}, // TODO(dneto): Should this have a literal {SPV_OPERAND_TYPE_NONE}}, // TODO(dneto): Should this have a literal
// number argument? // number argument?
{"Alignment", {"Alignment",
@ -812,18 +744,9 @@ static const spv_operand_desc_t builtInEntries[] = {
SpvBuiltInHelperInvocation, SpvBuiltInHelperInvocation,
SPV_CAPABILITY_AS_MASK(SpvCapabilityShader), SPV_CAPABILITY_AS_MASK(SpvCapabilityShader),
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"NumWorkgroups", {"NumWorkgroups", SpvBuiltInNumWorkgroups, 0, {SPV_OPERAND_TYPE_NONE}},
SpvBuiltInNumWorkgroups, {"WorkgroupSize", SpvBuiltInWorkgroupSize, 0, {SPV_OPERAND_TYPE_NONE}},
0, {"WorkgroupId", SpvBuiltInWorkgroupId, 0, {SPV_OPERAND_TYPE_NONE}},
{SPV_OPERAND_TYPE_NONE}},
{"WorkgroupSize",
SpvBuiltInWorkgroupSize,
0,
{SPV_OPERAND_TYPE_NONE}},
{"WorkgroupId",
SpvBuiltInWorkgroupId,
0,
{SPV_OPERAND_TYPE_NONE}},
{"LocalInvocationId", {"LocalInvocationId",
SpvBuiltInLocalInvocationId, SpvBuiltInLocalInvocationId,
0, 0,
@ -895,14 +818,8 @@ static const spv_operand_desc_t builtInEntries[] = {
}; };
static const spv_operand_desc_t selectionControlEntries[] = { static const spv_operand_desc_t selectionControlEntries[] = {
{"None", {"None", SpvSelectionControlMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvSelectionControlMaskNone, {"Flatten", SpvSelectionControlFlattenMask, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"Flatten",
SpvSelectionControlFlattenMask,
0,
{SPV_OPERAND_TYPE_NONE}},
{"DontFlatten", {"DontFlatten",
SpvSelectionControlDontFlattenMask, SpvSelectionControlDontFlattenMask,
0, 0,
@ -910,67 +827,34 @@ static const spv_operand_desc_t selectionControlEntries[] = {
}; };
static const spv_operand_desc_t loopControlEntries[] = { static const spv_operand_desc_t loopControlEntries[] = {
{"None", {"None", SpvLoopControlMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvLoopControlMaskNone, {"Unroll", SpvLoopControlUnrollMask, 0, {SPV_OPERAND_TYPE_NONE}},
0, {"DontUnroll", SpvLoopControlDontUnrollMask, 0, {SPV_OPERAND_TYPE_NONE}},
{SPV_OPERAND_TYPE_NONE}},
{"Unroll",
SpvLoopControlUnrollMask,
0,
{SPV_OPERAND_TYPE_NONE}},
{"DontUnroll",
SpvLoopControlDontUnrollMask,
0,
{SPV_OPERAND_TYPE_NONE}},
}; };
static const spv_operand_desc_t functionControlEntries[] = { static const spv_operand_desc_t functionControlEntries[] = {
{"None", {"None", SpvFunctionControlMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvFunctionControlMaskNone, {"Inline", SpvFunctionControlInlineMask, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"Inline",
SpvFunctionControlInlineMask,
0,
{SPV_OPERAND_TYPE_NONE}},
{"DontInline", {"DontInline",
SpvFunctionControlDontInlineMask, SpvFunctionControlDontInlineMask,
0, 0,
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"Pure", {"Pure", SpvFunctionControlPureMask, 0, {SPV_OPERAND_TYPE_NONE}},
SpvFunctionControlPureMask, {"Const", SpvFunctionControlConstMask, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"Const",
SpvFunctionControlConstMask,
0,
{SPV_OPERAND_TYPE_NONE}},
}; };
static const spv_operand_desc_t memorySemanticsEntries[] = { static const spv_operand_desc_t memorySemanticsEntries[] = {
// "Relaxed" should be a synonym for "None". // "Relaxed" should be a synonym for "None".
// Put the Relaxed entry first so that the disassembler // Put the Relaxed entry first so that the disassembler
// will prefer to emit "Relaxed". // will prefer to emit "Relaxed".
{"Relaxed", {"Relaxed", SpvMemorySemanticsMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvMemorySemanticsMaskNone, {"None", SpvMemorySemanticsMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"None",
SpvMemorySemanticsMaskNone,
0,
{SPV_OPERAND_TYPE_NONE}},
{"SequentiallyConsistent", {"SequentiallyConsistent",
SpvMemorySemanticsSequentiallyConsistentMask, SpvMemorySemanticsSequentiallyConsistentMask,
0, 0,
{SPV_OPERAND_TYPE_NONE}}, {SPV_OPERAND_TYPE_NONE}},
{"Acquire", {"Acquire", SpvMemorySemanticsAcquireMask, 0, {SPV_OPERAND_TYPE_NONE}},
SpvMemorySemanticsAcquireMask, {"Release", SpvMemorySemanticsReleaseMask, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"Release",
SpvMemorySemanticsReleaseMask,
0,
{SPV_OPERAND_TYPE_NONE}},
{"UniformMemory", {"UniformMemory",
SpvMemorySemanticsUniformMemoryMask, SpvMemorySemanticsUniformMemoryMask,
SPV_CAPABILITY_AS_MASK(SpvCapabilityShader), SPV_CAPABILITY_AS_MASK(SpvCapabilityShader),
@ -1000,45 +884,24 @@ static const spv_operand_desc_t memorySemanticsEntries[] = {
}; };
static const spv_operand_desc_t memoryAccessEntries[] = { static const spv_operand_desc_t memoryAccessEntries[] = {
{"None", {"None", SpvMemoryAccessMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvMemoryAccessMaskNone, {"Volatile", SpvMemoryAccessVolatileMask, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"Volatile",
SpvMemoryAccessVolatileMask,
0,
{SPV_OPERAND_TYPE_NONE}},
{ {
"Aligned", "Aligned",
SpvMemoryAccessAlignedMask, SpvMemoryAccessAlignedMask,
0, 0,
{SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_NONE}, {SPV_OPERAND_TYPE_LITERAL_INTEGER, SPV_OPERAND_TYPE_NONE},
}, },
{"Nontemporal", {"Nontemporal", SpvMemoryAccessNontemporalMask, 0, {SPV_OPERAND_TYPE_NONE}},
SpvMemoryAccessNontemporalMask,
0,
{SPV_OPERAND_TYPE_NONE}},
}; };
static const spv_operand_desc_t scopeEntries[] = { static const spv_operand_desc_t scopeEntries[] = {
{"CrossDevice", {"CrossDevice", SpvScopeCrossDevice, 0, {SPV_OPERAND_TYPE_NONE}},
SpvScopeCrossDevice,
0,
{SPV_OPERAND_TYPE_NONE}},
{"Device", SpvScopeDevice, 0, {SPV_OPERAND_TYPE_NONE}}, {"Device", SpvScopeDevice, 0, {SPV_OPERAND_TYPE_NONE}},
{"Workgroup", {"Workgroup", SpvScopeWorkgroup, 0, {SPV_OPERAND_TYPE_NONE}},
SpvScopeWorkgroup, {"Subgroup", SpvScopeSubgroup, 0, {SPV_OPERAND_TYPE_NONE}},
0,
{SPV_OPERAND_TYPE_NONE}},
{"Subgroup",
SpvScopeSubgroup,
0,
{SPV_OPERAND_TYPE_NONE}},
{ {
"Invocation", "Invocation", SpvScopeInvocation, 0, {SPV_OPERAND_TYPE_NONE},
SpvScopeInvocation,
0,
{SPV_OPERAND_TYPE_NONE},
}, },
}; };
@ -1073,10 +936,7 @@ static const spv_operand_desc_t kernelKernelEnqueueFlagssEntries[] = {
}; };
static const spv_operand_desc_t kernelProfilingInfoEntries[] = { static const spv_operand_desc_t kernelProfilingInfoEntries[] = {
{"None", {"None", SpvKernelProfilingInfoMaskNone, 0, {SPV_OPERAND_TYPE_NONE}},
SpvKernelProfilingInfoMaskNone,
0,
{SPV_OPERAND_TYPE_NONE}},
{"CmdExecTime", {"CmdExecTime",
SpvKernelProfilingInfoCmdExecTimeMask, SpvKernelProfilingInfoCmdExecTimeMask,
SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel), SPV_CAPABILITY_AS_MASK(SpvCapabilityKernel),

View File

@ -27,21 +27,21 @@
#include "print.h" #include "print.h"
#if defined(SPIRV_LINUX) || defined(SPIRV_MAC) #if defined(SPIRV_LINUX) || defined(SPIRV_MAC)
clr::reset::operator const char *() { return "\e[0m"; } clr::reset::operator const char*() { return "\e[0m"; }
clr::grey::operator const char *() { return "\e[1;30m"; } clr::grey::operator const char*() { return "\e[1;30m"; }
clr::red::operator const char *() { return "\e[31m"; } clr::red::operator const char*() { return "\e[31m"; }
clr::green::operator const char *() { return "\e[32m"; } clr::green::operator const char*() { return "\e[32m"; }
clr::yellow::operator const char *() { return "\e[33m"; } clr::yellow::operator const char*() { return "\e[33m"; }
clr::blue::operator const char *() { return "\e[34m"; } clr::blue::operator const char*() { return "\e[34m"; }
#elif defined(SPIRV_WINDOWS) #elif defined(SPIRV_WINDOWS)
#include <Windows.h> #include <Windows.h>
clr::reset::operator const char *() { clr::reset::operator const char*() {
const DWORD color = 0Xf; const DWORD color = 0Xf;
HANDLE hConsole; HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
@ -51,7 +51,7 @@ clr::reset::operator const char *() {
return ""; return "";
} }
clr::grey::operator const char *() { clr::grey::operator const char*() {
const DWORD color = 0x8; const DWORD color = 0x8;
HANDLE hConsole; HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
@ -61,7 +61,7 @@ clr::grey::operator const char *() {
return ""; return "";
} }
clr::red::operator const char *() { clr::red::operator const char*() {
const DWORD color = 0x4; const DWORD color = 0x4;
HANDLE hConsole; HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
@ -71,7 +71,7 @@ clr::red::operator const char *() {
return ""; return "";
} }
clr::green::operator const char *() { clr::green::operator const char*() {
const DWORD color = 0x2; const DWORD color = 0x2;
HANDLE hConsole; HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
@ -81,7 +81,7 @@ clr::green::operator const char *() {
return ""; return "";
} }
clr::yellow::operator const char *() { clr::yellow::operator const char*() {
const DWORD color = 0x6; const DWORD color = 0x6;
HANDLE hConsole; HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
@ -91,7 +91,7 @@ clr::yellow::operator const char *() {
return ""; return "";
} }
clr::blue::operator const char *() { clr::blue::operator const char*() {
const DWORD color = 0x1; const DWORD color = 0x1;
HANDLE hConsole; HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE); hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

View File

@ -34,9 +34,9 @@
class out_stream { class out_stream {
public: public:
out_stream() : pStream(nullptr) {} out_stream() : pStream(nullptr) {}
out_stream(std::stringstream &stream) : pStream(&stream) {} out_stream(std::stringstream& stream) : pStream(&stream) {}
std::ostream &get() { std::ostream& get() {
if (pStream) { if (pStream) {
return *pStream; return *pStream;
} }
@ -44,33 +44,33 @@ class out_stream {
} }
private: private:
std::stringstream *pStream; std::stringstream* pStream;
}; };
namespace clr { namespace clr {
/// @brief Reset console color /// @brief Reset console color
struct reset { struct reset {
operator const char *(); operator const char*();
}; };
/// @brief Set console color to grey /// @brief Set console color to grey
struct grey { struct grey {
operator const char *(); operator const char*();
}; };
/// @brief Set console color to red /// @brief Set console color to red
struct red { struct red {
operator const char *(); operator const char*();
}; };
/// @brief Set console color to green /// @brief Set console color to green
struct green { struct green {
operator const char *(); operator const char*();
}; };
/// @brief Set console color to yellow /// @brief Set console color to yellow
struct yellow { struct yellow {
operator const char *(); operator const char*();
}; };
/// @brief Set console color to blue /// @brief Set console color to blue
struct blue { struct blue {
operator const char *(); operator const char*();
}; };
} }

View File

@ -61,7 +61,6 @@ typedef struct spv_literal_t {
} value; } value;
} spv_literal_t; } spv_literal_t;
// Functions // Functions
/// @brief Convert the input text to one of the number types, or to /// @brief Convert the input text to one of the number types, or to
@ -74,6 +73,6 @@ typedef struct spv_literal_t {
/// @param[out] pLiteral the returned literal /// @param[out] pLiteral the returned literal
/// ///
/// @return result code /// @return result code
spv_result_t spvTextToLiteral(const char *textValue, spv_literal_t *pLiteral); spv_result_t spvTextToLiteral(const char* textValue, spv_literal_t* pLiteral);
#endif // LIBSPIRV_TEXT_H_ #endif // LIBSPIRV_TEXT_H_

View File

@ -111,7 +111,7 @@ spv_result_t advance(spv_text text, spv_position position) {
/// @param[out] endPosition one past the end of the returned word /// @param[out] endPosition one past the end of the returned word
/// ///
/// @return result code /// @return result code
spv_result_t getWord(spv_text text, spv_position position, std::string &word, spv_result_t getWord(spv_text text, spv_position position, std::string& word,
spv_position endPosition) { spv_position endPosition) {
if (!text->str || !text->length) return SPV_ERROR_INVALID_TEXT; if (!text->str || !text->length) return SPV_ERROR_INVALID_TEXT;
if (!position || !endPosition) return SPV_ERROR_INVALID_POINTER; if (!position || !endPosition) return SPV_ERROR_INVALID_POINTER;
@ -173,7 +173,7 @@ const IdType kUnknownType = {0, false, IdTypeClass::kBottom};
// This represents all of the data that is only valid for the duration of // This represents all of the data that is only valid for the duration of
// a single compilation. // a single compilation.
uint32_t AssemblyContext::spvNamedIdAssignOrGet(const char *textValue) { uint32_t AssemblyContext::spvNamedIdAssignOrGet(const char* textValue) {
if (named_ids_.end() == named_ids_.find(textValue)) { if (named_ids_.end() == named_ids_.find(textValue)) {
named_ids_[std::string(textValue)] = bound_++; named_ids_[std::string(textValue)] = bound_++;
} }
@ -185,7 +185,7 @@ spv_result_t AssemblyContext::advance() {
return ::advance(text_, &current_position_); return ::advance(text_, &current_position_);
} }
spv_result_t AssemblyContext::getWord(std::string &word, spv_result_t AssemblyContext::getWord(std::string& word,
spv_position endPosition) { spv_position endPosition) {
return ::getWord(text_, &current_position_, word, endPosition); return ::getWord(text_, &current_position_, word, endPosition);
} }
@ -248,13 +248,13 @@ void AssemblyContext::seekForward(uint32_t size) {
} }
spv_result_t AssemblyContext::binaryEncodeU32(const uint32_t value, spv_result_t AssemblyContext::binaryEncodeU32(const uint32_t value,
spv_instruction_t *pInst) { spv_instruction_t* pInst) {
spvInstructionAddWord(pInst, value); spvInstructionAddWord(pInst, value);
return SPV_SUCCESS; return SPV_SUCCESS;
} }
spv_result_t AssemblyContext::binaryEncodeU64(const uint64_t value, spv_result_t AssemblyContext::binaryEncodeU64(const uint64_t value,
spv_instruction_t *pInst) { spv_instruction_t* pInst) {
uint32_t low = uint32_t(0x00000000ffffffff & value); uint32_t low = uint32_t(0x00000000ffffffff & value);
uint32_t high = uint32_t((0xffffffff00000000 & value) >> 32); uint32_t high = uint32_t((0xffffffff00000000 & value) >> 32);
binaryEncodeU32(low, pInst); binaryEncodeU32(low, pInst);
@ -263,8 +263,8 @@ spv_result_t AssemblyContext::binaryEncodeU64(const uint64_t value,
} }
spv_result_t AssemblyContext::binaryEncodeNumericLiteral( spv_result_t AssemblyContext::binaryEncodeNumericLiteral(
const char *val, spv_result_t error_code, const IdType &type, const char* val, spv_result_t error_code, const IdType& type,
spv_instruction_t *pInst) { spv_instruction_t* pInst) {
const bool is_bottom = type.type_class == libspirv::IdTypeClass::kBottom; const bool is_bottom = type.type_class == libspirv::IdTypeClass::kBottom;
const bool is_floating = libspirv::isScalarFloating(type); const bool is_floating = libspirv::isScalarFloating(type);
const bool is_integer = libspirv::isScalarIntegral(type); const bool is_integer = libspirv::isScalarIntegral(type);
@ -286,8 +286,8 @@ spv_result_t AssemblyContext::binaryEncodeNumericLiteral(
return binaryEncodeIntegerLiteral(val, error_code, type, pInst); return binaryEncodeIntegerLiteral(val, error_code, type, pInst);
} }
spv_result_t AssemblyContext::binaryEncodeString( spv_result_t AssemblyContext::binaryEncodeString(const char* value,
const char *value, spv_instruction_t *pInst) { spv_instruction_t* pInst) {
const size_t length = strlen(value); const size_t length = strlen(value);
const size_t wordCount = (length / 4) + 1; const size_t wordCount = (length / 4) + 1;
const size_t oldWordCount = pInst->words.size(); const size_t oldWordCount = pInst->words.size();
@ -305,18 +305,18 @@ spv_result_t AssemblyContext::binaryEncodeString(
// write a partial word at the end. // write a partial word at the end.
pInst->words.back() = 0; pInst->words.back() = 0;
char *dest = (char *)&pInst->words[oldWordCount]; char* dest = (char*)&pInst->words[oldWordCount];
strncpy(dest, value, length); strncpy(dest, value, length);
return SPV_SUCCESS; return SPV_SUCCESS;
} }
spv_result_t AssemblyContext::recordTypeDefinition( spv_result_t AssemblyContext::recordTypeDefinition(
const spv_instruction_t *pInst) { const spv_instruction_t* pInst) {
uint32_t value = pInst->words[1]; uint32_t value = pInst->words[1];
if (types_.find(value) != types_.end()) { if (types_.find(value) != types_.end()) {
return diagnostic() return diagnostic() << "Value " << value
<< "Value " << value << " has already been used to generate a type"; << " has already been used to generate a type";
} }
if (pInst->opcode == SpvOpTypeInt) { if (pInst->opcode == SpvOpTypeInt) {
@ -345,7 +345,7 @@ IdType AssemblyContext::getTypeOfTypeGeneratingValue(uint32_t value) const {
IdType AssemblyContext::getTypeOfValueInstruction(uint32_t value) const { IdType AssemblyContext::getTypeOfValueInstruction(uint32_t value) const {
auto type_value = value_types_.find(value); auto type_value = value_types_.find(value);
if (type_value == value_types_.end()) { if (type_value == value_types_.end()) {
return { 0, false, IdTypeClass::kBottom}; return {0, false, IdTypeClass::kBottom};
} }
return getTypeOfTypeGeneratingValue(std::get<1>(*type_value)); return getTypeOfTypeGeneratingValue(std::get<1>(*type_value));
} }
@ -361,8 +361,8 @@ spv_result_t AssemblyContext::recordTypeIdForValue(uint32_t value,
} }
spv_result_t AssemblyContext::binaryEncodeFloatingPointLiteral( spv_result_t AssemblyContext::binaryEncodeFloatingPointLiteral(
const char *val, spv_result_t error_code, const IdType &type, const char* val, spv_result_t error_code, const IdType& type,
spv_instruction_t *pInst) { spv_instruction_t* pInst) {
const auto bit_width = assumedBitWidth(type); const auto bit_width = assumedBitWidth(type);
switch (bit_width) { switch (bit_width) {
case 16: case 16:
@ -389,8 +389,8 @@ spv_result_t AssemblyContext::binaryEncodeFloatingPointLiteral(
} }
spv_result_t AssemblyContext::binaryEncodeIntegerLiteral( spv_result_t AssemblyContext::binaryEncodeIntegerLiteral(
const char *val, spv_result_t error_code, const IdType &type, const char* val, spv_result_t error_code, const IdType& type,
spv_instruction_t *pInst) { spv_instruction_t* pInst) {
const bool is_bottom = type.type_class == libspirv::IdTypeClass::kBottom; const bool is_bottom = type.type_class == libspirv::IdTypeClass::kBottom;
const auto bit_width = assumedBitWidth(type); const auto bit_width = assumedBitWidth(type);
@ -437,8 +437,8 @@ spv_result_t AssemblyContext::binaryEncodeIntegerLiteral(
template <typename T> template <typename T>
spv_result_t AssemblyContext::checkRangeAndIfHexThenSignExtend( spv_result_t AssemblyContext::checkRangeAndIfHexThenSignExtend(
T value, spv_result_t error_code, const IdType &type, bool is_hex, T value, spv_result_t error_code, const IdType& type, bool is_hex,
T *updated_value_for_hex) { T* updated_value_for_hex) {
// The encoded result has three regions of bits that are of interest, from // The encoded result has three regions of bits that are of interest, from
// least to most significant: // least to most significant:
// - magnitude bits, where the magnitude of the number would be stored if // - magnitude bits, where the magnitude of the number would be stored if
@ -497,4 +497,4 @@ spv_result_t AssemblyContext::checkRangeAndIfHexThenSignExtend(
return SPV_SUCCESS; return SPV_SUCCESS;
} }
} // namespace libspirv } // namespace libspirv

View File

@ -43,31 +43,30 @@ namespace libspirv {
// This is a lattice for tracking types. // This is a lattice for tracking types.
enum class IdTypeClass { enum class IdTypeClass {
kBottom = 0, // We have no information yet. kBottom = 0, // We have no information yet.
kScalarIntegerType, kScalarIntegerType,
kScalarFloatType, kScalarFloatType,
kOtherType kOtherType
}; };
// Contains ID type information that needs to be tracked across all Ids. // Contains ID type information that needs to be tracked across all Ids.
// Bitwidth is only valid when type_class is kScalarIntegerType or // Bitwidth is only valid when type_class is kScalarIntegerType or
// kScalarFloatType. // kScalarFloatType.
struct IdType { struct IdType {
uint32_t bitwidth; // Safe to assume that we will not have > 2^32 bits. uint32_t bitwidth; // Safe to assume that we will not have > 2^32 bits.
bool isSigned; // This is only significant if type_class is integral. bool isSigned; // This is only significant if type_class is integral.
IdTypeClass type_class; IdTypeClass type_class;
}; };
// Default equality operator for IdType. Tests if all members are the same. // Default equality operator for IdType. Tests if all members are the same.
inline bool operator==(const IdType &first, const IdType &second) { inline bool operator==(const IdType& first, const IdType& second) {
return (first.bitwidth == second.bitwidth) && return (first.bitwidth == second.bitwidth) &&
(first.isSigned == second.isSigned) && (first.isSigned == second.isSigned) &&
(first.type_class == second.type_class); (first.type_class == second.type_class);
} }
// Tests whether any member of the IdTypes do not match. // Tests whether any member of the IdTypes do not match.
inline bool operator!=(const IdType &first, const IdType &second) { inline bool operator!=(const IdType& first, const IdType& second) {
return !(first == second); return !(first == second);
} }
@ -88,7 +87,7 @@ inline bool isScalarFloating(const IdType& type) {
// This is only valid for bottom, scalar integer, and scalar floating // This is only valid for bottom, scalar integer, and scalar floating
// classes. For bottom, assume 32 bits. // classes. For bottom, assume 32 bits.
inline int assumedBitWidth(const IdType& type) { inline int assumedBitWidth(const IdType& type) {
switch(type.type_class) { switch (type.type_class) {
case IdTypeClass::kBottom: case IdTypeClass::kBottom:
return 32; return 32;
case IdTypeClass::kScalarIntegerType: case IdTypeClass::kScalarIntegerType:
@ -104,7 +103,7 @@ inline int assumedBitWidth(const IdType& type) {
// Encapsulates the data used during the assembly of a SPIR-V module. // Encapsulates the data used during the assembly of a SPIR-V module.
class AssemblyContext { class AssemblyContext {
public: public:
AssemblyContext(spv_text text, spv_diagnostic *diagnostic) AssemblyContext(spv_text text, spv_diagnostic* diagnostic)
: current_position_({}), : current_position_({}),
pDiagnostic_(diagnostic), pDiagnostic_(diagnostic),
text_(text), text_(text),
@ -112,7 +111,7 @@ class AssemblyContext {
// Assigns a new integer value to the given text ID, or returns the previously // Assigns a new integer value to the given text ID, or returns the previously
// assigned integer value if the ID has been seen before. // assigned integer value if the ID has been seen before.
uint32_t spvNamedIdAssignOrGet(const char *textValue); uint32_t spvNamedIdAssignOrGet(const char* textValue);
// Returns the largest largest numeric ID that has been assigned. // Returns the largest largest numeric ID that has been assigned.
uint32_t getBound() const; uint32_t getBound() const;
@ -123,7 +122,7 @@ class AssemblyContext {
// Sets word to the next word in the input text. Fills endPosition with // Sets word to the next word in the input text. Fills endPosition with
// the next location past the end of the word. // the next location past the end of the word.
spv_result_t getWord(std::string &word, spv_position endPosition); spv_result_t getWord(std::string& word, spv_position endPosition);
// Returns the next word in the input stream. It is invalid to call this // Returns the next word in the input stream. It is invalid to call this
// method if position has been set to a location in the stream that does not // method if position has been set to a location in the stream that does not
@ -160,22 +159,22 @@ class AssemblyContext {
void seekForward(uint32_t size); void seekForward(uint32_t size);
// Sets the current position in the input stream to the given position. // Sets the current position in the input stream to the given position.
void setPosition(const spv_position_t &newPosition) { void setPosition(const spv_position_t& newPosition) {
current_position_ = newPosition; current_position_ = newPosition;
} }
// Returns the current position in the input stream. // Returns the current position in the input stream.
const spv_position_t &position() const { return current_position_; } const spv_position_t& position() const { return current_position_; }
// Appends the given 32-bit value to the given instruction. // Appends the given 32-bit value to the given instruction.
// Returns SPV_SUCCESS if the value could be correctly inserted in the // Returns SPV_SUCCESS if the value could be correctly inserted in the
// instruction. // instruction.
spv_result_t binaryEncodeU32(const uint32_t value, spv_instruction_t *pInst); spv_result_t binaryEncodeU32(const uint32_t value, spv_instruction_t* pInst);
// Appends the given string to the given instruction. // Appends the given string to the given instruction.
// Returns SPV_SUCCESS if the value could be correctly inserted in the // Returns SPV_SUCCESS if the value could be correctly inserted in the
// instruction. // instruction.
spv_result_t binaryEncodeString(const char *value, spv_instruction_t *pInst); spv_result_t binaryEncodeString(const char* value, spv_instruction_t* pInst);
// Appends the given numeric literal to the given instruction. // Appends the given numeric literal to the given instruction.
// Validates and respects the bitwidth supplied in the IdType argument. // Validates and respects the bitwidth supplied in the IdType argument.
@ -184,10 +183,10 @@ class AssemblyContext {
// Returns SPV_SUCCESS if the value could be correctly added to the // Returns SPV_SUCCESS if the value could be correctly added to the
// instruction. Returns the given error code on failure, and emits // instruction. Returns the given error code on failure, and emits
// a diagnotic if that error code is not SPV_FAILED_MATCH. // a diagnotic if that error code is not SPV_FAILED_MATCH.
spv_result_t binaryEncodeNumericLiteral(const char *numeric_literal, spv_result_t binaryEncodeNumericLiteral(const char* numeric_literal,
spv_result_t error_code, spv_result_t error_code,
const IdType &type, const IdType& type,
spv_instruction_t *pInst); spv_instruction_t* pInst);
// Returns the IdType associated with this type-generating value. // Returns the IdType associated with this type-generating value.
// If the type has not been previously recorded with recordTypeDefinition, // If the type has not been previously recorded with recordTypeDefinition,
@ -216,13 +215,14 @@ class AssemblyContext {
// referenced by value_pointer. On failure, returns the given error code, // referenced by value_pointer. On failure, returns the given error code,
// and emits a diagnostic if that error code is not SPV_FAILED_MATCH. // and emits a diagnostic if that error code is not SPV_FAILED_MATCH.
template <typename T> template <typename T>
spv_result_t parseNumber(const char *text, spv_result_t error_code, spv_result_t parseNumber(const char* text, spv_result_t error_code,
T *value_pointer, T* value_pointer,
const char *error_message_fragment) { const char* error_message_fragment) {
// C++11 doesn't define std::istringstream(int8_t&), so calling this method // C++11 doesn't define std::istringstream(int8_t&), so calling this method
// with a single-byte type leads to implementation-defined behaviour. // with a single-byte type leads to implementation-defined behaviour.
// Similarly for uint8_t. // Similarly for uint8_t.
static_assert(sizeof(T) > 1, "Don't use a single-byte type this parse method"); static_assert(sizeof(T) > 1,
"Don't use a single-byte type this parse method");
std::istringstream text_stream(text); std::istringstream text_stream(text);
// Allow both decimal and hex input for integers. // Allow both decimal and hex input for integers.
@ -257,20 +257,20 @@ class AssemblyContext {
// returns the given error code, and emits a diagnostic if that error // returns the given error code, and emits a diagnostic if that error
// code is not SPV_FAILED_MATCH. // code is not SPV_FAILED_MATCH.
// Only 32 and 64 bit floating point numbers are supported. // Only 32 and 64 bit floating point numbers are supported.
spv_result_t binaryEncodeFloatingPointLiteral(const char *numeric_literal, spv_result_t binaryEncodeFloatingPointLiteral(const char* numeric_literal,
spv_result_t error_code, spv_result_t error_code,
const IdType& type, const IdType& type,
spv_instruction_t *pInst); spv_instruction_t* pInst);
// Appends the given integer literal to the given instruction. // Appends the given integer literal to the given instruction.
// Returns SPV_SUCCESS if the value was correctly parsed. Otherwise // Returns SPV_SUCCESS if the value was correctly parsed. Otherwise
// returns the given error code, and emits a diagnostic if that error // returns the given error code, and emits a diagnostic if that error
// code is not SPV_FAILED_MATCH. // code is not SPV_FAILED_MATCH.
// Integers up to 64 bits are supported. // Integers up to 64 bits are supported.
spv_result_t binaryEncodeIntegerLiteral(const char *numeric_literal, spv_result_t binaryEncodeIntegerLiteral(const char* numeric_literal,
spv_result_t error_code, spv_result_t error_code,
const IdType &type, const IdType& type,
spv_instruction_t *pInst); spv_instruction_t* pInst);
// Returns SPV_SUCCESS if the given value fits within the target scalar // Returns SPV_SUCCESS if the given value fits within the target scalar
// integral type. The target type may have an unusual bit width. // integral type. The target type may have an unusual bit width.
@ -281,13 +281,14 @@ class AssemblyContext {
// On failure, return the given error code and emit a diagnostic if that error // On failure, return the given error code and emit a diagnostic if that error
// code is not SPV_FAILED_MATCH. // code is not SPV_FAILED_MATCH.
template <typename T> template <typename T>
spv_result_t checkRangeAndIfHexThenSignExtend(T value, spv_result_t error_code, spv_result_t checkRangeAndIfHexThenSignExtend(T value,
const IdType &type, bool is_hex, spv_result_t error_code,
T *updated_value_for_hex); const IdType& type, bool is_hex,
T* updated_value_for_hex);
// Writes the given 64-bit literal value into the instruction. // Writes the given 64-bit literal value into the instruction.
// return SPV_SUCCESS if the value could be written in the instruction. // return SPV_SUCCESS if the value could be written in the instruction.
spv_result_t binaryEncodeU64(const uint64_t value, spv_instruction_t *pInst); spv_result_t binaryEncodeU64(const uint64_t value, spv_instruction_t* pInst);
// Maps ID names to their corresponding numerical ids. // Maps ID names to their corresponding numerical ids.
using spv_named_id_table = std::unordered_map<std::string, uint32_t>; using spv_named_id_table = std::unordered_map<std::string, uint32_t>;
// Maps type-defining IDs to their IdType. // Maps type-defining IDs to their IdType.
@ -299,7 +300,7 @@ class AssemblyContext {
spv_id_to_type_map types_; spv_id_to_type_map types_;
spv_id_to_type_id value_types_; spv_id_to_type_id value_types_;
spv_position_t current_position_; spv_position_t current_position_;
spv_diagnostic *pDiagnostic_; spv_diagnostic* pDiagnostic_;
spv_text text_; spv_text text_;
uint32_t bound_; uint32_t bound_;
}; };

View File

@ -42,11 +42,11 @@
#define spvCheckReturn(expression) \ #define spvCheckReturn(expression) \
if (spv_result_t error = (expression)) return error; if (spv_result_t error = (expression)) return error;
spv_result_t spvValidateOperandsString(const uint32_t *words, spv_result_t spvValidateOperandsString(const uint32_t* words,
const uint16_t wordCount, const uint16_t wordCount,
spv_position position, spv_position position,
spv_diagnostic *pDiagnostic) { spv_diagnostic* pDiagnostic) {
const char *str = (const char *)words; const char* str = (const char*)words;
uint64_t strWordCount = strlen(str) / sizeof(uint32_t) + 1; uint64_t strWordCount = strlen(str) / sizeof(uint32_t) + 1;
if (strWordCount < wordCount) { if (strWordCount < wordCount) {
DIAGNOSTIC << "Instruction word count is too short, string extends past " DIAGNOSTIC << "Instruction word count is too short, string extends past "
@ -56,11 +56,11 @@ spv_result_t spvValidateOperandsString(const uint32_t *words,
return SPV_SUCCESS; return SPV_SUCCESS;
} }
spv_result_t spvValidateOperandsLiteral(const uint32_t *words, spv_result_t spvValidateOperandsLiteral(const uint32_t* words,
const uint32_t length, const uint32_t length,
const uint16_t maxLength, const uint16_t maxLength,
spv_position position, spv_position position,
spv_diagnostic *pDiagnostic) { spv_diagnostic* pDiagnostic) {
// NOTE: A literal could either be a number consuming up to 2 words or a // NOTE: A literal could either be a number consuming up to 2 words or a
// null terminated string. // null terminated string.
(void)words; (void)words;
@ -75,7 +75,7 @@ spv_result_t spvValidateOperandValue(const spv_operand_type_t type,
const uint32_t word, const uint32_t word,
const spv_operand_table operandTable, const spv_operand_table operandTable,
spv_position position, spv_position position,
spv_diagnostic *pDiagnostic) { spv_diagnostic* pDiagnostic) {
switch (type) { switch (type) {
case SPV_OPERAND_TYPE_ID: case SPV_OPERAND_TYPE_ID:
case SPV_OPERAND_TYPE_RESULT_ID: { case SPV_OPERAND_TYPE_RESULT_ID: {
@ -125,14 +125,14 @@ spv_result_t spvValidateOperandValue(const spv_operand_type_t type,
return SPV_SUCCESS; return SPV_SUCCESS;
} }
spv_result_t spvValidateBasic(const spv_instruction_t *pInsts, spv_result_t spvValidateBasic(const spv_instruction_t* pInsts,
const uint64_t instCount, const uint64_t instCount,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
spv_position position, spv_position position,
spv_diagnostic *pDiagnostic) { spv_diagnostic* pDiagnostic) {
for (uint64_t instIndex = 0; instIndex < instCount; ++instIndex) { for (uint64_t instIndex = 0; instIndex < instCount; ++instIndex) {
const uint32_t *words = pInsts[instIndex].words.data(); const uint32_t* words = pInsts[instIndex].words.data();
uint16_t wordCount; uint16_t wordCount;
SpvOp opcode; SpvOp opcode;
spvOpcodeSplit(words[0], &wordCount, &opcode); spvOpcodeSplit(words[0], &wordCount, &opcode);
@ -182,18 +182,18 @@ spv_result_t spvValidateBasic(const spv_instruction_t *pInsts,
return SPV_SUCCESS; return SPV_SUCCESS;
} }
spv_result_t spvValidateIDs(const spv_instruction_t *pInsts, spv_result_t spvValidateIDs(const spv_instruction_t* pInsts,
const uint64_t count, const uint32_t bound, const uint64_t count, const uint32_t bound,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
spv_position position, spv_position position,
spv_diagnostic *pDiagnostic) { spv_diagnostic* pDiagnostic) {
std::vector<spv_id_info_t> idUses; std::vector<spv_id_info_t> idUses;
std::vector<spv_id_info_t> idDefs; std::vector<spv_id_info_t> idDefs;
for (uint64_t instIndex = 0; instIndex < count; ++instIndex) { for (uint64_t instIndex = 0; instIndex < count; ++instIndex) {
const uint32_t *words = pInsts[instIndex].words.data(); const uint32_t* words = pInsts[instIndex].words.data();
SpvOp opcode; SpvOp opcode;
spvOpcodeSplit(words[0], nullptr, &opcode); spvOpcodeSplit(words[0], nullptr, &opcode);
@ -263,7 +263,7 @@ spv_result_t spvValidate(const spv_binary binary,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
const uint32_t options, spv_diagnostic *pDiagnostic) { const uint32_t options, spv_diagnostic* pDiagnostic) {
if (!opcodeTable || !operandTable) return SPV_ERROR_INVALID_TABLE; if (!opcodeTable || !operandTable) return SPV_ERROR_INVALID_TABLE;
if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC; if (!pDiagnostic) return SPV_ERROR_INVALID_DIAGNOSTIC;

View File

@ -35,7 +35,7 @@
typedef struct spv_id_info_t { typedef struct spv_id_info_t {
uint32_t id; uint32_t id;
SpvOp opcode; SpvOp opcode;
const spv_instruction_t *inst; const spv_instruction_t* inst;
spv_position_t position; spv_position_t position;
} spv_id_info_t; } spv_id_info_t;
@ -56,12 +56,12 @@ typedef struct spv_id_info_t {
/// ///
/// @return result code /// @return result code
spv_result_t spvValidateInstructionIDs( spv_result_t spvValidateInstructionIDs(
const spv_instruction_t *pInsts, const uint64_t instCount, const spv_instruction_t* pInsts, const uint64_t instCount,
const spv_id_info_t *pIdUses, const uint64_t idUsesCount, const spv_id_info_t* pIdUses, const uint64_t idUsesCount,
const spv_id_info_t *pIdDefs, const uint64_t idDefsCount, const spv_id_info_t* pIdDefs, const uint64_t idDefsCount,
const spv_opcode_table opcodeTable, const spv_operand_table operandTable, const spv_opcode_table opcodeTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, spv_position position, const spv_ext_inst_table extInstTable, spv_position position,
spv_diagnostic *pDiag); spv_diagnostic* pDiag);
/// @brief Validate the ID's within a SPIR-V binary /// @brief Validate the ID's within a SPIR-V binary
/// ///
@ -74,11 +74,11 @@ spv_result_t spvValidateInstructionIDs(
/// @param[out] pDiagnostic contains diagnostic on failure /// @param[out] pDiagnostic contains diagnostic on failure
/// ///
/// @return result code /// @return result code
spv_result_t spvValidateIDs(const spv_instruction_t *pInstructions, spv_result_t spvValidateIDs(const spv_instruction_t* pInstructions,
const uint64_t count, const uint32_t bound, const uint64_t count, const uint32_t bound,
const spv_opcode_table opcodeTable, const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_ext_inst_table extInstTable,
spv_position position, spv_diagnostic *pDiagnostic); spv_position position, spv_diagnostic* pDiagnostic);
#endif // LIBSPIRV_VALIDATE_H_ #endif // LIBSPIRV_VALIDATE_H_

View File

@ -46,11 +46,11 @@ class idUsage {
public: public:
idUsage(const spv_opcode_table opcodeTable, idUsage(const spv_opcode_table opcodeTable,
const spv_operand_table operandTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, const spv_id_info_t *pIdUses, const spv_ext_inst_table extInstTable, const spv_id_info_t* pIdUses,
const uint64_t idUsesCount, const spv_id_info_t *pIdDefs, const uint64_t idUsesCount, const spv_id_info_t* pIdDefs,
const uint64_t idDefsCount, const spv_instruction_t *pInsts, const uint64_t idDefsCount, const spv_instruction_t* pInsts,
const uint64_t instCount, spv_position position, const uint64_t instCount, spv_position position,
spv_diagnostic *pDiagnostic) spv_diagnostic* pDiagnostic)
: opcodeTable(opcodeTable), : opcodeTable(opcodeTable),
operandTable(operandTable), operandTable(operandTable),
extInstTable(extInstTable), extInstTable(extInstTable),
@ -66,17 +66,17 @@ class idUsage {
} }
} }
bool isValid(const spv_instruction_t *inst); bool isValid(const spv_instruction_t* inst);
template <SpvOp> template <SpvOp>
bool isValid(const spv_instruction_t *inst, const spv_opcode_desc); bool isValid(const spv_instruction_t* inst, const spv_opcode_desc);
std::unordered_map<uint32_t, spv_id_info_t>::iterator find( std::unordered_map<uint32_t, spv_id_info_t>::iterator find(
const uint32_t &id) { const uint32_t& id) {
return idDefs.find(id); return idDefs.find(id);
} }
std::unordered_map<uint32_t, spv_id_info_t>::const_iterator find( std::unordered_map<uint32_t, spv_id_info_t>::const_iterator find(
const uint32_t &id) const { const uint32_t& id) const {
return idDefs.find(id); return idDefs.find(id);
} }
@ -88,11 +88,11 @@ class idUsage {
} }
std::unordered_map<uint32_t, std::vector<spv_id_info_t>>::iterator findUses( std::unordered_map<uint32_t, std::vector<spv_id_info_t>>::iterator findUses(
const uint32_t &id) { const uint32_t& id) {
return idUses.find(id); return idUses.find(id);
} }
std::unordered_map<uint32_t, std::vector<spv_id_info_t>>::const_iterator std::unordered_map<uint32_t, std::vector<spv_id_info_t>>::const_iterator
findUses(const uint32_t &id) const { findUses(const uint32_t& id) const {
return idUses.find(id); return idUses.find(id);
} }
@ -109,10 +109,10 @@ class idUsage {
const spv_opcode_table opcodeTable; const spv_opcode_table opcodeTable;
const spv_operand_table operandTable; const spv_operand_table operandTable;
const spv_ext_inst_table extInstTable; const spv_ext_inst_table extInstTable;
const spv_instruction_t *const firstInst; const spv_instruction_t* const firstInst;
const uint64_t instCount; const uint64_t instCount;
spv_position position; spv_position position;
spv_diagnostic *pDiagnostic; spv_diagnostic* pDiagnostic;
std::unordered_map<uint32_t, std::vector<spv_id_info_t>> idUses; std::unordered_map<uint32_t, std::vector<spv_id_info_t>> idUses;
std::unordered_map<uint32_t, spv_id_info_t> idDefs; std::unordered_map<uint32_t, spv_id_info_t> idDefs;
}; };
@ -131,7 +131,7 @@ bool idUsage::isValid<SpvOpUndef>(const spv_instruction_t *inst,
#endif #endif
template <> template <>
bool idUsage::isValid<SpvOpName>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpName>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto targetIndex = 1; auto targetIndex = 1;
auto target = find(inst->words[targetIndex]); auto target = find(inst->words[targetIndex]);
@ -143,7 +143,7 @@ bool idUsage::isValid<SpvOpName>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpMemberName>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpMemberName>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto typeIndex = 1; auto typeIndex = 1;
auto type = find(inst->words[typeIndex]); auto type = find(inst->words[typeIndex]);
@ -169,7 +169,7 @@ bool idUsage::isValid<SpvOpMemberName>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpLine>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpLine>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto fileIndex = 1; auto fileIndex = 1;
auto file = find(inst->words[fileIndex]); auto file = find(inst->words[fileIndex]);
@ -185,7 +185,7 @@ bool idUsage::isValid<SpvOpLine>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpDecorate>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpDecorate>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto targetIndex = 1; auto targetIndex = 1;
auto target = find(inst->words[targetIndex]); auto target = find(inst->words[targetIndex]);
@ -197,7 +197,7 @@ bool idUsage::isValid<SpvOpDecorate>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpMemberDecorate>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpMemberDecorate>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto structTypeIndex = 1; auto structTypeIndex = 1;
auto structType = find(inst->words[structTypeIndex]); auto structType = find(inst->words[structTypeIndex]);
@ -223,7 +223,7 @@ bool idUsage::isValid<SpvOpMemberDecorate>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpGroupDecorate>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpGroupDecorate>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto decorationGroupIndex = 1; auto decorationGroupIndex = 1;
auto decorationGroup = find(inst->words[decorationGroupIndex]); auto decorationGroup = find(inst->words[decorationGroupIndex]);
@ -238,7 +238,8 @@ bool idUsage::isValid<SpvOpGroupDecorate>(const spv_instruction_t *inst,
<< inst->words[decorationGroupIndex] << inst->words[decorationGroupIndex]
<< "' is not a decoration group."; << "' is not a decoration group.";
return false); return false);
for (size_t targetIndex = 2; targetIndex < inst->words.size(); ++targetIndex) { for (size_t targetIndex = 2; targetIndex < inst->words.size();
++targetIndex) {
auto target = find(inst->words[targetIndex]); auto target = find(inst->words[targetIndex]);
spvCheck(!found(target), DIAG(targetIndex) spvCheck(!found(target), DIAG(targetIndex)
<< "OpGroupDecorate Target <id> '" << "OpGroupDecorate Target <id> '"
@ -262,7 +263,7 @@ bool idUsage::isValid<SpvOpExtInst>(const spv_instruction_t *inst,
#endif #endif
template <> template <>
bool idUsage::isValid<SpvOpEntryPoint>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpEntryPoint>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto entryPointIndex = 2; auto entryPointIndex = 2;
auto entryPoint = find(inst->words[entryPointIndex]); auto entryPoint = find(inst->words[entryPointIndex]);
@ -296,7 +297,7 @@ bool idUsage::isValid<SpvOpEntryPoint>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpExecutionMode>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpExecutionMode>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto entryPointIndex = 1; auto entryPointIndex = 1;
auto entryPoint = find(inst->words[entryPointIndex]); auto entryPoint = find(inst->words[entryPointIndex]);
@ -323,7 +324,7 @@ bool idUsage::isValid<SpvOpExecutionMode>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeVector>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypeVector>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto componentIndex = 2; auto componentIndex = 2;
auto componentType = find(inst->words[componentIndex]); auto componentType = find(inst->words[componentIndex]);
@ -341,7 +342,7 @@ bool idUsage::isValid<SpvOpTypeVector>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeMatrix>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypeMatrix>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto columnTypeIndex = 2; auto columnTypeIndex = 2;
auto columnType = find(inst->words[columnTypeIndex]); auto columnType = find(inst->words[columnTypeIndex]);
@ -359,14 +360,14 @@ bool idUsage::isValid<SpvOpTypeMatrix>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeSampler>(const spv_instruction_t *, bool idUsage::isValid<SpvOpTypeSampler>(const spv_instruction_t*,
const spv_opcode_desc) { const spv_opcode_desc) {
// OpTypeSampler takes no arguments in Rev31 and beyond. // OpTypeSampler takes no arguments in Rev31 and beyond.
return true; return true;
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeArray>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypeArray>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto elementTypeIndex = 2; auto elementTypeIndex = 2;
auto elementType = find(inst->words[elementTypeIndex]); auto elementType = find(inst->words[elementTypeIndex]);
@ -434,7 +435,7 @@ bool idUsage::isValid<SpvOpTypeArray>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeRuntimeArray>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypeRuntimeArray>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto elementTypeIndex = 2; auto elementTypeIndex = 2;
auto elementType = find(inst->words[elementTypeIndex]); auto elementType = find(inst->words[elementTypeIndex]);
@ -452,7 +453,7 @@ bool idUsage::isValid<SpvOpTypeRuntimeArray>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeStruct>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypeStruct>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
for (size_t memberTypeIndex = 2; memberTypeIndex < inst->words.size(); for (size_t memberTypeIndex = 2; memberTypeIndex < inst->words.size();
++memberTypeIndex) { ++memberTypeIndex) {
@ -472,7 +473,7 @@ bool idUsage::isValid<SpvOpTypeStruct>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypePointer>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypePointer>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto typeIndex = 3; auto typeIndex = 3;
auto type = find(inst->words[typeIndex]); auto type = find(inst->words[typeIndex]);
@ -488,7 +489,7 @@ bool idUsage::isValid<SpvOpTypePointer>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypeFunction>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpTypeFunction>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto returnTypeIndex = 2; auto returnTypeIndex = 2;
auto returnType = find(inst->words[returnTypeIndex]); auto returnType = find(inst->words[returnTypeIndex]);
@ -520,14 +521,14 @@ bool idUsage::isValid<SpvOpTypeFunction>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpTypePipe>(const spv_instruction_t *, bool idUsage::isValid<SpvOpTypePipe>(const spv_instruction_t*,
const spv_opcode_desc) { const spv_opcode_desc) {
// OpTypePipe has no ID arguments. // OpTypePipe has no ID arguments.
return true; return true;
} }
template <> template <>
bool idUsage::isValid<SpvOpConstantTrue>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpConstantTrue>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -545,7 +546,7 @@ bool idUsage::isValid<SpvOpConstantTrue>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpConstantFalse>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpConstantFalse>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -563,7 +564,7 @@ bool idUsage::isValid<SpvOpConstantFalse>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpConstant>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpConstant>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -582,7 +583,7 @@ bool idUsage::isValid<SpvOpConstant>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpConstantComposite>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpConstantComposite>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -773,7 +774,7 @@ bool idUsage::isValid<SpvOpConstantComposite>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpConstantSampler>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpConstantSampler>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -791,7 +792,7 @@ bool idUsage::isValid<SpvOpConstantSampler>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpConstantNull>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpConstantNull>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -842,7 +843,8 @@ bool idUsage::isValid<SpvOpConstantNull>(const spv_instruction_t *inst,
} break; } break;
case SpvOpTypeStruct: { case SpvOpTypeStruct: {
for (size_t elementIndex = 2; for (size_t elementIndex = 2;
elementIndex < resultType->second.inst->words.size(); ++elementIndex) { elementIndex < resultType->second.inst->words.size();
++elementIndex) {
auto element = find(resultType->second.inst->words[elementIndex]); auto element = find(resultType->second.inst->words[elementIndex]);
spvCheck(!found(element), assert(0 && "Unreachable!")); spvCheck(!found(element), assert(0 && "Unreachable!"));
spvCheck(!spvOpcodeIsBasicTypeNullable(element->second.inst->opcode), spvCheck(!spvOpcodeIsBasicTypeNullable(element->second.inst->opcode),
@ -858,7 +860,7 @@ bool idUsage::isValid<SpvOpConstantNull>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpSpecConstantTrue>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpSpecConstantTrue>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -876,7 +878,7 @@ bool idUsage::isValid<SpvOpSpecConstantTrue>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpSpecConstantFalse>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpSpecConstantFalse>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -894,7 +896,7 @@ bool idUsage::isValid<SpvOpSpecConstantFalse>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpSpecConstant>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpSpecConstant>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -923,7 +925,7 @@ bool idUsage::isValid<SpvOpSpecConstantOp>(const spv_instruction_t *inst) {}
#endif #endif
template <> template <>
bool idUsage::isValid<SpvOpVariable>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpVariable>(const spv_instruction_t* inst,
const spv_opcode_desc opcodeEntry) { const spv_opcode_desc opcodeEntry) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -955,7 +957,7 @@ bool idUsage::isValid<SpvOpVariable>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpLoad>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpLoad>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -987,7 +989,7 @@ bool idUsage::isValid<SpvOpLoad>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpStore>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpStore>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto pointerIndex = 1; auto pointerIndex = 1;
auto pointer = find(inst->words[pointerIndex]); auto pointer = find(inst->words[pointerIndex]);
@ -1004,10 +1006,10 @@ bool idUsage::isValid<SpvOpStore>(const spv_instruction_t *inst,
spvCheck(!found(pointerType), assert(0 && "Unreachable!")); spvCheck(!found(pointerType), assert(0 && "Unreachable!"));
auto type = find(pointerType->second.inst->words[3]); auto type = find(pointerType->second.inst->words[3]);
spvCheck(!found(type), assert(0 && "Unreachable!")); spvCheck(!found(type), assert(0 && "Unreachable!"));
spvCheck(SpvOpTypeVoid == type->second.opcode, DIAG(pointerIndex) spvCheck(SpvOpTypeVoid == type->second.opcode,
<< "OpStore Pointer <id> '" DIAG(pointerIndex) << "OpStore Pointer <id> '"
<< inst->words[pointerIndex] << inst->words[pointerIndex]
<< "'s type is void."; << "'s type is void.";
return false); return false);
auto objectIndex = 2; auto objectIndex = 2;
@ -1038,7 +1040,7 @@ bool idUsage::isValid<SpvOpStore>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpCopyMemory>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpCopyMemory>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto targetIndex = 1; auto targetIndex = 1;
auto target = find(inst->words[targetIndex]); auto target = find(inst->words[targetIndex]);
@ -1071,7 +1073,7 @@ bool idUsage::isValid<SpvOpCopyMemory>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpCopyMemorySized>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpCopyMemorySized>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto targetIndex = 1; auto targetIndex = 1;
auto target = find(inst->words[targetIndex]); auto target = find(inst->words[targetIndex]);
@ -1172,7 +1174,7 @@ bool idUsage::isValid<SpvOpGenericPtrMemSemantics>(
#endif #endif
template <> template <>
bool idUsage::isValid<SpvOpFunction>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpFunction>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -1205,7 +1207,7 @@ bool idUsage::isValid<SpvOpFunction>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpFunctionParameter>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpFunctionParameter>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -1244,7 +1246,7 @@ bool idUsage::isValid<SpvOpFunctionParameter>(const spv_instruction_t *inst,
} }
template <> template <>
bool idUsage::isValid<SpvOpFunctionCall>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpFunctionCall>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto resultTypeIndex = 1; auto resultTypeIndex = 1;
auto resultType = find(inst->words[resultTypeIndex]); auto resultType = find(inst->words[resultTypeIndex]);
@ -1935,7 +1937,7 @@ bool idUsage::isValid<OpSwitch>(const spv_instruction_t *inst,
#endif #endif
template <> template <>
bool idUsage::isValid<SpvOpReturnValue>(const spv_instruction_t *inst, bool idUsage::isValid<SpvOpReturnValue>(const spv_instruction_t* inst,
const spv_opcode_desc) { const spv_opcode_desc) {
auto valueIndex = 1; auto valueIndex = 1;
auto value = find(inst->words[valueIndex]); auto value = find(inst->words[valueIndex]);
@ -1951,7 +1953,7 @@ bool idUsage::isValid<SpvOpReturnValue>(const spv_instruction_t *inst,
auto valueType = find(value->second.inst->words[1]); auto valueType = find(value->second.inst->words[1]);
spvCheck(!found(valueType), assert(0 && "Unreachable!")); spvCheck(!found(valueType), assert(0 && "Unreachable!"));
// NOTE: Find OpFunction // NOTE: Find OpFunction
const spv_instruction_t *function = inst - 1; const spv_instruction_t* function = inst - 1;
while (firstInst != function) { while (firstInst != function) {
spvCheck(SpvOpFunction == function->opcode, break); spvCheck(SpvOpFunction == function->opcode, break);
function--; function--;
@ -2364,12 +2366,12 @@ bool idUsage::isValid<OpGroupCommitWritePipe>(
#undef DIAG #undef DIAG
bool idUsage::isValid(const spv_instruction_t *inst) { bool idUsage::isValid(const spv_instruction_t* inst) {
spv_opcode_desc opcodeEntry = nullptr; spv_opcode_desc opcodeEntry = nullptr;
spvCheck(spvOpcodeTableValueLookup(opcodeTable, inst->opcode, &opcodeEntry), spvCheck(spvOpcodeTableValueLookup(opcodeTable, inst->opcode, &opcodeEntry),
return false); return false);
#define CASE(OpCode) \ #define CASE(OpCode) \
case Spv##OpCode: \ case Spv##OpCode: \
return isValid<Spv##OpCode>(inst, opcodeEntry); return isValid<Spv##OpCode>(inst, opcodeEntry);
#define FAIL(OpCode) \ #define FAIL(OpCode) \
case Spv##OpCode: \ case Spv##OpCode: \
@ -2592,12 +2594,12 @@ bool idUsage::isValid(const spv_instruction_t *inst) {
} // anonymous namespace } // anonymous namespace
spv_result_t spvValidateInstructionIDs( spv_result_t spvValidateInstructionIDs(
const spv_instruction_t *pInsts, const uint64_t instCount, const spv_instruction_t* pInsts, const uint64_t instCount,
const spv_id_info_t *pIdUses, const uint64_t idUsesCount, const spv_id_info_t* pIdUses, const uint64_t idUsesCount,
const spv_id_info_t *pIdDefs, const uint64_t idDefsCount, const spv_id_info_t* pIdDefs, const uint64_t idDefsCount,
const spv_opcode_table opcodeTable, const spv_operand_table operandTable, const spv_opcode_table opcodeTable, const spv_operand_table operandTable,
const spv_ext_inst_table extInstTable, spv_position position, const spv_ext_inst_table extInstTable, spv_position position,
spv_diagnostic *pDiag) { spv_diagnostic* pDiag) {
idUsage idUsage(opcodeTable, operandTable, extInstTable, pIdUses, idUsesCount, idUsage idUsage(opcodeTable, operandTable, extInstTable, pIdUses, idUsesCount,
pIdDefs, idDefsCount, pInsts, instCount, position, pDiag); pIdDefs, idDefsCount, pInsts, instCount, position, pDiag);
for (uint64_t instIndex = 0; instIndex < instCount; ++instIndex) { for (uint64_t instIndex = 0; instIndex < instCount; ++instIndex) {

View File

@ -38,8 +38,7 @@ using RoundTripLiteralsTest =
spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>; spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
TEST_P(RoundTripLiteralsTest, Sample) { TEST_P(RoundTripLiteralsTest, Sample) {
EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), Eq(GetParam()));
Eq(GetParam()));
} }
// clang-format off // clang-format off

View File

@ -145,8 +145,7 @@ struct FailedDecodeCase {
}; };
using BinaryToTextFail = using BinaryToTextFail =
spvtest::TextToBinaryTestBase < spvtest::TextToBinaryTestBase<::testing::TestWithParam<FailedDecodeCase>>;
::testing::TestWithParam<FailedDecodeCase>>;
TEST_P(BinaryToTextFail, EncodeSuccessfullyDecodeFailed) { TEST_P(BinaryToTextFail, EncodeSuccessfullyDecodeFailed) {
EXPECT_THAT(EncodeSuccessfullyDecodeFailed(GetParam().source_text, EXPECT_THAT(EncodeSuccessfullyDecodeFailed(GetParam().source_text,
@ -305,8 +304,7 @@ using RoundTripInstructionsTest =
spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>; spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
TEST_P(RoundTripInstructionsTest, Sample) { TEST_P(RoundTripInstructionsTest, Sample) {
EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), Eq(GetParam()));
Eq(GetParam()));
}; };
// clang-format off // clang-format off

View File

@ -92,7 +92,7 @@ TEST_P(ExtInstOpenCLStdRoundTripTest, ParameterizedExtInst) {
#define CASE3Round(Enum, Name, Mode) \ #define CASE3Round(Enum, Name, Mode) \
{ \ { \
uint32_t(OpenCLLIB::Entrypoints::Enum), #Name, "%4 %5 %6 " #Mode, { \ uint32_t(OpenCLLIB::Entrypoints::Enum), #Name, "%4 %5 %6 " #Mode, { \
4, 5, 6, uint32_t(SpvFPRoundingMode##Mode) \ 4, 5, 6, uint32_t(SpvFPRoundingMode##Mode) \
} \ } \
} }
@ -395,8 +395,7 @@ TEST_F(TextToBinaryTest, DISABLED_ExtInstFromTwoDifferentImports) {
CompiledInstructions(input), CompiledInstructions(input),
Eq(Concatenate({ Eq(Concatenate({
MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("OpenCL.std")), MakeInstruction(SpvOpExtInstImport, {1}, MakeVector("OpenCL.std")),
MakeInstruction(SpvOpExtInstImport, {2}, MakeInstruction(SpvOpExtInstImport, {2}, MakeVector("GLSL.std.450")),
MakeVector("GLSL.std.450")),
MakeInstruction( MakeInstruction(
SpvOpExtInst, SpvOpExtInst,
{3, 4, 1, uint32_t(OpenCLLIB::Entrypoints::Native_sqrt), 5}), {3, 4, 1, uint32_t(OpenCLLIB::Entrypoints::Native_sqrt), 5}),

View File

@ -65,8 +65,8 @@ OpEntryPoint Vertex %2 "main"
%4 = OpTypeFunction %3 %4 = OpTypeFunction %3
%2 = OpFunction %3 None %5 %2 = OpFunction %3 None %5
%6 = OpLabel %6 = OpLabel
%8 = OpExtInst %7 %1 )" + std::string(GetParam().extInstOpName) + " " + %8 = OpExtInst %7 %1 )" + std::string(GetParam().extInstOpName) +
GetParam().extInstOperandVars + R"( " " + GetParam().extInstOperandVars + R"(
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
)"; )";

277
test/HexFloat.cpp Executable file → Normal file
View File

@ -61,75 +61,73 @@ TEST_P(HexFloatTest, DecodeCorrectly) {
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
Float32Tests, HexFloatTest, Float32Tests, HexFloatTest,
::testing::ValuesIn( ::testing::ValuesIn(std::vector<std::pair<FloatProxy<float>, std::string>>({
std::vector<std::pair<FloatProxy<float>, std::string>>({ {0.f, "0x0p+0"},
{0.f, "0x0p+0"}, {1.f, "0x1p+0"},
{1.f, "0x1p+0"}, {2.f, "0x1p+1"},
{2.f, "0x1p+1"}, {3.f, "0x1.8p+1"},
{3.f, "0x1.8p+1"}, {0.5f, "0x1p-1"},
{0.5f, "0x1p-1"}, {0.25f, "0x1p-2"},
{0.25f, "0x1p-2"}, {0.75f, "0x1.8p-1"},
{0.75f, "0x1.8p-1"}, {-0.f, "-0x0p+0"},
{-0.f, "-0x0p+0"}, {-1.f, "-0x1p+0"},
{-1.f, "-0x1p+0"}, {-0.5f, "-0x1p-1"},
{-0.5f, "-0x1p-1"}, {-0.25f, "-0x1p-2"},
{-0.25f, "-0x1p-2"}, {-0.75f, "-0x1.8p-1"},
{-0.75f, "-0x1.8p-1"},
// Larger numbers // Larger numbers
{512.f, "0x1p+9"}, {512.f, "0x1p+9"},
{-512.f, "-0x1p+9"}, {-512.f, "-0x1p+9"},
{1024.f, "0x1p+10"}, {1024.f, "0x1p+10"},
{-1024.f, "-0x1p+10"}, {-1024.f, "-0x1p+10"},
{1024.f + 8.f, "0x1.02p+10"}, {1024.f + 8.f, "0x1.02p+10"},
{-1024.f - 8.f, "-0x1.02p+10"}, {-1024.f - 8.f, "-0x1.02p+10"},
// Small numbers // Small numbers
{1.0f / 512.f, "0x1p-9"}, {1.0f / 512.f, "0x1p-9"},
{1.0f / -512.f, "-0x1p-9"}, {1.0f / -512.f, "-0x1p-9"},
{1.0f / 1024.f, "0x1p-10"}, {1.0f / 1024.f, "0x1p-10"},
{1.0f / -1024.f, "-0x1p-10"}, {1.0f / -1024.f, "-0x1p-10"},
{1.0f / 1024.f + 1.0f / 8.f, "0x1.02p-3"}, {1.0f / 1024.f + 1.0f / 8.f, "0x1.02p-3"},
{1.0f / -1024.f - 1.0f / 8.f, "-0x1.02p-3"}, {1.0f / -1024.f - 1.0f / 8.f, "-0x1.02p-3"},
// lowest non-denorm // lowest non-denorm
{float(ldexp(1.0f, -126)), "0x1p-126"}, {float(ldexp(1.0f, -126)), "0x1p-126"},
{float(ldexp(-1.0f, -126)), "-0x1p-126"}, {float(ldexp(-1.0f, -126)), "-0x1p-126"},
// Denormalized values // Denormalized values
{float(ldexp(1.0f, -127)), "0x1p-127"}, {float(ldexp(1.0f, -127)), "0x1p-127"},
{float(ldexp(1.0f, -127) / 2.0f), "0x1p-128"}, {float(ldexp(1.0f, -127) / 2.0f), "0x1p-128"},
{float(ldexp(1.0f, -127) / 4.0f), "0x1p-129"}, {float(ldexp(1.0f, -127) / 4.0f), "0x1p-129"},
{float(ldexp(1.0f, -127) / 8.0f), "0x1p-130"}, {float(ldexp(1.0f, -127) / 8.0f), "0x1p-130"},
{float(ldexp(-1.0f, -127)), "-0x1p-127"}, {float(ldexp(-1.0f, -127)), "-0x1p-127"},
{float(ldexp(-1.0f, -127) / 2.0f), "-0x1p-128"}, {float(ldexp(-1.0f, -127) / 2.0f), "-0x1p-128"},
{float(ldexp(-1.0f, -127) / 4.0f), "-0x1p-129"}, {float(ldexp(-1.0f, -127) / 4.0f), "-0x1p-129"},
{float(ldexp(-1.0f, -127) / 8.0f), "-0x1p-130"}, {float(ldexp(-1.0f, -127) / 8.0f), "-0x1p-130"},
{float(ldexp(1.0, -127) + (ldexp(1.0, -127) / 2.0f)), "0x1.8p-127"}, {float(ldexp(1.0, -127) + (ldexp(1.0, -127) / 2.0f)), "0x1.8p-127"},
{float(ldexp(1.0, -127) / 2.0 + (ldexp(1.0, -127) / 4.0f)), {float(ldexp(1.0, -127) / 2.0 + (ldexp(1.0, -127) / 4.0f)),
"0x1.8p-128"}, "0x1.8p-128"},
}))); })));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
Float32NanTests, HexFloatTest, Float32NanTests, HexFloatTest,
::testing::ValuesIn( ::testing::ValuesIn(std::vector<std::pair<FloatProxy<float>, std::string>>({
std::vector<std::pair<FloatProxy<float>, std::string>>({ // Various NAN and INF cases
// Various NAN and INF cases {uint32_t(0xFF800000), "-0x1p+128"}, // -inf
{uint32_t(0xFF800000), "-0x1p+128"}, // -inf {uint32_t(0x7F800000), "0x1p+128"}, // inf
{uint32_t(0x7F800000), "0x1p+128"}, // inf {uint32_t(0xFFC00000), "-0x1.8p+128"}, // -nan
{uint32_t(0xFFC00000), "-0x1.8p+128"}, // -nan {uint32_t(0xFF800100), "-0x1.0002p+128"}, // -nan
{uint32_t(0xFF800100), "-0x1.0002p+128"}, // -nan {uint32_t(0xFF800c00), "-0x1.0018p+128"}, // -nan
{uint32_t(0xFF800c00), "-0x1.0018p+128"}, // -nan {uint32_t(0xFF80F000), "-0x1.01ep+128"}, // -nan
{uint32_t(0xFF80F000), "-0x1.01ep+128"}, // -nan {uint32_t(0xFFFFFFFF), "-0x1.fffffep+128"}, // -nan
{uint32_t(0xFFFFFFFF), "-0x1.fffffep+128"}, // -nan {uint32_t(0x7FC00000), "0x1.8p+128"}, // +nan
{uint32_t(0x7FC00000), "0x1.8p+128"}, // +nan {uint32_t(0x7F800100), "0x1.0002p+128"}, // +nan
{uint32_t(0x7F800100), "0x1.0002p+128"}, // +nan {uint32_t(0x7f800c00), "0x1.0018p+128"}, // +nan
{uint32_t(0x7f800c00), "0x1.0018p+128"}, // +nan {uint32_t(0x7F80F000), "0x1.01ep+128"}, // +nan
{uint32_t(0x7F80F000), "0x1.01ep+128"}, // +nan {uint32_t(0x7FFFFFFF), "0x1.fffffep+128"}, // +nan
{uint32_t(0x7FFFFFFF), "0x1.fffffep+128"}, // +nan })));
})));
TEST_P(DecodeHexFloatTest, DecodeCorrectly) { TEST_P(DecodeHexFloatTest, DecodeCorrectly) {
std::stringstream ss(std::get<0>(GetParam())); std::stringstream ss(std::get<0>(GetParam()));
@ -144,38 +142,35 @@ TEST_P(DecodeHexFloatTest, DecodeCorrectly) {
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
Float32DecodeTests, DecodeHexFloatTest, Float32DecodeTests, DecodeHexFloatTest,
::testing::ValuesIn( ::testing::ValuesIn(std::vector<std::pair<std::string, FloatProxy<float>>>({
std::vector<std::pair<std::string, FloatProxy<float>>>({ {"0x0p+000", 0.f},
{"0x0p+000", 0.f}, {"0x0p0", 0.f},
{"0x0p0", 0.f}, {"0x0p-0", 0.f},
{"0x0p-0", 0.f},
// flush to zero cases // flush to zero cases
{"0x1p-500", 0.f}, // Exponent underflows. {"0x1p-500", 0.f}, // Exponent underflows.
{"-0x1p-500", -0.f}, {"-0x1p-500", -0.f},
{"0x0.00000000001p-126", 0.f}, // Fraction causes underflow. {"0x0.00000000001p-126", 0.f}, // Fraction causes underflow.
{"-0x0.0000000001p-127", -0.f}, {"-0x0.0000000001p-127", -0.f},
{"-0x0.01p-142", {"-0x0.01p-142", -0.f}, // Fraction causes undeflow to underflow more.
-0.f}, // Fraction causes undeflow to underflow more. {"0x0.01p-142", 0.f},
{"0x0.01p-142", 0.f},
// Some floats that do not encode the same way as the decode. // Some floats that do not encode the same way as the decode.
{"0x2p+0", 2.f}, {"0x2p+0", 2.f},
{"0xFFp+0", 255.f}, {"0xFFp+0", 255.f},
{"0x0.8p+0", 0.5f}, {"0x0.8p+0", 0.5f},
{"0x0.4p+0", 0.25f}, {"0x0.4p+0", 0.25f},
}))); })));
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
Float32DecodeInfTests, DecodeHexFloatTest, Float32DecodeInfTests, DecodeHexFloatTest,
::testing::ValuesIn( ::testing::ValuesIn(std::vector<std::pair<std::string, FloatProxy<float>>>({
std::vector<std::pair<std::string, FloatProxy<float>>>({ // inf cases
// inf cases {"-0x1p+128", uint32_t(0xFF800000)}, // -inf
{"-0x1p+128", uint32_t(0xFF800000)}, // -inf {"0x32p+127", uint32_t(0x7F800000)}, // inf
{"0x32p+127", uint32_t(0x7F800000)}, // inf {"0x32p+500", uint32_t(0x7F800000)}, // inf
{"0x32p+500", uint32_t(0x7F800000)}, // inf {"-0x32p+127", uint32_t(0xFF800000)}, // -inf
{"-0x32p+127", uint32_t(0xFF800000)}, // -inf })));
})));
TEST(FloatProxy, ValidConversion) { TEST(FloatProxy, ValidConversion) {
EXPECT_THAT(FloatProxy<float>(1.f).getAsFloat(), Eq(1.0f)); EXPECT_THAT(FloatProxy<float>(1.f).getAsFloat(), Eq(1.0f));
@ -185,78 +180,44 @@ TEST(FloatProxy, ValidConversion) {
EXPECT_THAT(FloatProxy<float>(-0.f).getAsFloat(), Eq(-0.0f)); EXPECT_THAT(FloatProxy<float>(-0.f).getAsFloat(), Eq(-0.0f));
EXPECT_THAT(FloatProxy<float>(1.2e32f).getAsFloat(), Eq(1.2e32f)); EXPECT_THAT(FloatProxy<float>(1.2e32f).getAsFloat(), Eq(1.2e32f));
EXPECT_TRUE( EXPECT_TRUE(std::isinf(FloatProxy<float>(uint32_t(0xFF800000)).getAsFloat()));
std::isinf(FloatProxy<float>(uint32_t(0xFF800000)).getAsFloat())); EXPECT_TRUE(std::isinf(FloatProxy<float>(uint32_t(0x7F800000)).getAsFloat()));
EXPECT_TRUE( EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0xFFC00000)).getAsFloat()));
std::isinf(FloatProxy<float>(uint32_t(0x7F800000)).getAsFloat())); EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0xFF800100)).getAsFloat()));
EXPECT_TRUE( EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0xFF800c00)).getAsFloat()));
std::isnan(FloatProxy<float>(uint32_t(0xFFC00000)).getAsFloat())); EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0xFF80F000)).getAsFloat()));
EXPECT_TRUE( EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0xFFFFFFFF)).getAsFloat()));
std::isnan(FloatProxy<float>(uint32_t(0xFF800100)).getAsFloat())); EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7FC00000)).getAsFloat()));
EXPECT_TRUE( EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7F800100)).getAsFloat()));
std::isnan(FloatProxy<float>(uint32_t(0xFF800c00)).getAsFloat())); EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7f800c00)).getAsFloat()));
EXPECT_TRUE( EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7F80F000)).getAsFloat()));
std::isnan(FloatProxy<float>(uint32_t(0xFF80F000)).getAsFloat())); EXPECT_TRUE(std::isnan(FloatProxy<float>(uint32_t(0x7FFFFFFF)).getAsFloat()));
EXPECT_TRUE(
std::isnan(FloatProxy<float>(uint32_t(0xFFFFFFFF)).getAsFloat()));
EXPECT_TRUE(
std::isnan(FloatProxy<float>(uint32_t(0x7FC00000)).getAsFloat()));
EXPECT_TRUE(
std::isnan(FloatProxy<float>(uint32_t(0x7F800100)).getAsFloat()));
EXPECT_TRUE(
std::isnan(FloatProxy<float>(uint32_t(0x7f800c00)).getAsFloat()));
EXPECT_TRUE(
std::isnan(FloatProxy<float>(uint32_t(0x7F80F000)).getAsFloat()));
EXPECT_TRUE(
std::isnan(FloatProxy<float>(uint32_t(0x7FFFFFFF)).getAsFloat()));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800000)).data(), EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800000)).data(), Eq(0xFF800000));
Eq(0xFF800000)); EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800000)).data(), Eq(0x7F800000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800000)).data(), EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFC00000)).data(), Eq(0xFFC00000));
Eq(0x7F800000)); EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800100)).data(), Eq(0xFF800100));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFC00000)).data(), EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800c00)).data(), Eq(0xFF800c00));
Eq(0xFFC00000)); EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF80F000)).data(), Eq(0xFF80F000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800100)).data(), EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFFFFFFF)).data(), Eq(0xFFFFFFFF));
Eq(0xFF800100)); EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FC00000)).data(), Eq(0x7FC00000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF800c00)).data(), EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800100)).data(), Eq(0x7F800100));
Eq(0xFF800c00)); EXPECT_THAT(FloatProxy<float>(uint32_t(0x7f800c00)).data(), Eq(0x7f800c00));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFF80F000)).data(), EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F80F000)).data(), Eq(0x7F80F000));
Eq(0xFF80F000)); EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FFFFFFF)).data(), Eq(0x7FFFFFFF));
EXPECT_THAT(FloatProxy<float>(uint32_t(0xFFFFFFFF)).data(),
Eq(0xFFFFFFFF));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FC00000)).data(),
Eq(0x7FC00000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F800100)).data(),
Eq(0x7F800100));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7f800c00)).data(),
Eq(0x7f800c00));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7F80F000)).data(),
Eq(0x7F80F000));
EXPECT_THAT(FloatProxy<float>(uint32_t(0x7FFFFFFF)).data(),
Eq(0x7FFFFFFF));
} }
TEST(FloatProxy, Nan) { TEST(FloatProxy, Nan) {
EXPECT_TRUE( EXPECT_TRUE(FloatProxy<float>(uint32_t(0xFFC00000)).isNan());
FloatProxy<float>(uint32_t(0xFFC00000)).isNan()); EXPECT_TRUE(FloatProxy<float>(uint32_t(0xFF800100)).isNan());
EXPECT_TRUE( EXPECT_TRUE(FloatProxy<float>(uint32_t(0xFF800c00)).isNan());
FloatProxy<float>(uint32_t(0xFF800100)).isNan()); EXPECT_TRUE(FloatProxy<float>(uint32_t(0xFF80F000)).isNan());
EXPECT_TRUE( EXPECT_TRUE(FloatProxy<float>(uint32_t(0xFFFFFFFF)).isNan());
FloatProxy<float>(uint32_t(0xFF800c00)).isNan()); EXPECT_TRUE(FloatProxy<float>(uint32_t(0x7FC00000)).isNan());
EXPECT_TRUE( EXPECT_TRUE(FloatProxy<float>(uint32_t(0x7F800100)).isNan());
FloatProxy<float>(uint32_t(0xFF80F000)).isNan()); EXPECT_TRUE(FloatProxy<float>(uint32_t(0x7f800c00)).isNan());
EXPECT_TRUE( EXPECT_TRUE(FloatProxy<float>(uint32_t(0x7F80F000)).isNan());
FloatProxy<float>(uint32_t(0xFFFFFFFF)).isNan()); EXPECT_TRUE(FloatProxy<float>(uint32_t(0x7FFFFFFF)).isNan());
EXPECT_TRUE(
FloatProxy<float>(uint32_t(0x7FC00000)).isNan());
EXPECT_TRUE(
FloatProxy<float>(uint32_t(0x7F800100)).isNan());
EXPECT_TRUE(
FloatProxy<float>(uint32_t(0x7f800c00)).isNan());
EXPECT_TRUE(
FloatProxy<float>(uint32_t(0x7F80F000)).isNan());
EXPECT_TRUE(
FloatProxy<float>(uint32_t(0x7FFFFFFF)).isNan());
} }
TEST(FloatProxy, Negation) { TEST(FloatProxy, Negation) {
@ -275,9 +236,9 @@ TEST(FloatProxy, Negation) {
EXPECT_THAT( EXPECT_THAT(
(-FloatProxy<float>(std::numeric_limits<float>::infinity())).getAsFloat(), (-FloatProxy<float>(std::numeric_limits<float>::infinity())).getAsFloat(),
Eq(-std::numeric_limits<float>::infinity())); Eq(-std::numeric_limits<float>::infinity()));
EXPECT_THAT( EXPECT_THAT((-FloatProxy<float>(-std::numeric_limits<float>::infinity()))
(-FloatProxy<float>(-std::numeric_limits<float>::infinity())).getAsFloat(), .getAsFloat(),
Eq(std::numeric_limits<float>::infinity())); Eq(std::numeric_limits<float>::infinity()));
} }
// TODO(awoloszyn): Add double tests // TODO(awoloszyn): Add double tests

View File

@ -32,7 +32,7 @@
namespace { namespace {
TEST(NamedId, Default) { TEST(NamedId, Default) {
const char *spirv = R"( const char* spirv = R"(
OpCapability Shader OpCapability Shader
OpMemoryModel Logical Simple OpMemoryModel Logical Simple
OpEntryPoint Vertex %main "foo" OpEntryPoint Vertex %main "foo"

View File

@ -66,10 +66,11 @@ TEST_P(EnumCapabilityTest, Sample) {
// See SPIR-V Section 3.3 Execution Model // See SPIR-V Section 3.3 Execution Model
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
ExecutionModel, EnumCapabilityTest, ExecutionModel, EnumCapabilityTest,
::testing::ValuesIn( std::vector<EnumCapabilityCase>{ ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
CASE1(EXECUTION_MODEL, ExecutionModelVertex, Shader), CASE1(EXECUTION_MODEL, ExecutionModelVertex, Shader),
CASE1(EXECUTION_MODEL, ExecutionModelTessellationControl, Tessellation), CASE1(EXECUTION_MODEL, ExecutionModelTessellationControl, Tessellation),
CASE1(EXECUTION_MODEL, ExecutionModelTessellationEvaluation, Tessellation), CASE1(EXECUTION_MODEL, ExecutionModelTessellationEvaluation,
Tessellation),
CASE1(EXECUTION_MODEL, ExecutionModelGeometry, Geometry), CASE1(EXECUTION_MODEL, ExecutionModelGeometry, Geometry),
CASE1(EXECUTION_MODEL, ExecutionModelFragment, Shader), CASE1(EXECUTION_MODEL, ExecutionModelFragment, Shader),
CASE1(EXECUTION_MODEL, ExecutionModelGLCompute, Shader), CASE1(EXECUTION_MODEL, ExecutionModelGLCompute, Shader),
@ -86,13 +87,12 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// See SPIR-V Section 3.5 Memory Model // See SPIR-V Section 3.5 Memory Model
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(MemoryModel, EnumCapabilityTest,
MemoryModel, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE1(MEMORY_MODEL, MemoryModelSimple, Shader),
CASE1(MEMORY_MODEL, MemoryModelSimple, Shader), CASE1(MEMORY_MODEL, MemoryModelGLSL450, Shader),
CASE1(MEMORY_MODEL, MemoryModelGLSL450, Shader), CASE1(MEMORY_MODEL, MemoryModelOpenCL, Kernel),
CASE1(MEMORY_MODEL, MemoryModelOpenCL, Kernel), }));
}));
// See SPIR-V Section 3.6 Execution Mode // See SPIR-V Section 3.6 Execution Mode
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
@ -119,11 +119,13 @@ INSTANTIATE_TEST_CASE_P(
CASE1(EXECUTION_MODE, ExecutionModeInputPoints, Geometry), CASE1(EXECUTION_MODE, ExecutionModeInputPoints, Geometry),
CASE1(EXECUTION_MODE, ExecutionModeInputLines, Geometry), CASE1(EXECUTION_MODE, ExecutionModeInputLines, Geometry),
CASE1(EXECUTION_MODE, ExecutionModeInputLinesAdjacency, Geometry), CASE1(EXECUTION_MODE, ExecutionModeInputLinesAdjacency, Geometry),
CASE2(EXECUTION_MODE, ExecutionModeInputTriangles, Geometry, Tessellation), CASE2(EXECUTION_MODE, ExecutionModeInputTriangles, Geometry,
Tessellation),
CASE1(EXECUTION_MODE, ExecutionModeInputTrianglesAdjacency, Geometry), CASE1(EXECUTION_MODE, ExecutionModeInputTrianglesAdjacency, Geometry),
CASE1(EXECUTION_MODE, ExecutionModeInputQuads, Tessellation), CASE1(EXECUTION_MODE, ExecutionModeInputQuads, Tessellation),
CASE1(EXECUTION_MODE, ExecutionModeInputIsolines, Tessellation), CASE1(EXECUTION_MODE, ExecutionModeInputIsolines, Tessellation),
CASE2(EXECUTION_MODE, ExecutionModeOutputVertices, Geometry, Tessellation), CASE2(EXECUTION_MODE, ExecutionModeOutputVertices, Geometry,
Tessellation),
CASE1(EXECUTION_MODE, ExecutionModeOutputPoints, Geometry), CASE1(EXECUTION_MODE, ExecutionModeOutputPoints, Geometry),
CASE1(EXECUTION_MODE, ExecutionModeOutputLineStrip, Geometry), CASE1(EXECUTION_MODE, ExecutionModeOutputLineStrip, Geometry),
CASE1(EXECUTION_MODE, ExecutionModeOutputTriangleStrip, Geometry), CASE1(EXECUTION_MODE, ExecutionModeOutputTriangleStrip, Geometry),
@ -154,10 +156,8 @@ INSTANTIATE_TEST_CASE_P(
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
Dim, EnumCapabilityTest, Dim, EnumCapabilityTest,
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
CASE1(DIMENSIONALITY, Dim1D, Sampled1D), CASE1(DIMENSIONALITY, Dim1D, Sampled1D), CASE0(DIMENSIONALITY, Dim2D),
CASE0(DIMENSIONALITY, Dim2D), CASE0(DIMENSIONALITY, Dim3D), CASE1(DIMENSIONALITY, DimCube, Shader),
CASE0(DIMENSIONALITY, Dim3D),
CASE1(DIMENSIONALITY, DimCube, Shader),
CASE1(DIMENSIONALITY, DimRect, SampledRect), CASE1(DIMENSIONALITY, DimRect, SampledRect),
CASE1(DIMENSIONALITY, DimBuffer, SampledBuffer), CASE1(DIMENSIONALITY, DimBuffer, SampledBuffer),
CASE1(DIMENSIONALITY, DimInputTarget, InputTarget), CASE1(DIMENSIONALITY, DimInputTarget, InputTarget),
@ -168,10 +168,12 @@ INSTANTIATE_TEST_CASE_P(
SamplerAddressingMode, EnumCapabilityTest, SamplerAddressingMode, EnumCapabilityTest,
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeNone, Kernel), CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeNone, Kernel),
CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeClampToEdge, Kernel), CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeClampToEdge,
Kernel),
CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeClamp, Kernel), CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeClamp, Kernel),
CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeRepeat, Kernel), CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeRepeat, Kernel),
CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeRepeatMirrored, Kernel), CASE1(SAMPLER_ADDRESSING_MODE, SamplerAddressingModeRepeatMirrored,
Kernel),
})); }));
// See SPIR-V Section 3.10 Sampler Filter Mode // See SPIR-V Section 3.10 Sampler Filter Mode
@ -261,15 +263,21 @@ INSTANTIATE_TEST_CASE_P(
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSnormInt16, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSnormInt16, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt8, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt8, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt16, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt16, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormShort565, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormShort565,
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormShort555, Kernel), Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt101010, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormShort555,
Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt101010,
Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSignedInt8, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSignedInt8, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSignedInt16, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSignedInt16, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSignedInt32, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeSignedInt32, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnsignedInt8, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnsignedInt8,
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnsignedInt16, Kernel), Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnsignedInt32, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnsignedInt16,
Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnsignedInt32,
Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeHalfFloat, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeHalfFloat, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeFloat, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeFloat, Kernel),
CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt24, Kernel), CASE1(IMAGE_CHANNEL_DATA_TYPE, ImageChannelDataTypeUnormInt24, Kernel),
@ -303,22 +311,20 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// See SPIR-V Section 3.16 FP Rounding Mode // See SPIR-V Section 3.16 FP Rounding Mode
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(FPRoundingMode, EnumCapabilityTest,
FPRoundingMode, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE1(FP_ROUNDING_MODE, FPRoundingModeRTE, Kernel),
CASE1(FP_ROUNDING_MODE, FPRoundingModeRTE, Kernel), CASE1(FP_ROUNDING_MODE, FPRoundingModeRTZ, Kernel),
CASE1(FP_ROUNDING_MODE, FPRoundingModeRTZ, Kernel), CASE1(FP_ROUNDING_MODE, FPRoundingModeRTP, Kernel),
CASE1(FP_ROUNDING_MODE, FPRoundingModeRTP, Kernel), CASE1(FP_ROUNDING_MODE, FPRoundingModeRTN, Kernel),
CASE1(FP_ROUNDING_MODE, FPRoundingModeRTN, Kernel), }));
}));
// See SPIR-V Section 3.17 Linkage Type // See SPIR-V Section 3.17 Linkage Type
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(LinkageType, EnumCapabilityTest,
LinkageType, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE1(LINKAGE_TYPE, LinkageTypeExport, Linkage),
CASE1(LINKAGE_TYPE, LinkageTypeExport, Linkage), CASE1(LINKAGE_TYPE, LinkageTypeImport, Linkage),
CASE1(LINKAGE_TYPE, LinkageTypeImport, Linkage), }));
}));
// See SPIR-V Section 3.18 Access Qualifier // See SPIR-V Section 3.18 Access Qualifier
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
@ -330,18 +336,26 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// See SPIR-V Section 3.19 Function Parameter Attribute // See SPIR-V Section 3.19 Function Parameter Attribute
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(FunctionParameterAttribute, EnumCapabilityTest,
FunctionParameterAttribute, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeZext, Kernel), FunctionParameterAttributeZext, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeSext, Kernel), CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeByVal, Kernel), FunctionParameterAttributeSext, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeSret, Kernel), CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeNoAlias, Kernel), FunctionParameterAttributeByVal, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeNoCapture, Kernel), CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeNoWrite, Kernel), FunctionParameterAttributeSret, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE, FunctionParameterAttributeNoReadWrite, Kernel), CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
})); FunctionParameterAttributeNoAlias, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
FunctionParameterAttributeNoCapture, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
FunctionParameterAttributeNoWrite, Kernel),
CASE1(FUNCTION_PARAMETER_ATTRIBUTE,
FunctionParameterAttributeNoReadWrite,
Kernel),
}));
// See SPIR-V Section 3.20 Decoration // See SPIR-V Section 3.20 Decoration
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
@ -390,7 +404,9 @@ INSTANTIATE_TEST_CASE_P(
CASE1(DECORATION, DecorationFPFastMathMode, Kernel), CASE1(DECORATION, DecorationFPFastMathMode, Kernel),
CASE1(DECORATION, DecorationLinkageAttributes, Linkage), CASE1(DECORATION, DecorationLinkageAttributes, Linkage),
CASE1(DECORATION, DecorationNoContraction, Shader), CASE1(DECORATION, DecorationNoContraction, Shader),
CASE1(DECORATION, DecorationInputTargetIndex, Shader), // TODO(dneto): Should be InputTarget. Fixed in 1.0 Rev 2 CASE1(
DECORATION, DecorationInputTargetIndex,
Shader), // TODO(dneto): Should be InputTarget. Fixed in 1.0 Rev 2
CASE1(DECORATION, DecorationAlignment, Kernel), CASE1(DECORATION, DecorationAlignment, Kernel),
})); }));
@ -454,30 +470,30 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// See SPIR-V Section 3.23 Loop Control // See SPIR-V Section 3.23 Loop Control
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(LoopControl, EnumCapabilityTest,
LoopControl, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE0(LOOP_CONTROL, LoopControlMaskNone),
CASE0(LOOP_CONTROL, LoopControlMaskNone), CASE0(LOOP_CONTROL, LoopControlUnrollMask),
CASE0(LOOP_CONTROL, LoopControlUnrollMask), CASE0(LOOP_CONTROL, LoopControlDontUnrollMask),
CASE0(LOOP_CONTROL, LoopControlDontUnrollMask), }));
}));
// See SPIR-V Section 3.24 Function Control // See SPIR-V Section 3.24 Function Control
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(FunctionControl, EnumCapabilityTest,
FunctionControl, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE0(FUNCTION_CONTROL, FunctionControlMaskNone),
CASE0(FUNCTION_CONTROL, FunctionControlMaskNone), CASE0(FUNCTION_CONTROL, FunctionControlInlineMask),
CASE0(FUNCTION_CONTROL, FunctionControlInlineMask), CASE0(FUNCTION_CONTROL,
CASE0(FUNCTION_CONTROL, FunctionControlDontInlineMask), FunctionControlDontInlineMask),
CASE0(FUNCTION_CONTROL, FunctionControlPureMask), CASE0(FUNCTION_CONTROL, FunctionControlPureMask),
CASE0(FUNCTION_CONTROL, FunctionControlConstMask), CASE0(FUNCTION_CONTROL, FunctionControlConstMask),
})); }));
// See SPIR-V Section 3.25 Memory Semantics <id> // See SPIR-V Section 3.25 Memory Semantics <id>
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
MemorySemantics, EnumCapabilityTest, MemorySemantics, EnumCapabilityTest,
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
// TODO(dneto): This enum is expanded and renumbered in SPIR-V 1.0 Rev 1. // TODO(dneto): This enum is expanded and renumbered in SPIR-V 1.0 Rev
// 1.
CASE0(MEMORY_SEMANTICS, MemorySemanticsMaskNone), CASE0(MEMORY_SEMANTICS, MemorySemanticsMaskNone),
CASE0(MEMORY_SEMANTICS, MemorySemanticsAcquireMask), CASE0(MEMORY_SEMANTICS, MemorySemanticsAcquireMask),
CASE0(MEMORY_SEMANTICS, MemorySemanticsReleaseMask), CASE0(MEMORY_SEMANTICS, MemorySemanticsReleaseMask),
@ -501,15 +517,14 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// See SPIR-V Section 3.27 Scope <id> // See SPIR-V Section 3.27 Scope <id>
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(Scope, EnumCapabilityTest,
Scope, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE0(EXECUTION_SCOPE, ScopeCrossDevice),
CASE0(EXECUTION_SCOPE, ScopeCrossDevice), CASE0(EXECUTION_SCOPE, ScopeDevice),
CASE0(EXECUTION_SCOPE, ScopeDevice), CASE0(EXECUTION_SCOPE, ScopeWorkgroup),
CASE0(EXECUTION_SCOPE, ScopeWorkgroup), CASE0(EXECUTION_SCOPE, ScopeSubgroup),
CASE0(EXECUTION_SCOPE, ScopeSubgroup), CASE0(EXECUTION_SCOPE, ScopeInvocation),
CASE0(EXECUTION_SCOPE, ScopeInvocation), }));
}));
// See SPIR-V Section 3.28 Group Operation // See SPIR-V Section 3.28 Group Operation
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
@ -530,12 +545,13 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// See SPIR-V Section 3.30 Kernel Profiling Info // See SPIR-V Section 3.30 Kernel Profiling Info
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(KernelProfilingInfo, EnumCapabilityTest,
KernelProfilingInfo, EnumCapabilityTest, ::testing::ValuesIn(std::vector<EnumCapabilityCase>{
::testing::ValuesIn(std::vector<EnumCapabilityCase>{ CASE0(KERNEL_PROFILING_INFO,
CASE0(KERNEL_PROFILING_INFO, KernelProfilingInfoMaskNone), KernelProfilingInfoMaskNone),
CASE1(KERNEL_PROFILING_INFO, KernelProfilingInfoCmdExecTimeMask, Kernel), CASE1(KERNEL_PROFILING_INFO,
})); KernelProfilingInfoCmdExecTimeMask, Kernel),
}));
// See SPIR-V Section 3.31 Capability // See SPIR-V Section 3.31 Capability
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(

View File

@ -137,8 +137,7 @@ class TextToBinaryTestBase : public T {
// is then decoded. This is expected to fail. // is then decoded. This is expected to fail.
// Returns the error message. // Returns the error message.
std::string EncodeSuccessfullyDecodeFailed( std::string EncodeSuccessfullyDecodeFailed(
const std::string& text, const std::string& text, const SpirvVector& words_to_append) {
const SpirvVector& words_to_append) {
SpirvVector code = spvtest::Concatenate( SpirvVector code = spvtest::Concatenate(
{CompileSuccessfully(text, SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT), {CompileSuccessfully(text, SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT),
words_to_append}); words_to_append});

View File

@ -71,8 +71,8 @@ TEST(TextAdvance, LeadingWhitespaceAfterCommentLine) {
AutoText input("; comment\n \t \tWord"); AutoText input("; comment\n \t \tWord");
AssemblyContext data(input, nullptr); AssemblyContext data(input, nullptr);
ASSERT_EQ(SPV_SUCCESS, data.advance()); ASSERT_EQ(SPV_SUCCESS, data.advance());
ASSERT_EQ(4, data.position().column); ASSERT_EQ(4, data.position().column);
ASSERT_EQ(1, data.position().line); ASSERT_EQ(1, data.position().line);
ASSERT_EQ(14, data.position().index); ASSERT_EQ(14, data.position().index);
} }

View File

@ -31,7 +31,6 @@
#include <string> #include <string>
using ::testing::Eq; using ::testing::Eq;
namespace { namespace {
@ -119,26 +118,25 @@ TEST_P(GoodStringTest, GoodStrings) {
INSTANTIATE_TEST_CASE_P( INSTANTIATE_TEST_CASE_P(
TextLiteral, GoodStringTest, TextLiteral, GoodStringTest,
::testing::ValuesIn(std::vector<std::pair<const char*, const char*>>{ ::testing::ValuesIn(std::vector<std::pair<const char*, const char*>>{
{R"("-")", "-"}, {R"("-")", "-"},
{R"("--")", "--"}, {R"("--")", "--"},
{R"("1-2")", "1-2"}, {R"("1-2")", "1-2"},
{R"("123a")", "123a"}, {R"("123a")", "123a"},
{R"("12.2.3")", "12.2.3"}, {R"("12.2.3")", "12.2.3"},
{R"("\"")", "\""}, {R"("\"")", "\""},
{R"("\\")", "\\"}, {R"("\\")", "\\"},
{"\"\\foo\nbar\"", "foo\nbar"}, {"\"\\foo\nbar\"", "foo\nbar"},
{"\"\\foo\\\nbar\"", "foo\nbar"}, {"\"\\foo\\\nbar\"", "foo\nbar"},
{"\"\xE4\xBA\xB2\"", "\xE4\xBA\xB2"}, {"\"\xE4\xBA\xB2\"", "\xE4\xBA\xB2"},
{"\"\\\xE4\xBA\xB2\"", "\xE4\xBA\xB2"}, {"\"\\\xE4\xBA\xB2\"", "\xE4\xBA\xB2"},
{"\"this \\\" and this \\\\ and \\\xE4\xBA\xB2\"", {"\"this \\\" and this \\\\ and \\\xE4\xBA\xB2\"",
"this \" and this \\ and \xE4\xBA\xB2"} "this \" and this \\ and \xE4\xBA\xB2"}}));
}));
TEST(TextLiteral, StringTooLong) { TEST(TextLiteral, StringTooLong) {
spv_literal_t l; spv_literal_t l;
std::string too_long = std::string("\"") + std::string too_long =
std::string(SPV_LIMIT_LITERAL_STRING_BYTES_MAX + 1, 'a') + std::string("\"") +
"\""; std::string(SPV_LIMIT_LITERAL_STRING_BYTES_MAX + 1, 'a') + "\"";
EXPECT_EQ(SPV_ERROR_OUT_OF_MEMORY, spvTextToLiteral(too_long.data(), &l)); EXPECT_EQ(SPV_ERROR_OUT_OF_MEMORY, spvTextToLiteral(too_long.data(), &l));
} }
@ -175,19 +173,15 @@ struct TextLiteralCase {
std::vector<uint32_t> expected_values; std::vector<uint32_t> expected_values;
}; };
using IntegerTest = spvtest::TextToBinaryTestBase< using IntegerTest =
::testing::TestWithParam<TextLiteralCase>>; spvtest::TextToBinaryTestBase<::testing::TestWithParam<TextLiteralCase>>;
std::vector<uint32_t> successfulEncode(const TextLiteralCase& test, std::vector<uint32_t> successfulEncode(const TextLiteralCase& test,
libspirv::IdTypeClass type) { libspirv::IdTypeClass type) {
spv_instruction_t inst; spv_instruction_t inst;
spv_diagnostic diagnostic; spv_diagnostic diagnostic;
libspirv::IdType expected_type { libspirv::IdType expected_type{test.bitwidth, test.is_signed, type};
test.bitwidth, EXPECT_EQ(SPV_SUCCESS,
test.is_signed,
type
};
EXPECT_EQ(SPV_SUCCESS,
libspirv::AssemblyContext(nullptr, &diagnostic) libspirv::AssemblyContext(nullptr, &diagnostic)
.binaryEncodeNumericLiteral(test.text, SPV_ERROR_INVALID_TEXT, .binaryEncodeNumericLiteral(test.text, SPV_ERROR_INVALID_TEXT,
expected_type, &inst)) expected_type, &inst))
@ -199,11 +193,7 @@ std::string failedEncode(const TextLiteralCase& test,
libspirv::IdTypeClass type) { libspirv::IdTypeClass type) {
spv_instruction_t inst; spv_instruction_t inst;
spv_diagnostic diagnostic; spv_diagnostic diagnostic;
libspirv::IdType expected_type { libspirv::IdType expected_type{test.bitwidth, test.is_signed, type};
test.bitwidth,
test.is_signed,
type
};
EXPECT_EQ(SPV_ERROR_INVALID_TEXT, EXPECT_EQ(SPV_ERROR_INVALID_TEXT,
libspirv::AssemblyContext(nullptr, &diagnostic) libspirv::AssemblyContext(nullptr, &diagnostic)
.binaryEncodeNumericLiteral(test.text, SPV_ERROR_INVALID_TEXT, .binaryEncodeNumericLiteral(test.text, SPV_ERROR_INVALID_TEXT,
@ -395,8 +385,7 @@ TEST(OverflowIntegerParse, Decimal) {
TEST(OverflowIntegerParse, Hex) { TEST(OverflowIntegerParse, Hex) {
std::string input = "0x10000000000000000"; std::string input = "0x10000000000000000";
std::string expected_message = std::string expected_message = "Invalid unsigned integer literal: " + input;
"Invalid unsigned integer literal: " + input;
EXPECT_THAT(failedEncode(Make_Bad_Signed(64, input.c_str()), EXPECT_THAT(failedEncode(Make_Bad_Signed(64, input.c_str()),
libspirv::IdTypeClass::kScalarIntegerType), libspirv::IdTypeClass::kScalarIntegerType),
Eq(expected_message)); Eq(expected_message));

View File

@ -34,12 +34,9 @@ using libspirv::AssemblyContext;
using spvtest::AutoText; using spvtest::AutoText;
TEST(TextStartsWithOp, YesAtStart) { TEST(TextStartsWithOp, YesAtStart) {
EXPECT_TRUE( EXPECT_TRUE(AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst());
AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst()); EXPECT_TRUE(AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst());
EXPECT_TRUE( EXPECT_TRUE(AssemblyContext(AutoText("OpEnCL"), nullptr).isStartOfNewInst());
AssemblyContext(AutoText("OpFoo"), nullptr).isStartOfNewInst());
EXPECT_TRUE(
AssemblyContext(AutoText("OpEnCL"), nullptr).isStartOfNewInst());
} }
TEST(TextStartsWithOp, YesAtMiddle) { TEST(TextStartsWithOp, YesAtMiddle) {
@ -62,30 +59,25 @@ TEST(TextStartsWithOp, NoIfTooFar) {
} }
TEST(TextStartsWithOp, NoRegular) { TEST(TextStartsWithOp, NoRegular) {
EXPECT_FALSE(AssemblyContext(AutoText("Fee Fi Fo Fum"), nullptr)
.isStartOfNewInst());
EXPECT_FALSE( EXPECT_FALSE(
AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst()); AssemblyContext(AutoText("Fee Fi Fo Fum"), nullptr).isStartOfNewInst());
EXPECT_FALSE( EXPECT_FALSE(AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst());
AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst()); EXPECT_FALSE(AssemblyContext(AutoText("123456"), nullptr).isStartOfNewInst());
EXPECT_FALSE( EXPECT_FALSE(AssemblyContext(AutoText("OpenCL"), nullptr).isStartOfNewInst());
AssemblyContext(AutoText("OpenCL"), nullptr).isStartOfNewInst());
} }
TEST(TextStartsWithOp, YesForValueGenerationForm) { TEST(TextStartsWithOp, YesForValueGenerationForm) {
EXPECT_TRUE(AssemblyContext(AutoText("%foo = OpAdd"), nullptr) EXPECT_TRUE(
.isStartOfNewInst()); AssemblyContext(AutoText("%foo = OpAdd"), nullptr).isStartOfNewInst());
EXPECT_TRUE(AssemblyContext(AutoText("%foo = OpAdd"), nullptr) EXPECT_TRUE(
.isStartOfNewInst()); AssemblyContext(AutoText("%foo = OpAdd"), nullptr).isStartOfNewInst());
} }
TEST(TextStartsWithOp, NoForNearlyValueGeneration) { TEST(TextStartsWithOp, NoForNearlyValueGeneration) {
EXPECT_FALSE( EXPECT_FALSE(
AssemblyContext(AutoText("%foo = "), nullptr).isStartOfNewInst()); AssemblyContext(AutoText("%foo = "), nullptr).isStartOfNewInst());
EXPECT_FALSE( EXPECT_FALSE(AssemblyContext(AutoText("%foo "), nullptr).isStartOfNewInst());
AssemblyContext(AutoText("%foo "), nullptr).isStartOfNewInst()); EXPECT_FALSE(AssemblyContext(AutoText("%foo"), nullptr).isStartOfNewInst());
EXPECT_FALSE(
AssemblyContext(AutoText("%foo"), nullptr).isStartOfNewInst());
} }
} // anonymous namespace } // anonymous namespace

View File

@ -130,7 +130,7 @@ TEST_P(OpDecorateEnumTest, AnyEnumDecoration) {
"OpDecorate %1 " + GetParam().enum_name + " " + GetParam().name; "OpDecorate %1 " + GetParam().enum_name + " " + GetParam().name;
EXPECT_THAT(CompiledInstructions(input), EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(SpvOpDecorate, {1, GetParam().enum_value, Eq(MakeInstruction(SpvOpDecorate, {1, GetParam().enum_value,
GetParam().value}))); GetParam().value})));
} }
// Test OpDecorate BuiltIn. // Test OpDecorate BuiltIn.

View File

@ -57,8 +57,7 @@ TEST_F(OpMemoryBarrier, BadMissingScopeId) {
TEST_F(OpMemoryBarrier, BadInvalidScopeId) { TEST_F(OpMemoryBarrier, BadInvalidScopeId) {
const std::string input = "OpMemoryBarrier 99\n"; const std::string input = "OpMemoryBarrier 99\n";
EXPECT_THAT(CompileFailure(input), EXPECT_THAT(CompileFailure(input), Eq("Expected id to start with %."));
Eq("Expected id to start with %."));
} }
TEST_F(OpMemoryBarrier, BadMissingMemorySemanticsId) { TEST_F(OpMemoryBarrier, BadMissingMemorySemanticsId) {
@ -69,8 +68,7 @@ TEST_F(OpMemoryBarrier, BadMissingMemorySemanticsId) {
TEST_F(OpMemoryBarrier, BadInvalidMemorySemanticsId) { TEST_F(OpMemoryBarrier, BadInvalidMemorySemanticsId) {
const std::string input = "OpMemoryBarrier %scope 14\n"; const std::string input = "OpMemoryBarrier %scope 14\n";
EXPECT_THAT(CompileFailure(input), EXPECT_THAT(CompileFailure(input), Eq("Expected id to start with %."));
Eq("Expected id to start with %."));
} }
// TODO(dneto): OpControlBarrier // TODO(dneto): OpControlBarrier

View File

@ -219,11 +219,10 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// clang-format on // clang-format on
using OpSpecConstantValidTest = spvtest::TextToBinaryTestBase< using OpSpecConstantValidTest =
::testing::TestWithParam<ConstantTestCase>>; spvtest::TextToBinaryTestBase<::testing::TestWithParam<ConstantTestCase>>;
TEST_P(OpSpecConstantValidTest, ValidTypes) TEST_P(OpSpecConstantValidTest, ValidTypes) {
{
const std::string input = "%1 = " + GetParam().constant_type + const std::string input = "%1 = " + GetParam().constant_type +
"\n" "\n"
"%2 = OpSpecConstant %1 " + "%2 = OpSpecConstant %1 " +
@ -289,17 +288,16 @@ INSTANTIATE_TEST_CASE_P(
})); }));
// clang-format on // clang-format on
using OpSpecConstantInvalidTypeTest = spvtest::TextToBinaryTestBase< using OpSpecConstantInvalidTypeTest =
::testing::TestWithParam<std::string>>; spvtest::TextToBinaryTestBase<::testing::TestWithParam<std::string>>;
TEST_P(OpSpecConstantInvalidTypeTest, InvalidTypes) TEST_P(OpSpecConstantInvalidTypeTest, InvalidTypes) {
{
const std::string input = "%1 = " + GetParam() + const std::string input = "%1 = " + GetParam() +
"\n" "\n"
"%2 = OpSpecConstant %1 0\n"; "%2 = OpSpecConstant %1 0\n";
EXPECT_THAT( EXPECT_THAT(CompileFailure(input),
CompileFailure(input), Eq("Type for SpecConstant must be a scalar floating point or "
Eq("Type for SpecConstant must be a scalar floating point or integer type")); "integer type"));
} }
// clang-format off // clang-format off
@ -339,12 +337,12 @@ const int64_t kMaxSigned48Bit = (int64_t(1) << 47) - 1;
const int64_t kMinSigned48Bit = -kMaxSigned48Bit - 1; const int64_t kMinSigned48Bit = -kMaxSigned48Bit - 1;
TEST_P(RoundTripTest, Sample) { TEST_P(RoundTripTest, Sample) {
EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), EXPECT_THAT(EncodeAndDecodeSuccessfully(GetParam()), Eq(GetParam()));
Eq(GetParam()));
} }
// TODO(dneto): Enable support once this works. // TODO(dneto): Enable support once this works.
INSTANTIATE_TEST_CASE_P(DISABLED_OpConstantRoundTrip, RoundTripTest, INSTANTIATE_TEST_CASE_P(
DISABLED_OpConstantRoundTrip, RoundTripTest,
::testing::ValuesIn(std::vector<std::string>{ ::testing::ValuesIn(std::vector<std::string>{
// 16 bit // 16 bit
"%1 = OpTypeInt 16 0\n%2 = OpConstant %1 0\n", "%1 = OpTypeInt 16 0\n%2 = OpConstant %1 0\n",
@ -387,7 +385,8 @@ INSTANTIATE_TEST_CASE_P(DISABLED_OpConstantRoundTrip, RoundTripTest,
})); }));
// TODO(dneto): Enable support once this works. // TODO(dneto): Enable support once this works.
INSTANTIATE_TEST_CASE_P(DISABLED_OpSpecConstantRoundTrip, RoundTripTest, INSTANTIATE_TEST_CASE_P(
DISABLED_OpSpecConstantRoundTrip, RoundTripTest,
::testing::ValuesIn(std::vector<std::string>{ ::testing::ValuesIn(std::vector<std::string>{
// 16 bit // 16 bit
"%1 = OpTypeInt 16 0\n%2 = OpSpecConstant %1 0\n", "%1 = OpTypeInt 16 0\n%2 = OpSpecConstant %1 0\n",

View File

@ -84,9 +84,8 @@ using OpLoopMergeTest = spvtest::TextToBinaryTestBase<
TEST_P(OpLoopMergeTest, AnySingleLoopControlMask) { TEST_P(OpLoopMergeTest, AnySingleLoopControlMask) {
const std::string input = "OpLoopMerge %merge %continue " + GetParam().name(); const std::string input = "OpLoopMerge %merge %continue " + GetParam().name();
EXPECT_THAT( EXPECT_THAT(CompiledInstructions(input),
CompiledInstructions(input), Eq(MakeInstruction(SpvOpLoopMerge, {1, 2, GetParam().value()})));
Eq(MakeInstruction(SpvOpLoopMerge, {1, 2, GetParam().value()})));
} }
// clang-format off // clang-format off

View File

@ -74,10 +74,9 @@ TEST_P(OpSourceTest, AnyLanguage) {
const std::string input = std::string("OpSource ") + const std::string input = std::string("OpSource ") +
GetParam().language_name + " " + GetParam().language_name + " " +
std::to_string(GetParam().version); std::to_string(GetParam().version);
EXPECT_THAT( EXPECT_THAT(CompiledInstructions(input),
CompiledInstructions(input), Eq(MakeInstruction(SpvOpSource, {GetParam().get_language_value(),
Eq(MakeInstruction(SpvOpSource, {GetParam().get_language_value(), GetParam().version})));
GetParam().version})));
} }
INSTANTIATE_TEST_CASE_P(TextToBinaryTestDebug, OpSourceTest, INSTANTIATE_TEST_CASE_P(TextToBinaryTestDebug, OpSourceTest,
@ -100,10 +99,9 @@ TEST_F(TextToBinaryTest, OpSourceAcceptsOptionalSourceText) {
std::string fake_source = "To be or not to be"; std::string fake_source = "To be or not to be";
const std::string input = const std::string input =
"OpSource GLSL 450 %file_id \"" + fake_source + "\""; "OpSource GLSL 450 %file_id \"" + fake_source + "\"";
EXPECT_THAT( EXPECT_THAT(CompiledInstructions(input),
CompiledInstructions(input), Eq(MakeInstruction(SpvOpSource, {SpvSourceLanguageGLSL, 450, 1},
Eq(MakeInstruction(SpvOpSource, {SpvSourceLanguageGLSL, 450, 1}, MakeVector(fake_source))));
MakeVector(fake_source))));
}; };
// Test OpSourceContinued // Test OpSourceContinued

View File

@ -64,13 +64,13 @@ TEST_P(OpMemoryModelTest, AnyMemoryModelCase) {
EXPECT_THAT( EXPECT_THAT(
CompiledInstructions(input), CompiledInstructions(input),
Eq(MakeInstruction(SpvOpMemoryModel, {GetParam().get_addressing_value(), Eq(MakeInstruction(SpvOpMemoryModel, {GetParam().get_addressing_value(),
GetParam().get_memory_value()}))); GetParam().get_memory_value()})));
} }
#define CASE(ADDRESSING, MEMORY) \ #define CASE(ADDRESSING, MEMORY) \
{ \ { \
SpvAddressingModel##ADDRESSING, #ADDRESSING, SpvMemoryModel##MEMORY, \ SpvAddressingModel##ADDRESSING, #ADDRESSING, SpvMemoryModel##MEMORY, \
#MEMORY \ #MEMORY \
} }
// clang-format off // clang-format off
INSTANTIATE_TEST_CASE_P(TextToBinaryMemoryModel, OpMemoryModelTest, INSTANTIATE_TEST_CASE_P(TextToBinaryMemoryModel, OpMemoryModelTest,
@ -112,10 +112,10 @@ TEST_P(OpEntryPointTest, AnyEntryPointCase) {
// TODO(dneto): utf-8, escaping, quoting cases for entry point name. // TODO(dneto): utf-8, escaping, quoting cases for entry point name.
const std::string input = "OpEntryPoint " + GetParam().execution_name + const std::string input = "OpEntryPoint " + GetParam().execution_name +
" %1 \"" + GetParam().entry_point_name + "\""; " %1 \"" + GetParam().entry_point_name + "\"";
EXPECT_THAT(CompiledInstructions(input), EXPECT_THAT(
Eq(MakeInstruction(SpvOpEntryPoint, CompiledInstructions(input),
{GetParam().get_execution_value(), 1}, Eq(MakeInstruction(SpvOpEntryPoint, {GetParam().get_execution_value(), 1},
MakeVector(GetParam().entry_point_name)))); MakeVector(GetParam().entry_point_name))));
} }
// clang-format off // clang-format off

View File

@ -48,8 +48,8 @@ TEST_P(DimTest, AnyDim) {
GetParam().name() + " 2 3 0 4 Rgba8"; GetParam().name() + " 2 3 0 4 Rgba8";
EXPECT_THAT( EXPECT_THAT(
CompiledInstructions(input), CompiledInstructions(input),
Eq(MakeInstruction(SpvOpTypeImage, {1, 2, GetParam().value(), 2, 3, 0, Eq(MakeInstruction(SpvOpTypeImage, {1, 2, GetParam().value(), 2, 3, 0, 4,
4, SpvImageFormatRgba8}))); SpvImageFormatRgba8})));
} }
// clang-format off // clang-format off
@ -82,8 +82,8 @@ TEST_P(ImageFormatTest, AnyImageFormat) {
const std::string input = const std::string input =
"%imageType = OpTypeImage %sampledType 1D 2 3 0 4 " + GetParam().name(); "%imageType = OpTypeImage %sampledType 1D 2 3 0 4 " + GetParam().name();
EXPECT_THAT(CompiledInstructions(input), EXPECT_THAT(CompiledInstructions(input),
Eq(MakeInstruction(SpvOpTypeImage, {1, 2, SpvDim1D, 2, 3, 0, Eq(MakeInstruction(SpvOpTypeImage, {1, 2, SpvDim1D, 2, 3, 0, 4,
4, GetParam().value()}))); GetParam().value()})));
} }
// clang-format off // clang-format off

View File

@ -49,14 +49,10 @@ TEST(GetWord, Simple) {
EXPECT_EQ("", AssemblyContext(AutoText("\na"), nullptr).getWord()); EXPECT_EQ("", AssemblyContext(AutoText("\na"), nullptr).getWord());
EXPECT_EQ("abc", AssemblyContext(AutoText("abc"), nullptr).getWord()); EXPECT_EQ("abc", AssemblyContext(AutoText("abc"), nullptr).getWord());
EXPECT_EQ("abc", AssemblyContext(AutoText("abc "), nullptr).getWord()); EXPECT_EQ("abc", AssemblyContext(AutoText("abc "), nullptr).getWord());
EXPECT_EQ("abc", EXPECT_EQ("abc", AssemblyContext(AutoText("abc\t"), nullptr).getWord());
AssemblyContext(AutoText("abc\t"), nullptr).getWord()); EXPECT_EQ("abc", AssemblyContext(AutoText("abc\r"), nullptr).getWord());
EXPECT_EQ("abc", EXPECT_EQ("abc", AssemblyContext(AutoText("abc\v"), nullptr).getWord());
AssemblyContext(AutoText("abc\r"), nullptr).getWord()); EXPECT_EQ("abc", AssemblyContext(AutoText("abc\n"), nullptr).getWord());
EXPECT_EQ("abc",
AssemblyContext(AutoText("abc\v"), nullptr).getWord());
EXPECT_EQ("abc",
AssemblyContext(AutoText("abc\n"), nullptr).getWord());
} }
// An mask parsing test case. // An mask parsing test case.
@ -603,7 +599,8 @@ TEST(AssemblyContextParseMessages, Errors) {
int16_t i16; int16_t i16;
// No message is generated for a failure to parse an optional value. // No message is generated for a failure to parse an optional value.
EXPECT_EQ(SPV_FAILED_MATCH, context.parseNumber("abc", ec, &i16, "bad narrow int: ")); EXPECT_EQ(SPV_FAILED_MATCH,
context.parseNumber("abc", ec, &i16, "bad narrow int: "));
EXPECT_EQ(nullptr, diag); EXPECT_EQ(nullptr, diag);
// For a required value, use the message fragment. // For a required value, use the message fragment.

View File

@ -85,12 +85,11 @@ TEST(TextWordGet, MultipleWords) {
AssemblyContext data(input, nullptr); AssemblyContext data(input, nullptr);
spv_position_t endPosition = {}; spv_position_t endPosition = {};
const char *words[] = {"Words", "in", "a", "sentence"}; const char* words[] = {"Words", "in", "a", "sentence"};
std::string word; std::string word;
for (uint32_t wordIndex = 0; wordIndex < 4; ++wordIndex) { for (uint32_t wordIndex = 0; wordIndex < 4; ++wordIndex) {
ASSERT_EQ(SPV_SUCCESS, ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
data.getWord(word, &endPosition));
ASSERT_EQ(strlen(words[wordIndex]), ASSERT_EQ(strlen(words[wordIndex]),
endPosition.column - data.position().column); endPosition.column - data.position().column);
ASSERT_EQ(0, endPosition.line); ASSERT_EQ(0, endPosition.line);
@ -109,13 +108,12 @@ TEST(TextWordGet, MultipleWords) {
TEST(TextWordGet, QuotesAreKept) { TEST(TextWordGet, QuotesAreKept) {
AutoText input(R"("quotes" "around words")"); AutoText input(R"("quotes" "around words")");
const char *expected[] = {R"("quotes")", R"("around words")"}; const char* expected[] = {R"("quotes")", R"("around words")"};
AssemblyContext data(input, nullptr); AssemblyContext data(input, nullptr);
std::string word; std::string word;
spv_position_t endPosition = {}; spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
data.getWord(word, &endPosition));
EXPECT_EQ(8, endPosition.column); EXPECT_EQ(8, endPosition.column);
EXPECT_EQ(0, endPosition.line); EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(8, endPosition.index); EXPECT_EQ(8, endPosition.index);
@ -125,8 +123,7 @@ TEST(TextWordGet, QuotesAreKept) {
data.setPosition(endPosition); data.setPosition(endPosition);
data.seekForward(1); data.seekForward(1);
ASSERT_EQ(SPV_SUCCESS, ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
data.getWord(word, &endPosition));
EXPECT_EQ(23, endPosition.column); EXPECT_EQ(23, endPosition.column);
EXPECT_EQ(0, endPosition.line); EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(23, endPosition.index); EXPECT_EQ(23, endPosition.index);
@ -135,13 +132,12 @@ TEST(TextWordGet, QuotesAreKept) {
TEST(TextWordGet, QuotesBetweenWordsActLikeGlue) { TEST(TextWordGet, QuotesBetweenWordsActLikeGlue) {
AutoText input(R"(quotes" "between words)"); AutoText input(R"(quotes" "between words)");
const char *expected[] = {R"(quotes" "between)", "words"}; const char* expected[] = {R"(quotes" "between)", "words"};
AssemblyContext data(input, nullptr); AssemblyContext data(input, nullptr);
std::string word; std::string word;
spv_position_t endPosition = {}; spv_position_t endPosition = {};
ASSERT_EQ(SPV_SUCCESS, ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
data.getWord(word, &endPosition));
EXPECT_EQ(16, endPosition.column); EXPECT_EQ(16, endPosition.column);
EXPECT_EQ(0, endPosition.line); EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(16, endPosition.index); EXPECT_EQ(16, endPosition.index);
@ -151,8 +147,7 @@ TEST(TextWordGet, QuotesBetweenWordsActLikeGlue) {
data.setPosition(endPosition); data.setPosition(endPosition);
data.seekForward(1); data.seekForward(1);
ASSERT_EQ(SPV_SUCCESS, ASSERT_EQ(SPV_SUCCESS, data.getWord(word, &endPosition));
data.getWord(word, &endPosition));
EXPECT_EQ(22, endPosition.column); EXPECT_EQ(22, endPosition.column);
EXPECT_EQ(0, endPosition.line); EXPECT_EQ(0, endPosition.line);
EXPECT_EQ(22, endPosition.index); EXPECT_EQ(22, endPosition.index);

View File

@ -121,7 +121,6 @@ inline std::vector<uint32_t> MakeInstruction(
return result; return result;
} }
// Returns a vector of words representing a single instruction with the // Returns a vector of words representing a single instruction with the
// given opcode and whose operands are the concatenation of the two given // given opcode and whose operands are the concatenation of the two given
// argument lists. // argument lists.
@ -207,7 +206,7 @@ inline std::string MakeLongUTF8String(size_t num_4_byte_chars) {
std::string result; std::string result;
result.reserve(num_4_byte_chars * 4); result.reserve(num_4_byte_chars * 4);
for (size_t i = 0; i < num_4_byte_chars; i++ ) { for (size_t i = 0; i < num_4_byte_chars; i++) {
result += earth_africa; result += earth_africa;
} }
EXPECT_EQ(4 * num_4_byte_chars, result.size()); EXPECT_EQ(4 * num_4_byte_chars, result.size());

View File

@ -74,7 +74,7 @@ class ValidateID : public ::testing::Test {
// TODO: OpUndef // TODO: OpUndef
TEST_F(ValidateID, OpName) { TEST_F(ValidateID, OpName) {
const char *spirv = R"( const char* spirv = R"(
OpName %2 "name" OpName %2 "name"
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypePointer UniformConstant %1 %2 = OpTypePointer UniformConstant %1
@ -83,20 +83,20 @@ TEST_F(ValidateID, OpName) {
} }
TEST_F(ValidateID, OpMemberNameGood) { TEST_F(ValidateID, OpMemberNameGood) {
const char *spirv = R"( const char* spirv = R"(
OpMemberName %2 0 "foo" OpMemberName %2 0 "foo"
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeStruct %1)"; %2 = OpTypeStruct %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpMemberNameTypeBad) { TEST_F(ValidateID, OpMemberNameTypeBad) {
const char *spirv = R"( const char* spirv = R"(
OpMemberName %1 0 "foo" OpMemberName %1 0 "foo"
%1 = OpTypeInt 32 0)"; %1 = OpTypeInt 32 0)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpMemberNameMemberBad) { TEST_F(ValidateID, OpMemberNameMemberBad) {
const char *spirv = R"( const char* spirv = R"(
OpMemberName %2 1 "foo" OpMemberName %2 1 "foo"
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeStruct %1)"; %2 = OpTypeStruct %1)";
@ -104,7 +104,7 @@ TEST_F(ValidateID, OpMemberNameMemberBad) {
} }
TEST_F(ValidateID, OpLineGood) { TEST_F(ValidateID, OpLineGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpString "/path/to/source.file" %1 = OpString "/path/to/source.file"
OpLine %1 0 0 OpLine %1 0 0
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
@ -113,7 +113,7 @@ TEST_F(ValidateID, OpLineGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpLineFileBad) { TEST_F(ValidateID, OpLineFileBad) {
const char *spirv = R"( const char* spirv = R"(
OpLine %2 0 0 OpLine %2 0 0
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer Generic %2 %3 = OpTypePointer Generic %2
@ -122,33 +122,33 @@ TEST_F(ValidateID, OpLineFileBad) {
} }
TEST_F(ValidateID, OpDecorateGood) { TEST_F(ValidateID, OpDecorateGood) {
const char *spirv = R"( const char* spirv = R"(
OpDecorate %2 GLSLShared OpDecorate %2 GLSLShared
%1 = OpTypeInt 64 0 %1 = OpTypeInt 64 0
%2 = OpTypeStruct %1 %1)"; %2 = OpTypeStruct %1 %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpDecorateBad) { TEST_F(ValidateID, OpDecorateBad) {
const char *spirv = R"( const char* spirv = R"(
OpDecorate %1 GLSLShared)"; OpDecorate %1 GLSLShared)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpMemberDecorateGood) { TEST_F(ValidateID, OpMemberDecorateGood) {
const char *spirv = R"( const char* spirv = R"(
OpMemberDecorate %2 0 Uniform OpMemberDecorate %2 0 Uniform
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeStruct %1 %1)"; %2 = OpTypeStruct %1 %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpMemberDecorateBad) { TEST_F(ValidateID, OpMemberDecorateBad) {
const char *spirv = R"( const char* spirv = R"(
OpMemberDecorate %1 0 Uniform OpMemberDecorate %1 0 Uniform
%1 = OpTypeInt 32 0)"; %1 = OpTypeInt 32 0)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpMemberDecorateMemberBad) { TEST_F(ValidateID, OpMemberDecorateMemberBad) {
const char *spirv = R"( const char* spirv = R"(
OpMemberDecorate %2 3 Uniform OpMemberDecorate %2 3 Uniform
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeStruct %1 %1)"; %2 = OpTypeStruct %1 %1)";
@ -156,7 +156,7 @@ TEST_F(ValidateID, OpMemberDecorateMemberBad) {
} }
TEST_F(ValidateID, OpGroupDecorateGood) { TEST_F(ValidateID, OpGroupDecorateGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpDecorationGroup %1 = OpDecorationGroup
OpDecorate %1 Uniform OpDecorate %1 Uniform
OpDecorate %1 GLSLShared OpDecorate %1 GLSLShared
@ -167,7 +167,7 @@ TEST_F(ValidateID, OpGroupDecorateGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpGroupDecorateDecorationGroupBad) { TEST_F(ValidateID, OpGroupDecorateDecorationGroupBad) {
const char *spirv = R"( const char* spirv = R"(
OpGroupDecorate %2 %3 %4 OpGroupDecorate %2 %3 %4
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpConstant %2 42 %3 = OpConstant %2 42
@ -175,7 +175,7 @@ TEST_F(ValidateID, OpGroupDecorateDecorationGroupBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpGroupDecorateTargetBad) { TEST_F(ValidateID, OpGroupDecorateTargetBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpDecorationGroup %1 = OpDecorationGroup
OpDecorate %1 Uniform OpDecorate %1 Uniform
OpDecorate %1 GLSLShared OpDecorate %1 GLSLShared
@ -188,7 +188,7 @@ TEST_F(ValidateID, OpGroupDecorateTargetBad) {
// TODO: OpExtInst // TODO: OpExtInst
TEST_F(ValidateID, OpEntryPointGood) { TEST_F(ValidateID, OpEntryPointGood) {
const char *spirv = R"( const char* spirv = R"(
OpEntryPoint GLCompute %3 "" OpEntryPoint GLCompute %3 ""
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeFunction %1 %2 = OpTypeFunction %1
@ -200,13 +200,13 @@ TEST_F(ValidateID, OpEntryPointGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpEntryPointFunctionBad) { TEST_F(ValidateID, OpEntryPointFunctionBad) {
const char *spirv = R"( const char* spirv = R"(
OpEntryPoint GLCompute %1 "" OpEntryPoint GLCompute %1 ""
%1 = OpTypeVoid)"; %1 = OpTypeVoid)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpEntryPointParameterCountBad) { TEST_F(ValidateID, OpEntryPointParameterCountBad) {
const char *spirv = R"( const char* spirv = R"(
OpEntryPoint GLCompute %3 "" OpEntryPoint GLCompute %3 ""
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeFunction %1 %1 %2 = OpTypeFunction %1 %1
@ -217,7 +217,7 @@ TEST_F(ValidateID, OpEntryPointParameterCountBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpEntryPointReturnTypeBad) { TEST_F(ValidateID, OpEntryPointReturnTypeBad) {
const char *spirv = R"( const char* spirv = R"(
OpEntryPoint GLCompute %3 "" OpEntryPoint GLCompute %3 ""
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeFunction %1 %2 = OpTypeFunction %1
@ -229,7 +229,7 @@ TEST_F(ValidateID, OpEntryPointReturnTypeBad) {
} }
TEST_F(ValidateID, OpExecutionModeGood) { TEST_F(ValidateID, OpExecutionModeGood) {
const char *spirv = R"( const char* spirv = R"(
OpEntryPoint GLCompute %3 "" OpEntryPoint GLCompute %3 ""
OpExecutionMode %3 LocalSize 1 1 1 OpExecutionMode %3 LocalSize 1 1 1
%1 = OpTypeVoid %1 = OpTypeVoid
@ -241,7 +241,7 @@ TEST_F(ValidateID, OpExecutionModeGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpExecutionModeEntryPointBad) { TEST_F(ValidateID, OpExecutionModeEntryPointBad) {
const char *spirv = R"( const char* spirv = R"(
OpExecutionMode %3 LocalSize 1 1 1 OpExecutionMode %3 LocalSize 1 1 1
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeFunction %1 %2 = OpTypeFunction %1
@ -253,13 +253,13 @@ TEST_F(ValidateID, OpExecutionModeEntryPointBad) {
} }
TEST_F(ValidateID, OpTypeVectorGood) { TEST_F(ValidateID, OpTypeVectorGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 4)"; %2 = OpTypeVector %1 4)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeVectorComponentTypeBad) { TEST_F(ValidateID, OpTypeVectorComponentTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypePointer UniformConstant %1 %2 = OpTypePointer UniformConstant %1
%3 = OpTypeVector %2 4)"; %3 = OpTypeVector %2 4)";
@ -267,14 +267,14 @@ TEST_F(ValidateID, OpTypeVectorComponentTypeBad) {
} }
TEST_F(ValidateID, OpTypeMatrixGood) { TEST_F(ValidateID, OpTypeMatrixGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeVector %1 2 %2 = OpTypeVector %1 2
%3 = OpTypeMatrix %2 3)"; %3 = OpTypeMatrix %2 3)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeMatrixColumnTypeBad) { TEST_F(ValidateID, OpTypeMatrixColumnTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeMatrix %1 3)"; %2 = OpTypeMatrix %1 3)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
@ -282,27 +282,27 @@ TEST_F(ValidateID, OpTypeMatrixColumnTypeBad) {
TEST_F(ValidateID, OpTypeSamplerGood) { TEST_F(ValidateID, OpTypeSamplerGood) {
// In Rev31, OpTypeSampler takes no arguments. // In Rev31, OpTypeSampler takes no arguments.
const char *spirv = R"( const char* spirv = R"(
%s = OpTypeSampler)"; %s = OpTypeSampler)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeArrayGood) { TEST_F(ValidateID, OpTypeArrayGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 1 %2 = OpConstant %1 1
%3 = OpTypeArray %1 %2)"; %3 = OpTypeArray %1 %2)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeArrayElementTypeBad) { TEST_F(ValidateID, OpTypeArrayElementTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 1 %2 = OpConstant %1 1
%3 = OpTypeArray %2 %2)"; %3 = OpTypeArray %2 %2)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpTypeArrayLengthBad) { TEST_F(ValidateID, OpTypeArrayLengthBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 0 %2 = OpConstant %1 0
%3 = OpTypeArray %1 %2)"; %3 = OpTypeArray %1 %2)";
@ -310,13 +310,13 @@ TEST_F(ValidateID, OpTypeArrayLengthBad) {
} }
TEST_F(ValidateID, OpTypeRuntimeArrayGood) { TEST_F(ValidateID, OpTypeRuntimeArrayGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeRuntimeArray %1)"; %2 = OpTypeRuntimeArray %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeRuntimeArrayBad) { TEST_F(ValidateID, OpTypeRuntimeArrayBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 0 %2 = OpConstant %1 0
%3 = OpTypeRuntimeArray %2)"; %3 = OpTypeRuntimeArray %2)";
@ -326,7 +326,7 @@ TEST_F(ValidateID, OpTypeRuntimeArrayBad) {
// Unifrom Storage Class // Unifrom Storage Class
TEST_F(ValidateID, OpTypeStructGood) { TEST_F(ValidateID, OpTypeStructGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeFloat 64 %2 = OpTypeFloat 64
%3 = OpTypePointer Generic %1 %3 = OpTypePointer Generic %1
@ -334,7 +334,7 @@ TEST_F(ValidateID, OpTypeStructGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeStructMemberTypeBad) { TEST_F(ValidateID, OpTypeStructMemberTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeFloat 64 %2 = OpTypeFloat 64
%3 = OpConstant %2 0.0 %3 = OpConstant %2 0.0
@ -343,13 +343,13 @@ TEST_F(ValidateID, OpTypeStructMemberTypeBad) {
} }
TEST_F(ValidateID, OpTypePointerGood) { TEST_F(ValidateID, OpTypePointerGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypePointer Generic %1)"; %2 = OpTypePointer Generic %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypePointerBad) { TEST_F(ValidateID, OpTypePointerBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 0 %2 = OpConstant %1 0
%3 = OpTypePointer Generic %2)"; %3 = OpTypePointer Generic %2)";
@ -357,20 +357,20 @@ TEST_F(ValidateID, OpTypePointerBad) {
} }
TEST_F(ValidateID, OpTypeFunctionGood) { TEST_F(ValidateID, OpTypeFunctionGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeFunction %1)"; %2 = OpTypeFunction %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpTypeFunctionReturnTypeBad) { TEST_F(ValidateID, OpTypeFunctionReturnTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 0 %2 = OpConstant %1 0
%3 = OpTypeFunction %2)"; %3 = OpTypeFunction %2)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpTypeFunctionParameterBad) { TEST_F(ValidateID, OpTypeFunctionParameterBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpConstant %2 0 %3 = OpConstant %2 0
@ -379,7 +379,7 @@ TEST_F(ValidateID, OpTypeFunctionParameterBad) {
} }
TEST_F(ValidateID, OpTypePipeGood) { TEST_F(ValidateID, OpTypePipeGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 16 %2 = OpTypeVector %1 16
%3 = OpTypePipe ReadOnly)"; %3 = OpTypePipe ReadOnly)";
@ -387,46 +387,46 @@ TEST_F(ValidateID, OpTypePipeGood) {
} }
TEST_F(ValidateID, OpConstantTrueGood) { TEST_F(ValidateID, OpConstantTrueGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeBool %1 = OpTypeBool
%2 = OpConstantTrue %1)"; %2 = OpConstantTrue %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantTrueBad) { TEST_F(ValidateID, OpConstantTrueBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpConstantTrue %1)"; %2 = OpConstantTrue %1)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantFalseGood) { TEST_F(ValidateID, OpConstantFalseGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeBool %1 = OpTypeBool
%2 = OpConstantTrue %1)"; %2 = OpConstantTrue %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantFalseBad) { TEST_F(ValidateID, OpConstantFalseBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpConstantFalse %1)"; %2 = OpConstantFalse %1)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantGood) { TEST_F(ValidateID, OpConstantGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 1)"; %2 = OpConstant %1 1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantBad) { TEST_F(ValidateID, OpConstantBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpConstant !1 !0)"; %2 = OpConstant !1 !0)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeVectorGood) { TEST_F(ValidateID, OpConstantCompositeVectorGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 4 %2 = OpTypeVector %1 4
%3 = OpConstant %1 3.14 %3 = OpConstant %1 3.14
@ -434,7 +434,7 @@ TEST_F(ValidateID, OpConstantCompositeVectorGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantCompositeVectorResultTypeBad) { TEST_F(ValidateID, OpConstantCompositeVectorResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 4 %2 = OpTypeVector %1 4
%3 = OpConstant %1 3.14 %3 = OpConstant %1 3.14
@ -442,7 +442,7 @@ TEST_F(ValidateID, OpConstantCompositeVectorResultTypeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeVectorConstituentBad) { TEST_F(ValidateID, OpConstantCompositeVectorConstituentBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 4 %2 = OpTypeVector %1 4
%4 = OpTypeInt 32 0 %4 = OpTypeInt 32 0
@ -452,7 +452,7 @@ TEST_F(ValidateID, OpConstantCompositeVectorConstituentBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeMatrixGood) { TEST_F(ValidateID, OpConstantCompositeMatrixGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 4 %2 = OpTypeVector %1 4
%3 = OpTypeMatrix %2 4 %3 = OpTypeMatrix %2 4
@ -466,7 +466,7 @@ TEST_F(ValidateID, OpConstantCompositeMatrixGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantCompositeMatrixConstituentBad) { TEST_F(ValidateID, OpConstantCompositeMatrixConstituentBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpTypeVector %1 4 %2 = OpTypeVector %1 4
%11 = OpTypeVector %1 3 %11 = OpTypeVector %1 3
@ -481,7 +481,7 @@ TEST_F(ValidateID, OpConstantCompositeMatrixConstituentBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeMatrixColumnTypeBad) { TEST_F(ValidateID, OpConstantCompositeMatrixColumnTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeFloat 32 %2 = OpTypeFloat 32
%3 = OpTypeVector %1 2 %3 = OpTypeVector %1 2
@ -495,7 +495,7 @@ TEST_F(ValidateID, OpConstantCompositeMatrixColumnTypeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeArrayGood) { TEST_F(ValidateID, OpConstantCompositeArrayGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 4 %2 = OpConstant %1 4
%3 = OpTypeArray %1 %2 %3 = OpTypeArray %1 %2
@ -503,7 +503,7 @@ TEST_F(ValidateID, OpConstantCompositeArrayGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantCompositeArrayConstConstituentBad) { TEST_F(ValidateID, OpConstantCompositeArrayConstConstituentBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 4 %2 = OpConstant %1 4
%3 = OpTypeArray %1 %2 %3 = OpTypeArray %1 %2
@ -511,7 +511,7 @@ TEST_F(ValidateID, OpConstantCompositeArrayConstConstituentBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeArrayConstituentBad) { TEST_F(ValidateID, OpConstantCompositeArrayConstituentBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpConstant %1 4 %2 = OpConstant %1 4
%3 = OpTypeArray %1 %2 %3 = OpTypeArray %1 %2
@ -521,7 +521,7 @@ TEST_F(ValidateID, OpConstantCompositeArrayConstituentBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantCompositeStructGood) { TEST_F(ValidateID, OpConstantCompositeStructGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeInt 64 1 %2 = OpTypeInt 64 1
%3 = OpTypeStruct %1 %1 %2 %3 = OpTypeStruct %1 %1 %2
@ -531,7 +531,7 @@ TEST_F(ValidateID, OpConstantCompositeStructGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantCompositeStructMemberBad) { TEST_F(ValidateID, OpConstantCompositeStructMemberBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 0 %1 = OpTypeInt 32 0
%2 = OpTypeInt 64 1 %2 = OpTypeInt 64 1
%3 = OpTypeStruct %1 %1 %2 %3 = OpTypeStruct %1 %1 %2
@ -542,21 +542,21 @@ TEST_F(ValidateID, OpConstantCompositeStructMemberBad) {
} }
TEST_F(ValidateID, OpConstantSamplerGood) { TEST_F(ValidateID, OpConstantSamplerGood) {
const char *spirv = R"( const char* spirv = R"(
%float = OpTypeFloat 32 %float = OpTypeFloat 32
%samplerType = OpTypeSampler %samplerType = OpTypeSampler
%3 = OpConstantSampler %samplerType ClampToEdge 0 Nearest)"; %3 = OpConstantSampler %samplerType ClampToEdge 0 Nearest)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantSamplerResultTypeBad) { TEST_F(ValidateID, OpConstantSamplerResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpConstantSampler %1 Clamp 0 Nearest)"; %2 = OpConstantSampler %1 Clamp 0 Nearest)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantNullGood) { TEST_F(ValidateID, OpConstantNullGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeBool %1 = OpTypeBool
%2 = OpConstantNull %1 %2 = OpConstantNull %1
%3 = OpTypeInt 32 0 %3 = OpTypeInt 32 0
@ -586,13 +586,13 @@ TEST_F(ValidateID, OpConstantNullGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpConstantNullBasicBad) { TEST_F(ValidateID, OpConstantNullBasicBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpConstantNull %1)"; %2 = OpConstantNull %1)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantNullArrayBad) { TEST_F(ValidateID, OpConstantNullArrayBad) {
const char *spirv = R"( const char* spirv = R"(
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeSampler %3 = OpTypeSampler
%4 = OpConstant %2 4 %4 = OpConstant %2 4
@ -601,7 +601,7 @@ TEST_F(ValidateID, OpConstantNullArrayBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpConstantNullStructBad) { TEST_F(ValidateID, OpConstantNullStructBad) {
const char *spirv = R"( const char* spirv = R"(
%2 = OpTypeSampler %2 = OpTypeSampler
%3 = OpTypeStruct %2 %2 %3 = OpTypeStruct %2 %2
%4 = OpConstantNull %3)"; %4 = OpConstantNull %3)";
@ -609,39 +609,39 @@ TEST_F(ValidateID, OpConstantNullStructBad) {
} }
TEST_F(ValidateID, OpSpecConstantTrueGood) { TEST_F(ValidateID, OpSpecConstantTrueGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeBool %1 = OpTypeBool
%2 = OpSpecConstantTrue %1)"; %2 = OpSpecConstantTrue %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpSpecConstantTrueBad) { TEST_F(ValidateID, OpSpecConstantTrueBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpSpecConstantTrue %1)"; %2 = OpSpecConstantTrue %1)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpSpecConstantFalseGood) { TEST_F(ValidateID, OpSpecConstantFalseGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeBool %1 = OpTypeBool
%2 = OpSpecConstantFalse %1)"; %2 = OpSpecConstantFalse %1)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpSpecConstantFalseBad) { TEST_F(ValidateID, OpSpecConstantFalseBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpSpecConstantFalse %1)"; %2 = OpSpecConstantFalse %1)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpSpecConstantGood) { TEST_F(ValidateID, OpSpecConstantGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeFloat 32 %1 = OpTypeFloat 32
%2 = OpSpecConstant %1 42)"; %2 = OpSpecConstant %1 42)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpSpecConstantBad) { TEST_F(ValidateID, OpSpecConstantBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpSpecConstant !1 !4)"; %2 = OpSpecConstant !1 !4)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
@ -651,14 +651,14 @@ TEST_F(ValidateID, OpSpecConstantBad) {
// TODO: OpSpecConstantOp // TODO: OpSpecConstantOp
TEST_F(ValidateID, OpVariableGood) { TEST_F(ValidateID, OpVariableGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 1 %1 = OpTypeInt 32 1
%2 = OpTypePointer Generic %1 %2 = OpTypePointer Generic %1
%3 = OpVariable %2 Generic)"; %3 = OpVariable %2 Generic)";
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpVariableInitializerGood) { TEST_F(ValidateID, OpVariableInitializerGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 1 %1 = OpTypeInt 32 1
%2 = OpTypePointer Generic %1 %2 = OpTypePointer Generic %1
%3 = OpConstant %1 42 %3 = OpConstant %1 42
@ -667,13 +667,13 @@ TEST_F(ValidateID, OpVariableInitializerGood) {
} }
// TODO: Positive test OpVariable with OpConstantNull of OpTypePointer // TODO: Positive test OpVariable with OpConstantNull of OpTypePointer
TEST_F(ValidateID, OpVariableResultTypeBad) { TEST_F(ValidateID, OpVariableResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 1 %1 = OpTypeInt 32 1
%2 = OpVariable %1 Generic)"; %2 = OpVariable %1 Generic)";
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpVariableInitializerBad) { TEST_F(ValidateID, OpVariableInitializerBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeInt 32 1 %1 = OpTypeInt 32 1
%2 = OpTypePointer Generic %1 %2 = OpTypePointer Generic %1
%3 = OpVariable %2 Generic %2)"; %3 = OpVariable %2 Generic %2)";
@ -681,7 +681,7 @@ TEST_F(ValidateID, OpVariableInitializerBad) {
} }
TEST_F(ValidateID, OpLoadGood) { TEST_F(ValidateID, OpLoadGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -696,7 +696,7 @@ TEST_F(ValidateID, OpLoadGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpLoadResultTypeBad) { TEST_F(ValidateID, OpLoadResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -711,7 +711,7 @@ TEST_F(ValidateID, OpLoadResultTypeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpLoadPointerBad) { TEST_F(ValidateID, OpLoadPointerBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%9 = OpTypeFloat 32 %9 = OpTypeFloat 32
@ -727,7 +727,7 @@ TEST_F(ValidateID, OpLoadPointerBad) {
} }
TEST_F(ValidateID, OpStoreGood) { TEST_F(ValidateID, OpStoreGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -742,7 +742,7 @@ TEST_F(ValidateID, OpStoreGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpStorePointerBad) { TEST_F(ValidateID, OpStorePointerBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -757,7 +757,7 @@ TEST_F(ValidateID, OpStorePointerBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpStoreObjectGood) { TEST_F(ValidateID, OpStoreObjectGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -772,7 +772,7 @@ TEST_F(ValidateID, OpStoreObjectGood) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpStoreTypeBad) { TEST_F(ValidateID, OpStoreTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%9 = OpTypeFloat 32 %9 = OpTypeFloat 32
@ -789,7 +789,7 @@ TEST_F(ValidateID, OpStoreTypeBad) {
} }
TEST_F(ValidateID, OpCopyMemoryGood) { TEST_F(ValidateID, OpCopyMemoryGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -807,7 +807,7 @@ TEST_F(ValidateID, OpCopyMemoryGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpCopyMemoryBad) { TEST_F(ValidateID, OpCopyMemoryBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -828,7 +828,7 @@ TEST_F(ValidateID, OpCopyMemoryBad) {
// TODO: OpCopyMemorySized // TODO: OpCopyMemorySized
TEST_F(ValidateID, OpCopyMemorySizedGood) { TEST_F(ValidateID, OpCopyMemorySizedGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -845,7 +845,7 @@ TEST_F(ValidateID, OpCopyMemorySizedGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpCopyMemorySizedTargetBad) { TEST_F(ValidateID, OpCopyMemorySizedTargetBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -861,7 +861,7 @@ TEST_F(ValidateID, OpCopyMemorySizedTargetBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpCopyMemorySizedSourceBad) { TEST_F(ValidateID, OpCopyMemorySizedSourceBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -877,7 +877,7 @@ TEST_F(ValidateID, OpCopyMemorySizedSourceBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpCopyMemorySizedSizeBad) { TEST_F(ValidateID, OpCopyMemorySizedSizeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -894,7 +894,7 @@ TEST_F(ValidateID, OpCopyMemorySizedSizeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpCopyMemorySizedSizeTypeBad) { TEST_F(ValidateID, OpCopyMemorySizedSizeTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypePointer UniformConstant %2 %3 = OpTypePointer UniformConstant %2
@ -920,7 +920,7 @@ TEST_F(ValidateID, OpCopyMemorySizedSizeTypeBad) {
// TODO: OpGenericPtrMemSemantics // TODO: OpGenericPtrMemSemantics
TEST_F(ValidateID, OpFunctionGood) { TEST_F(ValidateID, OpFunctionGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%3 = OpTypeFunction %1 %2 %2 %3 = OpTypeFunction %1 %2 %2
@ -929,7 +929,7 @@ TEST_F(ValidateID, OpFunctionGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpFunctionResultTypeBad) { TEST_F(ValidateID, OpFunctionResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%5 = OpConstant %2 42 %5 = OpConstant %2 42
@ -939,7 +939,7 @@ TEST_F(ValidateID, OpFunctionResultTypeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpFunctionFunctionTypeBad) { TEST_F(ValidateID, OpFunctionFunctionTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 1 %2 = OpTypeInt 32 1
%4 = OpFunction %1 None %2 %4 = OpFunction %1 None %2
@ -948,7 +948,7 @@ OpFunctionEnd)";
} }
TEST_F(ValidateID, OpFunctionParameterGood) { TEST_F(ValidateID, OpFunctionParameterGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %1 %2 %3 = OpTypeFunction %1 %2
@ -960,7 +960,7 @@ TEST_F(ValidateID, OpFunctionParameterGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpFunctionParameterResultTypeBad) { TEST_F(ValidateID, OpFunctionParameterResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %1 %2 %3 = OpTypeFunction %1 %2
@ -972,7 +972,7 @@ TEST_F(ValidateID, OpFunctionParameterResultTypeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpFunctionParameterOrderBad) { TEST_F(ValidateID, OpFunctionParameterOrderBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %1 %2 %3 = OpTypeFunction %1 %2
@ -987,7 +987,7 @@ TEST_F(ValidateID, OpFunctionParameterOrderBad) {
} }
TEST_F(ValidateID, OpFunctionCallGood) { TEST_F(ValidateID, OpFunctionCallGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %2 %2 %3 = OpTypeFunction %2 %2
@ -1009,7 +1009,7 @@ TEST_F(ValidateID, OpFunctionCallGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpFunctionCallResultTypeBad) { TEST_F(ValidateID, OpFunctionCallResultTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %2 %2 %3 = OpTypeFunction %2 %2
@ -1031,7 +1031,7 @@ TEST_F(ValidateID, OpFunctionCallResultTypeBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpFunctionCallFunctionBad) { TEST_F(ValidateID, OpFunctionCallFunctionBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %2 %2 %3 = OpTypeFunction %2 %2
@ -1046,7 +1046,7 @@ TEST_F(ValidateID, OpFunctionCallFunctionBad) {
CHECK(spirv, SPV_ERROR_INVALID_ID); CHECK(spirv, SPV_ERROR_INVALID_ID);
} }
TEST_F(ValidateID, OpFunctionCallArgumentTypeBad) { TEST_F(ValidateID, OpFunctionCallArgumentTypeBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %2 %2 %3 = OpTypeFunction %2 %2
@ -1227,7 +1227,7 @@ TEST_F(ValidateID, OpFunctionCallArgumentCountBar) {
// TODO: OpSwitch // TODO: OpSwitch
TEST_F(ValidateID, OpReturnValueConstantGood) { TEST_F(ValidateID, OpReturnValueConstantGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %2 %2 %3 = OpTypeFunction %2 %2
@ -1239,7 +1239,7 @@ TEST_F(ValidateID, OpReturnValueConstantGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpReturnValueVariableGood) { TEST_F(ValidateID, OpReturnValueVariableGood) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 ;10 %2 = OpTypeInt 32 0 ;10
%3 = OpTypeFunction %2 %2 ;14 %3 = OpTypeFunction %2 %2 ;14
@ -1253,7 +1253,7 @@ TEST_F(ValidateID, OpReturnValueVariableGood) {
CHECK(spirv, SPV_SUCCESS); CHECK(spirv, SPV_SUCCESS);
} }
TEST_F(ValidateID, OpReturnValueBad) { TEST_F(ValidateID, OpReturnValueBad) {
const char *spirv = R"( const char* spirv = R"(
%1 = OpTypeVoid %1 = OpTypeVoid
%2 = OpTypeInt 32 0 %2 = OpTypeInt 32 0
%3 = OpTypeFunction %2 %2 %3 = OpTypeFunction %2 %2

View File

@ -26,7 +26,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
int main(int argc, char **argv) { int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }

View File

@ -30,7 +30,7 @@
#include <string.h> #include <string.h>
#include <vector> #include <vector>
void print_usage(char *argv0) { void print_usage(char* argv0) {
printf( printf(
"Assemble a *.svasm file into a *.sv binary.\n\n" "Assemble a *.svasm file into a *.sv binary.\n\n"
"USAGE: %s [options] <filename>\n\n" "USAGE: %s [options] <filename>\n\n"
@ -40,23 +40,23 @@ void print_usage(char *argv0) {
argv0); argv0);
} }
int main(int argc, char **argv) { int main(int argc, char** argv) {
if (2 > argc) { if (2 > argc) {
print_usage(argv[0]); print_usage(argv[0]);
return 1; return 1;
} }
const char *inFile = nullptr; const char* inFile = nullptr;
const char *outFile = nullptr; const char* outFile = nullptr;
const char *assembly_format_prefix = "--assembly-format="; const char* assembly_format_prefix = "--assembly-format=";
spv_assembly_syntax_format_t format = SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT; spv_assembly_syntax_format_t format = SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT;
for (int argi = 1; argi < argc; ++argi) { for (int argi = 1; argi < argc; ++argi) {
if ('-' == argv[argi][0]) { if ('-' == argv[argi][0]) {
if (!strncmp(assembly_format_prefix, argv[argi], if (!strncmp(assembly_format_prefix, argv[argi],
strlen(assembly_format_prefix))) { strlen(assembly_format_prefix))) {
const char *parameter = argv[argi] + strlen(assembly_format_prefix); const char* parameter = argv[argi] + strlen(assembly_format_prefix);
if (!strcmp("canonical", parameter)) { if (!strcmp("canonical", parameter)) {
format = SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL; format = SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL;
} else if (!strcmp("assignment", parameter)) { } else if (!strcmp("assignment", parameter)) {
@ -100,7 +100,7 @@ int main(int argc, char **argv) {
} }
std::vector<char> contents; std::vector<char> contents;
if (FILE *fp = fopen(inFile, "r")) { if (FILE* fp = fopen(inFile, "r")) {
char buf[1024]; char buf[1024];
while (size_t len = fread(buf, 1, sizeof(buf), fp)) while (size_t len = fread(buf, 1, sizeof(buf), fp))
contents.insert(contents.end(), buf, buf + len); contents.insert(contents.end(), buf, buf + len);
@ -139,7 +139,7 @@ int main(int argc, char **argv) {
return error; return error;
} }
if (FILE *fp = fopen(outFile, "wb")) { if (FILE* fp = fopen(outFile, "wb")) {
size_t written = size_t written =
fwrite(binary->code, sizeof(uint32_t), (size_t)binary->wordCount, fp); fwrite(binary->code, sizeof(uint32_t), (size_t)binary->wordCount, fp);
if (binary->wordCount != written) { if (binary->wordCount != written) {

View File

@ -30,7 +30,7 @@
#include <string.h> #include <string.h>
#include <vector> #include <vector>
void print_usage(char *argv0) { void print_usage(char* argv0) {
printf( printf(
"Dissassemble a *.sv file into a *.svasm text file.\n\n" "Dissassemble a *.sv file into a *.svasm text file.\n\n"
"USAGE: %s [options] <filename>\n\n" "USAGE: %s [options] <filename>\n\n"
@ -43,24 +43,24 @@ void print_usage(char *argv0) {
argv0); argv0);
} }
int main(int argc, char **argv) { int main(int argc, char** argv) {
if (2 > argc) { if (2 > argc) {
print_usage(argv[0]); print_usage(argv[0]);
return 1; return 1;
} }
uint32_t options = SPV_BINARY_TO_TEXT_OPTION_NONE; uint32_t options = SPV_BINARY_TO_TEXT_OPTION_NONE;
const char *inFile = nullptr; const char* inFile = nullptr;
const char *outFile = nullptr; const char* outFile = nullptr;
const char *assembly_format_prefix = "--assembly-format="; const char* assembly_format_prefix = "--assembly-format=";
spv_assembly_syntax_format_t format = SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT; spv_assembly_syntax_format_t format = SPV_ASSEMBLY_SYNTAX_FORMAT_DEFAULT;
for (int argi = 1; argi < argc; ++argi) { for (int argi = 1; argi < argc; ++argi) {
if ('-' == argv[argi][0]) { if ('-' == argv[argi][0]) {
if (!strncmp(assembly_format_prefix, argv[argi], if (!strncmp(assembly_format_prefix, argv[argi],
strlen(assembly_format_prefix))) { strlen(assembly_format_prefix))) {
const char *parameter = argv[argi] + strlen(assembly_format_prefix); const char* parameter = argv[argi] + strlen(assembly_format_prefix);
if (!strcmp("canonical", parameter)) { if (!strcmp("canonical", parameter)) {
format = SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL; format = SPV_ASSEMBLY_SYNTAX_FORMAT_CANONICAL;
} else if (!strcmp("assignment", parameter)) { } else if (!strcmp("assignment", parameter)) {
@ -110,7 +110,7 @@ int main(int argc, char **argv) {
} }
std::vector<uint32_t> contents; std::vector<uint32_t> contents;
if (FILE *fp = fopen(inFile, "rb")) { if (FILE* fp = fopen(inFile, "rb")) {
uint32_t buf[1024]; uint32_t buf[1024];
while (size_t len = fread(buf, sizeof(uint32_t), 1024, fp)) { while (size_t len = fread(buf, sizeof(uint32_t), 1024, fp)) {
contents.insert(contents.end(), buf, buf + len); contents.insert(contents.end(), buf, buf + len);
@ -149,7 +149,7 @@ int main(int argc, char **argv) {
const bool printOptionOn = const bool printOptionOn =
spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_PRINT, options); spvIsInBitfield(SPV_BINARY_TO_TEXT_OPTION_PRINT, options);
spv_text text; spv_text text;
spv_text *textOrNull = printOptionOn ? nullptr : &text; spv_text* textOrNull = printOptionOn ? nullptr : &text;
spv_diagnostic diagnostic = nullptr; spv_diagnostic diagnostic = nullptr;
error = spvBinaryToTextWithFormat(contents.data(), contents.size(), options, error = spvBinaryToTextWithFormat(contents.data(), contents.size(), options,
opcodeTable, operandTable, extInstTable, opcodeTable, operandTable, extInstTable,
@ -162,7 +162,7 @@ int main(int argc, char **argv) {
// Output the result. // Output the result.
if (!printOptionOn) { if (!printOptionOn) {
if (FILE *fp = fopen(outFile, "w")) { if (FILE* fp = fopen(outFile, "w")) {
size_t written = size_t written =
fwrite(text->str, sizeof(char), (size_t)text->length, fp); fwrite(text->str, sizeof(char), (size_t)text->length, fp);
if (text->length != written) { if (text->length != written) {

View File

@ -32,7 +32,7 @@
#include <vector> #include <vector>
void print_usage(char *argv0) { void print_usage(char* argv0) {
printf( printf(
"Validate a SPIR-V binary file.\n\n" "Validate a SPIR-V binary file.\n\n"
"USAGE: %s [options] <filename>\n\n" "USAGE: %s [options] <filename>\n\n"
@ -45,13 +45,13 @@ void print_usage(char *argv0) {
argv0); argv0);
} }
int main(int argc, char **argv) { int main(int argc, char** argv) {
if (2 > argc) { if (2 > argc) {
print_usage(argv[0]); print_usage(argv[0]);
return 1; return 1;
} }
const char *inFile = nullptr; const char* inFile = nullptr;
uint32_t options = 0; uint32_t options = 0;
for (int argi = 1; argi < argc; ++argi) { for (int argi = 1; argi < argc; ++argi) {
@ -84,7 +84,7 @@ int main(int argc, char **argv) {
} }
std::vector<uint32_t> contents; std::vector<uint32_t> contents;
if (FILE *fp = fopen(inFile, "rb")) { if (FILE* fp = fopen(inFile, "rb")) {
uint32_t buf[1024]; uint32_t buf[1024];
while (size_t len = fread(buf, sizeof(uint32_t), while (size_t len = fread(buf, sizeof(uint32_t),
sizeof(buf) / sizeof(uint32_t), fp)) { sizeof(buf) / sizeof(uint32_t), fp)) {