tvm
span.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
24 #ifndef TVM_IR_SPAN_H_
25 #define TVM_IR_SPAN_H_
26 
27 #include <tvm/node/node.h>
28 #include <tvm/runtime/object.h>
29 
30 #include <string>
31 
32 namespace tvm {
37 class SourceName;
41 class SourceNameNode : public Object {
42  public:
45  // override attr visitor
46  void VisitAttrs(AttrVisitor* v) { v->Visit("name", &name); }
47 
48  static constexpr bool _type_has_method_sequal_reduce = true;
49 
50  bool SEqualReduce(const SourceNameNode* other, SEqualReducer equal) const {
51  return equal(name, other->name);
52  }
53 
54  static constexpr const char* _type_key = "SourceName";
56 };
57 
62 class SourceName : public ObjectRef {
63  public:
70  TVM_DLL static SourceName Get(const String& name);
71 
73 };
74 
78 class Span;
82 class SpanNode : public Object {
83  public:
87  int line;
89  int column;
91  int end_line;
94 
95  // override attr visitor
97  v->Visit("source_name", &source_name);
98  v->Visit("line", &line);
99  v->Visit("column", &column);
100  v->Visit("end_line", &end_line);
101  v->Visit("end_column", &end_column);
102  }
103  static constexpr bool _type_has_method_sequal_reduce = true;
104 
105  bool SEqualReduce(const SpanNode* other, SEqualReducer equal) const {
106  return equal(source_name, other->source_name) && equal(line, other->line) &&
107  equal(column, other->column) && equal(end_line, other->end_line) &&
108  equal(end_column, other->end_column);
109  }
110 
111  static constexpr const char* _type_key = "Span";
113 };
114 
115 class Span : public ObjectRef {
116  public:
117  TVM_DLL Span(SourceName source_name, int line, int end_line, int column, int end_column);
118 
120  TVM_DLL Span Merge(const Span& other) const;
121 
123 };
124 
125 } // namespace tvm
126 #endif // TVM_IR_SPAN_H_
tvm::Span Span
Definition: base.h:65
Definitions and helper macros for IR/AST nodes.
bool SEqualReduce(const SpanNode *other, SEqualReducer equal) const
Definition: span.h:105
The name of a source fragment.
Definition: span.h:41
A Reducer class to reduce the structural equality result of two objects.
Definition: structural_equal.h:124
runtime implementation for LibTorch/TorchScript.
Definition: analyzer.h:36
static constexpr bool _type_has_method_sequal_reduce
Definition: span.h:48
PrimExpr equal(PrimExpr a, PrimExpr b, Span span=Span())
equal
tvm::SourceName SourceName
Definition: base.h:64
SourceName source_name
The source name.
Definition: span.h:85
TVM_DECLARE_FINAL_OBJECT_INFO(SourceNameNode, Object)
base class of all object containers.
Definition: object.h:167
int column
The column offset.
Definition: span.h:89
int line
The line number.
Definition: span.h:87
Visitor class to get the attributes of an AST/IR node. The content is going to be called for each fie...
Definition: reflection.h:52
Definition: span.h:115
String name
The source name.
Definition: span.h:44
The source name of a file span.
Definition: span.h:62
void VisitAttrs(AttrVisitor *v)
Definition: span.h:96
int end_column
The end column number.
Definition: span.h:93
static constexpr const char * _type_key
Definition: span.h:54
Reference to string objects.
Definition: string.h:97
#define TVM_DEFINE_OBJECT_REF_METHODS(TypeName, ParentType, ObjectName)
Definition: object.h:713
bool SEqualReduce(const SourceNameNode *other, SEqualReducer equal) const
Definition: span.h:50
int end_line
The end line number.
Definition: span.h:91
Base class of all object reference.
Definition: object.h:511
Stores locations in frontend source that generated a node.
Definition: span.h:82
A managed object in the TVM runtime.
Map< K, V > Merge(Map< K, V > lhs, const Map< K, V > &rhs)
Merge two Maps.
Definition: map.h:1471
void VisitAttrs(AttrVisitor *v)
Definition: span.h:46