1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
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 
16 #ifndef TENSORFLOW_COMPILER_XLA_TOOLS_PARSER_HLO_TOKEN_H_
17 #define TENSORFLOW_COMPILER_XLA_TOOLS_PARSER_HLO_TOKEN_H_
18 
19 #include <string>
20 
21 #include "tensorflow/compiler/xla/types.h"
22 #include "tensorflow/core/platform/types.h"
23 
24 namespace xla {
25 namespace tools {
26 
27 // Defines different kinds of tokens in a hlo module string.
28 enum class TokKind {
29   // Markers
30   kEof,
31   kError,
32 
33   // Tokens with no info.
34   kEqual,  // =
35   kComma,  // ,
36   kColon,  // :
37   kLsquare,
38   kRsquare,  // [  ]
39   kLbrace,
40   kRbrace,  // {  }
41   kLparen,
42   kRparen,  // (  )
43 
44   kArrow,    // ->
45   kComment,  // /*xxx*/
46 
47   // Keywords
48   kw_HloModule,
49   kw_ENTRY,
50   kw_ROOT,
51   kw_true,
52   kw_false,
53   kw_maximal,
54   kw_replicated,
55   kw_nan,
56   kw_inf,
57 
58   kNegInf,  // -inf
59 
60   // Typed tokens.
61   kName,           // %foo
62   kAttributeName,  // dimensions=
63   kDimLabels,      // [0-9bf]{2,}_[0-9io]{2,}->[0-9bf]{2,}
64   kDxD,            // [0-9]+(x[0-9]+)+
65   kPad,            // [0-9]+_[0-9]+(_[0-9]+)?(x[0-9]+_[0-9]+(_[0-9]+)?)*
66   kIdent,          // other identifiers
67   kString,         // "abcd\"\n"
68   kShape,          // f32[2,3]{1,0}
69   kInt,            // 42
70   kDecimal,        // 4.2
71 };
72 
73 string TokKindToString(TokKind kind);
74 
75 }  // namespace tools
76 }  // namespace xla
77 
78 #endif  // TENSORFLOW_COMPILER_XLA_TOOLS_PARSER_HLO_TOKEN_H_
79