Appearance
Spec: Import from HDL
Overview
Parse simple VHDL or Verilog files and generate a schematic circuit in DigitalWorks, providing the reverse path of HDL export. Enables importing existing designs and learning HDL by seeing the graphical equivalent.
Motivation
- Students can paste textbook HDL examples and see the circuit visually.
- Existing VHDL/Verilog designs from other tools can be brought into DigitalWorks.
- Enables round-trip workflow: design in schematic → export to HDL → modify in HDL → re-import.
- Bridges the gap for users transitioning between schematic and text-based design.
Requirements
Functional Requirements
- Verilog Import: Parse synthesizable Verilog (structural and simple behavioral).
- VHDL Import: Parse synthesizable VHDL (structural and simple behavioral).
- Structural Import: Direct mapping of component instantiations to DigitalWorks components.
- Behavioral Synthesis: Convert simple
assign/ concurrent signal assignments to gate networks. - Hierarchy Preservation: Modules/entities become macros in DigitalWorks.
- Port Mapping: Module/entity ports become circuit I/O components.
- Auto-Layout: Imported circuits are auto-laid out (uses auto-layout engine).
- Error Reporting: Clear error messages for unsupported constructs.
- Partial Import: Import what can be understood; flag unsupported sections.
- Preview: Show imported circuit preview before inserting into editor.
Supported HDL Subset
Verilog:
- Module declarations with port lists.
- Wire and reg declarations.
- Continuous assignments (
assign out = a & b;). - Gate-level primitives (
and,or,not,xor,nand,nor,xnor,buf). - Module instantiation (structural).
- Simple
always @(posedge clk)for flip-flop inference.
VHDL:
- Entity/architecture declarations.
- Signal declarations.
- Concurrent signal assignments (
out <= a and b;). - Component instantiation.
- Simple
process(clk)for flip-flop inference.
Not Supported (initial version)
- Generate statements (loops).
- Memory/array declarations.
- Complex behavioral code (case, if-else trees beyond basic MUX inference).
- Testbench constructs.
Non-Functional Requirements
- Parsing completes in under 5 seconds for files up to 1000 lines.
- Generated circuit is functionally equivalent to the HDL (verifiable via simulation).
- Import errors clearly indicate line number and construct that failed.
Design
Import Pipeline
HDL Source File
→ Lexer/Parser (generate AST)
→ Semantic Analysis (resolve signals, check types)
→ Netlist Extraction (structural) or Synthesis (behavioral)
→ Component Mapping (HDL primitives → DigitalWorks components)
→ Circuit Construction (create Components, Wires, Pins)
→ Auto-Layout
→ Preview / Insert into EditorParser Strategy
Use a recursive descent parser for the supported subset:
csharp
public interface IHdlParser
{
HdlModule Parse(string sourceCode);
List<ParseError> Errors { get; }
}
public class HdlModule
{
public string Name { get; set; }
public List<HdlPort> Ports { get; set; }
public List<HdlSignal> InternalSignals { get; set; }
public List<HdlAssignment> Assignments { get; set; }
public List<HdlInstantiation> Instantiations { get; set; }
}
public class HdlAssignment
{
public string Target { get; set; }
public HdlExpression Expression { get; set; } // AST of Boolean expression
}Expression-to-Gates Synthesis
Expression AST → Gate Network
a & b → AND gate
a | b → OR gate
~a → NOT gate
a ^ b → XOR gate
a ? b : c → MUX
(complex) → Decompose into primitivesImport Dialog
┌─────────────────────────────────────┐
│ Import HDL │
├─────────────────────────────────────┤
│ File: [C:\designs\alu.v ] [...] │
│ Format: ● Verilog ○ VHDL │
│ │
│ Status: ✓ Parsed successfully │
│ Modules found: 2 (alu, adder) │
│ Warnings: 1 │
│ │
│ Import as: │
│ ○ Flat circuit (inline all) │
│ ● Hierarchical (macros) │
│ │
│ [Preview] [Import] [Cancel] │
└─────────────────────────────────────┘Implementation Tasks
- Create
DigitalWorks.Core/Import/namespace. - Implement Verilog lexer and parser (supported subset).
- Implement VHDL lexer and parser (supported subset).
- Implement structural import (instantiation → component mapping).
- Implement expression synthesis (assign → gate network).
- Implement flip-flop inference from
always/processblocks. - Implement hierarchy handling (module → macro conversion).
- Integrate with auto-layout engine for imported circuits.
- Create import dialog with file selection and preview.
- Implement error reporting with line numbers and suggestions.
- Add menu item (File → Import → VHDL/Verilog).
Risks & Open Questions
- How much behavioral Verilog/VHDL to support? (scope creep risk)
- Should unsupported constructs be black-boxed (empty macro with correct ports)?
- Third-party parser libraries vs. hand-written parser for the subset?
- How to validate that the imported circuit matches the original HDL behavior?
Priority
Medium — Enables round-trip workflows and HDL learning.