Table of Contents
Fetching ...

The CoCompiler: DSL Lifting via Relational Compilation

Naomi Spargo, Santiago Cuéllar, Jonathan Daugherty, Chris Phifer, David Darais

TL;DR

The paper tackles the challenge of lifting low-level C into Lustre for reactive systems by introducing the CoCompiler, a bidirectional C <-> Lustre tool built by porting a verified Lustre→C compiler into a relational framework using Walrus. The core idea is to model compilation as a relation, enabling both forward compilation and backward lifting, while employing simple horizontal canonicalization passes to handle real-world C outside the canonical sublanguage. Key contributions include a relational, bidirectional core that reuses Vélus, a modular toolchain connecting Lustre, Clight, and SCADE, and a practical lifting example from C to Lustre to a graphical SCADE model. The approach demonstrates that relational programming can rapidly produce DSL lifters by repurposing existing compilers, with future work aimed at expanding support to additional DSLs such as SysML and enhancing horizontal canonicalization and SCADE translation.

Abstract

Lifting low-level or legacy code into a domain-specific language (DSL) improves our ability to understand it, enables deeper formal reasoning, and facilitates safe modification. We present the CoCompiler, a bidirectional compiler and lifter between C and Lustre, a synchronous dataflow language used for reactive systems. The key insight behind the CoCompiler is that writing a compiler as a relation, rather than as a traditional function, yields a DSL lifter "for free". We implement this idea by rewriting the verified Lustre-to-C compiler Vélus in the Walrus relational programming language. This solves what we call the vertical lifting problem, translating canonical C into Lustre. To address the complementary horizontal problem-handling real-world C outside the compiler's image-we apply semantic-preserving canonicalization passes in Haskell. The resulting tool, the CoCompiler, supports lifting real reactive C code into Lustre and onward into graphical behavioral models. Our approach is modular, language-agnostic, and fast to implement, demonstrating that relational programming offers a practical foundation for building DSL lifters by repurposing existing compilers.

The CoCompiler: DSL Lifting via Relational Compilation

TL;DR

The paper tackles the challenge of lifting low-level C into Lustre for reactive systems by introducing the CoCompiler, a bidirectional C <-> Lustre tool built by porting a verified Lustre→C compiler into a relational framework using Walrus. The core idea is to model compilation as a relation, enabling both forward compilation and backward lifting, while employing simple horizontal canonicalization passes to handle real-world C outside the canonical sublanguage. Key contributions include a relational, bidirectional core that reuses Vélus, a modular toolchain connecting Lustre, Clight, and SCADE, and a practical lifting example from C to Lustre to a graphical SCADE model. The approach demonstrates that relational programming can rapidly produce DSL lifters by repurposing existing compilers, with future work aimed at expanding support to additional DSLs such as SysML and enhancing horizontal canonicalization and SCADE translation.

Abstract

Lifting low-level or legacy code into a domain-specific language (DSL) improves our ability to understand it, enables deeper formal reasoning, and facilitates safe modification. We present the CoCompiler, a bidirectional compiler and lifter between C and Lustre, a synchronous dataflow language used for reactive systems. The key insight behind the CoCompiler is that writing a compiler as a relation, rather than as a traditional function, yields a DSL lifter "for free". We implement this idea by rewriting the verified Lustre-to-C compiler Vélus in the Walrus relational programming language. This solves what we call the vertical lifting problem, translating canonical C into Lustre. To address the complementary horizontal problem-handling real-world C outside the compiler's image-we apply semantic-preserving canonicalization passes in Haskell. The resulting tool, the CoCompiler, supports lifting real reactive C code into Lustre and onward into graphical behavioral models. Our approach is modular, language-agnostic, and fast to implement, demonstrating that relational programming offers a practical foundation for building DSL lifters by repurposing existing compilers.

Paper Structure

This paper contains 10 sections, 4 equations, 10 figures.

Figures (10)

  • Figure 1: A Lustre program that adds all its inputs.
  • Figure 2: SCADE model for count
  • Figure 3: Vélus compilation phases velusNvelusWeb
  • Figure 4: mulR and squareR relations in Walrus
  • Figure 5: Compiler, decompiler, and ideal lifter
  • ...and 5 more figures