cuda_rust_wasm/transpiler/
mod.rs1pub mod ast;
4pub mod kernel_translator;
5pub mod memory_mapper;
6pub mod type_converter;
7pub mod builtin_functions;
8pub mod code_generator;
9pub mod wgsl;
10
11#[cfg(test)]
12mod tests;
13
14use crate::{Result, translation_error};
15use crate::parser::ast::Ast;
16
17pub struct Transpiler {
19 }
21
22pub struct CudaTranspiler {
24 inner: Transpiler,
25}
26
27impl Transpiler {
28 pub fn new() -> Self {
30 Self {}
31 }
32
33 pub fn transpile(&self, ast: Ast) -> Result<String> {
35 let mut code_gen = code_generator::CodeGenerator::new();
36 code_gen.generate(ast)
37 }
38
39 pub fn to_wgsl(&self, ast: Ast) -> Result<String> {
41 let mut wgsl_gen = wgsl::WgslGenerator::new();
42 wgsl_gen.generate(ast)
43 }
44}
45
46impl Default for Transpiler {
47 fn default() -> Self {
48 Self::new()
49 }
50}
51
52impl Default for CudaTranspiler {
53 fn default() -> Self {
54 Self::new()
55 }
56}
57
58impl CudaTranspiler {
59 pub fn new() -> Self {
61 Self {
62 inner: Transpiler::new(),
63 }
64 }
65
66 pub fn transpile(&self, cuda_source: &str, _optimize: bool, _detect_patterns: bool) -> Result<String> {
68 use crate::parser::CudaParser;
69 let parser = CudaParser::new();
70 let ast = parser.parse(cuda_source)?;
71 self.inner.transpile(ast)
72 }
73
74 #[cfg(feature = "webgpu-only")]
76 pub fn generate_wgsl(&self, cuda_source: &str) -> Result<String> {
77 use crate::parser::CudaParser;
78 let parser = CudaParser::new();
79 let ast = parser.parse(cuda_source)?;
80 self.inner.to_wgsl(ast)
81 }
82
83 #[cfg(not(feature = "webgpu-only"))]
85 pub fn generate_wgsl(&self, _cuda_source: &str) -> Result<String> {
86 Ok("// WGSL generation requires webgpu-only feature".to_string())
87 }
88}