[be] Extract Environment to a separate file
Precursor to making the environment configurable
Joe Savona committed
Feb 16, 2023 at 10:47 UTC
158c9e4fc12f0d0f0cd9c91c946110e2e03fe8ac
6 files changed
+15
-15
compiler/forget/src/HIR/BuildHIR.ts
+2
-1
@@ -11,6 +11,7 @@ import invariant from "invariant";
11
import { CompilerError, ErrorSeverity } from "../CompilerError";
12
import { Err, Ok, Result } from "../Utils/Result";
13
import { assertExhaustive } from "../Utils/utils";
14
+import { Environment } from "./Environment";
15
import {
16
BlockId,
17
BranchTerminal,
@@ -29,7 +30,7 @@ import {
30
SourceLocation,
31
ThrowTerminal,
32
} from "./HIR";
32
-import HIRBuilder, { Environment } from "./HIRBuilder";
33
+import HIRBuilder from "./HIRBuilder";
34
35
// *******************************************************************************************
36
// *******************************************************************************************
compiler/forget/src/HIR/Environment.ts
new
+9
@@ -0,0 +1,9 @@
1
+import { IdentifierId, makeIdentifierId } from "./HIR";
2
+
3
+export class Environment {
4
+ #nextIdentifer: number = 0;
5
+
6
+ get nextIdentifierId(): IdentifierId {
7
+ return makeIdentifierId(this.#nextIdentifer++);
8
+ }
9
+}
compiler/forget/src/HIR/HIR.ts
+1
-1
@@ -7,7 +7,7 @@
7
8
import * as t from "@babel/types";
9
import invariant from "invariant";
10
-import { Environment } from "./HIRBuilder";
10
+import { Environment } from "./Environment";
11
12
// *******************************************************************************************
13
// *******************************************************************************************
compiler/forget/src/HIR/HIRBuilder.ts
+1
-10
@@ -11,6 +11,7 @@ import invariant from "invariant";
11
import { CompilerError } from "../CompilerError";
12
import { logHIR } from "../Utils/logger";
13
import { assertExhaustive } from "../Utils/utils";
14
+import { Environment } from "./Environment";
15
import { getOrAddGlobal } from "./Globals";
16
import {
17
BasicBlock,
@@ -20,10 +21,8 @@ import {
21
GotoVariant,
22
HIR,
23
Identifier,
23
- IdentifierId,
24
Instruction,
25
makeBlockId,
26
- makeIdentifierId,
26
makeInstructionId,
27
makeType,
28
Terminal,
@@ -71,14 +70,6 @@ function newBlock(id: BlockId, kind: BlockKind): WipBlock {
70
return { id, kind, instructions: [] };
71
}
72
74
-export class Environment {
75
- #nextIdentifer: number = 0;
76
-
77
- get nextIdentifierId(): IdentifierId {
78
- return makeIdentifierId(this.#nextIdentifer++);
79
- }
80
-}
81
-
73
/**
74
* Helper class for constructing a CFG
75
*/
compiler/forget/src/HIR/index.ts
+1
-1
@@ -6,9 +6,9 @@
6
*/
7
8
export { lower } from "./BuildHIR";
9
+export { Environment } from "./Environment";
10
export * from "./HIR";
11
export {
11
- Environment,
12
markInstructionIds,
13
markPredecessors,
14
removeUnreachableFallthroughs,
compiler/forget/src/SSA/EnterSSA.ts
+1
-2
@@ -1,5 +1,6 @@
1
import invariant from "invariant";
2
import { CompilerError } from "../CompilerError";
3
+import { Environment } from "../HIR/Environment";
4
import {
5
BasicBlock,
6
BlockId,
@@ -12,14 +13,12 @@ import {
13
Phi,
14
Place,
15
} from "../HIR/HIR";
15
-import { Environment } from "../HIR/HIRBuilder";
16
import { printIdentifier } from "../HIR/PrintHIR";
17
import {
18
eachTerminalSuccessor,
19
mapInstructionOperands,
20
mapTerminalOperands,
21
} from "../HIR/visitors";
22
-import { todoInvariant } from "../Utils/todo";
22
23
type IncompletePhi = {
24
oldId: Identifier;