Enum Class SleighProgramCompiler
- All Implemented Interfaces:
Serializable
,Comparable<SleighProgramCompiler>
,Constable
Depending on the purpose, special provisions may be necessary around the execution of the
resulting program. Many utility methods are declared public here because they, well, they have
utility. The main public methods of this class, however, all start with compile
....
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
A p-code parser that provides programmatic access to error diagnostics.static interface
static interface
A factory forPcodeProgram
sNested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static ghidra.pcodeCPort.slghsymbol.VarnodeSymbol
addNilSymbol
(PcodeParser parser) Add a symbol for unwanted resultprotected static void
addParserSymbols
(PcodeParser parser, Map<Integer, ghidra.pcodeCPort.slghsymbol.UserOpSymbol> symbols) Add extra user-op symbols to the parser's tablebuildOps
(Language language, ConstructTpl template) Construct a list of p-code ops from the given templatestatic PcodeExpression
compileExpression
(SleighLanguage language, String expression) Compile the given Sleigh expression into a p-code program that can evaluate itstatic PcodeExpression
compileExpression
(PcodeParser parser, SleighLanguage language, String expression) Compile the given Sleigh expression into a p-code program that can evaluate it, using the given parserstatic PcodeProgram
compileProgram
(SleighLanguage language, String sourceName, String source, PcodeUseropLibrary<?> library) Compile the given Sleigh source into a simple p-code programstatic PcodeProgram
compileProgram
(PcodeParser parser, SleighLanguage language, String sourceName, String source, PcodeUseropLibrary<?> library) Compile the given Sleigh source into a simple p-code program with the given parserstatic ConstructTpl
compileTemplate
(Language language, PcodeParser parser, String sourceName, String source) Compile the given source into a p-code templatestatic PcodeProgram
compileUserop
(SleighLanguage language, String opName, List<String> params, String source, PcodeUseropLibrary<?> library, List<Varnode> args) Compile the definition of a p-code userop from Sleigh source into a p-code programstatic <T extends PcodeProgram>
TconstructProgram
(SleighProgramCompiler.PcodeProgramConstructor<T> ctor, SleighLanguage language, ConstructTpl template, Map<Integer, ghidra.pcodeCPort.slghsymbol.UserOpSymbol> libSyms) Invoke the given constructor with the given template and library symbolsstatic PcodeParser
createParser
(SleighLanguage language) Create a p-code parser for the given languagestatic ghidra.pcodeCPort.slghsymbol.VarnodeSymbol
paramSym
(Language language, ghidra.pcodeCPort.sleighbase.SleighBase sleigh, String opName, String paramName, Varnode arg) Generate a Sleigh symbol for context when compiling a userop definitionstatic SleighProgramCompiler
Returns the enum constant of this class with the specified name.static SleighProgramCompiler[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Field Details
-
NIL_SYMBOL_NAME
- See Also:
-
-
Method Details
-
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
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 nameNullPointerException
- if the argument is null
-
createParser
Create a p-code parser for the given language- Parameters:
language
- the language- Returns:
- a parser
-
compileTemplate
public static ConstructTpl compileTemplate(Language language, PcodeParser parser, String sourceName, String source) Compile the given source into a p-code template- Parameters:
language
- the languageparser
- the parsersourceName
- the name of the program, for error diagnosticssource
- the Sleigh source- Returns:
- the constructor template
- See Also:
-
buildOps
public static List<PcodeOp> buildOps(Language language, ConstructTpl template) throws UnknownInstructionException, MemoryAccessException, IOException Construct a list of p-code ops from the given template- Parameters:
language
- the language generating the template and p-codetemplate
- the template- Returns:
- the list of p-code ops
- Throws:
UnknownInstructionException
- in case of crossbuilds, the target instruction is unknownMemoryAccessException
- in case of crossbuilds, the target address cannot be accessedIOException
- for errors in during emitting
-
addParserSymbols
protected static void addParserSymbols(PcodeParser parser, Map<Integer, ghidra.pcodeCPort.slghsymbol.UserOpSymbol> symbols) Add extra user-op symbols to the parser's tableThe map cannot contain symbols whose user-op indices are already defined by the language.
- Parameters:
parser
- the parser to modifysymbols
- the map of extra symbols
-
addNilSymbol
Add a symbol for unwanted resultThis is basically a hack to avoid NPEs when no output varnode is given.
- Parameters:
parser
- the parser to add the symbol to- Returns:
- the nil symbol
-
constructProgram
public static <T extends PcodeProgram> T constructProgram(SleighProgramCompiler.PcodeProgramConstructor<T> ctor, SleighLanguage language, ConstructTpl template, Map<Integer, ghidra.pcodeCPort.slghsymbol.UserOpSymbol> libSyms) Invoke the given constructor with the given template and library symbols- Type Parameters:
T
- the type of the p-code program- Parameters:
ctor
- the constructor, often a method reference to::new
language
- the language producing the p-codetemplate
- the p-code constructor templatelibSyms
- the map of symbols by userop ID- Returns:
- the p-code program
-
compileProgram
public static PcodeProgram compileProgram(PcodeParser parser, SleighLanguage language, String sourceName, String source, PcodeUseropLibrary<?> library) Compile the given Sleigh source into a simple p-code program with the given parserThis is suitable for modifying program state using Sleigh statements. Most likely, in scripting, or perhaps in a Sleigh repl. The library given during compilation must match the library given for execution, at least in its binding of userop IDs to symbols.
- Parameters:
parser
- the parser to uselanguage
- the language of the target p-code machinesourceName
- a diagnostic name for the Sleigh sourcesource
- the Sleigh sourcelibrary
- the userop library or stub library for binding userop symbols- Returns:
- the compiled p-code program
-
compileProgram
public static PcodeProgram compileProgram(SleighLanguage language, String sourceName, String source, PcodeUseropLibrary<?> library) Compile the given Sleigh source into a simple p-code program- See Also:
-
compileExpression
public static PcodeExpression compileExpression(PcodeParser parser, SleighLanguage language, String expression) Compile the given Sleigh expression into a p-code program that can evaluate it, using the given parserTODO: Currently, expressions cannot be compiled for a user-supplied userop library. The evaluator p-code program uses its own library as a means of capturing the result; however, userop libraries are easily composed. It should be easy to add that feature if needed.
- Parameters:
language
- the languge of the target p-code machineexpression
- the Sleigh expression to be evaluated- Returns:
- a p-code program whose
PcodeExpression.evaluate(PcodeExecutor)
method will evaluate the expression on the given executor and its state.
-
compileExpression
Compile the given Sleigh expression into a p-code program that can evaluate it- See Also:
-
paramSym
public static ghidra.pcodeCPort.slghsymbol.VarnodeSymbol paramSym(Language language, ghidra.pcodeCPort.sleighbase.SleighBase sleigh, String opName, String paramName, Varnode arg) Generate a Sleigh symbol for context when compiling a userop definition- Parameters:
language
- the language of the target p-code machinesleigh
- a means of translating address spaces between execution and compilation contextsopName
- a diagnostic name for the userop in which this parameter appliesparamName
- the symbol name for the parameterarg
- the varnode to bind to the parameter symbol- Returns:
- the named Sleigh symbol bound to the given varnode
-
compileUserop
public static PcodeProgram compileUserop(SleighLanguage language, String opName, List<String> params, String source, PcodeUseropLibrary<?> library, List<Varnode> args) Compile the definition of a p-code userop from Sleigh source into a p-code programTODO: Defining a userop from Sleigh source is currently a bit of a hack. It would be nice if there were a formalization of Sleigh/p-code subroutines. At the moment, the control flow for subroutines is handled out of band, which actually works fairly well. However, parameter passing and returning results is not well defined. The current solution is to alias the parameters to their arguments, implementing a pass-by-reference scheme. Similarly, the output variable is aliased to the symbol named
SleighPcodeUseropDefinition.OUT_SYMBOL_NAME
, which could be problematic if no output variable is given. In this setup, the use of temporary variables is tenuous, since no provision is made to ensure a subroutine's allocation of temporary variables do not collide with those of callers lower in the stack. This could be partly resolved by creating a fresh unique space for each invocation, but then it becomes necessary to copy values from the caller's to the callee's. If we're strict about parameters being inputs, this is straightforward. If parameters can be used to communicate results, then we may need parameter attributes to indicate in, out, or inout. Of course, having a separate unique space per invocation implies the executor state can't simply have one unique space. Likely, thePcodeFrame
would come to own its own unique space, but thePcodeExecutorState
should probably still manufacture it.- Parameters:
language
- the language of the target p-code machineopName
- the name of the userop (used only for diagnostics here)params
- the names of parameters in order. Index 0 names the output symbol, probablySleighPcodeUseropDefinition.OUT_SYMBOL_NAME
source
- the Sleigh sourcelibrary
- the userop library or stub library for binding userop symbolsargs
- the varnode arguments in order. Index 0 is the output varnode.- Returns:
- a p-code program that implements the userop for the given arguments
-