muctx.rs 12 KB
Newer Older
1 2
use super::common::*;

3
pub struct MuCtx {
4
    /// ref to MuVM
5
    mvm: *const MuVM,
6 7 8 9 10

    /// Point to the C-visible CMuCtx so that `close_context` can deallocate itself.
    pub c_struct: *mut CMuCtx,
}

11 12
impl MuCtx {
    pub fn new(mvm: *const MuVM) -> Box<MuCtx> {
13 14 15 16 17 18 19 20
        Box::new(MuCtx {
            mvm: mvm,
            c_struct: ptr::null_mut(),
        })
    }

    #[inline(always)]
    fn get_mvm(&mut self) -> &MuVM {
21 22
        //self.mvm
        unsafe { & *self.mvm }
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
    }

    pub fn id_of(&mut self, name: MuName) -> MuID {
        self.get_mvm().id_of(name)
    }

    pub fn name_of(&mut self, id: MuID) -> CMuCString {
        self.get_mvm().name_of(id)
    }

    fn deallocate(&mut self) {
        let c_struct = self.c_struct;
        let ctx_ptr = self as *mut MuCtx;
        debug!("Deallocating MuCtx {:?} and CMuCtx {:?}...", ctx_ptr, c_struct);
        unsafe {
            Box::from_raw(c_struct);
            Box::from_raw(ctx_ptr);
        }
    }

    pub fn close_context(&mut self) {
        info!("Closing MuCtx...");
        self.deallocate();
    }

    pub fn load_bundle(&mut self, buf: &[c_char]) {
        panic!("The fast implementation does not support the text form.")
    }

