cpp-to-dafny-translator

Featured

Translate C/C++ programs to equivalent Dafny code while preserving semantics and ensuring verification. Use when users ask to convert, translate, or port C/C++ code to Dafny, or when they need to formally verify C/C++ algorithms using Dafny's verification capabilities. Handles functions, structs, pointers, arrays, memory management, and ensures the generated Dafny code is well-typed, executable, verifiable, and can successfully run.

Data & Documents 252 stars 23 forks Updated 3 weeks ago Apache-2.0

Install

View on GitHub

Quality Score: 87/100

Stars 20%
80
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# C/C++ to Dafny Translator Translate C/C++ programs into equivalent, verifiable Dafny code while preserving program semantics and ensuring memory safety. ## Overview This skill provides systematic guidance for translating C/C++ code to Dafny, handling memory management, pointer semantics, type conversions, and ensuring well-typed, verifiable output with appropriate specifications. ## Translation Workflow ``` C/C++ Input → Analyze Structure → Map Types & Memory → Translate → Add Specifications → Verify ├─ Identify types, pointers, memory patterns ├─ Map C/C++ constructs to Dafny equivalents ├─ Handle memory safety and ownership ├─ Add preconditions, postconditions, invariants └─ Validate executability and verification ``` ## Core Translation Principles ### 1. Memory Safety First Dafny enforces memory safety. Every translation must: - Replace raw pointers with safe references or arrays - Make memory bounds explicit - Ensure no null pointer dereferences - Handle dynamic memory with sequences or arrays ### 2. Preserve Semantics The translated code must maintain the same computational behavior, preserve function contracts, keep algorithmic complexity, and handle all edge cases including error conditions. ### 3. Enable Verification Generated Dafny code must include specifications (preconditions, postconditions, invariants), be verifiable by Dafny's verifier, compile and execute correctly, and follow Dafny idioms. ## Type Mapping Reference ### Basi...

Details

Author
ArabelaTso
Repository
ArabelaTso/Skills-4-SE
Created
6 months ago
Last Updated
3 weeks ago
Language
Python
License
Apache-2.0

Similar Skills

Semantically similar based on skill content — not just same category