用统一中间表示实现多语言代码双向翻译,写一次代码就能在多种平台运行。
CrossTL: A Universal Programming Language Translator with Unified Intermediate Representation
- 用统一中间表示CrossGL连接多种编程语言,避免每对语言单独开发翻译器。
- 支持CUDA、HIP、Metal等9种语言,可成功编译并跨平台执行。
- 模块化设计让新增语言只需改前端和后端,适合工具开发者和跨平台程序员。
我们提出CrossTL,一种通过统一中间表示CrossGL实现多语言双向翻译的通用编程语言转换器。传统方法需为每对语言单独构建翻译器,导致复杂度呈指数增长。CrossTL利用单一通用中间表示,支持CUDA、HIP、Metal、DirectX HLSL、OpenGL GLSL、Vulkan SPIR-V、Rust和Mojo等语言,Slang支持正在开发中。系统包含:将源码转为抽象语法树的语言特定词法分析器/解析器,实现从代码导入的ToCrossGLConverter类与目标生成的CodeGen类,以及完整的后端实现处理全链路翻译。通过跨编程领域的综合评估,证明所有支持后端均能成功编译与执行。统一中间表示的设计使新增语言仅需添加语言特定的前端和后端组件。贡献包括:(1) 覆盖多种编程范式的统一中间表示;(2) 可扩展的模块化架构;(3) 支持GPU计算、图形编程与系统语言的完整框架;(4) 实证验证通用代码翻译的实际可行性。CrossTL标志着向无语言依赖编程迈进的重要一步,实现写一次、部署到处。
原文摘要 · Abstract (English)
We present CrossTL, a universal programming language translator enabling bidirectional translation between multiple languages through a unified intermediate representation called CrossGL. Traditional approaches require separate translators for each language pair, leading to exponential complexity growth. CrossTL uses a single universal IR to facilitate translations between CUDA, HIP, Metal, DirectX HLSL, OpenGL GLSL, Vulkan SPIR-V, Rust, and Mojo, with Slang support in development. Our system consists of: language-specific lexers/parsers converting source code to ASTs, bidirectional CrossGL translation modules implementing ToCrossGLConverter classes for importing code and CodeGen classes for target generation, and comprehensive backend implementations handling full translation pipelines. We demonstrate effectiveness through comprehensive evaluation across programming domains, achieving successful compilation and execution across all supported backends. The universal IR design enables adding new languages with minimal effort, requiring only language-specific frontend/backend components. Our contributions include: (1) a unified IR capturing semantics of multiple programming paradigms, (2) a modular architecture enabling extensibility, (3) a comprehensive framework supporting GPU compute, graphics programming, and systems languages, and (4) empirical validation demonstrating practical viability of universal code translation. CrossTL represents a significant step toward language-agnostic programming, enabling write-once, deploy-everywhere development.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。