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.

vm_options.rs 5.64 KB
Newer Older
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
1
// Copyright 2017 The Australian National University
2
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
3 4 5
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
6
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
9 10 11 12 13 14
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

qinsoon's avatar
qinsoon committed
15 16
#![cfg_attr(rustfmt, rustfmt_skip)]

qinsoon's avatar
qinsoon committed
17 18 19
extern crate docopt;

use self::docopt::Docopt;
20
use std;
qinsoon's avatar
qinsoon committed
21 22
use std::default::Default;

qinsoon's avatar
qinsoon committed
23 24 25 26 27 28 29
const USAGE: &'static str = "
zebu (mu implementation). Pass arguments as a strings to init it.

Usage:
  init_mu [options]

VM:
30 31
  --log-level=<level>                   logging level: none, error, warn, info, debug, trace, env
                                        [default: env]
qinsoon's avatar
qinsoon committed
32

33
Compiler:
34
  --disable-inline                      disable compiler function inlining
qinsoon's avatar
qinsoon committed
35
  --disable-regalloc-validate           disable register allocation validation
qinsoon's avatar
fix  
qinsoon committed
36
  --disable-ir-validate                 disable IR validation
qinsoon's avatar
qinsoon committed
37
  --emit-debug-info                     emit debugging information
qinsoon's avatar
fix  
qinsoon committed
38

39
AOT Compiler:
40 41
  --aot-emit-dir=<dir>                  the emit directory for ahead-of-time compiling
                                        [default: emit]
qinsoon's avatar
fix  
qinsoon committed
42
  --aot-link-static                     link boot image to libmu statically (defaults to dynamic)
43 44 45 46
  --bootimage-external-lib=<lib> ...       library that will be linked against when making bootimage
                                           [default: ]
  --bootimage-external-libpath=<path> ...  path for the libraries during bootimage generation
                                           [default: ]
qinsoon's avatar
qinsoon committed
47 48

Garbage Collection:
49
  --gc-disable-collection               disable collection
50 51 52 53
  --gc-immixspace-size=<kb>             immix space size (default 65536kb = 64mb)
                                        [default: 67108864]
  --gc-lospace-size=<kb>                large object space size (default 65536kb = 64mb)
                                        [default: 67108864]
54
  --gc-nthreads=<n>                     number of threads for parallel gc [default: 8]
qinsoon's avatar
qinsoon committed
55 56
";

57
#[derive(Debug, Deserialize)]
58 59
pub struct VMOptions {
    // The comments here indicate the offset into the struct
qinsoon's avatar
qinsoon committed
60
    // VM
61
    pub flag_log_level: MuLogLevel,
qinsoon's avatar
qinsoon committed
62 63

    // Compiler
64 65
    pub flag_disable_inline: bool,
    pub flag_disable_regalloc_validate: bool,
qinsoon's avatar
fix  
qinsoon committed
66
    pub flag_disable_ir_validate: bool,
67
    pub flag_emit_debug_info: bool,
qinsoon's avatar
fix  
qinsoon committed
68

qinsoon's avatar
qinsoon committed
69
    // AOT compiler
70
    pub flag_aot_emit_dir: String,
qinsoon's avatar
fix  
qinsoon committed
71
    pub flag_aot_link_static: bool,
72 73
    pub flag_bootimage_external_lib: Vec<String>,
    pub flag_bootimage_external_libpath: Vec<String>,
74

qinsoon's avatar
qinsoon committed
75
    // GC
76 77 78 79
    pub flag_gc_disable_collection: bool,
    pub flag_gc_immixspace_size: usize,
    pub flag_gc_lospace_size: usize,
    pub flag_gc_nthreads: usize
qinsoon's avatar
qinsoon committed
80 81
}

