Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions .github/workflows/nodejs.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Ruby CI

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Yosys
run: |
sudo apt-get update
sudo apt-get install -y yosys

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Run Tests
run: bundle exec rspec
37 changes: 33 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
/node_modules
/dist
*.swp
*.swo
# Node.js
node_modules/
dist/
npm-debug.log*

# Ruby
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Bundler
/.bundle/
/vendor/bundle/

# IDEs
.vscode/
.idea/

# System
.DS_Store
Thumbs.db

# Yosys output (if any generated in root)
output.json
*.json
13 changes: 12 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# Changelog
# Change Log

## [1.0.0] - 2026-01-24
### Changed
- **REWRITE**: Ported entire codebase from Node.js (TypeScript) to Ruby.
- **Architecture**: Converted from a standalone microservice to a Ruby Gem library (`yosys2digitaljs`).
- **Logic**: Implemented custom 3-Valued Logic (`3vl`) engine in Ruby.
- **Conversion**: Implemented full Yosys-to-DigitalJS conversion logic including Memories (`$mem`), FSMs (`$fsm`), and Bus Grouping.
- **Infrastructure**: Replaced `nodejs.yml` CI with `ruby.yml`. Updated Dockerfile to Ruby 3.2.
- **Testing**: Migrated all 17 SystemVerilog test cases to RSpec fixtures.

## [Legacy Node.js Versions]
All notable changes to this project will be documented in this file.

## [0.7.0] -- 2023-03-2023
Expand Down
29 changes: 14 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Dockerfile

FROM node:lts-slim
RUN apt-get update -qq
RUN apt-get install -y yosys
RUN mkdir -p /opt/app
WORKDIR /opt/app
COPY ./package.json ./package.json
COPY ./package-lock.json ./package-lock.json
RUN npm install
COPY ./ ./
RUN npm run build
EXPOSE 3040
ENV NODE_ENV=production
CMD [ "npm", "run", "server" ]
FROM ruby:3.2-slim

# Install Yosys
RUN apt-get update && apt-get install -y yosys git build-essential

# Setup App
WORKDIR /app
COPY . .

# Install Gems
RUN bundle install

# Default command (Testing)
CMD ["bundle", "exec", "rspec"]
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Load dependencies from the .gemspec file
gemspec
48 changes: 48 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
PATH
remote: .
specs:
yosys2digitaljs (0.1.0)
json

GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.6.2)
json (2.6.3)
rake (13.0.6)
rspec (3.13.2)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
rspec-mocks (~> 3.13.0)
rspec-core (3.13.6)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.5)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.7)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.6)

PLATFORMS
ruby
x86_64-linux-gnu

DEPENDENCIES
rake
rspec (~> 3.0)
yosys2digitaljs!

CHECKSUMS
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
json (2.6.3)
rake (13.0.6) sha256=5ce4bf5037b4196c24ac62834d8db1ce175470391026bd9e557d669beeb19097
rspec (3.13.2) sha256=206284a08ad798e61f86d7ca3e376718d52c0bc944626b2349266f239f820587
rspec-core (3.13.6) sha256=a8823c6411667b60a8bca135364351dda34cd55e44ff94c4be4633b37d828b2d
rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
rspec-mocks (3.13.7) sha256=0979034e64b1d7a838aaaddf12bf065ea4dc40ef3d4c39f01f93ae2c66c62b1c
rspec-support (3.13.6) sha256=2e8de3702427eab064c9352fe74488cc12a1bfae887ad8b91cba480ec9f8afb2
yosys2digitaljs (0.1.0)

BUNDLED WITH
4.0.4
88 changes: 60 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
# yosys2digitaljs
This program converts JSON netlist output generated by [Yosys](https://yosyshq.net/yosys/)
circuit synthesis software (Github repo [here](https://github.com/YosysHQ/yosys/)) for use with the
[DigitalJS](http://github.com/tilk/digitaljs) graphical circuit simulator.

# Usage
You need to have [Yosys](https://yosyshq.net/yosys/) installed to run
yosys2digitaljs. For example, in Debian/Ubuntu, run:
```bash
apt install yosys
# Yosys2Digitaljs Ruby Gem

A pure Ruby port of the `yosys2digitaljs` compiler. It runs Yosys on Verilog code and converts the resulting netlist into a DigitalJS-compatible JSON format.

## Architecture Change
> [!NOTE]
> This repository was formerly a Node.js microservice. As of v1.0.0, it is a **Ruby Gem**.
> It is designed to be bundled directly into your Rails application (CircuitVerse), eliminating the need for a separate sidecar service.

## Requirements
* **Ruby** 3.0+
* **Yosys**: The `yosys` binary must be in your system PATH (or Docker container).
* Ubuntu: `sudo apt-get install yosys`

## Installation
Add this line to your application's Gemfile:

```ruby
gem 'yosys2digitaljs', path: 'vendor/gems/yosys2digitaljs'
# Or via git if pushed to a repo
# gem 'yosys2digitaljs', git: 'https://github.com/CircuitVerse/yosys2digitaljs-server.git'
```
Clone the repository and install dependencies using npm:

And then execute:
```bash
git clone https://github.com/tilk/yosys2digitaljs.git
cd yosys2digitaljs
npm install
$ bundle install
```
Now you can run yosys2digitaljs on your Verilog or SystemVerilog files:
```bash
./process.js file.v file.sv ...

## Usage

```ruby
require 'yosys2digitaljs'

verilog_code = <<~VERILOG
module top(input a, output y);
assign y = ~a;
endmodule
VERILOG

# Compile to DigitalJS JSON
# Returns a Hash (ready for JSON.generate)
circuit_json = Yosys2Digitaljs::Runner.compile(verilog_code)

puts JSON.pretty_generate(circuit_json)
```
The generated JSON is printed on standard output.

# API
Yosys2digitaljs can be used as a library. The API is promise (or async/await) based. Available functions are:
## Development

- `yosys2digitaljs(json, options)` - converts the Yosys JSON output `json` (passed as an JS object) to a DigitalJS representation of the same circuit.
- `process_sv(sv_text, options)` - converts a single SystemVerilog source passed as a string.
- `process_files(texts, options)` - converts multiple Verilog/SystemVerilog sources. The `texts` parameter is an object, with keys being file names, and corresponding values containing the file contents as strings. Example: `{ 'test.sv': 'module test; ...' }`.
- `process(filenames, dirname, options)` - converts Verilog/SystemVerilog sources saved on the filesystem under names `filenames` in the directory `dirname`.
### Running Tests
The project includes a comprehensive test suite of 17 SystemVerilog fixtures ported from the original project.

The functions return a promise, which fulfills with an object value with following keys:
```bash
# Install dependencies
bundle install

- `output`: the conversion result as JS object, which can be stringified to JSON.
- `yosys_stdout` and `yosys_stderr`: standard output and error output received from Yosys.
# Run all tests
bundle exec rspec
```

### Docker
A `Dockerfile` is provided for containerized testing.

```bash
docker build -t yosys-ruby .
docker run --rm yosys-ruby
```

For bigger example, see the [online app demo](http://github.com/tilk/digitaljs_online).
## License
BSD-2-Clause
5 changes: 5 additions & 0 deletions lib/three_valued_logic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require_relative "three_valued_logic/vector"

module ThreeValuedLogic
class Error < StandardError; end
end
Loading
Loading