1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#[macro_use]
extern crate bitflags;
#[macro_use]
pub mod arenas;
pub mod errors;
pub mod grind;
pub mod id;
pub mod lexer;
pub mod name;
pub mod score;
pub mod source;
pub mod util;
pub use self::id::NodeId;
use crate::errors::{DiagBuilder2, DiagEmitter, Severity};
use std::cell::Cell;
pub struct Session {
pub opts: SessionOptions,
pub failed: Cell<bool>,
}
impl Session {
pub fn new() -> Session {
Session {
opts: Default::default(),
failed: Cell::new(false),
}
}
pub fn failed(&self) -> bool {
self.failed.get()
}
}
impl DiagEmitter for Session {
fn emit(&self, diag: DiagBuilder2) {
if diag.severity >= Severity::Error {
self.failed.set(true);
}
eprintln!("{}", diag);
}
}
impl SessionContext for Session {
fn has_verbosity(&self, verb: Verbosity) -> bool {
self.opts.verbosity.contains(verb)
}
}
pub trait SessionContext: DiagEmitter {
fn has_verbosity(&self, verb: Verbosity) -> bool;
}
#[derive(Debug, Default)]
pub struct SessionOptions {
pub ignore_duplicate_defs: bool,
pub trace_scoreboard: bool,
pub verbosity: Verbosity,
pub opt_level: usize,
}
bitflags! {
#[derive(Default)]
pub struct Verbosity: u16 {
const TYPES = 1 << 0;
const EXPR_TYPES = 1 << 1;
const TYPE_CONTEXTS = 1 << 2;
const TYPECK = 1 << 3;
const NAMES = 1 << 4;
const CASTS = 1 << 5;
const PORTS = 1 << 6;
const CONSTS = 1 << 7;
const INSTS = 1 << 8;
}
}