pub mod ast;
pub mod kernel_translator;
pub mod memory_mapper;
pub mod type_converter;
pub mod builtin_functions;
pub mod code_generator;
pub mod wgsl;
#[cfg(test)]
mod tests;
use crate::{Result, translation_error};
use crate::parser::ast::Ast;
pub struct Transpiler {
}
pub struct CudaTranspiler {
inner: Transpiler,
}
impl Transpiler {
pub fn new() -> Self {
Self {}
}
pub fn transpile(&self, ast: Ast) -> Result<String> {
let mut code_gen = code_generator::CodeGenerator::new();
code_gen.generate(ast)
}
pub fn to_wgsl(&self, ast: Ast) -> Result<String> {
let mut wgsl_gen = wgsl::WgslGenerator::new();
wgsl_gen.generate(ast)
}
}
impl Default for Transpiler {
fn default() -> Self {
Self::new()
}
}
impl Default for CudaTranspiler {
fn default() -> Self {
Self::new()
}
}
impl CudaTranspiler {
pub fn new() -> Self {
Self {
inner: Transpiler::new(),
}
}
pub fn transpile(&self, cuda_source: &str, _optimize: bool, _detect_patterns: bool) -> Result<String> {
use crate::parser::CudaParser;
let parser = CudaParser::new();
let ast = parser.parse(cuda_source)?;
self.inner.transpile(ast)
}
pub fn generate_wgsl(&self, cuda_source: &str) -> Result<String> {
use crate::parser::CudaParser;
let parser = CudaParser::new();
let ast = parser.parse(cuda_source)?;
self.inner.to_wgsl(ast)
}
}