Builder

Builder interface, nodes, and passes.

Overview

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

Classes

Enumerations

Enumeration Type Documentation

NodeType : uint8_tenumstrong

Type of node used by BaseBuilder and BaseCompiler.

ConstantDescription
kNone 

Invalid node (internal, don't use).

kInst 

Node is InstNode or InstExNode.

kSection 

Node is SectionNode.

kLabel 

Node is LabelNode.

kAlign 

Node is AlignNode.

kEmbedData 

Node is EmbedDataNode.

kEmbedLabel 

Node is EmbedLabelNode.

kEmbedLabelDelta 

Node is EmbedLabelDeltaNode.

kConstPool 

Node is ConstPoolNode.

kComment 

Node is CommentNode.

kSentinel 

Node is SentinelNode.

kJump 

Node is JumpNode (acts as InstNode).

kFunc 

Node is FuncNode (acts as LabelNode).

kFuncRet 

Node is FuncRetNode (acts as InstNode).

kInvoke 

Node is InvokeNode (acts as InstNode).

kUser 

First id of a user-defined node.

NodeFlags : uint8_tenumstrong

Node flags, specify what the node is and/or does.

ConstantDescription
kNone 

No flags.

kIsCode 

Node is code that can be executed (instruction, label, align, etc...).

kIsData 

Node is data that cannot be executed (data, const-pool, etc...).

kIsInformative 

Node is informative, can be removed and ignored.

kIsRemovable 

Node can be safely removed if unreachable.

kHasNoEffect 

Node does nothing when executed (label, align, explicit nop).

kActsAsInst 

Node is an instruction or acts as it.

kActsAsLabel 

Node is a label or acts as it.

kIsActive 

Node is active (part of the code).

SentinelType : uint8_tenumstrong

Type of the sentinel (purery informative purpose).

ConstantDescription
kUnknown 

Type of the sentinel is not known.

kFuncEnd 

This is a sentinel used at the end of FuncNode.