retdec
Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
retdec::llvmir2hll::CompoundSemantics Class Reference

A class providing compound semantics from several different semantics. More...

#include <compound_semantics.h>

Inheritance diagram for retdec::llvmir2hll::CompoundSemantics:
Inheritance graph
[legend]
Collaboration diagram for retdec::llvmir2hll::CompoundSemantics:
Collaboration graph
[legend]

Public Member Functions

void prependSemantics (ShPtr< Semantics > semantics)
 Inserts the given semantics to the beginning of the list of compound semantics that this instance provides. More...
 
void appendSemantics (ShPtr< Semantics > semantics)
 Inserts the given semantics to the end of the list of compound semantics that this instance provides. More...
 
Semantics Interface
virtual std::string getId () const override
 Returns the ID of the semantics. More...
 
virtual std::optional< std::string > getMainFuncName () const override
 Returns the name of the main function. More...
 
virtual std::optional< std::string > getCHeaderFileForFunc (const std::string &funcName) const override
 Returns the C header file for the given function. More...
 
virtual std::optional< bool > funcNeverReturns (const std::string &funcName) const override
 Gets the information whether the given function never returns. More...
 
virtual std::optional< std::string > getNameOfVarStoringResult (const std::string &funcName) const override
 Returns an appropriate name of the variable that stores the result of calls to the given function. More...
 
virtual std::optional< std::string > getNameOfParam (const std::string &funcName, unsigned paramPos) const override
 Returns an appropriate name of the given function's parameter. More...
 
virtual std::optional< IntStringMapgetSymbolicNamesForParam (const std::string &funcName, unsigned paramPos) const override
 Returns a mapping of integers into their symbolic names for the given parameter of the given function. More...
 
- Public Member Functions inherited from retdec::llvmir2hll::Semantics
virtual ~Semantics ()=default
 

Static Public Member Functions

static ShPtr< CompoundSemanticscreate ()
 Creates a new semantics. More...
 

Protected Types

using SemanticsList = std::deque< ShPtr< Semantics > >
 A list of semantics. More...
 

Protected Member Functions

 CompoundSemantics ()
 Constructs the semantics. More...
 
- Protected Member Functions inherited from retdec::llvmir2hll::Semantics
 Semantics ()=default
 

Protected Attributes

SemanticsList providedSemantics
 A list of provided semantics. More...
 

Detailed Description

A class providing compound semantics from several different semantics.

For example, consider that we have semantics for the standard C library (sem1), for the extensions to this library as defined by POSIX (sem2), and some specific semantics for the GCC compiler version 4.8 on GNU/Linux (sem3). Then, after creating this semantics by calling create(), we may do the following actions to set-up this compound semantics:

compoundSemantics->appendSemantics(sem1);
compoundSemantics->appendSemantics(sem2);
compoundSemantics->appendSemantics(sem3);

Then, when calling a function from the Semantics' interface, sem1 is asked first. If it knows the answer, it is returned. Otherwise, if it doesn't know the answer, sem2 is asked and so on. When none of the semantics know the answer, an "I don't know" answer is returned.

This class is not registered in SemanticsFactory.

To create an instance of it by simply providing a list of identifiers of semantics to be used, use CompoundSemanticsBuilder.

Instances of this class have reference object semantics.

Member Typedef Documentation

◆ SemanticsList

A list of semantics.

Constructor & Destructor Documentation

◆ CompoundSemantics()

retdec::llvmir2hll::CompoundSemantics::CompoundSemantics ( )
protected

Constructs the semantics.

Member Function Documentation

◆ appendSemantics()

void retdec::llvmir2hll::CompoundSemantics::appendSemantics ( ShPtr< Semantics semantics)

Inserts the given semantics to the end of the list of compound semantics that this instance provides.

When the functions from the Semantics' interface are called, the newly added semantics is asked last.

◆ create()

ShPtr< CompoundSemantics > retdec::llvmir2hll::CompoundSemantics::create ( )
static

Creates a new semantics.

◆ funcNeverReturns()

std::optional< bool > retdec::llvmir2hll::CompoundSemantics::funcNeverReturns ( const std::string &  funcName) const
overridevirtual

Gets the information whether the given function never returns.

Returns
true if the given function never returns, false if the function may return, and std::nullopt otherwise.
Parameters
[in]funcNameName of the function.

For example, semantics describing the standard C library may return true for "exit".

Implements retdec::llvmir2hll::Semantics.

◆ getCHeaderFileForFunc()

std::optional< std::string > retdec::llvmir2hll::CompoundSemantics::getCHeaderFileForFunc ( const std::string &  funcName) const
overridevirtual

Returns the C header file for the given function.

Returns
"file" if the header file is known, std::nullopt otherwise.
Parameters
[in]funcNameName of the function.

For example, semantics describing the standard C library may return "stdio.h" for "printf".

Implements retdec::llvmir2hll::Semantics.

◆ getId()

virtual std::string retdec::llvmir2hll::CompoundSemantics::getId ( ) const
inlineoverridevirtual

Returns the ID of the semantics.

Implements retdec::llvmir2hll::Semantics.

◆ getMainFuncName()

std::optional< std::string > retdec::llvmir2hll::CompoundSemantics::getMainFuncName ( ) const
overridevirtual

Returns the name of the main function.

Implements retdec::llvmir2hll::Semantics.

◆ getNameOfParam()

std::optional< std::string > retdec::llvmir2hll::CompoundSemantics::getNameOfParam ( const std::string &  funcName,
unsigned  paramPos 
) const
overridevirtual

Returns an appropriate name of the given function's parameter.

Returns
"name" if the name is known, std::nullopt otherwise.
Parameters
[in]funcNameName of the function.
[in]paramPosPosition of the parameter.

For example, semantics describing the standard C library may return "file_path" for the first parameter of "fopen".

Implements retdec::llvmir2hll::Semantics.

◆ getNameOfVarStoringResult()

std::optional< std::string > retdec::llvmir2hll::CompoundSemantics::getNameOfVarStoringResult ( const std::string &  funcName) const
overridevirtual

Returns an appropriate name of the variable that stores the result of calls to the given function.

Returns
"name" if the name is known, std::nullopt otherwise.
Parameters
[in]funcNameName of the function.

For example, semantics describing the standard C library may return "c" for "getchar".

Implements retdec::llvmir2hll::Semantics.

◆ getSymbolicNamesForParam()

std::optional< IntStringMap > retdec::llvmir2hll::CompoundSemantics::getSymbolicNamesForParam ( const std::string &  funcName,
unsigned  paramPos 
) const
overridevirtual

Returns a mapping of integers into their symbolic names for the given parameter of the given function.

Returns
map if the mapping is known, std::nullopt otherwise.
Parameters
[in]funcNameName of the function.
[in]paramPosPosition of the parameter.

For example, a semantics may return

1 -> LOCK_SH
2 -> LOCK_EX
4 -> LOCK_NB
8 -> LOCK_UN

for "flock" and 2.

Implements retdec::llvmir2hll::Semantics.

◆ prependSemantics()

void retdec::llvmir2hll::CompoundSemantics::prependSemantics ( ShPtr< Semantics semantics)

Inserts the given semantics to the beginning of the list of compound semantics that this instance provides.

When the functions from the Semantics' interface are called, the newly added semantics is asked first.

Member Data Documentation

◆ providedSemantics

SemanticsList retdec::llvmir2hll::CompoundSemantics::providedSemantics
protected

A list of provided semantics.


The documentation for this class was generated from the following files: