pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
    // acquire lock and function
    let funcs = vm.funcs().read().unwrap();
    let func = funcs.get(&fv.func_id).unwrap().read().unwrap();

    // acquire lock and compiled function
    let compiled_funcs = vm.compiled_funcs().read().unwrap();
    let cf = compiled_funcs.get(&fv.id()).unwrap().read().unwrap();

    // create 'emit' directory
    create_emit_directory(vm);

    // create emit file
    let mut file_path = path::PathBuf::new();
    file_path.push(&vm.vm_options.flag_aot_emit_dir);
    file_path.push((*func.name()).clone() + ".S");
    {
        let mut file = match File::create(file_path.as_path()) {
            Err(why) => {
                panic!(
                    "couldn't create emission file {}: {}",
                    file_path.to_str().unwrap(),
                    why
                )
            }
            Ok(file) => file
        };
        // constants in text section
        file.write("\t.text\n".as_bytes()).unwrap();

        // write constants
        for (id, constant) in cf.consts.iter() {
            let mem = cf.const_mem.get(id).unwrap();
            write_const(&mut file, constant.clone(), mem.clone());
        }

        // write code
        let code = cf.mc.as_ref().unwrap().emit();
        match file.write_all(code.as_slice()) {
            Err(why) => {
                panic!(
                    "couldn'd write to file {}: {}",
                    file_path.to_str().unwrap(),
                    why
                )
            }
            Ok(_) => info!("emit code to {}", file_path.to_str().unwrap())
        }
    }
    info!("write demangled code...");
    // Read the file we just wrote above an demangle it
    {
        let mut demangled_path = path::PathBuf::new();
        demangled_path.push(&vm.vm_options.flag_aot_emit_dir);
        demangled_path.push((*func.name()).clone() + ".demangled.S");

        let mut demangled_file = match File::create(demangled_path.as_path()) {
            Err(why) => {
                panic!(
                    "couldn't create demangled emission file {}: {}",
                    demangled_path.to_str().unwrap(),
                    why
                )
            }
            Ok(file) => file
        };
        let mut mangled_file = match File::open(file_path.as_path()) {
            Err(why) => {
                panic!(
                    "couldn't create demangled emission file {}: {}",
                    demangled_path.to_str().unwrap(),
                    why
                )
            }
            Ok(file) => file
        };
        let mut f = String::new();
        mangled_file.read_to_string(&mut f).unwrap();
        let d = demangle_text(&f);
        match demangled_file.write_all(d.as_bytes()) {
            Err(why) => {
                panic!(
                    "couldn'd write to file {}: {}",
                    demangled_path.to_str().unwrap(),
                    why
                )
            }
            Ok(_) => {
                info!(
                    "emit demangled code to {}",
                    demangled_path.to_str().unwrap()
                )
            }
        }
    }
}
/// emit assembly file for a function version
emit assembly file for a function version
emit assembly file for a function version
pub fn emit_code(fv: &mut MuFunctionVersion, vm: &VM) {
    // acquire lock and function
    let funcs = vm.funcs().read().unwrap();
    let func = funcs.get(&fv.func_id).unwrap().read().unwrap();
    // acquire lock and compiled function
    let compiled_funcs = vm.compiled_funcs().read().unwrap();
    let cf = compiled_funcs.get(&fv.id()).unwrap().read().unwrap();
    // create 'emit' directory
    create_emit_directory(vm);
    // create emit file
    let mut file_path = path::PathBuf::new();
    file_path.push(&vm.vm_options.flag_aot_emit_dir);
    file_path.push((*func.name()).clone() + ".S");
    {
        let mut file = match File::create(file_path.as_path()) {
            Err(why) => {
                panic!(
                    "couldn't create emission file {}: {}",
                    file_path.to_str().unwrap(),
                    why
                )
            }
            Ok(file) => file
        };
        // constants in text section
        file.write("\t.text\n".as_bytes()).unwrap();
        // write constants
        for (id, constant) in cf.consts.iter() {
            let mem = cf.const_mem.get(id).unwrap();
            write_const(&mut file, constant.clone(), mem.clone());
        }
        // write code
        let code = cf.mc.as_ref().unwrap().emit();
        match file.write_all(code.as_slice()) {
            Err(why) => {
                panic!(
                    "couldn'd write to file {}: {}",
                    file_path.to_str().unwrap(),
                    why
                )
            }
            Ok(_) => info!("emit code to {}", file_path.to_str().unwrap())
        }
    }
    info!("write demangled code...");
    // Read the file we just wrote above an demangle it
    {
        let mut demangled_path = path::PathBuf::new();
        demangled_path.push(&vm.vm_options.flag_aot_emit_dir);
        demangled_path.push((*func.name()).clone() + ".demangled.S");
        let mut demangled_file = match File::create(demangled_path.as_path()) {
            Err(why) => {
                panic!(
                    "couldn't create demangled emission file {}: {}",
                    demangled_path.to_str().unwrap(),
                    why
                )
            }
            Ok(file) => file
        };
        let mut mangled_file = match File::open(file_path.as_path()) {
            Err(why) => {
                panic!(
                    "couldn't create demangled emission file {}: {}",
                    demangled_path.to_str().unwrap(),
                    why
                )
            }
            Ok(file) => file
        };
        let mut f = String::new();
        mangled_file.read_to_string(&mut f).unwrap();
        let d = demangle_text(&f);
        match demangled_file.write_all(d.as_bytes()) {
            Err(why) => {
                panic!(
                    "couldn'd write to file {}: {}",
                    demangled_path.to_str().unwrap(),
                    why
                )
            }
            Ok(_) => {
                info!(
                    "emit demangled code to {}",
                    demangled_path.to_str().unwrap()
                )
            }
        }
    }
}
pub fn emit_code ( fv : & mut MuFunctionVersion , vm : & VM ) { // acquire lock and function let funcs = vm . funcs ( ) . read ( ) . unwrap ( ) ; let func = funcs . get ( & fv . func_id ) . unwrap ( ) . read ( ) . unwrap ( ) ; // acquire lock and compiled function let compiled_funcs = vm . compiled_funcs ( ) . read ( ) . unwrap ( ) ; let cf = compiled_funcs . get ( & fv . id ( ) ) . unwrap ( ) . read ( ) . unwrap ( ) ; // create 'emit' directory create_emit_directory ( vm ) ; // create emit file let mut file_path = path :: PathBuf :: new ( ) ; file_path . push ( & vm . vm_options . flag_aot_emit_dir ) ; file_path . push ( ( * func . name ( ) ) . clone ( ) + " " ) ; { let mut file = match File :: create ( file_path . as_path ( ) ) { Err ( why ) => { panic ! ( " " file_path to_str ( ) unwrap ( ) why ) } Ok ( file ) => file } ; // constants in text section file . write ( " \t \n " . as_bytes ( ) ) . unwrap ( ) ; // write constants for ( id , constant ) in cf . consts . iter ( ) { let mem = cf . const_mem . get ( id ) . unwrap ( ) ; write_const ( & mut file , constant . clone ( ) , mem . clone ( ) ) ; } // write code let code = cf . mc . as_ref ( ) . unwrap ( ) . emit ( ) ; match file . write_all ( code . as_slice ( ) ) { Err ( why ) => { panic ! ( " " file_path to_str ( ) unwrap ( ) why ) } Ok ( _ ) => info ! ( " " file_path to_str ( ) unwrap ( ) ) } } info ! ( " " ) ; // Read the file we just wrote above an demangle it { let mut demangled_path = path :: PathBuf :: new ( ) ; demangled_path . push ( & vm . vm_options . flag_aot_emit_dir ) ; demangled_path . push ( ( * func . name ( ) ) . clone ( ) + " " ) ; let mut demangled_file = match File :: create ( demangled_path . as_path ( ) ) { Err ( why ) => { panic ! ( " " demangled_path to_str ( ) unwrap ( ) why ) } Ok ( file ) => file } ; let mut mangled_file = match File :: open ( file_path . as_path ( ) ) { Err ( why ) => { panic ! ( " " demangled_path to_str ( ) unwrap ( ) why ) } Ok ( file ) => file } ; let mut f = String :: new ( ) ; mangled_file . read_to_string ( & mut f ) . unwrap ( ) ; let d = demangle_text ( & f ) ; match demangled_file . write_all ( d . as_bytes ( ) ) { Err ( why ) => { panic ! ( " " demangled_path to_str ( ) unwrap ( ) why ) } Ok ( _ ) => { info ! ( " " demangled_path to_str ( ) unwrap ( ) ) } } } }
emit assembly file for a function version
emit assembly file for a function version
fv
&mut MuFunctionVersion
vm
&VM
fv
&mut MuFunctionVersion
vm
&VM