Source code for symforce.codegen.backends.slang.slang_config
# ----------------------------------------------------------------------------
# SymForce - Copyright 2022, Skydio, Inc.
# This source code is under the Apache 2.0 license found in the LICENSE file.
# ----------------------------------------------------------------------------
from dataclasses import dataclass
from dataclasses import field
from pathlib import Path
import sympy
from sympy.printing.codeprinter import CodePrinter
from symforce import typing as T
from symforce.codegen.backends.slang import slang_code_printer
from symforce.codegen.codegen_config import CodegenConfig
CURRENT_DIR = Path(__file__).parent
[docs]
@dataclass
class SlangConfig(CodegenConfig):
"""
Code generation config for the Slang backend.
Args:
doc_comment_line_prefix: Prefix applied to each line in a docstring
line_length: Maximum allowed line length in docstrings; used for formatting docstrings.
use_eigen_types: Use eigen_lcm types for vectors instead of lists (not supported in Slang)
override_methods: Add special function overrides in dictionary with symforce function keys
builtin_vector_variables: Names of inputs and outputs that should use Slang's built-in
vector types (float2/float3/float4) instead of fixed-size arrays
"""
doc_comment_line_prefix: str = " * "
line_length: int = 100
use_eigen_types: bool = False
override_methods: T.Optional[T.Dict[sympy.Function, str]] = None
builtin_vector_variables: T.Set[str] = field(default_factory=set)
[docs]
@classmethod
def backend_name(cls) -> str:
return "slang"
[docs]
@classmethod
def template_dir(cls) -> Path:
return CURRENT_DIR / "templates"
[docs]
@staticmethod
def templates_to_render(generated_file_name: str) -> T.List[T.Tuple[str, str]]:
return [("function/FUNCTION.slang.jinja", f"{generated_file_name}.slang")]
[docs]
def printer(self) -> CodePrinter:
return slang_code_printer.SlangCodePrinter(override_methods=self.override_methods)