WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.6% of users enabled 2FA.

mod.rs 1.7 KB
Newer Older
1
use ast::ir::*;
qinsoon's avatar
qinsoon committed
2
use ast::ptr::*;
qinsoon's avatar
qinsoon committed
3 4
use vm::context::VMContext;

5 6 7 8 9 10 11 12 13 14 15 16 17
use std::cell::RefCell;

pub mod passes;

pub struct Compiler {
    policy: RefCell<CompilerPolicy>
}

impl Compiler {
    pub fn new(policy: CompilerPolicy) -> Compiler {
        Compiler{policy: RefCell::new(policy)}
    }
    
qinsoon's avatar
qinsoon committed
18
    pub fn compile(&self, vm: &VMContext, func: &mut MuFunction) {
19
        for pass in self.policy.borrow_mut().passes.iter_mut() {
qinsoon's avatar
qinsoon committed
20
            pass.execute(vm, func);
21 22 23 24 25 26 27 28 29 30 31
        }
    }
}

pub struct CompilerPolicy {
    passes: Vec<Box<CompilerPass>>
}

impl CompilerPolicy {
    pub fn default() -> CompilerPolicy {
        let mut passes : Vec<Box<CompilerPass>> = vec![];
qinsoon's avatar
qinsoon committed
32
        passes.push(Box::new(passes::tree_gen::TreeGenerationPass::new("Tree Generation")));
33 34 35 36 37 38
        
        CompilerPolicy{passes: passes}
    }
}

pub trait CompilerPass {
qinsoon's avatar
qinsoon committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    fn name(&self) -> &'static str;
    
    fn execute(&mut self, vm_context: &VMContext, func: &mut MuFunction) {
        debug!("---CompilerPass {} for {}---", self.name(), func.fn_name);
        
        self.visit_function(vm_context, func);
        
        for entry in func.blocks.iter_mut() {
            let label : MuTag = entry.0;
            let ref mut block : &mut Block = &mut entry.1;
            
            debug!("block: {}", label);
            
            for node in block.content.as_mut().unwrap().body.iter_mut() {
                debug!("{:?}", node);
            }
            
            debug!("---finish---");
        }
    }
    
    fn visit_function(&mut self, vm_context: &VMContext, func: &mut MuFunction) {}
    fn visit_block(&mut self, vm_context: &VMContext, block: &mut Block) {}
    fn visit_node(&mut self, vm_context: &VMContext, node: &mut TreeNode) {}
63
}