Class PcodeParser

java.lang.Object
ghidra.pcodeCPort.slgh_compile.PcodeCompile
ghidra.program.model.lang.PcodeParser
Direct Known Subclasses:
SleighProgramCompiler.ErrorCollectingPcodeParser

public class PcodeParser extends ghidra.pcodeCPort.slgh_compile.PcodeCompile
This class is intended to parse p-code snippets, typically from compiler specification files or extensions. This is outside the normal SLEIGH compilation process, and the parser is built on top of an existing SleighLanguage.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    This class wraps on existing SleighLanguage with the SleighBase interface expected by PcodeCompile.
  • Field Summary

    Fields inherited from class ghidra.pcodeCPort.slgh_compile.PcodeCompile

    log, noplist
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    PcodeParser(SleighLanguage language, long ubase)
    Build parser from an existing SleighLanguage.
    protected
    PcodeParser(ghidra.pcodeCPort.sleighbase.SleighBase sleigh)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addOperand(Location loc, String name, int index)
    Inject a symbol representing an "operand" to the pcode snippet.
    void
    addSymbol(ghidra.pcodeCPort.slghsymbol.SleighSymbol sym)
     
    long
     
    void
     
    compilePcode(String pcodeStatements, String srcFile, int srcLine)
    Compile pcode semantic statements.
    VectorSTL<ghidra.pcodeCPort.semantics.OpTpl>
    createCrossBuild(Location where, ghidra.pcodeCPort.semantics.VarnodeTpl v, ghidra.pcodeCPort.slghsymbol.SectionSymbol second)
     
    VectorSTL<ghidra.pcodeCPort.semantics.OpTpl>
    createMacroUse(Location location, ghidra.pcodeCPort.slghsymbol.MacroSymbol sym, VectorSTL<ghidra.pcodeCPort.slgh_compile.ExprTree> param)
     
    ghidra.pcodeCPort.slgh_compile.SectionVector
    finalNamedSection(ghidra.pcodeCPort.slgh_compile.SectionVector vec, ghidra.pcodeCPort.semantics.ConstructTpl section)
     
    ghidra.pcodeCPort.slghsymbol.SleighSymbol
     
    ghidra.pcodeCPort.slgh_compile.SectionVector
    firstNamedSection(ghidra.pcodeCPort.semantics.ConstructTpl main, ghidra.pcodeCPort.slghsymbol.SectionSymbol sym)
     
    ghidra.pcodeCPort.space.AddrSpace
     
    ghidra.pcodeCPort.space.AddrSpace
     
    long
     
    ghidra.pcodeCPort.sleighbase.SleighBase
     
    ghidra.pcodeCPort.space.AddrSpace
     
    ghidra.pcodeCPort.slghsymbol.SectionSymbol
     
    ghidra.pcodeCPort.slgh_compile.SectionVector
    nextNamedSection(ghidra.pcodeCPort.slgh_compile.SectionVector vec, ghidra.pcodeCPort.semantics.ConstructTpl section, ghidra.pcodeCPort.slghsymbol.SectionSymbol sym)
     
    void
    recordNop(Location location)
     
    ghidra.pcodeCPort.slgh_compile.SectionVector
    standaloneSection(ghidra.pcodeCPort.semantics.ConstructTpl main)
     
    translateConstructTpl(ghidra.pcodeCPort.semantics.ConstructTpl constructTpl)
     
    translateConstTpl(ghidra.pcodeCPort.semantics.ConstTpl constTpl)
     
    translateHandleTpl(ghidra.pcodeCPort.semantics.HandleTpl handleTpl)
     
    translateOpTpl(ghidra.pcodeCPort.semantics.OpTpl opTpl)
     
    translateVarnodeTpl(ghidra.pcodeCPort.semantics.VarnodeTpl varnodeTpl)
     

    Methods inherited from class ghidra.pcodeCPort.slgh_compile.PcodeCompile

    addressOf, appendOp, assignBitRange, buildTemporary, buildTruncatedVarnode, createBitRange, createLoad, createOp, createOp, createOpConst, createOpNoOut, createOpNoOut, createOpOut, createOpOutUnary, createStore, createUserOp, createUserOpNoOut, createVariadic, defineLabel, entry, fillinZero, findInternalFunction, getErrors, getWarnings, isInternalFunction, matchSize, newLocalDefinition, newLocalDefinition, newOutput, newOutput, placeLabel, propagateSize, reportError, reportWarning, resetLabelCount, setEnforceLocalKey, setResultStarVarnode, setResultVarnode

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PcodeParser

      protected PcodeParser(ghidra.pcodeCPort.sleighbase.SleighBase sleigh)
    • PcodeParser

      public PcodeParser(SleighLanguage language, long ubase)
      Build parser from an existing SleighLanguage.
      Parameters:
      language - is the existing language
      ubase - is the starting offset for allocating temporary registers
  • Method Details

    • addOperand

      public void addOperand(Location loc, String name, int index)
      Inject a symbol representing an "operand" to the pcode snippet.

      This puts a placeholder in the resulting template, which gets filled in with the context specific storage locations when final p-code is generated

      Parameters:
      loc - is location information for the operand
      name - of operand symbol
      index - to use for the placeholder
    • addSymbol

      public void addSymbol(ghidra.pcodeCPort.slghsymbol.SleighSymbol sym)
      Specified by:
      addSymbol in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • clearSymbols

      public void clearSymbols()
    • getNextTempOffset

      public long getNextTempOffset()
    • allocateTemp

      public long allocateTemp()
      Specified by:
      allocateTemp in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • createMacroUse

      public VectorSTL<ghidra.pcodeCPort.semantics.OpTpl> createMacroUse(Location location, ghidra.pcodeCPort.slghsymbol.MacroSymbol sym, VectorSTL<ghidra.pcodeCPort.slgh_compile.ExprTree> param)
      Specified by:
      createMacroUse in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • findSymbol

      public ghidra.pcodeCPort.slghsymbol.SleighSymbol findSymbol(String nm)
      Specified by:
      findSymbol in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • getSleigh

      public ghidra.pcodeCPort.sleighbase.SleighBase getSleigh()
    • getConstantSpace

      public ghidra.pcodeCPort.space.AddrSpace getConstantSpace()
      Specified by:
      getConstantSpace in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • getDefaultSpace

      public ghidra.pcodeCPort.space.AddrSpace getDefaultSpace()
      Specified by:
      getDefaultSpace in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • getUniqueSpace

      public ghidra.pcodeCPort.space.AddrSpace getUniqueSpace()
      Specified by:
      getUniqueSpace in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • recordNop

      public void recordNop(Location location)
      Specified by:
      recordNop in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • translateConstructTpl

      public ConstructTpl translateConstructTpl(ghidra.pcodeCPort.semantics.ConstructTpl constructTpl)
    • translateHandleTpl

      public HandleTpl translateHandleTpl(ghidra.pcodeCPort.semantics.HandleTpl handleTpl)
    • translateOpTpl

      public OpTpl translateOpTpl(ghidra.pcodeCPort.semantics.OpTpl opTpl)
    • translateVarnodeTpl

      public VarnodeTpl translateVarnodeTpl(ghidra.pcodeCPort.semantics.VarnodeTpl varnodeTpl)
    • translateConstTpl

      public ConstTpl translateConstTpl(ghidra.pcodeCPort.semantics.ConstTpl constTpl)
    • compilePcode

      public ConstructTpl compilePcode(String pcodeStatements, String srcFile, int srcLine) throws SleighException
      Compile pcode semantic statements.
      Parameters:
      pcodeStatements - is the raw source to parse
      srcFile - source filename from which pcodeStatements came (
      srcLine - line number in srcFile corresponding to pcodeStatements
      Returns:
      ConstructTpl. A null may be returned or an exception thrown if parsing/compiling fails (see application log for errors).
      Throws:
      SleighException - pcode compile error
    • newSectionSymbol

      public ghidra.pcodeCPort.slghsymbol.SectionSymbol newSectionSymbol(Location where, String text)
      Specified by:
      newSectionSymbol in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • createCrossBuild

      public VectorSTL<ghidra.pcodeCPort.semantics.OpTpl> createCrossBuild(Location where, ghidra.pcodeCPort.semantics.VarnodeTpl v, ghidra.pcodeCPort.slghsymbol.SectionSymbol second)
      Specified by:
      createCrossBuild in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • standaloneSection

      public ghidra.pcodeCPort.slgh_compile.SectionVector standaloneSection(ghidra.pcodeCPort.semantics.ConstructTpl main)
      Specified by:
      standaloneSection in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • firstNamedSection

      public ghidra.pcodeCPort.slgh_compile.SectionVector firstNamedSection(ghidra.pcodeCPort.semantics.ConstructTpl main, ghidra.pcodeCPort.slghsymbol.SectionSymbol sym)
      Specified by:
      firstNamedSection in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • nextNamedSection

      public ghidra.pcodeCPort.slgh_compile.SectionVector nextNamedSection(ghidra.pcodeCPort.slgh_compile.SectionVector vec, ghidra.pcodeCPort.semantics.ConstructTpl section, ghidra.pcodeCPort.slghsymbol.SectionSymbol sym)
      Specified by:
      nextNamedSection in class ghidra.pcodeCPort.slgh_compile.PcodeCompile
    • finalNamedSection

      public ghidra.pcodeCPort.slgh_compile.SectionVector finalNamedSection(ghidra.pcodeCPort.slgh_compile.SectionVector vec, ghidra.pcodeCPort.semantics.ConstructTpl section)
      Specified by:
      finalNamedSection in class ghidra.pcodeCPort.slgh_compile.PcodeCompile