[valueblocks] Scaffolding for ternary terminals

Core representation for terminals, without the lowering and conversion logic.
This commit is contained in:
Joe Savona
2023-01-31 13:39:34 -08:00
parent aca0e27012
commit dc7ac6fea4
6 changed files with 40 additions and 1 deletions
+10 -1
View File
@@ -238,7 +238,8 @@ export type Terminal =
| SwitchTerminal
| ForTerminal
| WhileTerminal
| LogicalTerminal;
| LogicalTerminal
| TernaryTerminal;
/**
* Terminal nodes allowed for a value block
@@ -321,6 +322,14 @@ export type LogicalTerminal = {
loc: SourceLocation;
};
export type TernaryTerminal = {
kind: "ternary";
test: BlockId;
fallthrough: BlockId;
id: InstructionId;
loc: SourceLocation;
};
/**
* Instructions generally represent expressions but with all nesting flattened away,
* such that all operands to each instruction are either primitive values OR are
+1
View File
@@ -562,6 +562,7 @@ export function reversePostorderBlocks(func: HIR): void {
}
break;
}
case "ternary":
case "logical": {
visit(terminal.test);
break;
+5
View File
@@ -79,6 +79,7 @@ export function printMixedHIR(
case "branch":
case "if":
case "logical":
case "ternary":
case "return":
case "switch":
case "throw":
@@ -146,6 +147,10 @@ export function printTerminal(terminal: Terminal): Array<string> | string {
value = `[${terminal.id}] Logical ${terminal.operator} test:bb${terminal.test} fallthrough=bb${terminal.fallthrough}`;
break;
}
case "ternary": {
value = `[${terminal.id}] Ternary test:bb${terminal.test} fallthrough=bb${terminal.fallthrough}`;
break;
}
case "throw": {
value = `[${terminal.id}] Throw ${printPlace(terminal.value)}`;
break;
+14
View File
@@ -294,6 +294,17 @@ export function mapTerminalSuccessors(
loc: terminal.loc,
};
}
case "ternary": {
const test = fn(terminal.test);
const fallthrough = fn(terminal.fallthrough);
return {
kind: "ternary",
test,
fallthrough,
id: makeInstructionId(0),
loc: terminal.loc,
};
}
case "return": {
return {
kind: "return",
@@ -373,6 +384,7 @@ export function* eachTerminalSuccessor(terminal: Terminal): Iterable<BlockId> {
}
break;
}
case "ternary":
case "logical": {
yield terminal.test;
break;
@@ -432,6 +444,7 @@ export function mapTerminalOperands(
}
break;
}
case "ternary":
case "logical":
case "while":
case "for":
@@ -476,6 +489,7 @@ export function* eachTerminalOperand(terminal: Terminal): Iterable<Place> {
}
break;
}
case "ternary":
case "logical":
case "while":
case "for":
@@ -406,6 +406,7 @@ class Driver {
break;
}
case "ternary":
case "logical": {
const fallthroughId = terminal.fallthrough;
invariant(
@@ -103,6 +103,10 @@ function printTerminalLabel(terminal: Terminal): string {
buffer.push(`Logical ${terminal.operator}`);
break;
}
case "ternary": {
buffer.push("Ternary");
break;
}
case "while":
buffer.push("While");
break;
@@ -144,6 +148,11 @@ function printTerminalArrows(blockId: BlockId, terminal: Terminal): string {
buffer.push(printJumpArrow(blockId, terminal.fallthrough, "fallthrough"));
break;
}
case "ternary": {
buffer.push(printJumpArrow(blockId, terminal.test, "test"));
buffer.push(printJumpArrow(blockId, terminal.fallthrough, "fallthrough"));
break;
}
case "goto": {
buffer.push(printJumpArrow(blockId, terminal.block, null));
break;