82
// The fields need to be listed here in the order rust stores them in
83 84 85 86 87 88 89 90 91 92
rodal_struct!(VMOptions {
    flag_aot_emit_dir,
    flag_bootimage_external_lib,
    flag_bootimage_external_libpath,
    flag_gc_immixspace_size,
    flag_gc_lospace_size,
    flag_gc_nthreads,
    flag_log_level,
    flag_disable_inline,
    flag_disable_regalloc_validate,
qinsoon's avatar
fix  
qinsoon committed
93
    flag_disable_ir_validate,
94
    flag_emit_debug_info,
qinsoon's avatar
fix  
qinsoon committed
95
    flag_aot_link_static,
96
    flag_gc_disable_collection
97
});
98

99
#[derive(Debug, Clone, Copy, Deserialize)]
qinsoon's avatar
qinsoon committed
100
pub enum MuLogLevel {
101 102 103 104 105 106
    None,
    Error,
    Warn,
    Info,
    Debug,
    Trace,
107
    Env
108
}
109 110 111

rodal_value!(MuLogLevel); // This enum has no fields with pointers, so just dump a strait value

112 113 114 115 116 117 118 119 120
impl MuLogLevel {
    pub fn from_string(s: String) -> MuLogLevel {
        match s.as_str() {
            "none" => MuLogLevel::None,
            "error" => MuLogLevel::Error,
            "warn" => MuLogLevel::Warn,
            "info" => MuLogLevel::Info,
            "debug" => MuLogLevel::Debug,
            "trace" => MuLogLevel::Trace,
121
            _ => panic!("Unrecognised log level {}", s)
122 123
        }
    }
qinsoon's avatar
qinsoon committed
124 125 126 127
}

impl VMOptions {
    pub fn init(str: &str) -> VMOptions {
128
        info!("init vm options with: {:?}", str);
qinsoon's avatar
qinsoon committed
129

130
        let mut ret: VMOptions = Docopt::new(USAGE)
qinsoon's avatar
qinsoon committed
131
            .and_then(|d| d.argv(str.split_whitespace().into_iter()).parse())
132 133 134
            .unwrap_or_else(|e| e.exit())
            .deserialize()
            .unwrap();
qinsoon's avatar
qinsoon committed
135

136
        info!("parsed as {:?}", ret);
qinsoon's avatar
qinsoon committed
137

qinsoon's avatar
qinsoon committed
138
        // at the moment disable collection for debugging
qinsoon's avatar
qinsoon committed
139 140
        // also because currently GC is buggy, and we are going to rewrite the GC
        // See Issue #12
141 142 143 144
        if !ret.flag_gc_disable_collection {
            warn!("gc-disabled-collection is forced to true (opposite to user setting)");
            ret.flag_gc_disable_collection = true;
        }
qinsoon's avatar
qinsoon committed
145

qinsoon's avatar
qinsoon committed
146
        // at the moment always emit debug info
147 148 149 150
        if !ret.flag_emit_debug_info {
            warn!("emit-debug-info is forced to true (opposite to user setting)");
            ret.flag_emit_debug_info = true;
        }
qinsoon's avatar
qinsoon committed
151

152
        // always disable register validation
qinsoon's avatar
qinsoon committed
153
        // register validation is buggy. See Issue #19
154 155 156 157 158 159
        if !ret.flag_disable_regalloc_validate {
            warn!("disable-regalloc-validate is forced to true (opposite to user setting)");
            ret.flag_disable_regalloc_validate = true;
        }

        if cfg!(target_os = "macos") {
qinsoon's avatar
fix  
qinsoon committed
160
            if !ret.flag_aot_link_static {
161
                warn!("link-statically is forced to true (opposite to user setting)");
qinsoon's avatar
fix  
qinsoon committed
162
                ret.flag_aot_link_static = true;
163 164
            }
        }
qinsoon's avatar
qinsoon committed
165

qinsoon's avatar
qinsoon committed
166 167 168
        ret
    }
}
qinsoon's avatar
qinsoon committed
169 170 171

impl Default for VMOptions {
    fn default() -> VMOptions {
qinsoon's avatar
qinsoon committed
172
        VMOptions::init("")
qinsoon's avatar
qinsoon committed
173
    }
174
}