Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/wabt/literal.h
1 /* 2 * Copyright 2016 WebAssembly Community Group participants 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef WABT_LITERAL_H_ 18 #define WABT_LITERAL_H_ 19 20 #include <cstdint> 21 22 #include "wabt/common.h" 23 24 namespace wabt { 25 26 // These functions all return Result::Ok on success and Result::Error on 27 // failure. 28 // 29 // NOTE: the functions are written for use with wast-lexer, assuming that the 30 // literal has already matched the patterns defined there. As a result, the 31 // only validation that is done is for overflow, not for otherwise bogus input. 32 33 enum class LiteralType { 34 Int, 35 Float, 36 Hexfloat, 37 Infinity, 38 Nan, 39 }; 40 41 enum class ParseIntType { 42 UnsignedOnly = 0, 43 SignedAndUnsigned = 1, 44 }; 45 46 /* Size of char buffer required to hold hex representation of a float/double */ 47 #define WABT_MAX_FLOAT_HEX 20 48 #define WABT_MAX_DOUBLE_HEX 40 49 50 Result ParseHexdigit(char c, uint32_t* out); 51 Result ParseInt8(const char* s, 52 const char* end, 53 uint8_t* out, 54 ParseIntType parse_type); 55 Result ParseInt16(const char* s, 56 const char* end, 57 uint16_t* out, 58 ParseIntType parse_type); 59 Result ParseInt32(const char* s, 60 const char* end, 61 uint32_t* out, 62 ParseIntType parse_type); 63 Result ParseInt64(const char* s, 64 const char* end, 65 uint64_t* out, 66 ParseIntType parse_type); 67 Result ParseUint64(const char* s, const char* end, uint64_t* out); 68 Result ParseUint128(const char* s, const char* end, v128* out); 69 Result ParseFloat(LiteralType literal_type, 70 const char* s, 71 const char* end, 72 uint32_t* out_bits); 73 Result ParseDouble(LiteralType literal_type, 74 const char* s, 75 const char* end, 76 uint64_t* out_bits); 77 78 // Same as above but taking a string_view 79 inline Result ParseInt8(std::string_view v, 80 uint8_t* out, 81 ParseIntType parse_type) { 82 return ParseInt8(v.data(), v.data() + v.size(), out, parse_type); 83 } 84 85 inline Result ParseInt16(std::string_view v, 86 uint16_t* out, 87 ParseIntType parse_type) { 88 return ParseInt16(v.data(), v.data() + v.size(), out, parse_type); 89 } 90 91 inline Result ParseInt32(std::string_view v, 92 uint32_t* out, 93 ParseIntType parse_type) { 94 return ParseInt32(v.data(), v.data() + v.size(), out, parse_type); 95 } 96 97 inline Result ParseInt64(std::string_view v, 98 uint64_t* out, 99 ParseIntType parse_type) { 100 return ParseInt64(v.data(), v.data() + v.size(), out, parse_type); 101 } 102 103 inline Result ParseUint64(std::string_view v, uint64_t* out) { 104 return ParseUint64(v.data(), v.data() + v.size(), out); 105 } 106 107 inline Result ParseUint128(std::string_view v, v128* out) { 108 return ParseUint128(v.data(), v.data() + v.size(), out); 109 } 110 111 inline Result ParseFloat(LiteralType literal_type, 112 std::string_view v, 113 uint32_t* out_bits) { 114 return ParseFloat(literal_type, v.data(), v.data() + v.size(), out_bits); 115 } 116 117 inline Result ParseDouble(LiteralType literal_type, 118 std::string_view v, 119 uint64_t* out_bits) { 120 return ParseDouble(literal_type, v.data(), v.data() + v.size(), out_bits); 121 } 122 123 void WriteFloatHex(char* buffer, size_t size, uint32_t bits); 124 void WriteDoubleHex(char* buffer, size_t size, uint64_t bits); 125 void WriteUint128(char* buffer, size_t size, v128 bits); 126 127 } // namespace wabt 128 129 #endif /* WABT_LITERAL_H_ */