mirror of
https://github.com/Noratrieb/uwucc.git
synced 2026-01-14 08:35:08 +01:00
more ir
This commit is contained in:
parent
1407eb299a
commit
9039dbb90d
2 changed files with 67 additions and 0 deletions
66
analysis/src/ir.rs
Normal file
66
analysis/src/ir.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/// A low level IR used for codegen.
|
||||
///
|
||||
/// The following expression is lowered to the following IR:
|
||||
///
|
||||
/// ```c
|
||||
/// int i = 0;
|
||||
/// long l = 1;
|
||||
/// int y = ((int)&i)+l;
|
||||
/// ```
|
||||
///
|
||||
/// ```c
|
||||
/// int _0; // i
|
||||
/// long _1; // l
|
||||
/// int *_2; // tmp &i
|
||||
/// int _3; // tmp (int)&i
|
||||
/// int _4; // tmp l (implicit cast to int)
|
||||
/// int _5; // y
|
||||
///
|
||||
/// _0 = Const(0)
|
||||
/// _1 = Const(1)
|
||||
/// _2 = AddrOf(_0)
|
||||
/// _3 = Cast(Ptr, Int, _2)
|
||||
/// _4 = Cast(Long, Int, _1)
|
||||
/// _5 = _3 + _4
|
||||
/// ```
|
||||
|
||||
use parser::Span;
|
||||
|
||||
use crate::hir::Ty;
|
||||
|
||||
struct Body {
|
||||
locals: Vec<LocalDecl>,
|
||||
statements: Vec<Statement>,
|
||||
}
|
||||
|
||||
struct LocalDecl {
|
||||
pub ty: Ty,
|
||||
}
|
||||
|
||||
struct Statement {
|
||||
pub span: Span,
|
||||
pub kind: StatementKind,
|
||||
}
|
||||
|
||||
enum StatementKind {
|
||||
Assign(LValue, RValue),
|
||||
}
|
||||
|
||||
enum RValue {
|
||||
BinOp(BinOpKind, Operand),
|
||||
Const,
|
||||
}
|
||||
|
||||
enum BinOpKind {
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Mod,
|
||||
}
|
||||
|
||||
enum Operand {
|
||||
Local(usize),
|
||||
}
|
||||
|
||||
enum LValue {}
|
||||
|
|
@ -2,4 +2,5 @@
|
|||
#![warn(rust_2018_idioms)]
|
||||
|
||||
mod hir;
|
||||
mod ir;
|
||||
mod lower;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue