Skip to content

ahmed-agiza/vcd-parser

Repository files navigation

vcd-parser

A Node.js parsing tool for Value Change Dump (VCD) files and generating a readable JSON document. It can be used with different hardware simulation tools such as Icarus Iverilog.

Installation

npm install --save vcd-parser

Usage example

const VCDParser = require('vcd-parser');
VCDParser.parse(
	`
	$date
	Tue Feb 12 14:01:15 2019
	$end
	$version
	Icarus Verilog
	$end
	$timescale
	1ns
	$end
	$scope module test_tb $end
	$var reg 1 ! clk $end
	$var wire 1 " rst $end
	$upscope $end
	$enddefinitions $end
	#0
	$dumpvars
	0"
	0!
	$end
	#15
	1"
	#20
	1!
	#40
	0!
	#60
	1!
	#80
	0!
	#100
	1!
	#115
`
)
	.then(parsedData => {
		console.log(parsedData);
		// {
		// 	"date": "Tue Feb 12 14:01:15 2019",
		// 	"version": "Icarus Verilog",
		// 	"timescale": "1ns",
		// 	"endtime": "115",
		// 	"scale": "1ns",
		// 	"signal": [
		// 		{
		// 			"type": "reg",
		// 			"size": 1,
		// 			"refName": "!",
		// 			"signalName": "clk",
		// 			"module": "test_tb",
		// 			"name": "test_tb.clk",
		// 			"wave": [
		// 				[
		// 					"0",
		// 					"0"
		// 				],
		// 				[
		// 					"20",
		// 					"1"
		// 				],
		// 				[
		// 					"40",
		// 					"0"
		// 				],
		// 				[
		// 					"60",
		// 					"1"
		// 				],
		// 				[
		// 					"80",
		// 					"0"
		// 				],
		// 				[
		// 					"100",
		// 					"1"
		// 				]
		// 			]
		// 		},
		// 		{
		// 			"type": "wire",
		// 			"size": 1,
		// 			"refName": "\"",
		// 			"signalName": "rst",
		// 			"module": "test_tb",
		// 			"name": "test_tb.rst",
		// 			"wave": [
		// 				[
		// 					"0",
		// 					"0"
		// 				],
		// 				[
		// 					"15",
		// 					"1"
		// 				]
		// 			]
		// 		}
		// 	]
		// }
	})
	.catch(err => {
		console.error(err);
	});

API Documentation

VCDParser.parse(content, [opts], [cb]) ⇒ Promise.<ParsedData>

Parse VCD text content and generate a valid JSON representation. The function returns a promise unless a callback is provided.

Returns: Promise.<ParsedData> - that resolves with the parsed data

Param Type Default Description
content string The text content of the VCD file
[opts] Options {} Optional configuration to customize the parsing process
[cb] ParseCallback Optional callback if you don't prefer to use promises

VCDParser:Options : Object

The optional configuration for the VCD parser

Properties

Name Type Description
compress boolean Compress the output wave by ignoring the unchanged values
expandAmbigousBus boolean If the bus has some ambigous value (z or x), it gets expanded to represent the whole bus signal

VCDParser:ParsedData : Object

The parsed VCD object generated by the parser

Properties

Name Type Description
[...meta] string The values of different initial meta-data, e.g. date, timescale..etc
endtime string The endtime of the simulation
scale string The time-scale unit of the simulation
signal Array.<Signal> The signal values of the simulation

VCDParser:Signal : Object

The object representing one signal data

Properties

Name Type Description
name string The full name of the signal
type string The type of the signal, e.g. wire, reg,..etc
size number The size/width of the signal in bits
refName string The reference for this signal used inside the VCD file
module string The name of the top module for which this signal belongs
wave Array.<SignalValue> The values of the signal at different points of time

VCDParser:SignalValue : Array.<number>

The value of a signal at a specific point of time, represnted as a tuple [time, value]

Properties

Name Type Description
0 number The time of the event
1 number The value of the signal at that event

VCDParser:ParseCallback : function

The callback for the parsing function.

Param Type Description
err error The error generated while parsing
parsedJSON ParsedData The JSON document generated by the parser

About

VCD Parser for Node.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published