finish mir def
This commit is contained in:
parent
81d8e32a04
commit
b70ba48e0a
@ -1,4 +1,11 @@
|
|||||||
import { Span } from "../diagnostics.ts";
|
import { Span } from "../diagnostics.ts";
|
||||||
|
import { IdBase } from "../ids.ts";
|
||||||
|
|
||||||
|
export type Block = {
|
||||||
|
id: BlockId;
|
||||||
|
stmts: Stmt[];
|
||||||
|
terminator?: Terminator;
|
||||||
|
};
|
||||||
|
|
||||||
export type Stmt = {
|
export type Stmt = {
|
||||||
kind: StmtKind;
|
kind: StmtKind;
|
||||||
@ -6,22 +13,37 @@ export type Stmt = {
|
|||||||
|
|
||||||
export type StmtKind =
|
export type StmtKind =
|
||||||
| { tag: "error" }
|
| { tag: "error" }
|
||||||
| { tag: "assign" } & AssignStmt
|
| { tag: "assign"; place: Place; rval: RVal }
|
||||||
| { tag: "fake_read" } & FakeReadStmt
|
| { tag: "fake_read"; place: Place }
|
||||||
| { tag: "deinit" } & DeinitStmt
|
| { tag: "deinit"; place: Place }
|
||||||
| { tag: "live" } & LiveStmt
|
| { tag: "live"; local: LocalId }
|
||||||
| { tag: "dead" } & DeadStmt
|
| { tag: "dead"; local: LocalId }
|
||||||
| { tag: "mention" } & MentionStmt;
|
| { tag: "mention"; place: Place };
|
||||||
|
|
||||||
export type AssignStmt = { place: Place; rval: RVal };
|
export type Terminator = {
|
||||||
export type FakeReadStmt = { place: Place };
|
kind: TerminatorKind;
|
||||||
export type DeinitStmt = { place: Place };
|
};
|
||||||
export type LiveStmt = { local: Local };
|
|
||||||
export type DeadStmt = { local: Local };
|
export type TerminatorKind =
|
||||||
export type MentionStmt = { place: Place };
|
| { tag: "goto"; target: BlockId }
|
||||||
|
| {
|
||||||
|
tag: "switch";
|
||||||
|
discr: Operand;
|
||||||
|
targets: SwitchTarget[];
|
||||||
|
otherwise: BlockId;
|
||||||
|
}
|
||||||
|
| { tag: "return" }
|
||||||
|
| { tag: "unreachable" }
|
||||||
|
| { tag: "drop"; place: Place; target: BlockId }
|
||||||
|
| { tag: "call"; func: Operand; args: Operand[]; dest: Operand };
|
||||||
|
|
||||||
|
export type SwitchTarget = {
|
||||||
|
value: number;
|
||||||
|
target: BlockId;
|
||||||
|
};
|
||||||
|
|
||||||
export type Place = {
|
export type Place = {
|
||||||
local: Local;
|
local: LocalId;
|
||||||
proj: ProjElem[];
|
proj: ProjElem[];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -30,11 +52,48 @@ export type ProjElem =
|
|||||||
| { tag: "deref" }
|
| { tag: "deref" }
|
||||||
| { tag: "repeat" }
|
| { tag: "repeat" }
|
||||||
| { tag: "field"; fieldIdx: number }
|
| { tag: "field"; fieldIdx: number }
|
||||||
| { tag: "index": local: Local }
|
| { tag: "index"; local: LocalId }
|
||||||
| { tag: }
|
| { tag: "downcast"; variantIdx: number };
|
||||||
|
|
||||||
// https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/mir/enum.Rvalue.html
|
// https://doc.rust-lang.org/beta/nightly-rustc/rustc_middle/mir/enum.Rvalue.html
|
||||||
export type RVal = {};
|
export type RVal =
|
||||||
|
| { tag: "use"; operand: Operand }
|
||||||
|
| { tag: "repeat"; operand: Operand; length: Const }
|
||||||
|
| { tag: "ref"; place: Place; mut: boolean }
|
||||||
|
| { tag: "ptr"; place: Place; mut: boolean }
|
||||||
|
| { tag: "binary"; binaryType: BinaryType; left: Operand; right: Operand }
|
||||||
|
| { tag: "unary"; unaryType: UnaryType; operand: Operand };
|
||||||
|
|
||||||
export type Local = {};
|
export type BinaryType =
|
||||||
|
| "add"
|
||||||
|
| "sub"
|
||||||
|
| "mul"
|
||||||
|
| "div"
|
||||||
|
| "rem"
|
||||||
|
| "xor"
|
||||||
|
| "and"
|
||||||
|
| "or"
|
||||||
|
| "shl"
|
||||||
|
| "shr"
|
||||||
|
| "eq"
|
||||||
|
| "ne"
|
||||||
|
| "lt"
|
||||||
|
| "lte"
|
||||||
|
| "gt"
|
||||||
|
| "gte";
|
||||||
|
|
||||||
|
export type UnaryType = "not" | "neg";
|
||||||
|
|
||||||
|
export type Operand =
|
||||||
|
| { tag: "copy"; place: Place }
|
||||||
|
| { tag: "move"; place: Place }
|
||||||
|
| { tag: "const"; val: Const };
|
||||||
|
|
||||||
|
export type Const =
|
||||||
|
| { tag: "null" }
|
||||||
|
| { tag: "int"; value: number }
|
||||||
|
| { tag: "bool"; value: boolean }
|
||||||
|
| { tag: "string"; value: string };
|
||||||
|
|
||||||
|
export type LocalId = IdBase & { readonly _: unique symbol };
|
||||||
|
export type BlockId = IdBase & { readonly _: unique symbol };
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Ctx } from "../ctx.ts";
|
import { Ctx, File } from "../ctx.ts";
|
||||||
import { Pos, Span } from "../diagnostics.ts";
|
import { Pos, Span } from "../diagnostics.ts";
|
||||||
import { File } from "../ids.ts";
|
|
||||||
import { ControlFlow, range } from "../util.ts";
|
import { ControlFlow, range } from "../util.ts";
|
||||||
import { Token, TokenIter } from "./token.ts";
|
import { Token, TokenIter } from "./token.ts";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user