Code Monkey home page Code Monkey logo

istyle-verilog-formatter's Introduction

iStyle v1

Fast and Free Automatic Formatter for Verilog Source Code

    Created by haimag
    Thanks to Tal Davidson & Astyle
    Report bugs https://github.com/thomasrussellmurphy/istyle-verilog-formatter/issues

Originally hosted at http://code.google.com/p/istyle-verilog-formatter before Google Code EOL

Usage:
    iStyle [options] Foo.v  B*r.v  [...]
    OR, use stdin/stdout
    iStyle [options] <Foo.v >Foo_formatted.v

When indenting a specific file, the resulting indented file RETAINS the
original file-name. The original pre-indented file is renamed, with a
suffix of ".orig" added to the original filename.

By default, iStyle is set up to indent Verilog files, with 4 spaces per
indent, a maximal indentation of 40 spaces inside continuous statements,
and NO formatting.

Option's Format:


    Long options (starting with '--') must be written one at a time.
    Short options (starting with '-') may be appended together.
    Thus, -bps4 is the same as -b -p -s4.

Predefined Styling options:


    --style=ansi
    ANSI style formatting/indenting.

    --style=kr
    Kernighan&Ritchie style formatting/indenting.

    --style=gnu
    GNU style formatting/indenting.

Indentation options:


    -s   OR   -s#   OR   --indent=spaces=#
    Indent using # spaces per indent. Not specifying #
    will result in a default of 4 spaces per indent.

    -t   OR   -t#   OR   --indent=tab=#
    Indent using tab characters, assuming that each
    tab is # spaces long. Not specifying # will result
    in a default assumption of 4 spaces per tab.

    -T#   OR   --force-indent=tab=#
    Indent using tab characters, assuming that each
    tab is # spaces long. Force tabs to be used in areas
    iStyle would prefer to use spaces.

    -B   OR   --indent-brackets
    Add extra indentation to 'begin' and 'end' block brackets.

    -G   OR   --indent-blocks
    Add extra indentation entire blocks (including brackets).

    -m#  OR  --min-conditional-indent=#
    Indent a minimal # spaces in a continuous conditional
    belonging to a conditional header.

    -M#  OR  --max-instatement-indent=#
    Indent a maximal # spaces in a continuous statement,
    relatively to the previous line.

    -E  OR  --fill-empty-lines
    Fill empty lines with the white space of their
    previous lines.

    --indent-preprocessor
    Indent multi-line #define statements

Formatting options:


    -b  OR  --brackets=break
    Break brackets from pre-block code (i.e. ANSI C/C++ style).

    -a  OR  --brackets=attach
    Attach brackets to pre-block code (i.e. Java/K&R style).

    -o   OR  --one-line=keep-statements
    Don't break lines containing multiple statements into
    multiple single-statement lines.

    -O   OR  --one-line=keep-blocks
    Don't break blocks residing completely on one line

    -p   OR  --pad=oper
    Insert space paddings around operators only.

    --pad=paren
    Insert space paddings around parenthesies only.
    -l OR --pad=block
    Enclose one statement in a begin-end only for keyword if/else/while/for.

    -P   OR  --pad=all
    Insert space paddings around operators AND parenthesies.

    --convert-tabs
    Convert tabs to spaces.

    --break-blocks
    Insert empty lines around unrelated blocks, labels, ...

    --break-blocks=all
    Like --break-blocks, except also insert empty lines
    around closing headers (e.g. 'else', ...).

    --break-elseifs
    Break 'else if()' statements into two different lines.

Other options:


    --suffix=####
    Append the suffix #### instead of '.orig' to original filename.

    -n   OR  --suffix=none
    Tells Astyle not to keep backups of the original source files.
    WARNING: Use this option with care, as Astyle comes with NO WARRANTY...

    -X   OR  --errors-to-standard-output
    Print errors and help information to standard-output rather than
    to standard-error.

    -v   OR   --version
    Print version number

    -h   OR   -?   OR   --help
    Print this help message

    --options=####  OR --options=none
    Parse used the specified options file: ####, options=none, none
    parse options file, and not looks for parse options files

Default options file:


    iStyle looks for a default options file in the following order:
    1. The contents of the ISTYLE_OPTIONS environment
       variable if it exists.
    2. The file called .iStylerc in the directory pointed to by the
       HOME environment variable ( i.e. $HOME/.iStylerc ).
    3. The file called .iStylerc in the directory pointed to by the
       HOMEPATH environment variable ( i.e. %HOMEPATH%\.iStylerc ).
    If a default options file is found, the options in this file
    will be parsed BEFORE the command-line options.
    Options within the default option file may be written without
    the preliminary '-' or '--'.

istyle-verilog-formatter's People

Contributors

daniellimws avatar googlecodeexporter avatar lassik avatar mikewalrus avatar rpgp1 avatar thomasrussellmurphy avatar wisherhxl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

istyle-verilog-formatter's Issues

body of modules is not indented

Is there a way to force iStyle to indent the body of modules rather than putting it in column zero?

Example:

