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 }
24}
25
26#[cfg(feature = "rt")]
27mod rt_impls {
28 #[no_mangle]
29 pub extern "C" fn CVT_calltrace_print_tag(_tag: &str) {}
30 #[no_mangle]
31 pub extern "C" fn CVT_calltrace_print_u64_1(_tag: &str, _x: u64) {}
32 #[no_mangle]
33 pub extern "C" fn CVT_calltrace_print_u64_2(_tag: &str, _x: u64, _y: u64) {}
34 #[no_mangle]
35 pub extern "C" fn CVT_calltrace_print_u64_3(_tag: &str, _x: u64, _y: u64, _z: u64) {}
36 #[no_mangle]
37 pub extern "C" fn CVT_calltrace_print_u128(_tag: &str, _x: u128) {}
38 #[no_mangle]
39 pub extern "C" fn CVT_calltrace_print_i64_1(_tag: &str, _x: i64) {}
40 #[no_mangle]
41 pub extern "C" fn CVT_calltrace_print_i64_2(_tag: &str, _x: i64, _y: i64) {}
42 #[no_mangle]
43 pub extern "C" fn CVT_calltrace_print_i64_3(_tag: &str, _x: i64, _y: i64, _z: i64) {}
44 #[no_mangle]
45 pub extern "C" fn CVT_calltrace_print_i128(_tag: &str, _x: i128) {}
46 #[no_mangle]
47 pub extern "C" fn CVT_calltrace_print_u64_as_fixed(_tag: &str, _x: u64, _y: u64) {}
48 #[no_mangle]
49 pub extern "C" fn CVT_calltrace_print_string(_tag: &str, v: &str) {}
50 #[no_mangle]
51 pub extern "C" fn CVT_calltrace_print_location(_tag: &str, v: u64) {}
52 #[no_mangle]
53 pub extern "C" fn CVT_calltrace_attach_location(_tag: &str, v: u64) {}
54}
55pub use rt_decls::*;
56
57#[derive(Default)]
58pub struct CvlrLogger;
59
60impl CvlrLogger {
61 #[inline(always)]
62 pub fn new() -> Self {
63 Self {}
64 }
65 #[inline(always)]
66 pub fn log(&mut self, v: &str) {
67 unsafe {
68 CVT_calltrace_print_tag(v);
69 }
70 }
71
72 #[inline(always)]
73 pub fn log_str(&mut self, t: &str, v: &str) {
74 unsafe {
75 CVT_calltrace_print_string(t, v);
76 }
77 }
78
79 #[inline(always)]
80 pub fn log_u64(&mut self, t: &str, v: u64) {
81 unsafe {
82 CVT_calltrace_print_u64_1(t, v);
83 }
84 }
85
86 #[inline(always)]
87 pub fn log_u64_2(&mut self, t: &str, v0: u64, v1: u64) {
88 unsafe {
89 CVT_calltrace_print_u64_2(t, v0, v1);
90 }
91 }
92
93 #[inline(always)]
94 pub fn log_u64_3(&mut self, t: &str, v0: u64, v1: u64, v2: u64) {
95 unsafe {
96 CVT_calltrace_print_u64_3(t, v0, v1, v2);
97 }
98 }
99
100 #[inline(always)]
101 pub fn log_u128(&mut self, t: &str, v: u128) {
102 unsafe {
103 CVT_calltrace_print_u128(t, v);
104 }
105 }
106
107 #[inline(always)]
108 pub fn log_i64(&mut self, t: &str, v: i64) {
109 unsafe {
110 CVT_calltrace_print_i64_1(t, v);
111 }
112 }
113
114 #[inline(always)]
115 pub fn log_i128(&mut self, t: &str, v: i128) {
116 unsafe {
117 CVT_calltrace_print_i128(t, v);
118 }
119 }
120
121 #[inline(always)]
122 pub fn log_u64_as_fp(&mut self, t: &str, v: u64, b: u64) {
123 unsafe {
124 CVT_calltrace_print_u64_as_fixed(t, v, b);
125 }
126 }
127
128 #[inline(always)]
129 pub fn log_loc(&mut self, file: &str, line: u32) {
130 unsafe {
131 CVT_calltrace_print_location(file, line as u64);
132 }
133 }
134
135 #[inline(always)]
136 pub fn add_loc(&mut self, file: &str, line: u32) {
137 unsafe {
138 CVT_calltrace_attach_location(file, line as u64);
139 }
140 }
141}
142
143#[inline(always)]
144pub fn log(v: &str) {
145 let mut logger = CvlrLogger::new();
146 logger.log(v);
147}
148
149#[inline(always)]
150pub fn log_u64_as_fp(t: &str, v: u64, b: u64) {
151 let mut logger = CvlrLogger::new();
152 logger.log_u64_as_fp(t, v, b);
153}
154macro_rules! expose_log_fn {
155 ($name: ident, $ty: ty) => {
156 #[inline(always)]
157 pub fn $name(t: &str, v: $ty) {
158 let mut logger = CvlrLogger::new();
159 logger.$name(t, v)
160 }
161 };
162}
163
164expose_log_fn! {log_str, &str}
165expose_log_fn! {log_u64, u64}
166expose_log_fn! {log_i64, i64}
167expose_log_fn! {log_u128, u128}
168expose_log_fn! {log_i128, i128}
169expose_log_fn! {log_loc, u32}
170expose_log_fn! {add_loc, u32}