[hir] Update Place.type based on value inference

This commit is contained in:
Sathya Gunasekaran
2022-12-13 09:17:19 +00:00
parent 7f8ad49165
commit 74599a92a2
2 changed files with 22 additions and 1 deletions
+2
View File
@@ -402,4 +402,6 @@ export function makeInstructionId(id: number): InstructionId {
export enum Type {
Any,
Primitive,
Object,
}
+20 -1
View File
@@ -1,6 +1,13 @@
import invariant from "invariant";
import DisjointSet from "./DisjointSet";
import { HIRFunction, Identifier, Instruction, LValue, Place } from "./HIR";
import {
HIRFunction,
Identifier,
Instruction,
LValue,
Place,
Type,
} from "./HIR";
import { printInstructionValue } from "./PrintHIR";
type AbstractValue = AbstractObject | AbstractPrimitive;
@@ -13,6 +20,17 @@ type AbstractPrimitive = {
value: number | boolean | string | null | undefined;
};
function typeOf(value: AbstractValue) {
switch (value.kind) {
case "Primitive":
return Type.Primitive;
case "Object":
return Type.Object;
default:
return Type.Any;
}
}
class AbstractState {
#values = new Map<Identifier, AbstractValue>();
@@ -96,6 +114,7 @@ class AbstractState {
// Simple lvalue:
// lvalue = alias;
// lvalue = alias.memberPath;
lvalue.place.type = typeOf(value);
this.#values.set(lvalue.place.identifier, value);
}
}