Skip to content

mgwoo/verilog-parser

 
 

Repository files navigation

C++ Verilog Parser/Writer

Documentation Build Status Coverage Status Licence: MIT

This repository was forked from ben-marshall's verilog parser in C. This project is target to change C into modern C++ (i.e. modern g++ successfully can compile this project)


Getting Started

This will get you have c++ verilog parsing binary.

$ cd src/
$ make clean
$ make -j4

To start using the parser in your own code, take a look at main.cpp which is a simple demonstration app used for testing and coverage. The basic code which you need is something like this:

// Initialise the parser.
verilog_parser_init();

// Open A File handle to read data in.
FILE * fh = fopen("my_verilog_file.v", "r");

// Parse the file and store the result.
int result = verilog_parse_file(fh);

verilog::verilog_source_tree* ast = verilog::yy_verilog_source_tree;
verilog::verilog_resolve_modules(ast);

FILE* fout = fopen("writing_veilog.v", "w");
PrintVerilog(fout, ast);

You can keep calling verilog_parse_file(fh) on as many different file handles as you like to build up a multi-file project AST representation. The parser will automatically follow any include directives it finds.

Testing

The original author used ASIC World and OpenSPARCT1 to test codes, but I mainly focused on benchmarks of ICCAD Contest 2015; Problem C, kinds of gate-level netlist.


Solved issue

  • Both of gcc/g++ now successfully compile this project (void ptr/extern variable/operator problem)
  • Added static library linking options. (libverilog_parser.a)
  • Apply namespace(verilog) as not to conflict with oter variable name.
  • Implement Verilog Writer (with custom line break)

About

A Flex/Bison Parser for the IEEE 1364-2001 Verilog Standard, based on C++

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 52.3%
  • Yacc 30.7%
  • C++ 6.6%
  • Lex 5.1%
  • Verilog 2.3%
  • Shell 1.7%
  • Other 1.3%