| 1 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef SOURCE_TEXT_H_ |
| 16 | #define SOURCE_TEXT_H_ |
| 17 | |
| 18 | #include <string> |
| 19 | |
| 20 | #include "source/operand.h" |
| 21 | #include "source/spirv_constant.h" |
| 22 | #include "spirv-tools/libspirv.h" |
| 23 | |
| 24 | typedef enum spv_literal_type_t { |
| 25 | SPV_LITERAL_TYPE_INT_32, |
| 26 | SPV_LITERAL_TYPE_INT_64, |
| 27 | SPV_LITERAL_TYPE_UINT_32, |
| 28 | SPV_LITERAL_TYPE_UINT_64, |
| 29 | SPV_LITERAL_TYPE_FLOAT_32, |
| 30 | SPV_LITERAL_TYPE_FLOAT_64, |
| 31 | SPV_LITERAL_TYPE_STRING, |
| 32 | SPV_FORCE_32_BIT_ENUM(spv_literal_type_t) |
| 33 | } spv_literal_type_t; |
| 34 | |
| 35 | typedef struct spv_literal_t { |
| 36 | spv_literal_type_t type; |
| 37 | union value_t { |
| 38 | int32_t i32; |
| 39 | int64_t i64; |
| 40 | uint32_t u32; |
| 41 | uint64_t u64; |
| 42 | float f; |
| 43 | double d; |
| 44 | } value; |
| 45 | std::string str; // Special field for literal string. |
| 46 | } spv_literal_t; |
| 47 | |
| 48 | // Converts the given text string to a number/string literal and writes the |
| 49 | // result to *literal. String literals must be surrounded by double-quotes ("), |
| 50 | // which are then stripped. |
| 51 | spv_result_t spvTextToLiteral(const char* text, spv_literal_t* literal); |
| 52 | |
| 53 | #endif // SOURCE_TEXT_H_ |
| 54 | |