MCPcopy Create free account
hub / github.com/WebAssembly/wabt / ParseSimdV128Const

Method ParseSimdV128Const

src/wast-parser.cc:2908–3020  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2906}
2907
2908Result WastParser::ParseSimdV128Const(Const* const_,
2909 TokenType token_type,
2910 ConstType const_type) {
2911 WABT_TRACE(ParseSimdV128Const);
2912
2913 uint8_t lane_count = 0;
2914 bool integer = true;
2915 switch (token_type) {
2916 case TokenType::I8X16: { lane_count = 16; break; }
2917 case TokenType::I16X8: { lane_count = 8; break; }
2918 case TokenType::I32X4: { lane_count = 4; break; }
2919 case TokenType::I64X2: { lane_count = 2; break; }
2920 case TokenType::F32X4: { lane_count = 4; integer = false; break; }
2921 case TokenType::F64X2: { lane_count = 2; integer = false; break; }
2922 default: {
2923 Error(const_->loc,
2924 "Unexpected type at start of simd constant. "
2925 "Expected one of: i8x16, i16x8, i32x4, i64x2, f32x4, f64x2. "
2926 "Found \"%s\".",
2927 GetTokenTypeName(token_type));
2928 return Result::Error;
2929 }
2930 }
2931 DropToken();
2932
2933 const_->loc = GetLocation();
2934
2935 for (int lane = 0; lane < lane_count; ++lane) {
2936 Location loc = GetLocation();
2937
2938 // Check that the lane literal type matches the element type of the v128:
2939 Token token = GetToken();
2940 switch (token.token_type()) {
2941 case TokenType::Nat:
2942 case TokenType::Int:
2943 // OK.
2944 break;
2945
2946 case TokenType::Float:
2947 case TokenType::NanArithmetic:
2948 case TokenType::NanCanonical:
2949 if (integer) {
2950 goto error;
2951 }
2952 break;
2953
2954 error:
2955 default:
2956 if (integer) {
2957 return ErrorExpected({"a Nat or Integer literal"}, "123");
2958 } else {
2959 return ErrorExpected({"a Float literal"}, "42.0");
2960 }
2961 }
2962
2963 Result result;
2964
2965 // For each type, parse the next literal, bound check it, and write it to

Callers

nothing calls this directly

Calls 15

GetTokenTypeNameFunction · 0.85
FailedFunction · 0.85
token_typeMethod · 0.80
set_v128_u8Method · 0.80
set_v128_u16Method · 0.80
set_v128_u32Method · 0.80
set_v128_u64Method · 0.80
set_v128_f32Method · 0.80
set_v128_f64Method · 0.80
set_expected_nanMethod · 0.80
expected_nanMethod · 0.80
ParseInt8Function · 0.70

Tested by

no test coverage detected