Skip to content

pezy-computing/flgen

Repository files navigation

Gem Version CI codecov

FLGen

FLGen provides a DSL to write filelists and generator tool to generate a filelist which is given to EDA tools.

Install

Ruby

FLGen is written in Ruby programing language and its required version is 3.0 or later. You need to install Ruby before using FLGen. See this page for further details.

Install FLGen

Use the command below to isntall FLGen.

$ gem install flgen

Filelist

FLGen prives APIs listed below to describe your filelists.

  • source_file(path, from: nil)
    • Add the given source file to the current filelist.
  • file_list(path, from: nil)
    • Load the given filelist.
  • library_file(path, from: nil)
    • Add the given file to the list of library files.
  • include_directory(path, from: nil)
    • Add the given directory to the list of include direcotries.
  • library_directory(path, from: nil)
    • Add the given directory to the list of library directories.
  • find_files(patterns, from: nil)
    • Return an array of filenames matching the given patterns strings.
    • See here for the format of a pattern string.
  • find_file(patterns, from: nil)
    • Return the first filename matching the given pattern strings.
  • file?(path, from: :current)
    • Return true if the given file exists.
  • directory?(path, from: :current)
    • Return true if the given directory exists.
  • define_macro(name, value = nil)
    • Define a text macro.
  • undefine_macro(name)
    • Undefine the given macro.
  • macro?(name)/macro_defined?(name)
    • Return true if the given macro is defined.
  • macro(name)
    • Return the value of the given macro.
  • env?(name)
    • Return true if the givne environment variable is defined.
  • env(name)
    • Retunr the value of the given environment variable.
  • compile_argument(argument, tool: nil)
    • Add the given argument to the list of compile arguments.
    • If tool is specified the given argument is added only when tool is matched with the targe tool.
  • runtime_argumetn(argument, tool: nil)
    • Add the given argument to the list of runtime arguments.
    • If tool is specified the given argument is added only when tool is matched with the targe tool.
  • target_tool?(tool)
    • Return true if the given tool is matched with the targe tool.
  • default_search_path(**search_paths)
    • Change the default behavior when the from argument is not specified.
  • reset_default_search_path(*target_types)
    • Reset the default behavior when the from argument is not specified.

FLGen's filelist is designed as an inernal DSL with Ruby. Therefore you can use Ruby's syntax. For example:

if macro? :GATE_SIM
  source_file 'foo_top.v.gz' # synthsized netlist
else
  source_file 'foo_top.sv' # RTL
end

About the from argument

The from argument is to specify how to search the given file or directory. You can specify one of three below.

  • a directory path
    • Search the given file or directory from the directory path specified by the from argument.
  • :cwd
    • Search the given file or directory from the current working directory.
  • :current
    • Search the given file or directory from the directory where the current filelist is.
  • :root
    • Search the given file or directory from the repository root directories where the .git directory is.
    • Serch order is descending order.
      • from upper root direcotries to local root direcoty
  • :local_root
    • Search the given file or directory from the repository root directory where the current filelist belongs to.

Default behaviors when the from argument is not spcified are listed below:

API name Default from argument
source_file :current
file_list :root
library_file :current
include_directory :current
library_directory :current
find_files :current
find_file :current

You can change the above default behaviors by using the default_search_path API. In addition, you can reset the default behaviors by using the reset_default_search_path API.

default_search_path source_file: :root, file_list: :current
source_file 'foo.sv'    # FLGen will search the 'foo.sv' file from the root directories.
file_list 'bar.list.rb' # FLGen will eaarch the 'bar.list.rb' file from the directory where this file list is.

reset_default_search_path :source_file, :file_list
source_file 'baz.sv'    # FLGen will search the 'baz.sv' file from the directory where this file list is.
file_list 'qux.list.rb' # FLGen will eaarch the 'qux.list.rb' file from  the root directories.

Example

This is an exmaple directory structure.

foo_project
+-- .git
+-- bar_project
|   +-- .git
|   +-- common
|   |   `-- common.sv
|   `-- src
|       + bar.list.rb
|       ` bar.sv
`-- common
    `-- common.sv
  • source_file 'bar.sv', from: :current @ bar.list.rb
    • foo_project/bar_project/bar.sv is added.
  • source_file 'common/common.sv', from: :root @ bar.list.rb
    • foo_project/common/common.sv is added
  • source_file 'common/bar_common