vm_options.rs 4.56 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
17
18
extern crate docopt;

use self::docopt::Docopt;

19
use std;
qinsoon's avatar
qinsoon committed
20
21
use std::default::Default;

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

Usage:
  init_mu [options]

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

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

AOT Compiler:
37
38
39
40
  --aot-emit-dir=<dir>                  the emit directory for ahead-of-time compiling [default: emit]

  --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
41
42

Garbage Collection:
43
  --gc-disable-collection               disable collection
44
45
46
  --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
47
48
";

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

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

qinsoon's avatar
qinsoon committed
60
    // AOT compiler
61
62
    pub flag_aot_emit_dir: String,                    // +0
    pub flag_bootimage_external_lib: Vec<String>,     // +24
63
    pub flag_bootimage_external_libpath: Vec<String>, // +48
64

qinsoon's avatar
qinsoon committed
65
    // GC
66
    pub flag_gc_disable_collection: bool, // +100
67
68
    pub flag_gc_immixspace_size: usize,   // +72
    pub flag_gc_lospace_size: usize,      // +80
Isaac Oscar Gariano's avatar
Isaac Oscar Gariano committed
69
    pub flag_gc_nthreads: usize,          // +88
qinsoon's avatar
qinsoon committed
70
71
}

72
// The fields need to be listed here in the order rust stores them in
73
74
75
76
77
78
79
80
81
82
83
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
84
    flag_gc_disable_collection,
85
});
86

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

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

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

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

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

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

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

qinsoon's avatar
qinsoon committed
131
132
        // at the moment always emit debug info
        ret.flag_emit_debug_info = true;
qinsoon's avatar
qinsoon committed
133

134
        // always disable register validation
qinsoon's avatar
qinsoon committed
135
        // register validation is buggy. See Issue #19
136
        ret.flag_disable_regalloc_validate = true;
qinsoon's avatar
qinsoon committed
137

qinsoon's avatar
qinsoon committed
138
139
140
        ret
    }
}
qinsoon's avatar
qinsoon committed
141
142
143

impl Default for VMOptions {
    fn default() -> VMOptions {
qinsoon's avatar
qinsoon committed
144
        VMOptions::init("")
qinsoon's avatar
qinsoon committed
145
    }
146
}