1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
use tvm_macros::Object;
use crate::runtime::String as TString;
use crate::runtime::{self, external, IsObject, IsObjectRef, Object, ObjectPtr, ObjectRef};
use crate::DataType;
use super::relay;
use super::span::Span;
#[repr(C)]
#[derive(Object, Debug)]
#[ref_name = "BaseExpr"]
#[type_key = "Expr"]
pub struct BaseExprNode {
pub base: Object,
pub span: Span,
}
impl BaseExprNode {
pub fn base<T: IsObject>(span: Span) -> BaseExprNode {
BaseExprNode {
base: Object::base::<T>(),
span,
}
}
}
#[repr(C)]
#[derive(Object, Debug)]
#[ref_name = "PrimExpr"]
#[type_key = "PrimExpr"]
pub struct PrimExprNode {
pub base: BaseExprNode,
pub datatype: DataType,
}
impl PrimExprNode {
pub fn base<T: IsObject>(datatype: DataType, span: Span) -> PrimExprNode {
PrimExprNode {
base: BaseExprNode::base::<T>(span),
datatype,
}
}
}
#[repr(C)]
#[derive(Object, Debug)]
#[ref_name = "GlobalVar"]
#[type_key = "GlobalVar"]
pub struct GlobalVarNode {
pub base: relay::ExprNode,
pub name_hint: TString,
}
impl GlobalVar {
pub fn new(name_hint: String, span: Span) -> GlobalVar {
let node = GlobalVarNode {
base: relay::ExprNode::base::<GlobalVarNode>(span),
name_hint: name_hint.into(),
};
GlobalVar(Some(ObjectPtr::new(node)))
}
}
external! {
#[name("ir.AsText")]
fn _as_text(object: ObjectRef, show_meta_data: i32, annotate: runtime::Function) -> TString;
}
pub fn as_text<T: IsObjectRef>(object: T) -> String {
let no_func = unsafe { runtime::Function::null() };
_as_text(object.upcast(), 0, no_func)
.unwrap()
.as_str()
.unwrap()
.into()
}