1#![warn(missing_docs)]
2
3use chomsky_uir::IKun;
4use chomsky_uir::egraph::{Analysis, EGraph, Id};
5
6pub struct ContextInjector;
7
8impl ContextInjector {
9 pub fn inject_gpu<A: Analysis<IKun>>(egraph: &EGraph<IKun, A>, id: Id) -> Id {
11 let gpu_ctx = egraph.add(IKun::GpuContext);
12 egraph.add(IKun::WithContext(gpu_ctx, id))
13 }
14
15 pub fn inject_cpu<A: Analysis<IKun>>(egraph: &EGraph<IKun, A>, id: Id) -> Id {
17 let cpu_ctx = egraph.add(IKun::CpuContext);
18 egraph.add(IKun::WithContext(cpu_ctx, id))
19 }
20
21 pub fn inject_async<A: Analysis<IKun>>(egraph: &EGraph<IKun, A>, id: Id) -> Id {
23 let async_ctx = egraph.add(IKun::AsyncContext);
24 egraph.add(IKun::WithContext(async_ctx, id))
25 }
26
27 pub fn inject_spatial<A: Analysis<IKun>>(egraph: &EGraph<IKun, A>, id: Id) -> Id {
29 let spatial_ctx = egraph.add(IKun::SpatialContext);
30 egraph.add(IKun::WithContext(spatial_ctx, id))
31 }
32
33 pub fn inject_context<A: Analysis<IKun>>(
35 egraph: &EGraph<IKun, A>,
36 id: Id,
37 context: IKun,
38 ) -> Id {
39 let ctx_id = egraph.add(context);
40 egraph.add(IKun::WithContext(ctx_id, id))
41 }
42}