Skip to content

Commit

Permalink
Merge pull request #509 from avast-tl/removal-of-original-converter-i…
Browse files Browse the repository at this point in the history
…n-llvmir2hll

Remove the original converter of LLVM IR into BIR from llvmir2hll
  • Loading branch information
s3rvac authored Feb 28, 2019
2 parents 24aaa2c + 9759427 commit 5de7439
Show file tree
Hide file tree
Showing 58 changed files with 726 additions and 5,783 deletions.
100 changes: 68 additions & 32 deletions include/retdec/llvmir2hll/llvm/llvmir2bir_converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@

#include <string>

#include "retdec/llvmir2hll/llvm/llvmir2bir_converter.h"
#include "retdec/llvmir2hll/support/smart_ptr.h"
#include "retdec/llvmir2hll/support/types.h"
#include "retdec/utils/non_copyable.h"

namespace llvm {

class Function;
class GlobalVariable;
class Module;
class Pass;

Expand All @@ -23,61 +27,93 @@ namespace retdec {
namespace llvmir2hll {

class Config;
class Expression;
class Function;
class LLVMValueConverter;
class Module;
class Semantics;
class StructureConverter;
class Variable;
class VariablesManager;

/**
* @brief A base class for all converters of LLVM IR to BIR.
*
* This class should be used as a base class for all converters of LLVM IR to
* BIR.
*
* To implement a new converter:
* - subclass this class and implement getId() and convert()
* - create a static create() function and register the converter at
* LLVMIR2BIRConverterFactory (see the implementation of existing subclasses)
* @brief A converter of LLVM IR to BIR.
*
* Instances of this class have reference object semantics.
*/
class LLVMIR2BIRConverter: private retdec::utils::NonCopyable {
public:
virtual ~LLVMIR2BIRConverter();

/**
* @brief Returns the ID of the converter.
*/
virtual std::string getId() const = 0;

/**
* @brief Converts the given LLVM module into a module in BIR.
*
* @param[in] llvmModule LLVM module to be converted.
* @param[in] moduleName Identifier of the resulting module.
* @param[in] semantics The used semantics.
* @param[in] config Configuration for the module.
* @param[in] enableDebug If @c true, debugging messages will be emitted.
*
* @par Preconditions
* - both @a llvmModule and @a semantics are non-null
*/
virtual ShPtr<Module> convert(llvm::Module *llvmModule,
static ShPtr<LLVMIR2BIRConverter> create(llvm::Pass *basePass);

~LLVMIR2BIRConverter();

ShPtr<Module> convert(llvm::Module *llvmModule,
const std::string &moduleName, ShPtr<Semantics> semantics,
ShPtr<Config> config, bool enableDebug = false) = 0;
ShPtr<Config> config, bool enableDebug = false);

/// @name Options
/// @{
void setOptionStrictFPUSemantics(bool strict = true);
/// @}

protected:
private:
LLVMIR2BIRConverter(llvm::Pass *basePass);

protected:
/// @name Global variables conversion
/// @{
bool isExternal(const llvm::GlobalVariable &var) const;
bool shouldBeConvertedAndAdded(const llvm::GlobalVariable &globVar) const;
ShPtr<Variable> convertGlobalVariable(llvm::GlobalVariable &globVar) const;
ShPtr<Expression> convertGlobalVariableInitializer(
llvm::GlobalVariable &globVar) const;
void convertAndAddGlobalVariables();
/// @}

/// @name Functions conversion
/// @{
VarVector convertFuncParams(llvm::Function &func);
ShPtr<Function> convertFuncDeclaration(llvm::Function &func);
void updateFuncToDefinition(llvm::Function &func);
VarVector sortLocalVars(const VarSet &vars) const;
void generateVarDefinitions(ShPtr<Function> func) const;
bool shouldBeConvertedAndAdded(const llvm::Function &func) const;
void convertAndAddFuncsDeclarations();
void convertFuncsBodies();
/// @}

/// @name Ensure that identifiers are valid
/// @{
void makeIdentifiersValid();
void makeGlobVarsIdentifiersValid();
void makeFuncsIdentifiersValid();
void makeFuncIdentifiersValid(ShPtr<Function> func) const;
void makeFuncVariablesValid(ShPtr<Function> func) const;
/// @}

private:
/// Pass that have instantiated the converter.
llvm::Pass *basePass;

/// Use strict FPU semantics?
bool optionStrictFPUSemantics;

/// Should debugging messages be enabled?
bool enableDebug;

/// A converter from LLVM values to values in BIR.
ShPtr<LLVMValueConverter> converter;

/// The input LLVM module.
llvm::Module *llvmModule;

/// The resulting module in BIR.
ShPtr<Module> resModule;

/// A converter of the LLVM function structure.
UPtr<StructureConverter> structConverter;

/// Variables manager.
ShPtr<VariablesManager> variablesManager;
};

} // namespace llvmir2hll
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/basic_block_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/basic_block_converter.h
* @brief A converter of LLVM basic blocks.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_BASIC_BLOCK_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_BASIC_BLOCK_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_BASIC_BLOCK_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_BASIC_BLOCK_CONVERTER_H

#include <llvm/IR/InstVisitor.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/cfg_node.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/cfg_node.h
* @brief A representation of a control-flow graph node.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_CFG_NODE_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_CFG_NODE_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_CFG_NODE_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_CFG_NODE_H

#include <string>
#include <unordered_set>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/orig_llvmir2bir_converter/labels_handler.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/labels_handler.h
* @brief Handling of labels during conversion of LLVM IR to BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_ORIG_LLVMIR2BIR_CONVERTER_LABELS_HANDLER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_ORIG_LLVMIR2BIR_CONVERTER_LABELS_HANDLER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LABELS_HANDLER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LABELS_HANDLER_H

#include <string>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/llvm_constant_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/llvm_constant_converter.h
* @brief A converter from LLVM constant to constant in BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_CONSTANT_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_CONSTANT_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_CONSTANT_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_CONSTANT_CONVERTER_H

#include "retdec/llvmir2hll/support/smart_ptr.h"
#include "retdec/utils/non_copyable.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/llvm_fcmp_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/llvm_fcmp_converter.h
* @brief A converter from LLVM fcmp instruction to expression in BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_FCMP_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_FCMP_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_FCMP_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_FCMP_CONVERTER_H

#include "retdec/llvmir2hll/support/smart_ptr.h"
#include "retdec/llvmir2hll/support/types.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/llvm_instruction_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/llvm_instruction_converter.h
* @brief A converter from LLVM instruction to expression in BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_INSTRUCTION_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_INSTRUCTION_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_INSTRUCTION_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_INSTRUCTION_CONVERTER_H

#include <llvm/ADT/ArrayRef.h>
#include <llvm/IR/GetElementPtrTypeIterator.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/llvm_type_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/llvm_type_converter.h
* @brief A converter from LLVM type to type in BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_TYPE_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_TYPE_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_TYPE_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_TYPE_CONVERTER_H

#include <unordered_map>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/llvm_value_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/llvm_value_converter.h
* @brief A converter from LLVM values to values in BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_VALUE_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_LLVM_VALUE_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_VALUE_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_LLVM_VALUE_CONVERTER_H

#include <llvm/ADT/ArrayRef.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/structure_converter.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/structure_converter.h
* @brief A converter of the LLVM function structure.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_STRUCTURE_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_STRUCTURE_CONVERTER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_STRUCTURE_CONVERTER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_STRUCTURE_CONVERTER_H

#include <functional>
#include <queue>
Expand All @@ -15,7 +15,7 @@
#include <utility>
#include <vector>

#include "retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/cfg_node.h"
#include "retdec/llvmir2hll/llvm/llvmir2bir_converter/cfg_node.h"
#include "retdec/llvmir2hll/support/smart_ptr.h"
#include "retdec/llvmir2hll/support/types.h"
#include "retdec/utils/non_copyable.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converters/new_llvmir2bir_converter/variables_manager.h
* @file include/retdec/llvmir2hll/llvm/llvmir2bir_converter/variables_manager.h
* @brief Managing of local variables created during conversion of LLVM
* functions to BIR.
* @copyright (c) 2017 Avast Software, licensed under the MIT license
*/

#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_VARIABLES_MANAGER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTERS_NEW_LLVMIR2BIR_CONVERTER_VARIABLES_MANAGER_H
#ifndef RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_VARIABLES_MANAGER_H
#define RETDEC_LLVMIR2HLL_LLVM_LLVMIR2BIR_CONVERTER_VARIABLES_MANAGER_H

#include <unordered_map>

Expand Down
44 changes: 0 additions & 44 deletions include/retdec/llvmir2hll/llvm/llvmir2bir_converter_factory.h

This file was deleted.

Loading

0 comments on commit 5de7439

Please sign in to comment.