1/*
2 * Copyright 2015 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 wasm_parsing_h
18#define wasm_parsing_h
19
20#include <cmath>
21#include <ostream>
22#include <sstream>
23#include <string>
24
25#include "mixed_arena.h"
26#include "shared-constants.h"
27#include "support/colors.h"
28#include "support/utilities.h"
29#include "wasm-traversal.h"
30#include "wasm.h"
31
32namespace wasm {
33
34struct ParseException {
35 std::string text;
36 size_t line, col;
37
38 ParseException() : text("unknown parse error"), line(-1), col(-1) {}
39 ParseException(std::string text) : text(text), line(-1), col(-1) {}
40 ParseException(std::string text, size_t line, size_t col)
41 : text(text), line(line), col(col) {}
42
43 void dump(std::ostream& o) const;
44};
45
46struct MapParseException {
47 std::string text;
48
49 MapParseException() : text("unknown parse error") {}
50 MapParseException(std::string text) : text(text) {}
51
52 void dump(std::ostream& o) const;
53};
54
55// Helper for parsers that may not have unique label names. This transforms
56// the names into unique ones, as required by Binaryen IR.
57struct UniqueNameMapper {
58 std::vector<Name> labelStack;
59 // name in source => stack of uniquified names
60 std::map<Name, std::vector<Name>> labelMappings;
61 std::map<Name, Name> reverseLabelMapping; // uniquified name => name in source
62
63 Index otherIndex = 0;
64
65 Name getPrefixedName(Name prefix);
66
67 // receives a source name. generates a unique name, pushes it, and returns it
68 Name pushLabelName(Name sName);
69
70 void popLabelName(Name name);
71
72 Name sourceToUnique(Name sName);
73
74 Name uniqueToSource(Name name);
75
76 void clear();
77
78 // Given an expression, ensures all names are unique
79 static void uniquify(Expression* curr);
80};
81
82} // namespace wasm
83
84#endif // wasm_parsing_h
85

source code of dart_sdk/third_party/binaryen/src/src/parsing.h