visioncpp.codegen

visioncpp.codegen.clang_format(code, clang_format=None)[source]

Run clang-format over C++ code.

This function is safe to call, regardless of whether clang-format is present on the system. If clang-format is not found, the returned code is the same as the input.

Arguments:
code (str): C++ code. clang_format (str, optional): Path to clang-format.
Returns:
str: Formatted C++ code.
visioncpp.codegen.find_clang_format()[source]

Find clang-format binary.

Returns:
str: Path to clang-format if found, else None.
visioncpp.codegen.generate(expression, devtype, use_clang_format=True)[source]

Generate C++ code for an expression tree.

Arguments:
expression (VisionCpp.Operation): Root of the expression tree. devtype (str, optional): Execution device type.
Returns:
str: C++ code.
visioncpp.codegen.get_device(devtype='cpu', name='device')[source]

Return the lines to construct a VisionCPP device.

Arguments:
devtype (str, optional): Either “gpu” or “cpu”. name (str, optional): Name of the constructed device variable.
Returns:
str[]: C++ lines.
Raises:
VisionCppException: If device type is neither “cpu” or “gpu”.
visioncpp.codegen.library_source(lines)[source]

Return source code for a VisionCpp library.

The generated code will compile a callable library method “natvie_expression_tree()”.

Arguments:
lines (str[]): Program implementation.
Returns:
str: Source code
visioncpp.codegen.process_expression(root)[source]

Process an expression tree into a linear sequence of nodes.

TODO: Refactor the node name assignment into node construction.

Arguments:
root (VisionCpp.Operation): Expression tree.
Returns:
VisionCpp.Operation []: Serialized expression tree.