1pub mod rt_decls {
2 #[allow(improper_ctypes)]
3 extern "C" {
4 pub fn CVT_calltrace_print_tag(tag: &str);
5
6 pub fn CVT_calltrace_print_u64_1(tag: &str, x: u64);
7 pub fn CVT_calltrace_print_u64_2(tag: &str, x: u64, y: u64);
8 pub fn CVT_calltrace_print_u64_3(tag: &str, x: u64, y: u64, z: u64);
9 pub fn CVT_calltrace_print_u128(tag: &str, x: u128);
10
11 pub fn CVT_calltrace_print_i64_1(tag: &str, x: i64);
12 pub fn CVT_calltrace_print_i64_2(tag: &str, x: i64, y: i64);
13 pub fn CVT_calltrace_print_i64_3(tag: &str, x: i64, y: i64, z: i64);
14 pub fn CVT_calltrace_print_i128(tag: &str, x: i128);
15
16 pub fn CVT_calltrace_print_string(tag: &str, v: &str);
17
18 pub fn CVT_calltrace_print_u64_as_fixed(tag: &str, x: u64, y: u64);
19
20 pub fn CVT_calltrace_print_location(file: &str, line: u64);
21 pub fn CVT_calltrace_attach_location(file: &str, line: u64);
22
23 pub fn CVT_rule_location(file: &str, line: u64);
24
25 pub fn CVT_calltrace_scope_start(name: &str);
26 pub fn CVT_calltrace_scope_end(name: &str);
27 }
28}
29
30#[cfg(feature = "rt")]
31mod rt_impls {
32 #[no_mangle]
33 pub extern "C" fn CVT_calltrace_print_tag(_tag: &str) {}
34 #[no_mangle]
35 pub extern "C" fn CVT_calltrace_print_u64_1(_tag: &str, _x: u64) {}
36 #[no_mangle]
37 pub extern "C" fn CVT_calltrace_print_u64_2(_tag: &str, _x: u64, _y: u64) {}
38 #[no_mangle]
39 pub extern "C" fn CVT_calltrace_print_u64_3(_tag: &str, _x: u64, _y: u64, _z: u64) {}
40 #[no_mangle]
41 pub extern "C" fn CVT_calltrace_print_u128(_tag: &str, _x: u128) {}
42 #[no_mangle]
43 pub extern "C" fn CVT_calltrace_print_i64_1(_tag: &str, _x: i64) {}
44 #[no_mangle]
45 pub extern "C" fn CVT_calltrace_print_i64_2(_tag: &str, _x: i64, _y: i64) {}
46 #[no_mangle]
47 pub extern "C" fn CVT_calltrace_print_i64_3(_tag: &str, _x: i64, _y: i64, _z: i64) {}
48 #[no_mangle]
49 pub extern "C" fn CVT_calltrace_print_i128(_tag: &str, _x: i128) {}
50 #[no_mangle]
51 pub extern "C" fn CVT_calltrace_print_u64_as_fixed(_tag: &str, _x: u64, _y: u64) {}
52 #[no_mangle]
53 pub extern "C" fn CVT_calltrace_print_string(_tag: &str, v: &str) {}
54 #[no_mangle]
55 pub extern "C" fn CVT_calltrace_print_location(_tag: &str, v: u64) {}
56 #[no_mangle]
57 pub extern "C" fn CVT_calltrace_attach_location(_tag: &str, v: u64) {}
58 #[no_mangle]
59 pub extern "C" fn CVT_rule_location(_file: &str, _line: u64) {}
60 #[no_mangle]
61 pub extern "C" fn CVT_calltrace_scope_start(name: &str) {}
62 #[no_mangle]
63 pub extern "C" fn CVT_calltrace_scope_end(name: &str) {}
64}
65pub use rt_decls::*;
66
67#[derive(Default)]
68pub struct CvlrLogger;
69
70impl CvlrLogger {
71 #[inline(always)]
72 pub fn new() -> Self {
73 Self {}
74 }
75 #[inline(always)]
76 pub fn log(&mut self, v: &str) {
77 unsafe {
78 CVT_calltrace_print_tag(v);
79 }
80 }
81
82 #[inline(always)]
83 pub fn log_str(&mut self, t: &str, v: &str) {
84 unsafe {
85 CVT_calltrace_print_string(t, v);
86 }
87 }
88
89 #[inline(always)]
90 pub fn log_u64(&mut self, t: &str, v: u64) {
91 unsafe {
92 CVT_calltrace_print_u64_1(t, v);
93 }
94 }
95
96 #[inline(always)]
97 pub fn log_u64_2(&mut self, t: &str, v0: u64, v1: u64) {
98 unsafe {
99 CVT_calltrace_print_u64_2(t, v0, v1);
100 }
101 }
102
103 #[inline(always)]
104 pub fn log_u64_3(&mut self, t: &str, v0: u64, v1: u64, v2: u64) {
105 unsafe {
106 CVT_calltrace_print_u64_3(t, v0, v1, v2);
107 }
108 }
109
110 #[inline(always)]
111 pub fn log_u128(&mut self, t: &str, v: u128) {
112 unsafe {
113 CVT_calltrace_print_u128(t, v);
114 }
115 }
116
117 #[inline(always)]
118 pub fn log_i64(&mut self, t: &str, v: i64) {
119 unsafe {
120 CVT_calltrace_print_i64_1(t, v);
121 }
122 }
123
124 #[inline(always)]
125 pub fn log_i128(&mut self, t: &str, v: i128) {
126 unsafe {
127 CVT_calltrace_print_i128(t, v);
128 }
129 }
130
131 #[inline(always)]
132 pub fn log_u64_as_fp(&mut self, t: &str, v: u64, b: u64) {
133 unsafe {
134 CVT_calltrace_print_u64_as_fixed(t, v, b);
135 }
136 }
137
138 #[inline(always)]
139 pub fn log_loc(&mut self, file: &str, line: u32) {
140 unsafe {
141 CVT_calltrace_print_location(file, line as u64);
142 }
143 }
144
145 #[inline(always)]
146 pub fn add_loc(&mut self, file: &str, line: u32) {
147 unsafe {
148 CVT_calltrace_attach_location(file, line as u64);
149 }
150 }
151
152 #[inline(always)]
153 pub fn log_rule_location(&mut self, file: &str, line: u64) {
154 unsafe {
155 crate::CVT_rule_location(file, line);
156 }
157 }
158
159 #[inline(always)]
160 pub fn log_scope_start(&mut self, scope: &str) {
161 unsafe {
162 CVT_calltrace_scope_start(scope);
163 }
164 }
165
166 #[inline(always)]
167 pub fn log_scope_end(&mut self, scope: &str) {
168 unsafe {
169 CVT_calltrace_scope_end(scope);
170 }
171 }
172}
173
174#[inline(always)]
175pub fn log(v: &str) {
176 let mut logger = CvlrLogger::new();
177 logger.log(v);
178}
179
180#[inline(always)]
181pub fn log_u64_as_fp(t: &str, v: u64, b: u64) {
182 let mut logger = CvlrLogger::new();
183 logger.log_u64_as_fp(t, v, b);
184}
185
186#[inline(always)]
187pub fn log_rule_location(file: &str, line: u64) {
188 let mut logger = CvlrLogger::new();
189 logger.log_rule_location(file, line);
190}
191
192#[inline(always)]
193pub fn log_scope_start(scope: &str) {
194 let mut logger = CvlrLogger::new();
195 logger.log_scope_start(scope);
196}
197
198#[inline(always)]
199pub fn log_scope_end(scope: &str) {
200 let mut logger = CvlrLogger::new();
201 logger.log_scope_end(scope);
202}
203
204macro_rules! expose_log_fn {
205 ($name: ident, $ty: ty) => {
206 #[inline(always)]
207 pub fn $name(t: &str, v: $ty) {
208 let mut logger = CvlrLogger::new();
209 logger.$name(t, v)
210 }
211 };
212}
213
214expose_log_fn! {log_str, &str}
215expose_log_fn! {log_u64, u64}
216expose_log_fn! {log_i64, i64}
217expose_log_fn! {log_u128, u128}
218expose_log_fn! {log_i128, i128}
219expose_log_fn! {log_loc, u32}
220expose_log_fn! {add_loc, u32}
221
222#[macro_export]
223macro_rules! cvlr_rule_location {
224 () => {{
225 $crate::log_rule_location(std::file!(), std::line!() as u64)
226 }};
227}