Package icyllis.arc3d.compiler

# Class CodeGenerator

java.lang.Object
icyllis.arc3d.compiler.CodeGenerator

Direct Known Subclasses:
  `GLSLCodeGenerator`, `SPIRVCodeGenerator`

public abstract class CodeGenerator extends Object
Abstract superclass of all code generators, which take a `TranslationUnit` as input and produce code as output.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final ShaderCompiler`
  `mCompiler`
  `protected final TranslationUnit`
  `mTranslationUnit`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CodeGenerator(ShaderCompiler compiler, TranslationUnit translationUnit)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `abstract ByteBuffer`
  `generateCode()`
  Generates the code and returns the pointer value.
  `protected Context`
  `getContext()`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### mCompiler

    protected final ShaderCompiler mCompiler

  - ### mTranslationUnit

    protected final TranslationUnit mTranslationUnit

- ## Constructor Details

  - ### CodeGenerator

    public CodeGenerator(ShaderCompiler compiler, TranslationUnit translationUnit)

- ## Method Details

  - ### generateCode

    @Nullable public abstract ByteBuffer generateCode()
    Generates the code and returns the pointer value. The code size in bytes is `Buffer.remaining()`. Check errors via `Context.getErrorHandler()`.

    The return value is a direct buffer, see `ByteBuffer.allocateDirect(int)`. A direct buffer wraps an address that points to off-heap memory, i.e. a native pointer. The byte order is `ByteOrder.nativeOrder()` and it's safe to pass the result to OpenGL and Vulkan API. There is no way to free this buffer explicitly, as it is subject to GC.

    Returns:
      the generated code, or null if there's an error

  - ### getContext

    protected Context getContext()