Skip to content

Commit f18d3e3

Browse files
author
Jiefeng Li
committed
doc(rfel): refactoring plan
Signed-off-by: Jiefeng Li <jiefeng_li@hust.edu.cn>
1 parent 21490ae commit f18d3e3

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

rfel/plan.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# xfel to Rust rfel Refactoring To-Do List
2+
3+
## Phase 1: Foundational Work
4+
5+
- [ ] **Set up the basic Rust project structure.**
6+
- Define modules and file layout.
7+
- [ ] **Define core data structures and constants.**
8+
- [ ] **Implement command-line argument parsing.**
9+
- Define the structure for holding parsed arguments.
10+
- [ ] **Re-implement simple, self-contained utility functions.**
11+
such as:
12+
- `filedump`
13+
- `hexdump`
14+
15+
## Phase 2: Core Logic and Library Migration (Could be LLM-Assisted)
16+
17+
- [ ] **See the "Core Logic Refactoring Workflow" section for detailed tasks.**
18+
19+
## Phase 3: Integration and Verification
20+
21+
- [ ] **Integrate all refactored modules.**
22+
- [ ] **Write unit and integration tests.**
23+
- [ ] **Perform end-to-end testing to ensure functionality matches the original C project.**
24+
25+
## Low Priority
26+
27+
- [ ] **Investigate and understand the `payload` directory.**
28+
29+
30+
# LLM-Assisted Refactoring Workflow
31+
32+
## 1. Library and Dependency Replacement
33+
34+
* **Goal:** Replace C libraries and custom functions with modern, idiomatic Rust crates. An LLM can excel here due to its broad knowledge of libraries across different languages.
35+
* **Workflow:**
36+
* [ ] **Identify Candidates:** Use an LLM to scan the C source code and identify all external library calls (e.g. crypto libraries for `sha256.h/.c`, `ecdsa256.h/.c`) and custom utility functions that have common equivalents.
37+
* [ ] **Suggest Alternatives:** Prompt the LLM to suggest popular and well-maintained Rust crates that provide equivalent functionality.
38+
* [ ] **Generate Wrapper Code:** Once a crate is chosen, ask the LLM to help generate the necessary wrapper code or usage examples to integrate the new crate into our project structure.
39+
40+
## 2. Automated Translation and Idiomatic Refactoring
41+
42+
* **Goal:** Translate the core C logic into safe, idiomatic Rust, improving upon the direct output of automated tools like `c2rust`.
43+
* **Workflow:**
44+
* [ ] **Generate Baseline with `c2rust`:** Run the `c2rust` tool on a target C module to get an initial, albeit rough and unsafe, Rust translation.
45+
* [ ] **Semantic Refactoring with LLM:** Provide the LLM with both the **original C source code** (for semantic context) and the **`c2rust`-generated Rust code** (as a starting point).
46+
* [ ] **Prompt for Idiomatic Rewrite:** Instruct the LLM to refactor the `c2rust` output into safe, idiomatic Rust. This is the most critical step. (Notice that the context could not be too long, so maybe we need to break it into smaller parts.)
47+
* [ ] **Iterative Review:** This will be an iterative process. Start with small, pure functions and gradually move to more complex code. **Human oversight is critical** to validate the correctness and safety of the LLM's output.

0 commit comments

Comments
 (0)