module picosoc_mem #(
  parameter integer WORDS = 256
) (
  input clk,
  input [3:0] wen,
  input [21:0] addr,
  input [31:0] wdata,
  output reg [31:0] rdata
);
  reg [31:0] mem [0:WORDS-1];

  always @(posedge clk) begin
    rdata <= mem[addr];
    if (wen[0]) mem[addr][ 7: 0] <= wdata[ 7: 0];
    if (wen[1]) mem[addr][15: 8] <= wdata[15: 8];
    if (wen[2]) mem[addr][23:16] <= wdata[23:16];
    if (wen[3]) mem[addr][31:24] <= wdata[31:24];
  end
endmodule

Formatter does not handle comments in method declaration properly

What steps will reproduce the problem?
1. run `iStyle --indent=tab --style=kr --suffix=".old~" --pad=all DE0_TOP.v`
2. Examine comments in module declaration
3. Find that they are changed

What is the expected output? What do you see instead?
The expected output is no change in the file as it has already been formatted. 
However, in the module declaration, the text like `CLOCK_50, // 50 MHz` becomes 
`CLOCK_50,  // 50 MHz`. That is, there is a space added between the comma and 
the comment.

What version of the product are you using? On what operating system?
iStyle 1.20 on MacOS 10.9.2

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 11 Apr 2014 at 1:49

Attachments:

`--brackets=attach` breaks the code

original file:

module a(
        input b
    );
    always @(*) begin      
        if (b)                            
        begin
        end
        else
        begin
        end
    end
endmodule

after formatting using -a

module a(
        input b
    );
    always @(*) begin
        if (b)begin
        end
        elsebegin
        end
    end
    endmodule

expected

module a(
        input b
    );
    always @(*) begin
        if (b) begin
        end
        else begin
        end
    end
endmodule

This might have something to do with #20 and the member function ASFormatter::appendSpacePad().
When there is no character to peek (i.e.: at the end of the line), appendSpacePad refuses to append a space, which causes the content of the next line to "attach" to the current line without a space in between.

To fix this, the implementation of the newer AStyle might be helpful. They have two separate methods to append a space.

/**
 * append a space to the current formattedline, UNLESS the
 * last character is already a white-space character.
 */
void ASFormatter::appendSpacePad()
{
	int len = formattedLine.length();
	if (len > 0 && !isWhiteSpace(formattedLine[len - 1]))
	{
		formattedLine.append(1, ' ');
		spacePadNum++;
		if (maxCodeLength != string::npos)
		{
			// These compares reduce the frequency of function calls.
			if (isOkToSplitFormattedLine())
				updateFormattedLineSplitPoints(' ');
			if (formattedLine.length() > maxCodeLength)
				testForTimeToSplitFormattedLine();
		}
	}
}

/**
 * append a space to the current formattedline, UNLESS the
 * next character is already a white-space character.
 */
void ASFormatter::appendSpaceAfter()
{
	int len = currentLine.length();
	if (charNum + 1 < len && !isWhiteSpace(currentLine[charNum + 1]))
	{
		formattedLine.append(1, ' ');
		spacePadNum++;
		if (maxCodeLength != string::npos)
		{
			// These compares reduce the frequency of function calls.
			if (isOkToSplitFormattedLine())
				updateFormattedLineSplitPoints(' ');
			if (formattedLine.length() > maxCodeLength)
				testForTimeToSplitFormattedLine();
		}
	}
}

the following line after `protect should not be indented

The test is

    module test (); 
    
    `protect
    
    assign a = b;
    assign a = b;
    
    `endprotect
    // pragma protect end
    endmodule

the output of iStyle test.sv is

module test ();

`protect

    assign a = b;
assign a = b;

`endprotect
    // pragma protect end
    endmodule

Formatting any Verilog file gives "Assertion '__pos <= size()' failed"

Hello,
I am using Fedora 29 and running the utility on any Verilog file gives the following output:

iStyle 1.21 (Fast and Free Automatic Formatter for Verilog Source Code)
               (Created by haimag, Report Bugs: [email protected])
               (Thanks to Tal Davidson & Astyle)

/builddir/build/BUILD/gcc-8.2.1-20181215/obj-x86_64-redhat-linux/x86_64-redhat-linux/libstdc++-v3/include/bits/basic_string.h:1067: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference = char&; std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::size_type = long unsigned int]: Assertion '__pos <= size()' failed.                
zsh: abort (core dumped)  iStyle nzfe_tb.v

The .orig file is created, but the file to be formatted is truncated down to only a couple of lines.

import function

expected

module mem;

  import "DPI-C" function string get_env(input string name);

endmodule

got

module mem;

  import "DPI-C" function string get_env(input string name);

         endmodule

the weird indentation after line import "DPI-C" function string get_env(input string name);

Formatter does not handle exponentiation (**) operator

What steps will reproduce the problem?
1. Run 'iStyle --indent=tab --style=kr --suffix=".old~" --pad=all file.v`
2. Have 'file.v' include the exponentiation operator (parameter test = 2 ** 5 - 
1)
3. Observe that '**' becomes '* *', breaking the code

What is the expected output? What do you see instead?
No change to '**' is expected. However, it is changed to '* *'.

What version of the product are you using? On what operating system?
iStyle 1.20 on MacOS 10.9.2

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 11 Apr 2014 at 1:52

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.