[be] Extract Environment to a separate file

Precursor to making the environment configurable
This commit is contained in:
Joe Savona
2023-02-16 10:47:27 -08:00
parent 530231712f
commit 158c9e4fc1
6 changed files with 15 additions and 15 deletions
+2 -1
View File
@@ -11,6 +11,7 @@ import invariant from "invariant";
import { CompilerError, ErrorSeverity } from "../CompilerError";
import { Err, Ok, Result } from "../Utils/Result";
import { assertExhaustive } from "../Utils/utils";
import { Environment } from "./Environment";
import {
BlockId,
BranchTerminal,
@@ -29,7 +30,7 @@ import {
SourceLocation,
ThrowTerminal,
} from "./HIR";
import HIRBuilder, { Environment } from "./HIRBuilder";
import HIRBuilder from "./HIRBuilder";
// *******************************************************************************************
// *******************************************************************************************
+9
View File
@@ -0,0 +1,9 @@
import { IdentifierId, makeIdentifierId } from "./HIR";
export class Environment {
#nextIdentifer: number = 0;
get nextIdentifierId(): IdentifierId {
return makeIdentifierId(this.#nextIdentifer++);
}
}
+1 -1
View File
@@ -7,7 +7,7 @@
import * as t from "@babel/types";
import invariant from "invariant";
import { Environment } from "./HIRBuilder";
import { Environment } from "./Environment";
// *******************************************************************************************
// *******************************************************************************************
+1 -10
View File
@@ -11,6 +11,7 @@ import invariant from "invariant";
import { CompilerError } from "../CompilerError";
import { logHIR } from "../Utils/logger";
import { assertExhaustive } from "../Utils/utils";
import { Environment } from "./Environment";
import { getOrAddGlobal } from "./Globals";
import {
BasicBlock,
@@ -20,10 +21,8 @@ import {
GotoVariant,
HIR,
Identifier,
IdentifierId,
Instruction,
makeBlockId,
makeIdentifierId,
makeInstructionId,
makeType,
Terminal,
@@ -71,14 +70,6 @@ function newBlock(id: BlockId, kind: BlockKind): WipBlock {
return { id, kind, instructions: [] };
}
export class Environment {
#nextIdentifer: number = 0;
get nextIdentifierId(): IdentifierId {
return makeIdentifierId(this.#nextIdentifer++);
}
}
/**
* Helper class for constructing a CFG
*/
+1 -1
View File
@@ -6,9 +6,9 @@
*/
export { lower } from "./BuildHIR";
export { Environment } from "./Environment";
export * from "./HIR";
export {
Environment,
markInstructionIds,
markPredecessors,
removeUnreachableFallthroughs,
+1 -2
View File
@@ -1,5 +1,6 @@
import invariant from "invariant";
import { CompilerError } from "../CompilerError";
import { Environment } from "../HIR/Environment";
import {
BasicBlock,
BlockId,
@@ -12,14 +13,12 @@ import {
Phi,
Place,
} from "../HIR/HIR";
import { Environment } from "../HIR/HIRBuilder";
import { printIdentifier } from "../HIR/PrintHIR";
import {
eachTerminalSuccessor,
mapInstructionOperands,
mapTerminalOperands,
} from "../HIR/visitors";
import { todoInvariant } from "../Utils/todo";
type IncompletePhi = {
oldId: Identifier;