Skip to content
← Back

src/compiler/pass.ghul

1
namespace Compiler is
2
use System.NotImplementedException;
3
4
use Logging.TIMERS;
5
use Logging.TIMER;
6
7
class Pass(_timers: TIMERS, description: string) abstract is
8
// Position in the build pipeline. Assigned by COMPILER after the
9
// pass list is registered; lets callers ask "has this file been
10
// taken at least as far as pass X" by comparing orders.
11
order: int public;
12
13
// Whether a pass that did work for a file advances that file's
14
// compiled_through marker. A pass that walks the file but leaves
15
// behind nothing a later pass consumes - check-name-conventions,
16
// which only reports warnings - reports the walk so per-file work
17
// counters stay honest, without moving the marker.
18
advances_milestone: bool public;
19
20
init(..) is
21
advances_milestone = true;
22
si
23
24
start() is
25
_timers.start(description);
26
si
27
28
// Returns true if the pass actually walked this file (i.e. its
29
// flag-gated body ran). Passes whose gate was off for this file
30
// must return false, so the result is a truthful record of the
31
// work done. The build loop advances SOURCE_FILE.compiled_through
32
// from it, gated on advances_milestone.
33
apply(source_file: SOURCE_FILE) -> bool => throw NotImplementedException();
34
finish() is
35
_timers.finish(description);
36
si
37
38
get_hash_code() -> int => description.get_hash_code();
39
40
to_string() -> string => _timers[description].to_string();
41
si
42
43
class PASS(
44
timers: TIMERS,
45
description: string,
46
_start: (() -> void)?,
47
_apply: SOURCE_FILE -> bool,
48
_finish: (() -> void)?
49
): Pass is
50
super(timers, description);
51
52
start() is
53
super.start();
54
55
if _start? then
56
_start();
57
fi
58
si
59
60
apply(source_file: SOURCE_FILE) -> bool => _apply(source_file);
61
62
finish() is
63
if _finish? then
64
_finish();
65
fi
66
67
super.finish();
68
si
69
si
70
si