Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cranelift/isle/docs/language-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ The grammar accepted by the parser is as follows:

<type-body> ::= "(" "primitive" <ident> ")"
| "(" "enum" <enum-variant>* ")"
| "(" "struct" <variant-field>* ")"

<enum-variant> ::= <ident>
| "(" <ident> <variant-field>* ")"
Expand Down
3 changes: 0 additions & 3 deletions cranelift/isle/isle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ workspace = true
codespan-reporting = { version = "0.11.1", optional = true }
log = { workspace = true, optional = true }

[dev-dependencies]
tempfile = "3"

[features]
default = []

Expand Down
16 changes: 16 additions & 0 deletions cranelift/isle/isle/isle_examples/pass/struct.isle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(type A (struct (x u32) (y u32)))
(type B (struct (x u32)))
(type C (enum
(Ca (x A))
(Cb (x B))))
(type D (struct (x C)))

(decl D2B (D) B)

(rule 1
(D2B (D (C.Ca (A x _))))
(B x))

(rule 0
(D2B (D (C.Cb (B x))))
(B x))
8 changes: 8 additions & 0 deletions cranelift/isle/isle/isle_examples/run/struct_test.isle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(type A (struct (x u32) (y u32)))
(type B extern (struct (x u32)))
(type C (enum
(Ca (x A))
(Cb (x B))))
(type D extern (struct (x C)))

(type UnitStruct (struct))
40 changes: 40 additions & 0 deletions cranelift/isle/isle/isle_examples/run/struct_test_main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
extern crate alloc;
extern crate core;

mod struct_test;
use struct_test::{A, C, UnitStruct};

#[derive(Clone, Debug)]
pub struct B {
pub x: u32,
}

#[derive(Clone, Debug)]
pub struct D {
pub x: C,
}

struct Context();
impl struct_test::Context for Context {}

fn main() {
let a = D {
x: C::Ca {
x: A { x: 42, y: 123 },
},
};
let b = D {
x: C::Cb { x: B { x: 42 } },
};
for d in [a, b] {
match d {
D {
x: C::Ca { x: A { x, .. } } | C::Cb { x: B { x } },
} => {
assert_eq!(x, 42);
}
}
}

let unit = UnitStruct;
}
3 changes: 1 addition & 2 deletions cranelift/isle/isle/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ pub struct Type {
}

/// The actual type-value: a primitive or an enum with variants.
///
/// TODO: add structs as well?
#[derive(Clone, PartialEq, Eq, Debug)]
pub enum TypeValue {
Primitive(Ident, Pos),
Enum(Vec<Variant>, Pos),
Struct(Vec<Field>, Pos),
}

/// One variant of an enum type.
Expand Down
Loading
Loading