This repository contains the implementation for the paper "ReChisel: Effective Automatic Chisel Code Generation by LLM with Reflection", accepted at DAC 2025.
ReChisel is a system that enhances Large Language Models (LLMs) for hardware design by enabling them to automatically generate and verify Chisel code. The core of ReChisel is a reflection mechanism, where the LLM iteratively analyzes compilation and simulation feedback to correct its own code, significantly improving the success rate of generating functionally correct hardware designs.
- π Getting Started
- π Quickstart: Using the ReChisel CLI
- π Interactive Tutorials (Jupyter Notebooks)
- π Benchmark & Evaluation Details
- Citation
Install Tools:
-
SBT (Simple Build Tool for Scala)
- Purpose: Used to compile Chisel code into Verilog.
- Website: scala-sbt.org
- Chisel Installation Guide: Chisel Docs: Installing with SBT
- Note: This project is configured with
build.sbtto manage Chisel dependencies.
-
Icarus Verilog
- Purpose: Used to compile and simulate the generated Verilog code for functional verification.
- Website: steveicarus.github.io/iverilog/
git clone git@github.com:niujuxin/ReChisel.git
cd ReChisel
pip install -r requirements.txt# For OpenAI API
export OPENAI_API_KEY="your_openai_api_key"
# For Claude AWS Bedrock
export AWS_ACCESS_KEY_ID="your_aws_access_key_id"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key"The rechisel_cli.py script provides a complete, end-to-end pipeline for generating and verifying Chisel code from a natural language specification.
Click to see all CLI options
usage: rechisel_cli.py [-h] [--verbose] [-o OUTPUT] [-n NUM_ITERATIONS] [--prob-id PROB_ID]
--specification SPECIFICATION [--reference REFERENCE] --testbench TESTBENCH
[--top-module-name TOP_MODULE_NAME] --bm-type BM_TYPE
[--init-gen-system-prompt INIT_GEN_SYSTEM_PROMPT]
[--init-gen-model INIT_GEN_MODEL]
[--syntax-correction-system-prompt SYNTAX_CORRECTION_SYSTEM_PROMPT]
[--functionality-correction-system-prompt FUNCTIONALITY_CORRECTION_SYSTEM_PROMPT]
[--correction-model CORRECTION_MODEL]
[--sbt-reflection-system-prompt SBT_REFLECTION_SYSTEM_PROMPT]
[--iv-reflection-system-prompt IV_REFLECTION_SYSTEM_PROMPT]
[--functionality-reflection-system-prompt FUNCTIONALITY_REFLECTION_SYSTEM_PROMPT]
[--reviewer-model REVIEWER_MODEL] [--verifier-working-dir VERIFIER_WORKING_DIR]
[--use-in-context-history] [--use-llm-summary]
[--llm-summary-system-prompt LLM_SUMMARY_SYSTEM_PROMPT]
[--llm-summary-model LLM_SUMMARY_MODEL]
[--max-history-length MAX_HISTORY_LENGTH]
ReChisel CLI
options:
-h, --help show this help message and exit
# ... and all other optionsBelow is an example of a ReChisel CLI command, using benchmarks/VerilogEval_Prob030/ as an example:
python rechisel_cli.py \
--prob-id Prob030_popcount255 \
--specification benchmarks/VerilogEval_Prob030/Prob030_popcount255_spec.txt \
--reference benchmarks/VerilogEval_Prob030/Prob030_popcount255_ref.sv \
--testbench benchmarks/VerilogEval_Prob030/Prob030_popcount255_tb.sv \
--top-module-name TopModule \
--bm-type verilog-eval \
--use-in-context-history \
--use-llm-summary \
--verifier-working-dir output/VerilogEval_Prob030 \
--output output/VerilogEval_Prob030/result.json \
--verboseThis command will initiate the iterative generation and reflection process, with all intermediate procedures and the final result saved to the output/VerilogEval_Prob030/result.json path.
sample_result_by_rechisel_cli.py is the sample result of the above command. It shows the output produced by the ReChisel CLI.
We provide several Jupyter notebooks that break down the process step-by-step.
-
Main_code_gen_and_verify.ipynb- Demonstrates the basic workflow: generating Chisel code from a specification and verifying its correctness, without the reflection mechanism.
-
Main_one_round.ipynb- Illustrates a single round of reflection. Assuming an incorrect Chisel file and its verification report are available, this notebook shows how ReChisel analyzes the error and generates a corrected version. The
benchmarks/VerilogEval_Prob001folder contains multiple.scalaimplementations, each with a different type of error. They are used to demonstrate how reflection can be applied to different kinds of errors.
- Illustrates a single round of reflection. Assuming an incorrect Chisel file and its verification report are available, this notebook shows how ReChisel analyzes the error and generates a corrected version. The
-
Main_tracing.ipynb- Explains the full multi-turn reflection process. This notebook demonstrates how ReChisel performs multiple iterations of generation and correction, and how it logs this history (tracing) to potentially use as in-context learning for the LLM.
We evaluate ReChisel on three public benchmarks. The benchmarks/ directory only contains a few examples to demonstrate usage.
- VerilogEval (Spec-to-RTL): NVlabs/verilog-eval
- AutoChip (HDL-Bits): shailja-thakur/AutoChip
- RTLLM: hkust-zhiyao/RTLLM
For the VerilogEval's Spec-to-RTL and RTLLM benchmarks, they are directly compatible with Chisel. However, for AutoChip's HDL-Bits, the original specifications are provided in .v files, where the module signatures (i.e., name, inputs, outputs, etc.) are implemented in Verilog, and the descriptions exist as comments within the code. This type of benchmark requires some processing within the code to make it compatible with Chisel.
We have converted all benchmark specifications into the same format as VerilogEval's Spec-to-RTL. The benchmark/AutoChip_Vector5 directory contains an example of this conversion.
Example: Converting an AutoChip Specification
Here is an example of how a .v file from AutoChip is converted into a .txt specification.
Original Vector5_spec.v:
//Given five 1-bit signals (a, b, c, d, and e), compute all 25 pairwise one-bit comparisons
// in the 25-bit output vector. The output should be 1 if the two bits being compared are equal.
// Hint: out[24] = ~a ^ a; // a == a, so out[24] is always 1.
// out[23] = ~a ^ b;
// out[22] = ~a ^ c;
// ...
module top_module (
input a, b, c, d, e,
output [24:0] out );//
// The output is XNOR of two vectors created by
// concatenating and replicating the five inputs.
// assign out = ~{ ... } ^ { ... };
// Insert your code below
endmoduleConverted Vector5_spec.txt:
I would like you to implement a module named `TopModule` with the following interface.
All input and output ports are one bit wide unless otherwise specified.
Module Name: `TopModule`
Ports:
input a,
input b,
input c,
input d,
input e,
output [24:0] out
Given five 1-bit signals (a, b, c, d, and e), compute all 25 pairwise one-bit comparisons in the 25-bit output vector.
The output should be 1 if the two bits being compared are equal.
Hint:
out[24] = ~a ^ a; // a == a, so out[24] is always 1.
out[23] = ~a ^ b;
out[22] = ~a ^ c;
...
The SBT compiler compiles Chisel code into Verilog code. The Verilog code is then tested on the benchmark; if the Verilog code passes the tests, the Chisel code is considered correct. However, compiling Chisel code with the SBT compiler can lead to some compatibility issues.
-
No I/O Bundles:
- Problem: Using a
Bundlefor I/O ports causes the Chisel compiler to add a prefix (e.g.,io_) to all port names, breaking the testbench. - Solution: We instruct the LLM to declare each I/O port individually using
IO(Input(...))andIO(Output(...)). - Reference: Chisel Cookbook: How do I create I/O without a prefix?
- Problem: Using a
-
Use
RawModuleinstead ofModule:- Problem: A standard Chisel
Moduleautomatically includes implicitclockandresetsignals, which often conflicts with the testbench's port list. - Solution: We require the LLM to use
extends RawModule, which does not have implicit signals. For sequential logic, the clock and reset must be explicitly defined as inputs and used withwithClockAndReset(clock, reset) { ... }. - Reference: Chisel Docs: RawModule
- Problem: A standard Chisel
These constraints are embedded in the system prompts (prompts/chisel_generation.txt and prompts/syntax_iv_reflection.txt) to guide the LLM toward generating compatible code.
@inproceedings{niu2025rechisel,
author = {Juxin, Niu and Xiangfeng, Liu and Dan, Niu and Xi, Wang and Zhe, Jiang and Nan, Guan},
title = {Rechisel: Effective Automatic Chisel Code Generation by LLM with Reflection},
booktitle = {Proceedings of the 62nd ACM/IEEE Design Automation Conference (DAC)},
year = {2025}
}