To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

code_emission.rs 1.48 KB
Newer Older
1
2
3
4
#![allow(dead_code)]

use compiler::CompilerPass;
use ast::ir::*;
qinsoon's avatar
qinsoon committed
5
use vm::VM;
6
use compiler::backend::emit_code;
qinsoon's avatar
qinsoon committed
7
8
use std::any::Any;

qinsoon's avatar
qinsoon committed
9
10
11
12
13
14
15
16
17
18
const EMIT_MUIR : bool = true;

pub fn create_emit_directory(vm: &VM) {
    use std::fs;
    match fs::create_dir(&vm.vm_options.flag_aot_emit_dir) {
        Ok(_) => {},
        Err(_) => {}
    }
}

19
20
21
22
23
24
25
26
27
28
pub struct CodeEmission {
    name: &'static str
}

impl CodeEmission {
    pub fn new() -> CodeEmission {
        CodeEmission {
            name: "Code Emission"
        }
    }
qinsoon's avatar
qinsoon committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

    fn emit_muir(&self, func: &MuFunctionVersion, vm: &VM) {
        use std::path;
        use std::io::prelude::*;
        use std::fs::File;

        // create emit directory
        create_emit_directory(vm);

        let mut file_path = path::PathBuf::new();
        file_path.push(&vm.vm_options.flag_aot_emit_dir);
        file_path.push(func.name().unwrap().to_string() + ".muir");
        let mut file = match File::create(file_path.as_path()) {
            Err(why) => panic!("couldn't create muir file {}: {}", file_path.to_str().unwrap(), why),
            Ok(file) => file
        };

        file.write_fmt(format_args!("{:?}", func)).unwrap();
    }
48
49
50
51
52
53
}

impl CompilerPass for CodeEmission {
    fn name(&self) -> &'static str {
        self.name
    }
qinsoon's avatar
qinsoon committed
54

qinsoon's avatar
qinsoon committed
55
56
57
58
    fn as_any(&self) -> &Any {
        self
    }

qinsoon's avatar
qinsoon committed
59
60
    fn visit_function(&mut self, vm: &VM, func: &mut MuFunctionVersion) {
        emit_code(func, vm);
qinsoon's avatar
qinsoon committed
61
62
63
64

        if EMIT_MUIR {
            self.emit_muir(func, vm);
        }
65
    }
qinsoon's avatar
qinsoon committed
66
}