Unifex v0.2.3 Unifex.NativeCodeGenerator View Source

Module responsible for C code genearation based on Unifex specs

Link to this section Summary

Functions

Helper for generating code. Uses sigil_g/2 underneath

Generates C boilerplate for a native code based on a spec

Sigil used for indentation of generated code

Link to this section Types

Link to this section Functions

Helper for generating code. Uses sigil_g/2 underneath.

It supports all the flags supported by sigil_g/2 and the following ones:

  • j(joiner) - joins list of strings using joiner
  • n - alias for j(\n)

If passed a list and flags supported by sigil_g/2, each flag will be executed on each element of the list, until the list is joined by using j or n flag.

Link to this function

generate_code(name, specs) View Source
generate_code(name :: String.t(), specs :: Unifex.SpecsParser.parsed_specs_t()) ::
  {code_t(), code_t()}

Generates C boilerplate for a native code based on a spec

Takes the name for the .c and .h files and the specs parsed by Unifex.SpecsParser.parse_specs()/1 and generates code of header and source code, returning them in a tuple of 2 strings.

Link to this function

sigil_g(content, arg2) View Source
sigil_g(String.t(), charlist()) :: String.t()

Sigil used for indentation of generated code.

By itself it does nothing, but has very useful flags:

  • r trims trailing whitespaces of each line and removes subsequent empty lines
  • t trims the string
  • i indents all but the first line. Helpful when used inside string interpolation that already has been indented
  • I indents every line of string