From 4abbd3ca76bd0fad5bfbcb154c03dd1b7bccc05e Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 24 Sep 2022 16:15:57 +0200 Subject: [PATCH] idk --- Cargo.lock | 1 + analysis/Cargo.toml | 1 + analysis/src/hir.rs | 131 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 133 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index a3bb61f..9c7fc38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,6 +33,7 @@ name = "analysis" version = "0.1.0" dependencies = [ "bumpalo", + "indexmap", "lasso", "parser", "rustc-hash", diff --git a/analysis/Cargo.toml b/analysis/Cargo.toml index 5efaec8..6cca736 100644 --- a/analysis/Cargo.toml +++ b/analysis/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" [dependencies] bumpalo = "3.10.0" +indexmap = "1.9.1" lasso = "0.6.0" parser = { path = "../parser" } rustc-hash = "1.1.0" diff --git a/analysis/src/hir.rs b/analysis/src/hir.rs index 30e3048..55f4118 100644 --- a/analysis/src/hir.rs +++ b/analysis/src/hir.rs @@ -1,3 +1,4 @@ +use indexmap::IndexMap; use lasso::Spur; use parser::Spanned; @@ -9,8 +10,138 @@ pub struct Hir<'hir> { x: &'hir (), } +pub struct HirId(u32); +pub struct DefId(HirId); + +pub enum IntTySignedness { + Signed, + Unsigned, +} + +impl Default for IntTySignedness { + fn default() -> Self { + // C defaults to unsigned for integers. + Self::Signed + } +} + +pub enum IntTyKind { + Short, + Int, + Long, + LongLong, +} + +pub struct IntTy { + pub sign: IntTySignedness, + pub kind: IntTyKind, +} + +pub struct UnionTy { + variants: IndexMap, +} + +pub struct StructTy { + fields: IndexMap, +} + +pub struct EnumTy { + variants: IndexMap, +} + +pub enum TyKind { + Void, + Char, + SChar, + UChar, + Integer(IntTy), + Float, + Double, + LongDouble, + Bool, + Union(UnionTy), + Struct(StructTy), + Enum(EnumTy), +} + +pub struct Ty { + def_id: DefId, +} + +pub struct Node { + id: HirId, + kind: NodeKind, +} + +pub enum NodeKind { + FunctionDef(FunctionDef), +} + pub struct ExternalDecl; pub struct FunctionDef { + name: Symbol, } + +pub struct Expr<'hir> { + kind: ExprKind<'hir>, + ty: Ty, +} + +pub enum ExprKind<'hir> { + Var(DefId), + Binary(BinaryOp, &'hir Expr<'hir>, &'hir Expr<'hir>), + Unary(UnaryOp, &'hir Expr<'hir>), + Cast(CastExpr<'hir>), +} + +pub struct CastExpr<'hir> { + from: Ty, + to: Ty, + expr: &'hir Expr<'hir>, +} + +pub enum UnaryOp { + AddrOf, + Deref, + Plus, + Minus, + Tilde, + Bang, +} + +#[derive(Debug)] +pub enum ArithOpKind { + Mul, + Div, + Mod, + Add, + Sub, + Shl, + Shr, + BitAnd, + BitXor, + BitOr, +} + +#[derive(Debug)] +pub enum ComparisonKind { + Lt, + Gt, + LtEq, + GtEq, + Eq, + Neq, +} + +#[derive(Debug)] +pub enum BinaryOp { + Arith(ArithOpKind), + LogicalAnd, + LogicalOr, + Comparison(ComparisonKind), + Comma, + Index, // lhs[rhs] + Assign(Option), +}