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

vm_options.rs 4.78 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
  --log-level=<level>                   logging level: none, error, warn, info, debug, trace, env [default: env]
qinsoon's avatar
qinsoon committed
31

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

AOT Compiler:
38
  --aot-emit-dir=<dir>                  the emit directory for ahead-of-time compiling [default: emit]
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
39
  --link-statically                       link boot image to libmu statically (defaults to dynamic)
40
41
  --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
42
43

Garbage Collection:
44
  --gc-disable-collection               disable collection
45
46
47
  --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]
  --gc-nthreads=<n>                     number of threads for parallel gc [default: 8]
qinsoon's avatar
qinsoon committed
48
49
";

50
#[derive(Debug, Deserialize)]
51
52
pub struct VMOptions {
    // The comments here indicate the offset into the struct
qinsoon's avatar
qinsoon committed
53
    // VM
54
    pub flag_log_level: MuLogLevel, // +96
qinsoon's avatar
qinsoon committed
55
56

    // Compiler
57
    pub flag_disable_inline: bool,            // +97
58
    pub flag_disable_regalloc_validate: bool, // +98
59
    pub flag_emit_debug_info: bool,           // +99
60

qinsoon's avatar
qinsoon committed
61
    // AOT compiler
62
    pub flag_aot_emit_dir: String,                    // +0
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
63
    pub flag_link_statically: bool,                     // +100
64
    pub flag_bootimage_external_lib: Vec<String>,     // +24
65
    pub flag_bootimage_external_libpath: Vec<String>, // +48
66

qinsoon's avatar
qinsoon committed
67
    // GC
68
    pub flag_gc_disable_collection: bool, // +101
69
70
    pub flag_gc_immixspace_size: usize,   // +72
    pub flag_gc_lospace_size: usize,      // +80
qinsoon's avatar
qinsoon committed
71
    pub flag_gc_nthreads: usize,          // +88
qinsoon's avatar
qinsoon committed
72
73
}

74
// The fields need to be listed here in the order rust stores them in
75
76
77
78
79
80
81
82
83
84
85
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,
    flag_emit_debug_info,
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
86
    flag_link_statically,
87
    flag_gc_disable_collection
88
});
89

90
#[derive(Debug, Clone, Copy, Deserialize)]
qinsoon's avatar
qinsoon committed
91
pub enum MuLogLevel {
92
93
94
95
96
97
    None,
    Error,
    Warn,
    Info,
    Debug,
    Trace,
qinsoon's avatar
qinsoon committed
98
    Env,
99
}
100
101
102

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

103
104
105
106
107
108
109
110
111
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,
112
            _ => panic!("Unrecognised log level {}", s)
113
114
        }
    }
qinsoon's avatar
qinsoon committed
115
116
117
118
}

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

121
        let mut ret: VMOptions = Docopt::new(USAGE)
qinsoon's avatar
qinsoon committed
122
            .and_then(|d| d.argv(str.split_whitespace().into_iter()).parse())
123
124
125
            .unwrap_or_else(|e| e.exit())
            .deserialize()
            .unwrap();
qinsoon's avatar
qinsoon committed
126

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

qinsoon's avatar
qinsoon committed
129
        // at the moment disable collection for debugging
qinsoon's avatar
qinsoon committed
130
131
        // also because currently GC is buggy, and we are going to rewrite the GC
        // See Issue #12
qinsoon's avatar
qinsoon committed
132
        ret.flag_gc_disable_collection = true;
qinsoon's avatar
qinsoon committed
133

qinsoon's avatar
qinsoon committed
134
135
        // at the moment always emit debug info
        ret.flag_emit_debug_info = true;
qinsoon's avatar
qinsoon committed
136

137
        // always disable register validation
qinsoon's avatar
qinsoon committed
138
        // register validation is buggy. See Issue #19
139
        ret.flag_disable_regalloc_validate = true;
qinsoon's avatar
qinsoon committed
140

qinsoon's avatar
qinsoon committed
141
142
143
        ret
    }
}
qinsoon's avatar
qinsoon committed
144
145
146

impl Default for VMOptions {
    fn default() -> VMOptions {
qinsoon's avatar
qinsoon committed
147
        VMOptions::init("")
qinsoon's avatar
qinsoon committed
148
    }
149
}