MCPcopy Index your code
hub / github.com/apache/tvm / Source

Class Source

python/tvm/script/parser/core/diagnostics.py:28–100  ·  view source on GitHub ↗

Source code class for TVMScript. It is constructed by source code str or doc AST tree. Parameters ---------- source_name : str The filename of the file where the source code locates. start_line : int The first line number of the source code. start_column :

Source from the content-addressed store, hash-verified

26
27
28class Source:
29 """Source code class for TVMScript.
30
31 It is constructed by source code str or doc AST tree.
32
33 Parameters
34 ----------
35 source_name : str
36 The filename of the file where the source code locates.
37
38 start_line : int
39 The first line number of the source code.
40
41 start_column : int
42 The first column number of the first line of the source code.
43
44 source : str
45 The source code str of source code.
46
47 full_source : str
48 The complete source code of the file where the source code locates.
49 """
50
51 source_name: str
52 start_line: int
53 start_column: int
54 source: str
55 full_source: str
56
57 def __init__(self, program: str | doc.AST):
58 if isinstance(program, str):
59 self.source_name = "<str>"
60 self.start_line = 1
61 self.start_column = 0
62 self.source = program
63 self.full_source = program
64 return
65
66 self.source_name = inspect.getsourcefile(program) # type: ignore
67 lines, self.start_line = getsourcelines(program) # type: ignore
68 if lines:
69 self.start_column = len(lines[0]) - len(lines[0].lstrip())
70 else:
71 self.start_column = 0
72 if self.start_column and lines:
73 self.source = "\n".join([l[self.start_column :].rstrip() for l in lines])
74 else:
75 self.source = "".join(lines)
76 try:
77 # It will cause a problem when running in Jupyter Notebook.
78 # `mod` will be <module '__main__'>, which is a built-in module
79 # and `getsource` will throw a TypeError
80 mod = inspect.getmodule(program)
81 if mod:
82 self.full_source = inspect.getsource(mod)
83 else:
84 self.full_source = self.source
85 except TypeError:

Callers 5

test_source_baseFunction · 0.90
test_source_astFunction · 0.90
_calcFunction · 0.90
scan_macroFunction · 0.85
parseFunction · 0.85

Calls

no outgoing calls

Tested by 3

test_source_baseFunction · 0.72
test_source_astFunction · 0.72
_calcFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…