    pub fn load_hail(&mut self, buf: &[c_char]) {
        panic!("The fast implementation does not support the text form.")
    }

56
    pub fn handle_from_sint8(&mut self, num: i8, len: c_int) -> *const APIHandleKey {
57 58 59
        panic!("Not implemented")
    }

60
    pub fn handle_from_uint8(&mut self, num: u8, len: c_int) -> *const APIHandleKey {
61 62 63
        panic!("Not implemented")
    }

64
    pub fn handle_from_sint16(&mut self, num: i16, len: c_int) -> *const APIHandleKey {
65 66 67
        panic!("Not implemented")
    }

68
    pub fn handle_from_uint16(&mut self, num: u16, len: c_int) -> *const APIHandleKey {
69 70 71
        panic!("Not implemented")
    }

72
    pub fn handle_from_sint32(&mut self, num: i32, len: c_int) -> *const APIHandleKey {
73 74 75
        panic!("Not implemented")
    }

76
    pub fn handle_from_uint32(&mut self, num: u32, len: c_int) -> *const APIHandleKey {
77 78 79
        panic!("Not implemented")
    }

80
    pub fn handle_from_sint64(&mut self, num: i64, len: c_int) -> *const APIHandleKey {
81 82 83
        panic!("Not implemented")
    }

84
    pub fn handle_from_uint64(&mut self, num: u64, len: c_int) -> *const APIHandleKey {
85 86 87
        panic!("Not implemented")
    }

88
    pub fn handle_from_uint64s(&mut self, nums: &[u64], len: c_int) -> *const APIHandleKey {
89 90 91
        panic!("Not implemented")
    }

92
    pub fn handle_from_float(&mut self, num: f32) -> *const APIHandleKey {
93 94 95
        panic!("Not implemented")
    }

96
    pub fn handle_from_double(&mut self, num: f64) -> *const APIHandleKey {
97 98 99
        panic!("Not implemented")
    }

100
    pub fn handle_from_ptr(&mut self, mu_type: MuID, ptr: CMuCPtr) -> *const APIHandleKey {
101 102 103
        panic!("Not implemented")
    }

104
    pub fn handle_from_fp(&mut self, mu_type: MuID, fp: CMuCFP) -> *const APIHandleKey {
105 106 107
        panic!("Not implemented")
    }

108
    pub fn handle_to_sint8(&mut self, opnd: &APIHandleKey) -> i8 {
109 110 111
        panic!("Not implemented")
    }

112
    pub fn handle_to_uint8(&mut self, opnd: &APIHandleKey) -> u8 {
113 114 115
        panic!("Not implemented")
    }

116
    pub fn handle_to_sint16(&mut self, opnd: &APIHandleKey) -> i16 {
117 118 119
        panic!("Not implemented")
    }

120
    pub fn handle_to_uint16(&mut self, opnd: &APIHandleKey) -> u16 {
121 122 123
        panic!("Not implemented")
    }

124
    pub fn handle_to_sint32(&mut self, opnd: &APIHandleKey) -> i32 {
125 126 127
        panic!("Not implemented")
    }

128
    pub fn handle_to_uint32(&mut self, opnd: &APIHandleKey) -> u32 {
129 130 131
        panic!("Not implemented")
    }

132
    pub fn handle_to_sint64(&mut self, opnd: &APIHandleKey) -> i64 {
133 134 135
        panic!("Not implemented")
    }

136
    pub fn handle_to_uint64(&mut self, opnd: &APIHandleKey) -> u64 {
137 138 139
        panic!("Not implemented")
    }

140
    pub fn handle_to_float(&mut self, opnd: &APIHandleKey) -> f32 {
141 142 143
        panic!("Not implemented")
    }

144
    pub fn handle_to_double(&mut self, opnd: &APIHandleKey) -> f64 {
145 146 147
        panic!("Not implemented")
    }

148
    pub fn handle_to_ptr(&mut self, opnd: &APIHandleKey) -> CMuCPtr {
149 150 151
        panic!("Not implemented")
    }

152
    pub fn handle_to_fp(&mut self, opnd: &APIHandleKey) -> CMuCFP {
153 154 155
        panic!("Not implemented")
    }

156
    pub fn handle_from_const(&mut self, id: MuID) -> *const APIHandleKey {
157 158 159
        panic!("Not implemented")
    }

160
    pub fn handle_from_global(&mut self, id: MuID) -> *const APIHandleKey {
161 162 163
        panic!("Not implemented")
    }

164
    pub fn handle_from_func(&mut self, id: MuID) -> *const APIHandleKey {
165 166 167
        panic!("Not implemented")
    }

168
    pub fn handle_from_expose(&mut self, id: MuID) -> *const APIHandleKey {
169 170 171
        panic!("Not implemented")
    }

172
    pub fn delete_value(&mut self, opnd: &APIHandleKey) {
173 174 175
        panic!("Not implemented")
    }

176
    pub fn ref_eq(&mut self, lhs: &APIHandleKey, rhs: &APIHandleKey) -> bool {
177 178 179
        panic!("Not implemented")
    }

180
    pub fn ref_ult(&mut self, lhs: &APIHandleKey, rhs: &APIHandleKey) -> bool {
181 182 183
        panic!("Not implemented")
    }

184
    pub fn extract_value(&mut self, str: &APIHandleKey, index: c_int) -> *const APIHandleKey {
185 186 187
        panic!("Not implemented")
    }

188
    pub fn insert_value(&mut self, str: &APIHandleKey, index: c_int, newval: &APIHandleKey) -> *const APIHandleKey {
189 190 191
        panic!("Not implemented")
    }

192
    pub fn extract_element(&mut self, str: &APIHandleKey, index: &APIHandleKey) -> *const APIHandleKey {
193 194 195
        panic!("Not implemented")
    }

196
    pub fn insert_element(&mut self, str: &APIHandleKey, index: &APIHandleKey, newval: &APIHandleKey) -> *const APIHandleKey {
197 198 199
        panic!("Not implemented")
    }

200
    pub fn new_fixed(&mut self, mu_type: MuID) -> *const APIHandleKey {
201 202 203
        panic!("Not implemented")
    }

204
    pub fn new_hybrid(&mut self, mu_type: MuID, length: &APIHandleKey) -> *const APIHandleKey {
205 206 207
        panic!("Not implemented")
    }

208
    pub fn refcast(&mut self, opnd: &APIHandleKey, new_type: MuID) -> *const APIHandleKey {
209 210 211
        panic!("Not implemented")
    }

212
    pub fn get_iref(&mut self, opnd: &APIHandleKey) -> *const APIHandleKey {
213 214 215
        panic!("Not implemented")
    }

216
    pub fn get_field_iref(&mut self, opnd: &APIHandleKey, field: c_int) -> *const APIHandleKey {
217 218 219
        panic!("Not implemented")
    }

220
    pub fn get_elem_iref(&mut self, opnd: &APIHandleKey, index: &APIHandleKey) -> *const APIHandleKey {
221 222 223
        panic!("Not implemented")
    }

224
    pub fn shift_iref(&mut self, opnd: &APIHandleKey, offset: &APIHandleKey) -> *const APIHandleKey {
225 226 227
        panic!("Not implemented")
    }

228
    pub fn get_var_part_iref(&mut self, opnd: &APIHandleKey) -> *const APIHandleKey {
229 230 231
        panic!("Not implemented")
    }

232
    pub fn load(&mut self, ord: CMuMemOrd, loc: &APIHandleKey) -> *const APIHandleKey {
233 234 235
        panic!("Not implemented")
    }

236
    pub fn store(&mut self, ord: CMuMemOrd, loc: &APIHandleKey, newval: &APIHandleKey) {
237 238 239
        panic!("Not implemented")
    }

240
    pub fn cmpxchg(&mut self, ord_succ: CMuMemOrd, ord_fail: CMuMemOrd, weak: bool, loc: &APIHandleKey, expected: &APIHandleKey, desired: &APIHandleKey, is_succ: *mut CMuBool) -> *const APIHandleKey {
241 242 243
        panic!("Not implemented")
    }

244
    pub fn atomicrmw(&mut self, ord: CMuMemOrd, op: CMuAtomicRMWOptr, loc: &APIHandleKey, opnd: &APIHandleKey) -> *const APIHandleKey {
245 246 247 248 249 250 251
        panic!("Not implemented")
    }

