Add support for implicit type conversions to ISLE. This feature allows the DSL user to register to the compiler that a particular term (used as a constructor or extractor) converts from one type to another. The compiler will then *automatically* insert this term whenever a type mismatch involving that specific pair of types occurs. This significantly cleans up many uses of the ISLE DSL. For example, when defining the compiler backends, we often have newtypes like `Gpr` around `Reg` (signifying a particular type of register); we can define a conversion from Gpr to Reg automatically. Conversions can also have side-effects, as long as these side-effects are idempotent. For example, `put_value_in_reg` in a compiler backend has the effect of marking the value as used, causing codegen to produce it, and assigns a register to the value; but multiple invocations of this will return the same register for the same value. Thus it is safe to use it as an implicit conversion that may be invoked multiple times. This is documented in the ISLE-Cranelift integration document. This PR also adds some testing infrastructure to the ISLE compiler, checking that "pass" tests pass through the DSL compiler, "fail" tests do not, and "link" tests are able to generate code and link that code with corresponding Rust code.
29 lines
489 B
Common Lisp
29 lines
489 B
Common Lisp
(type T (enum (A) (B)))
|
|
(type U (enum (C) (D)))
|
|
(type V (enum (E) (F)))
|
|
(type u32 (primitive u32))
|
|
|
|
(convert T U t_to_u)
|
|
(convert U T u_to_t)
|
|
(convert U V u_to_v)
|
|
|
|
(decl t_to_u (T) U)
|
|
(decl u_to_t (U) T)
|
|
(decl u_to_v (U) V)
|
|
|
|
(rule (t_to_u (T.A)) (U.C))
|
|
(rule (t_to_u (T.B)) (U.D))
|
|
|
|
(rule (u_to_t (U.C)) (T.A))
|
|
(rule (u_to_t (U.D)) (T.B))
|
|
|
|
(rule (u_to_v (U.C)) (V.E))
|
|
(rule (u_to_v (U.D)) (V.F))
|
|
|
|
(extern extractor u_to_t u_to_t)
|
|
|
|
|
|
(decl X (T U) V)
|
|
(rule (X (U.C) (U.D))
|
|
(U.D))
|