Package ghidra.app.plugin.assembler.sleigh

# Class AbstractSleighAssembler<RP extends AssemblyResolvedPatterns>

java.lang.Object
ghidra.app.plugin.assembler.sleigh.AbstractSleighAssembler<RP>

All Implemented Interfaces:
  `GenericAssembler<RP>`

Direct Known Subclasses:
  `SleighAssembler`

public abstract class AbstractSleighAssembler<RP extends AssemblyResolvedPatterns> extends Object implements GenericAssembler<RP>

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `protected class`
  `AbstractSleighAssembler.ListenerForSymbolsRefresh`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final AssemblyContextGraph`
  `ctxGraph`
  `protected final AssemblyDefaultContext`
  `defaultContext`
  `protected final AbstractAssemblyResolutionFactory<RP,?>`
  `factory`
  `protected final SleighLanguage`
  `lang`
  `protected final Listing`
  `listing`
  `protected final Object`
  `lock`
  `protected final Memory`
  `memory`
  `protected final AssemblyParser`
  `parser`
  `protected final Program`
  `program`
  `protected final AssemblySelector`
  `selector`
  `protected AssemblyNumericSymbols`
  `symbols`

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `AbstractSleighAssembler(AbstractAssemblyResolutionFactory<RP,?> factory, AssemblySelector selector, SleighLanguage lang, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)`
  `protected`
  `AbstractSleighAssembler(AbstractAssemblyResolutionFactory<RP,?> factory, AssemblySelector selector, Program program, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `InstructionIterator`
  `assemble(Address at, String... assembly)`
  Assemble a sequence of instructions and place them at the given address.
  `byte[]`
  `assembleLine(Address at, String line)`
  Assemble a line instruction at the given address.
  `byte[]`
  `assembleLine(Address at, String line, AssemblyPatternBlock ctx)`
  Assemble a line instruction at the given address, assuming the given context.
  `AssemblyPatternBlock`
  `getContextAt(Address addr)`
  Get the context at a given address
  `SleighLanguage`
  `getLanguage()`
  Get the language of this assembler
  `protected AssemblyNumericSymbols`
  `getNumericSymbols()`
  A convenience to obtain assembly symbols
  `Program`
  `getProgram()`
  If the assembler is bound to a program, get that program
  `protected abstract AbstractAssemblyTreeResolver<RP>`
  `newResolver(Address at, AssemblyParseBranch tree, AssemblyPatternBlock ctx)`
  `Collection<AssemblyParseResult>`
  `parseLine(String line)`
  Parse a line instruction.
  `InstructionIterator`
  `patchProgram(byte[] insbytes, Address at)`
  Place instruction bytes into the bound program.
  `Instruction`
  `patchProgram(AssemblyResolvedPatterns res, Address at)`
  Place a resolved (and fully-masked) instruction into the bound program.
  `AssemblyResolutionResults`
  `resolveLine(Address at, String line)`
  Assemble a line instruction at the given address.
  `AssemblyResolutionResults`
  `resolveLine(Address at, String line, AssemblyPatternBlock ctx)`
  Assemble a line instruction at the given address, assuming the given context.
  `AssemblyResolutionResults`
  `resolveTree(AssemblyParseResult parse, Address at)`
  Resolve a given parse tree at the given address.
  `AssemblyResolutionResults`
  `resolveTree(AssemblyParseResult parse, Address at, AssemblyPatternBlock ctx)`
  Resolve a given parse tree at the given address, assuming the given context

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

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

- ## Field Details

  - ### lock

    protected final Object lock

  - ### lang

    protected final SleighLanguage lang

  - ### program

    protected final Program program

  - ### listing

    protected final Listing listing

  - ### memory

    protected final Memory memory

  - ### factory

    protected final AbstractAssemblyResolutionFactory<RP extends AssemblyResolvedPatterns,?> factory

  - ### selector

    protected final AssemblySelector selector

  - ### parser

    protected final AssemblyParser parser

  - ### defaultContext

    protected final AssemblyDefaultContext defaultContext

  - ### ctxGraph

    protected final AssemblyContextGraph ctxGraph

  - ### symbols

    protected AssemblyNumericSymbols symbols

- ## Constructor Details

  - ### AbstractSleighAssembler

    protected AbstractSleighAssembler(AbstractAssemblyResolutionFactory<RP,?> factory, AssemblySelector selector, Program program, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)

  - ### AbstractSleighAssembler

    protected AbstractSleighAssembler(AbstractAssemblyResolutionFactory<RP,?> factory, AssemblySelector selector, SleighLanguage lang, AssemblyParser parser, AssemblyDefaultContext defaultContext, AssemblyContextGraph ctxGraph)

- ## Method Details

  - ### newResolver

    protected abstract AbstractAssemblyTreeResolver<RP> newResolver(Address at, AssemblyParseBranch tree, AssemblyPatternBlock ctx)

  - ### getLanguage

    public SleighLanguage getLanguage()
    Description copied from interface: `GenericAssembler`
    Get the language of this assembler
    Specified by:
      `getLanguage` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Returns:
      the processor language

  - ### getProgram

    public Program getProgram()
    Description copied from interface: `GenericAssembler`
    If the assembler is bound to a program, get that program
    Specified by:
      `getProgram` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Returns:
      the program, or null

  - ### patchProgram

    public Instruction patchProgram(AssemblyResolvedPatterns res, Address at) throws MemoryAccessException
    Description copied from interface: `GenericAssembler`
    Place a resolved (and fully-masked) instruction into the bound program.

    This method is not valid without a program binding. Also, this method must be called during a program database transaction.

    Specified by:
      `patchProgram` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `res` - the resolved and fully-masked instruction
      `at` - the location of the start of the instruction
    Returns:
      the new `Instruction` code unit
    Throws:
      `MemoryAccessException` - there is an issue writing the result to program memory

  - ### patchProgram

    public InstructionIterator patchProgram(byte[] insbytes, Address at) throws MemoryAccessException
    Description copied from interface: `GenericAssembler`
    Place instruction bytes into the bound program.

    This method is not valid without a program binding. Also, this method must be called during a program database transaction.

    Specified by:
      `patchProgram` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `insbytes` - the instruction data
      `at` - the location of the start of the instruction
    Returns:
      an iterator over the disassembled instructions
    Throws:
      `MemoryAccessException` - there is an issue writing the result to program memory

  - ### assemble

    public InstructionIterator assemble(Address at, String... assembly) throws AssemblySyntaxException, AssemblySemanticException, MemoryAccessException, AddressOverflowException
    Description copied from interface: `GenericAssembler`
    Assemble a sequence of instructions and place them at the given address.

    This method is only valid if the assembler is bound to a program. An instance may optionally implement this method without a program binding. In that case, the returned iterator will refer to pseudo instructions.

    NOTE: There must be an active transaction on the bound program for this method to succeed.

    Specified by:
      `assemble` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `at` - the location where the resulting instructions should be placed
      `assembly` - a new-line separated or array sequence of instructions
    Returns:
      an iterator over the resulting instructions
    Throws:
      `AssemblySyntaxException` - a textual instruction is non well-formed
      `AssemblySemanticException` - a well-formed instruction cannot be assembled
      `MemoryAccessException` - there is an issue writing the result to program memory
      `AddressOverflowException` - the resulting block is beyond the valid address range

  - ### assembleLine

    public byte[] assembleLine(Address at, String line) throws AssemblySyntaxException, AssemblySemanticException
    Description copied from interface: `GenericAssembler`
    Assemble a line instruction at the given address.

    This method is valid with or without a bound program. Even if bound, the program is not modified; however, the appropriate context information is taken from the bound program. Without a program, the language's default context is taken at the given location.

    Specified by:
      `assembleLine` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `at` - the location of the start of the instruction
      `line` - the textual assembly code
    Returns:
      the binary machine code, suitable for placement at the given address
    Throws:
      `AssemblySyntaxException` - the textual instruction is not well-formed
      `AssemblySemanticException` - the well-formed instruction cannot be assembled

  - ### parseLine

    public Collection<AssemblyParseResult> parseLine(String line)
    Description copied from interface: `GenericAssembler`
    Parse a line instruction.

    Generally, you should just use `GenericAssembler.assembleLine(Address, String)`, but if you'd like access to the parse trees outside of an `AssemblySelector`, then this may be an acceptable option. Most notably, this is an excellent way to obtain suggestions for auto-completion.

    Each item in the returned collection is either a complete parse tree, or a syntax error Because all parse paths are attempted, it's possible to get many mixed results. For example, The input line may be a valid instruction; however, there may be suggestions to continue the line toward another valid instruction.

    Specified by:
      `parseLine` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `line` - the line (or partial line) to parse
    Returns:
      the results of parsing

  - ### resolveTree

    public AssemblyResolutionResults resolveTree(AssemblyParseResult parse, Address at, AssemblyPatternBlock ctx)
    Description copied from interface: `GenericAssembler`
    Resolve a given parse tree at the given address, assuming the given context

    Each item in the returned collection is either a completely resolved instruction, or a semantic error. Because all resolutions are attempted, it's possible to get many mixed results.

    NOTE: The resolved instructions are given as masks and values. Where the mask does not cover, you can choose any value.

    Specified by:
      `resolveTree` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `parse` - a parse result giving a valid tree
      `at` - the location of the start of the instruction
      `ctx` - the context register value at the start of the instruction
    Returns:
      the results of semantic resolution

  - ### resolveTree

    public AssemblyResolutionResults resolveTree(AssemblyParseResult parse, Address at)
    Description copied from interface: `GenericAssembler`
    Resolve a given parse tree at the given address.

    Each item in the returned collection is either a completely resolved instruction, or a semantic error. Because all resolutions are attempted, it's possible to get many mixed results.

    NOTE: The resolved instructions are given as masks and values. Where the mask does not cover, you can choose any value.

    Specified by:
      `resolveTree` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `parse` - a parse result giving a valid tree
      `at` - the location of the start of the instruction
    Returns:
      the results of semantic resolution

  - ### resolveLine

    public AssemblyResolutionResults resolveLine(Address at, String line) throws AssemblySyntaxException
    Description copied from interface: `GenericAssembler`
    Assemble a line instruction at the given address.

    This method works like `GenericAssembler.resolveLine(Address, String, AssemblyPatternBlock)`, except that it derives the context using `GenericAssembler.getContextAt(Address)`.

    Specified by:
      `resolveLine` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `at` - the location of the start of the instruction
      `line` - the textual assembly code
    Returns:
      the collection of semantic resolution results
    Throws:
      `AssemblySyntaxException` - the textual instruction is not well-formed

  - ### resolveLine

    public AssemblyResolutionResults resolveLine(Address at, String line, AssemblyPatternBlock ctx) throws AssemblySyntaxException
    Description copied from interface: `GenericAssembler`
    Assemble a line instruction at the given address, assuming the given context.

    This method works like `GenericAssembler.assembleLine(Address, String, AssemblyPatternBlock)`, except that it returns all possible resolutions for the parse trees that pass the `AssemblySelector`.

    Specified by:
      `resolveLine` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `at` - the location of the start of the instruction
      `line` - the textual assembly code
      `ctx` - the context register value at the start of the instruction
    Returns:
      the collection of semantic resolution results
    Throws:
      `AssemblySyntaxException` - the textual instruction is not well-formed

  - ### assembleLine

    public byte[] assembleLine(Address at, String line, AssemblyPatternBlock ctx) throws AssemblySemanticException, AssemblySyntaxException
    Description copied from interface: `GenericAssembler`
    Assemble a line instruction at the given address, assuming the given context.

    This method works like `GenericAssembler.assembleLine(Address, String)` except that it allows you to override the assumed context at that location.

    Specified by:
      `assembleLine` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `at` - the location of the start of the instruction
      `line` - the textual assembly code
      `ctx` - the context register value at the start of the instruction
    Returns:
      the results of semantic resolution (from all parse results)
    Throws:
      `AssemblySemanticException` - the well-formed instruction cannot be assembled
      `AssemblySyntaxException` - the textual instruction is not well-formed

  - ### getNumericSymbols

    protected AssemblyNumericSymbols getNumericSymbols()
    A convenience to obtain assembly symbols
    Returns:
      the map

  - ### getContextAt

    public AssemblyPatternBlock getContextAt(Address addr)
    Description copied from interface: `GenericAssembler`
    Get the context at a given address

    If there is a program binding, this will extract the actual context at the given address. Otherwise, it will obtain the default context at the given address for the language.

    Specified by:
      `getContextAt` in interface `GenericAssembler<RP extends AssemblyResolvedPatterns>`
    Parameters:
      `addr` - the address
    Returns:
      the context