    pub fn fence(&mut self, ord: CMuMemOrd) {
        panic!("Not implemented")
    }

252
    pub fn new_stack(&mut self, func: &APIHandleKey) -> *const APIHandleKey {
253 254 255
        panic!("Not implemented")
    }

256
    pub fn new_thread_nor(&mut self, stack: &APIHandleKey, threadlocal: Option<&APIHandleKey>, vals: Vec<&APIHandleKey>) -> *const APIHandleKey {
257 258 259
        panic!("Not implemented")
    }

260
    pub fn new_thread_exc(&mut self, stack: &APIHandleKey, threadlocal: Option<&APIHandleKey>, exc: &APIHandleKey) -> *const APIHandleKey {
261 262 263
        panic!("Not implemented")
    }

264
    pub fn kill_stack(&mut self, stack: &APIHandleKey) {
265 266 267
        panic!("Not implemented")
    }

268
    pub fn set_threadlocal(&mut self, thread: &APIHandleKey, threadlocal: &APIHandleKey) {
269 270 271
        panic!("Not implemented")
    }

272
    pub fn get_threadlocal(&mut self, thread: &APIHandleKey) -> *const APIHandleKey {
273 274 275
        panic!("Not implemented")
    }

276
    pub fn new_cursor(&mut self, stack: &APIHandleKey) -> *const APIHandleKey {
277 278 279
        panic!("Not implemented")
    }

280
    pub fn next_frame(&mut self, cursor: &APIHandleKey) {
281 282 283
        panic!("Not implemented")
    }

284
    pub fn copy_cursor(&mut self, cursor: &APIHandleKey) -> *const APIHandleKey {
285 286 287
        panic!("Not implemented")
    }

288
    pub fn close_cursor(&mut self, cursor: &APIHandleKey) {
289 290 291
        panic!("Not implemented")
    }

292
    pub fn cur_func(&mut self, cursor: &APIHandleKey) -> MuID {
293 294 295
        panic!("Not implemented")
    }

296
    pub fn cur_func_ver(&mut self, cursor: &APIHandleKey) -> MuID {
297 298 299
        panic!("Not implemented")
    }

300
    pub fn cur_inst(&mut self, cursor: &APIHandleKey) -> MuID {
301 302 303
        panic!("Not implemented")
    }

304
    pub fn dump_keepalives(&mut self, cursor: &APIHandleKey, results: *mut CMuValue) {
305 306 307
        panic!("Not implemented")
    }

308
    pub fn pop_frames_to(&mut self, cursor: &APIHandleKey) {
309 310 311
        panic!("Not implemented")
    }

312
    pub fn push_frame(&mut self, stack: &APIHandleKey, func: &APIHandleKey) {
313 314 315
        panic!("Not implemented")
    }

316
    pub fn tr64_is_fp(&mut self, value: &APIHandleKey) -> bool {
317 318 319
        panic!("Not implemented")
    }

320
    pub fn tr64_is_int(&mut self, value: &APIHandleKey) -> bool {
321 322 323
        panic!("Not implemented")
    }

324
    pub fn tr64_is_ref(&mut self, value: &APIHandleKey) -> bool {
325 326 327
        panic!("Not implemented")
    }

328
    pub fn tr64_to_fp(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
329 330 331
        panic!("Not implemented")
    }

332
    pub fn tr64_to_int(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
333 334 335
        panic!("Not implemented")
    }

336
    pub fn tr64_to_ref(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
337 338 339
        panic!("Not implemented")
    }

340
    pub fn tr64_to_tag(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
341 342 343
        panic!("Not implemented")
    }

344
    pub fn tr64_from_fp(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
345 346 347
        panic!("Not implemented")
    }

348
    pub fn tr64_from_int(&mut self, value: &APIHandleKey) -> *const APIHandleKey {
349 350 351
        panic!("Not implemented")
    }

352
    pub fn tr64_from_ref(&mut self, reff: &APIHandleKey, tag: &APIHandleKey) -> *const APIHandleKey {
353 354 355 356 357 358 359 360 361 362 363
        panic!("Not implemented")
    }

