What is a good "template" Yosys synthesis script? - yosys

I want to write my own Yosys synthesis script. What is a good template to start with? The manual and webpage contain various examples, but no "authoritative" hello world example.

The synth command runs the recommended script for general-purpose synthesis tasks. See help synth for a complete list of commands called by this meta-command.
Your script should either borrow from synth or simply call synth to get the general-purpose stuff done. Many scripts call synth -run coarse for the coarse-grain part of synthesis and then continue with a custom sequence of commands for fine grains synthesis. See for example synth_xilinx.
For ASIC synthesis to a library in liberty format, use the following script as a starting point:
# read design
read_verilog mydesign.v
# generic synthesis
synth -top mytop
# mapping to mycells.lib
dfflibmap -liberty mycells.lib
abc -liberty mycells.lib
clean
# write synthesized design
write_verilog synth.v
A less aggressive set of optimizations is often desired for scripts that do formal verification. In this cases the following sequence of commands is usually a good starting point for the "synthesis" portion of a formal verification flow:
hierarchy [-check -top <top-module>]
proc; opt; memory [-nomap]; opt -fast; check -assert

Don't forget to put the mycells.lib and mycells.v file in the directory where you invoke yosys. A good example is on yosys's GitHub site under the directory "examples/cmos", where they have placed examples of cmos_cell.lib and cmos_cell.v files.
read_verilog counter.v
read_verilog -lib cmos_cells.v
proc;; memory;; techmap;;
dfflibmap -liberty cmos_cells.lib
abc -liberty cmos_cells.lib;;
write_verilog synth.v
(Also, if you want a more human readable synthesis output you can modify the .lib and .v file to change NAND and NOR gates into AND and OR gates.)

Related

Parameters to Script

Is there some way to pass parameters (or command line arguments) to a Yosys script?
I see in this quetion (Can we have variables in a Yosys script?) you can run the Yosys script within a TCL interpreter. Is there some way to pass in an argument?
The reason I am doing this is that I have a script, and I want to be able to call the script with a parameterized path to a Verilog file. Surely this is a common need, and there must be some easy way to do this, but I'm not seeing it.
The only way to do that at the moment is using environment variables and TCL scripts. For example, you can write a TCL script test.tcl:
yosys read_verilog $::env(VLOG_FILE_NAME)
yosys synth -top $::env(TOP_MODULE)
yosys write_verilog output.v
And then call if with VLOG_FILE_NAME and TOP_MODULE set in the environment:
VLOG_FILE_NAME=tests/simple/fiedler-cooley.v TOP_MODULE=up3down5 yosys test.tcl
If you are running Yosys from a shell script you can also simply run something like export VLOG_FILE_NAME=... at the top of your script. Similarly you can use the export Makefile statement when you are running Yosys from a Makefile.
I was facing a similar case. This question showed up while I was working on a solution. I ended up with a different approach though:
I'm creating a wrapper to my top module, written in m4 language. It's very simple, it overrides the parameters value, and then includes my top module definition.
Then in the Makefile, I process the wrapper.m4 file, to create the resulting wrapper.v file, that will be input to yosys.
I have detailled the solution here.

What is g++ -I option (capital i)?

