Builder interface, nodes, and passes.


Both BaseBuilder and BaseCompiler interfaces describe emitters that emit into a representation that allows further processing. The code stored in such representation is completely safe to be patched, simplified, reordered, obfuscated, removed, injected, analyzed, or processed some other way. Each instruction, label, directive, or other building block is stored as BaseNode (or derived class like InstNode or LabelNode) and contains all the information necessary to pass that node later to the assembler.

BaseBuilder is an emitter that inherits from BaseEmitter interface. It was designed to provide a maximum compatibility with the existing BaseAssembler emitter so users can move from assembler to builder when needed, for example to implement post-processing, which is not possible with Assembler.

Builder Nodes

BaseBuilder doesn't generate machine code directly, it uses an intermediate representation based on nodes, however, it allows to serialize to BaseAssembler when the code is ready to be encoded.

There are multiple node types used by both BaseBuilder and BaseCompiler :

  • Basic nodes:
    • BaseNode - Base class for all nodes.
    • InstNode - Represents an instruction node.
    • AlignNode - Represents an alignment directive (.align).
    • LabelNode - Represents a location where to bound a Label.
  • Data nodes:
  • Informative nodes:
    • CommentNode - Represents a comment string, doesn't affect code generation.
    • SentinelNode - A marker that can be used to remember certain position in code or data, doesn't affect code generation. Used by FuncNode to mark the end of a function.
  • Other nodes are provided by Compiler infrastructure.

Builder Examples