-
Notifications
You must be signed in to change notification settings - Fork 144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Subtractor Component to misc menu #517
base: main
Are you sure you want to change the base?
Added Subtractor Component to misc menu #517
Conversation
WalkthroughThis update integrates a new circuit element named "Subtractor" into the simulator. The configuration file now includes the element in both the available element list and the hierarchy under the "Misc" category. In addition, the module setup file has been updated to import and register the new Subtractor, and a dedicated module file implements its class with methods to handle resolution, bit width adjustments, and Verilog code generation. Changes
Sequence Diagram(s)sequenceDiagram
participant S as Simulator
participant M as ModuleSetup
participant SB as Subtractor
S->>M: Initialize module set
M->>SB: Import & register Subtractor
S->>SB: Create Subtractor instance
SB->>SB: Validate inputs (isResolvable)
SB->>SB: Compute subtraction (resolve)
SB-->>S: Return computed outputs
Poem
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for circuitverse ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (2)
v0/src/simulator/src/modules/Subtractor.js (2)
76-93
: Improve the borrowOut calculation in the Verilog outputThe resolve method correctly handles the subtraction logic, borrow-in, and borrow-out calculations. However, the borrow-out signal is not included in the Verilog code generation method below.
95-100
: Include borrowOut in Verilog generationThe generateVerilog method only generates code for the difference output but not for the borrowOut signal. Consider adding Verilog code to handle the borrowOut signal as well.
generateVerilog() { if (this.borrowIn.verilogLabel) { - return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel} - ${this.borrowIn.verilogLabel};`; + return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel} - ${this.borrowIn.verilogLabel}; +assign ${this.borrowOut.verilogLabel} = (${this.inpA.verilogLabel} < ${this.inpB.verilogLabel} + ${this.borrowIn.verilogLabel});`; } - return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel};`; + return `assign ${this.diff.verilogLabel} = ${this.inpA.verilogLabel} - ${this.inpB.verilogLabel}; +assign ${this.borrowOut.verilogLabel} = (${this.inpA.verilogLabel} < ${this.inpB.verilogLabel});`; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (4)
v0/src/assets/img/Adder.svg
is excluded by!**/*.svg
v0/src/assets/img/Subtractor.svg
is excluded by!**/*.svg
v0/src/simulator/src/img/Adder.svg
is excluded by!**/*.svg
v0/src/simulator/src/img/Subtractor.svg
is excluded by!**/*.svg
📒 Files selected for processing (3)
v0/src/simulator/src/metadata.json
(2 hunks)v0/src/simulator/src/moduleSetup.js
(2 hunks)v0/src/simulator/src/modules/Subtractor.js
(1 hunks)
🔇 Additional comments (8)
v0/src/simulator/src/metadata.json (2)
24-24
: LGTM: Subtractor element added to circuitElementListThe Subtractor element has been correctly added to the circuit element list, positioned logically after the Adder element.
165-165
: LGTM: Subtractor added to Misc category hierarchyThe Subtractor element has been correctly added to the "Misc" category in the element hierarchy with appropriate name and label properties, positioned logically after the Adder element.
v0/src/simulator/src/moduleSetup.js (2)
3-3
: LGTM: Subtractor module import addedThe Subtractor module import has been correctly added, following a logical order after the Adder import.
88-88
: LGTM: Subtractor added to moduleSetThe Subtractor has been correctly added to the moduleSet object, maintaining the same ordering as the imports.
v0/src/simulator/src/modules/Subtractor.js (4)
17-30
: LGTM: Subtractor class structure and initializationThe Subtractor class extends CircuitElement appropriately and initializes with the correct parameters and node structure. The implementation follows the project's conventions for circuit elements.
37-49
: LGTM: Proper customSave implementationThe customSave method correctly saves the constructor parameters and node references, following the pattern established by other circuit elements.
56-58
: LGTM: Correct resolvability checkThe isResolvable method correctly checks that both input values are defined before attempting to resolve the subtractor.
65-70
: LGTM: Proper bitWidth handlingThe newBitWidth method correctly updates the bitWidth for the element and its input/output nodes.
Subtractor.prototype.tooltipText = 'Subtractor ToolTip : Performs subtraction of numbers.'; | ||
Subtractor.prototype.helplink = 'https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor'; | ||
Subtractor.prototype.objectType = 'Subtractor'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify documentation link
The helplink points to a specific URL that might not exist yet. Please ensure the documentation for the Subtractor component exists at this location or update the URL accordingly.
🌐 Web query:
Does the page https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor exist and contain documentation for the Subtractor component?
💡 Result:
The page https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor does not appear to exist in the provided documentation. While CircuitVerse's documentation ([2]) covers general usage of the simulator and digital circuit concepts, none of the search results reference this specific URL or confirm the existence of a dedicated "Subtractor" component documentation section at this address.
However, multiple CircuitVerse projects ([1][3][4][5][9][11]) demonstrate subtractor implementations (half/full subtractors, 2-bit to 8-bit variants) with detailed explanations of their logic equations, truth tables, and circuit designs. For example:
- Full subtractors use SOP forms like Diff=xy' z'+x' y' z+xyz+x'yz' and Borrow=x' z+x' y+yz [1][4]
- 4-bit adder-subtractor circuits implement two's complement subtraction through XOR gates and controlled inversion [3][5]
For official documentation, the main CircuitVerse docs ([2][6]) remain the primary resource, though subtractor-specific guidance would need to be inferred from general circuit design principles and community project examples.
Citations:
- 1: https://circuitverse.org/users/59463/projects/subtractors-ab5c00bb-e6d9-416c-86e5-da6236c87a44
- 2: https://docs.circuitverse.org
- 3: https://circuitverse.org/users/215952/projects/adder-subtractor-circuit-detail-explanation-f562eabf-9c8c-49de-9d14-d9fb364ba133
- 4: https://circuitverse.org/projects/tags/Full%20Subtractor
- 5: https://circuitverse.org/users/30250/projects/8-bit-binary-subtractor
- 6: https://circuitverse.org
- 7: https://circuitverse.org/projects/tags/Subtractor
- 8: https://circuitverse.org/projects/tags/subtractor
- 9: https://circuitverse.org/users/100380/projects/4-bit-subtractor-circuit-17b4c0d1-c2ca-4a92-882b-492480bea832
- 10: https://circuitverse.org/simulator
- 11: https://circuitverse.org/users/50246/projects/2-bit-adder-subtractor-circuit-93547b1b-4904-4c09-842b-59467dbe2a15
- 12: https://circuitverse.org/projects/tags/adder%2Fsubtractor%20circuit
- 13: https://circuitverse.org/users/5249/projects/full-subtractor-e12c069e-8038-4336-9dc2-aa7be5ae52c7
- 14: https://circuitverse.org/users/89897/projects/full-subtractor-circuit-e2ddc819-6272-4deb-b83b-f792872c9323
- 15: https://circuitverse.org/users/290502/projects/subtractor-652fd41e-315b-4e59-9c39-51d47282c0bb
- 16: https://circuitverse.org/users/84957/projects/adder-subtractor-b18e0777-78f0-4f0e-89ba-b179bb40f66b
Action Required: Update the Subtractor Documentation URL
The current helplink
property in v0/src/simulator/src/modules/Subtractor.js
(lines 109-111) points to:
https://docs.circuitverse.org/#/chapter4/8misc?id=subtractor
However, our verification indicates that this URL does not exist in the CircuitVerse documentation. Please update the URL to point to valid and relevant documentation for the Subtractor component, or remove it if no dedicated documentation is available.
- File:
v0/src/simulator/src/modules/Subtractor.js
- Lines: 109-111
- Issue: Invalid documentation link for the Subtractor component
Fixes #516 - Add Subtractor Module in Misc Menu
Summary of Changes:
Subtractor.js
inv0/src/simulator/src/modules
.moduleSetup.js
(v0/src/simulator/src/moduleSetup.js
).metadata.json
(v0/src/simulator/src/metadata.json
) to include the Subtractor.v0/src/assets/img
v0/src/simulator/src/img
Screenshots & Testing:
Screenshot:
🎥 Testing Video: Watch here
Additional Notes:
✔ Code follows project structure and conventions.
✔ Fully tested to ensure correct functionality.
✔ Please check "Allow edits from maintainers" for any required refinements.
Looking forward to your feedback! 🚀
Summary by CodeRabbit