Trying to do this and stumbled upon the -I option here: $ g++ -o version version.cpp -I/usr/local/qt4/include/QtCore -I/usr/local/qt4/include -L/usr/local/qt4/lib -lQtCore
I can't find any information about it
If you're looking for what -I does:
-I[/path/to/header-files]
Add search path to header files (.h) or (.hpp).
From https://caiorss.github.io/C-Cpp-Notes/compiler-flags-options.html
This pretty much just means that any #include statements you make to an external library (in your case qt) have to be referenced so that g++ knows where to look.
if my understanding is correct, question is about -i, not -L, I hope this helps:
-Idir Append directory dir to the list of directories searched for include files.
on this link
http://www.cs.virginia.edu/helpnet/Software_Development/compilers/g.html
g++ - GNU project C++ Compiler (v2 preliminary)
g++ [option | filename] ...
Capabilities
The C and C++ compilers are integrated. Both process input files through one or more of four stages: preprocessing, compilation, assembly, and linking.
C++ source files use one of the suffixes `.C', `.cc', or `.cxx'.
Options
There are many command-line options, including options to control details of optimization, warnings, and code generation, which are common to both gcc and g++. For full information on all options, see gcc(1).
Options must be separate: -dr' is quite different from- d -r '.
-c Compile or assemble the source files, but do not link. The compiler output is an object file corresponding to each source file.
-Dmacro Define macro macro with the string `1' as its definition.
-Dmacro=defn Define macro as defn
-E Stop after the preprocessing stage; do not run the compiler proper. The output is preprocessed source code, which is sent to the standard output.
- g Produce debugging information in the operating system's native format (for DBX or SDB or DWARF). GDB also can work with this debugging information. On most systems that use DBX format, `-g' enables use of extra debugging information that only GDB can use.
Unlike most other C compilers, GNU CC allows you to use ` -g' with `-O'. The shortcuts taken by optimized code may occasionally produce surprising results: some variables you declared may not exist at all; flow of control may briefly move where you did not expect it; some statements may not be executed because they compute constant results or their values were already at hand; some statements may execute in different places because they were moved out of loops.
Nevertheless it proves possible to debug optimized output. This makes it reasonable to use the optimizer for programs that might have bugs.
-Idir Append directory dir to the list of directories searched for include files.
-llibrary Use the library named library when linking. (C++ programs often require `-lg++' for successful linking.)
-O Optimize. Optimizing compilation takes somewhat more time, and a lot more memory for a large function.
Without `-O', the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results. Statements are independent: if you stop the program with a breakpoint between statements, you can then assign a new value to any variable or change the program counter to any other statement in the function and get exactly the results you would expect from the source code.
Without `-O', only variables declared register are allocated in registers. The resulting compiled code is a little worse than produced by PCC without `-O'.
With `-O', the compiler tries to reduce code size and execution time.
-o file Place output in file file.

CMake: migration guide/ cheat sheet for make users

I'm looking at replacing a configure/make style build process with CMake. CMake performs well on the complicated stuff, but it is more verbose on simple things.
For instance the GNU Make file:
hello:
echo "hello world" >$#
In CMake it would be:
add_custom_command(OUTPUT hello
COMMAND echo "hello world" > hello)
add_custom_target(all ALL DEPENDS hello)
See also Adding a custom command with the file name as a target.
Which is actually more like:
hello:
echo "hello world" >hello
all: hello
With more complex builds the absence of automatic variables is very noticeable.
After much routing around (it seems to be hard to search for $#) I found:
Automatic variables in CMake
Which suggests using wrapper functions and
Path to target output file
which suggests using generator expressions that are close to automatic variables,
but not close enough.
I have several related questions:
1a) Has CMake itself or best practice for doing this moved on since that question was asked?
1b) Is it likely CMake will ever provide an equivalent to automatic variables?
If not, why not?
Individual problems are quite well covered on Stack Overflow and elsewhere on the Internet, but:
2a) Are there any good guides or cheat sheets to help with migrating from using GNU make directly.
2b) Are they any good best practice guides for CMake?
That is beyond the suggestions in Makefile equivalent in CMake. I am gradually evolving my own style, but I would like to avoid horseless carriage type mistakes and needless complexity.
This is hard to answer, because CMake is not equivalent to make. It's much easier to compare CMake to autotools, for example, because it is a build system generator rather than a build system by itself.
Regardless, let's try to provide some answers.
1a+b) No, because it is not in the scope and philosophy of CMake to provide such constructs.
CMake's syntax is usually more on the side of verbosity, with explicit variable names such as ${CMAKE_CURRENT_SOURCE_DIR} as well as named command parameters. It looks more like a "classical" imperative programming language rather than a specialized textual description of a dependency graph which Makefiles are.
Also, CMake's output can be Makefiles or pretty much anything else, so a certain level of abstraction is needed.
The best practice in your case would be to use macros:
macro(build_echo_foo ${target})
add_custom_command(OUTPUT ${target}
COMMAND echo "hello world" > ${target})
add_custom_target(${target}_target ALL DEPENDS ${target})
endmacro()
build_echo_foo(hello)
build_echo_foo(another_hello)
Where Makefiles encourage the author to be as generic as possible, to minimize typing, CMake tries to make things as unambiguous as possible, for example by encouraging the maintainer to explicitly list source files instead of providing wildcards.
2a+b) Answering this is not exactly in the scope of Stack Overflow, but I'll say this.
The best source of inspiration is open-source projects using this system. As of 2014, there are a good number of high-profile projects that have migrated to CMake. You can even study CMake's own source code, which uses itself as build system.

Automated input generator for black-box testing

I am a newbie for software testing. I want to know, is there any open source tool for automated test case generator black-box testing.
I found this tool KLEE: unassisted and automatic generation of high-coverage tests for complex systems programs, but to use this tool I need to do some code instrumentation. Is there any way I can generate automated testcases without code instrumentation as I don't have access to the source code.
KLEE does work with programs without modification. You can have it generate symbolic command line inputs as well as symbolic input files. Here are some example commands that can be used for this purpose:
-sym-arg - Replace by a symbolic argument with length N
-sym-args - Replace by at least MIN arguments and at most
MAX arguments, each with maximum length N
-sym-files - Make stdin and up to NUM symbolic files, each
with maximum size N.
-sym-stdout - Make stdout symbolic.
Examples can be found in the tutorials on KLEE's website.

Are all scripts written in scripting languages?

I'm confused by the concept of scripts.
Can I say that makefile is a kind of script?
Are there scripts written in C or Java?
I'd refer to Wikipedia for a detailed explanation.
"Scripts" usually refer to a piece of code or set of instructions that run in the context of another program. They usually aren't a standalone executable piece of software.
Makefiles are a script that is run by "make", or MSBuild, etc.
C needs to be compiled into an executable or a library, so programs written in (standard) C would typically not be considered scripts. (There are exceptions, but this isn't the normal way of working with C.)
Java (and especially .net) is a bit different. A typical java program is compiled and run as an executable, but this is a grey area. It is possible to do runtime compilation of a "script" written in java and execute it.
In a very general sense the term "Scripts" relates to code that is deployed and expected to run from the lexical representation. As soon as you compile the code and distribute the resulting output instead of the code it ceases to be a "Script".
Minification and obsfication of a script is not consided a compile and the result is still consider a script.
It depends on your definition of script. For me, a script could be any small program you write for a small purpose. They are usually written in interpreted languages. However, there's nothing stopping you from writing a small program in a compiled language.
For me a script has to consist of a single file. And that file must be able to perform the task for which the script was written with no intermediate steps.
So these would be OK:
bash backup_my_home_dir.sh
perl munge_some_text.pl
python download_url.py
But this wouldn't qualify, even if the file is small:
javac HandyUtility.java
java HandyUtility
Yes it's possible to do scripting in Java. I've seen it many times :)
(this was sarcasm for bad spaghetti code)
The term 'scripting' can cover a fairly broad spectrum of activities. Examples being programming in imperative interpreted languages such as VBScript, Python, or shell scripts such as csh or bash, or expressing a task in declaritive languages such as XSL, SQL or Erlang.
Some scripting languages fall into a category referred to as Domain Specific Languages (DSL's). Good examples of DSL's are 'makefile's, many other types of configuration files, SQL, XSL and so on.
What you're asking is fairly subjective, one man's script is another man's application. If your interpretation of scripting means that using scripting languages should not force a user to follow the traditional compile -> link -> run cycle, then you could form the opinion that you can't write 'scripts' in C or Java.
A script is basically a non-compilable text file in almost any language, or shell, with an interpreter that is used to automate some process, or list of commands, that you perform repeatedly. Scripts are often used for backing up files, compiling routines, svn commits, shell initialization, etc., ad infinitum. There are a million and one things you can do with a script that an executable (complete with installation, etc.) would simply be overkill for.
I write scripts in F#. A recent one is a small data loader to take in some set of data, do a bit of processing to it, and dump it in a DB. ~40 lines. No separate compilation step needed; I can just make F# Interactive run it directly.
Benefit is that I get a fully powered language with a great IDE and all the safety static checking provides, while inference makes it not get verbose like say, Java or C#.
So, that's one language that offers a reasonably decent type system, compilation and checking, isn't interpreteded, but works fine for scripting.