    pub fn enable_watchpoint(&mut self, wpid: CMuWPID) {
        panic!("Not implemented")
    }

    pub fn disable_watchpoint(&mut self, wpid: CMuWPID) {
        panic!("Not implemented")
    }

364
    pub fn pin(&mut self, loc: &APIHandleKey) -> *const APIHandleKey {
365 366 367
        panic!("Not implemented")
    }

368
    pub fn unpin(&mut self, loc: &APIHandleKey) {
369 370 371
        panic!("Not implemented")
    }

372
    pub fn get_addr(&mut self, loc: &APIHandleKey) -> *const APIHandleKey {
373 374 375
        panic!("Not implemented")
    }

376
    pub fn expose(&mut self, func: &APIHandleKey, call_conv: CMuCallConv, cookie: &APIHandleKey) -> *const APIHandleKey {
377 378 379
        panic!("Not implemented")
    }

380
    pub fn unexpose(&mut self, call_conv: CMuCallConv, value: &APIHandleKey) {
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
        panic!("Not implemented")
    }

    pub fn new_ir_builder(&mut self) -> *mut CMuIRBuilder {
        info!("Creating MuIRBuilder...");

        let b: Box<MuIRBuilder> = MuIRBuilder::new(self.mvm);

        let b_ptr = Box::into_raw(b);

        debug!("The MuIRBuilder address: {:?}", b_ptr);

        let cb = make_new_MuIRBuilder(b_ptr as *mut c_void);

        debug!("The C-visible CMuIRBuilder struct address: {:?}", cb);

        unsafe{ (*b_ptr).c_struct = cb; }

        cb
    }

402
    pub fn make_boot_image(&mut self, whitelist: Vec<MuID>, primordial_func: Option<&APIHandleKey>, primordial_stack: Option<&APIHandleKey>, primordial_threadlocal: Option<&APIHandleKey>, sym_fields: Vec<&APIHandleKey>, sym_strings: Vec<String>, reloc_fields: Vec<&APIHandleKey>, reloc_strings: Vec<String>, output_file: String) {
403 404 405 406
        panic!("Not implemented")
    }

}