Enum Class SleighUtils

java.lang.Object
java.lang.Enum<SleighUtils>
ghidra.pcode.exec.SleighUtils
All Implemented Interfaces:
Serializable, Comparable<SleighUtils>, Constable

public enum SleighUtils extends Enum<SleighUtils>
A collection of utilities for parsing and manipulating Sleigh semantic source
  • Field Details

  • Method Details

    • values

      public static SleighUtils[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static SleighUtils valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • parseSleigh

      public static <T extends org.antlr.runtime.RuleReturnScope> T parseSleigh(SleighUtils.ParseFunction<T> nt, String text, String follow)
      Parse a non-terminal symbol from the Sleigh semantic grammar

      Because the ANTLR parsing function for the non-terminal symbol depends on the "follows" set to determine when it has finished, we can't just invoke the function in isolation without some hacking. If EOF is not in the non-terminal's follows set, then it won't recognize EOF as completing the non-terminal. Instead, we have to present some token that it will recognize. Furthermore, regardless of the follow token, we have to check that all of the given input was consumed by the parser.

      Type Parameters:
      T - the type of result from parsing
      Parameters:
      nt - the function from the parser implementing the non-terminal symbol
      text - the text to parse
      follow - a token that would ordinarily follow the non-terminal symbol, or empty for EOF
      Returns:
      the parsed result
    • parseSleighSemantic

      public static org.antlr.runtime.tree.Tree parseSleighSemantic(String sleigh)
      Parse a semantic block, that is a list of Sleigh semantic statements
      Parameters:
      sleigh - the source
      Returns:
      the parse tree
    • parseSleighExpression

      public static org.antlr.runtime.tree.Tree parseSleighExpression(String expression)
      Parse a semantic expression
      Parameters:
      expression - the expression as a string
      Returns:
      the parse tree
    • getChildren

      public static List<org.antlr.runtime.tree.Tree> getChildren(org.antlr.runtime.tree.Tree tree)
      Get the children of a parse tree node
      Parameters:
      tree - the node
      Returns:
      the list of children
    • matchTree

      public static void matchTree(org.antlr.runtime.tree.Tree tree, int type, Consumer<List<org.antlr.runtime.tree.Tree>> onChildren)
      Match the given tree to a given pattern
      Parameters:
      tree - the (sub-)tree to match, actually its root node
      type - the expected type of the given node
      onChildren - actions (usually sub-matching) to perform on the children
    • requireCount

      public static void requireCount(int count, List<?> list)
      Require (as part of pattern matching) that the given list of children has a particular size
      Parameters:
      count - the required size
      list - the list of children
    • match

      @SafeVarargs public static void match(org.antlr.runtime.tree.Tree tree, int type, Consumer<org.antlr.runtime.tree.Tree>... onChild)
      Match the given tree to a given pattern with per-child actions
      Parameters:
      tree - the (sub-)tree to match, actually its root node
      type - the expected type of the given node
      onChild - a list of actions (usually sub-matching) to perform on each corresponding child. The matcher will verify the number of children matches the number of actions.
    • matchDereference

      public static void matchDereference(org.antlr.runtime.tree.Tree tree, Consumer<org.antlr.runtime.tree.Tree> onSpace, Consumer<org.antlr.runtime.tree.Tree> onSize, Consumer<org.antlr.runtime.tree.Tree> onOffset)
    • isUnconditionalBreakpoint

      public static boolean isUnconditionalBreakpoint(org.antlr.runtime.tree.Tree tree)
      Check if the given tree represents an unconditional breakpoint in the emulator
      Parameters:
      tree - the result of parsing a semantic block
      Returns:
      true if an unconditional breakpoint, false otherwise
    • recoverConditionFromBreakpoint

      public static String recoverConditionFromBreakpoint(org.antlr.runtime.tree.Tree tree)
      Check if the given tree represents a conditional breakpoint, and recover that condition
      Parameters:
      tree - the result of parsing a semantic block
      Returns:
      the condition if matched, null otherwise
    • recoverConditionFromBreakpoint

      public static String recoverConditionFromBreakpoint(String sleigh)
      Check if the given Sleigh semantic block implements a conditional breakpoint, and recover that condition
      Parameters:
      sleigh - the source for a Sleigh semantic block
      Returns:
      the condition if matched, null otherwise
    • recoverAddressOf

      public static SleighUtils.AddressOf recoverAddressOf(String defaultSpace, org.antlr.runtime.tree.Tree tree)
    • recoverAddressOf

      public static SleighUtils.AddressOf recoverAddressOf(String defaultSpace, String expression)
    • makeTree

      public static org.antlr.runtime.tree.Tree makeTree(int type, String text, List<org.antlr.runtime.tree.Tree> children)
      Synthesize a tree (node)
      Parameters:
      type - the type of the node
      text - the "text" of the node
      children - the children
      Returns:
      the new node
    • generateSleighExpression

      public static String generateSleighExpression(org.antlr.runtime.tree.Tree tree)
      Generate source for the given Sleigh parse tree

      Currently, only nodes that could appear in a Sleigh expression are supported.

      Parameters:
      tree - the expression tree
      Returns:
      the generated string
    • removeParenthesisTree

      public static org.antlr.runtime.tree.Tree removeParenthesisTree(org.antlr.runtime.tree.Tree tree)
      Remove parenthesis from the root of the given tree

      If the root is parenthesis, this simply gets the child. This is applied recursively until a non-parenthesis child is encountered.

      Parameters:
      tree - the result of parsing a Sleigh expression
      Returns:
      the same or sub-tree
    • notTree

      public static org.antlr.runtime.tree.Tree notTree(org.antlr.runtime.tree.Tree boolExpr)
      Apply the boolean "not" operator to a Sleigh expression

      This will attempt to invert the expression when possible, e.g., by changing a top-level "equals" to "not equals." If that is not possible, the this adds parenthesis and applies the actual Sleigh boolean "not" operator.

      Parameters:
      boolExpr - the result of parsing a Sleigh expression
      Returns:
      the tree for the inverted expression
    • sleighForConditionalBreak

      public static String sleighForConditionalBreak(String condition)
      Generate Sleigh source for a breakpoint predicated on the given condition
      Parameters:
      condition - a Sleigh expression
      Returns:
      the Sleigh source