Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle remove --backend-aggressive-opts and all the related code #8

Conversation

restyled-io[bot]
Copy link

@restyled-io restyled-io bot commented Aug 3, 2024

Automated style fixes for #7, created by Restyled.

The following restylers made fixes:

To incorporate these changes, merge this Pull Request into the original. We
recommend using the Squash or Rebase strategies.

NOTE: As work continues on the original Pull Request, this process will
re-run and update (force-push) this Pull Request with updated style fixes as
necessary. If the style is fixed manually at any point (i.e. this process finds
no fixes to make), this Pull Request will be closed automatically.

Sorry if this was unexpected. To disable it, see our documentation.

Copy link

Unable to locate .performanceTestingBot config file

Copy link

cr-gpt bot commented Aug 3, 2024

Seems you are using me but didn't get OPENAI_API_KEY seted in Variables/Secrets for this repo. you could follow readme for more information

Copy link

git-greetings bot commented Aug 3, 2024

Thanks @restyled-io[bot] for opening this PR!

For COLLABORATOR only :

  • To add labels, comment on the issue
    /label add label1,label2,label3

  • To remove labels, comment on the issue
    /label remove label1,label2,label3

@restyled-io restyled-io bot closed this Aug 3, 2024
Copy link

@gitginie gitginie bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@restyled-io[bot]
Thank you for your contribution to this repository! We appreciate your effort in opening pull request.
Happy coding!

Copy link

Processing PR updates...

@restyled-io restyled-io bot deleted the restyled/remove-backend-aggressive-opts branch August 3, 2024 09:45
Copy link

git-greetings bot commented Aug 3, 2024

PR Details of @restyled-io[bot] in avast-retdec :

OPEN CLOSED TOTAL
2 6 8

Copy link

coderabbitai bot commented Aug 3, 2024

Important

Review skipped

Auto reviews are limited to specific labels.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@labels-and-badges labels-and-badges bot added NO JIRA This PR does not have a Jira Ticket PR:size/XXL Denotes a Pull Request that changes 1000+ lines. labels Aug 3, 2024
Comment on lines +24 to 185
/// @{
const std::string &getOrdinalNumbersDirectory() const;
const std::string &getInputFile() const;
const std::string &getInputPdbFile() const;
const std::string &getOutputFile() const;
const std::string &getOutputBitcodeFile() const;
const std::string &getOutputAsmFile() const;
const std::string &getOutputLlvmirFile() const;
const std::string &getOutputConfigFile() const;
const std::string &getOutputUnpackedFile() const;
const std::string &getOutputFormat() const;
const std::string &getLogFile() const;
const std::string &getErrFile() const;
uint64_t getMaxMemoryLimit() const;
uint64_t getTimeout() const;
retdec::common::Address getEntryPoint() const;
retdec::common::Address getMainAddress() const;
retdec::common::Address getSectionVMA() const;
const std::string &getBackendDisabledOpts() const;
const std::string &getBackendEnabledOpts() const;
const std::string &getBackendCallInfoObtainer() const;
const std::string &getBackendVarRenamer() const;
/// @}

void fixRelativePaths(const std::string &configPath);

template <typename Writer> void serialize(Writer &writer) const;
void deserialize(const rapidjson::Value &val);

public:
std::set<std::string> userStaticSignaturePaths;
std::set<std::string> staticSignaturePaths;
std::set<std::string> libraryTypeInfoPaths;
std::set<std::string> cryptoPatternPaths;
std::set<std::string> abiPaths;

/// Functions' names which were selected by the user through
/// selective decompilation.
std::set<std::string> selectedFunctions;

/// Selected functions' names from @c selectedFunctions which
/// were not found in the binary.
std::set<std::string> selectedNotFoundFunctions;

/// Address ranges selected by the user through selective decompilation.
common::AddressRangeContainer selectedRanges;

/// LLVM passes.
std::vector<std::string> llvmPasses;

private:
/// Decompilation will verbosely inform about the
/// decompilation process.
bool _verboseOutput = true;

/// Keep all functions in the decompiler's output.
/// Otherwise, only functions reachable from main are kept.
bool _keepAllFunctions = false;

/// Decode only parts selected through selective decompilation.
/// Otherwise, entire binary is decoded.
/// This speeds up decompilation, but usually produces lower-quality
/// results.
bool _selectedDecodeOnly = false;

std::string _ordinalNumbersDirectory;
std::string _inputFile;
std::string _inputPdbFile;
std::string _outputFile;
std::string _outputBitcodeFile;
std::string _outputAsmFile;
std::string _outputLlFile;
std::string _outputConfigFile;
std::string _outputUnpackedFile;
std::string _outputFormat;
std::string _logFile;
std::string _errFile;
uint64_t _maxMemoryLimit = 0;
bool _maxMemoryLimitHalfRam = true;
uint64_t _timeout = 0;

bool _detectStaticCode = true;
std::string _backendDisabledOpts;
std::string _backendEnabledOpts;
std::string _backendCallInfoObtainer = "optim";
std::string _backendVarRenamer = "readable";
bool _backendNoOpts = false;
bool _backendEmitCfg = false;
bool _backendEmitCg = false;
bool _backendKeepAllBrackets = false;
bool _backendKeepLibraryFuncs = false;
bool _backendNoTimeVaryingInfo = false;
bool _backendNoVarRenaming = false;
bool _backendNoCompoundOperators = false;
bool _backendNoSymbolicNames = false;

retdec::common::Address _entryPoint;
retdec::common::Address _mainAddress;
retdec::common::Address _sectionVMA;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Parameters class has a large number of member variables and methods, which can make it difficult to maintain and understand. This class could benefit from being broken down into smaller, more focused classes or structs. For example, you could create separate classes for handling backend options, file paths, and memory settings. This would improve modularity and make the codebase easier to manage.

Comment on lines +137 to +180
/// Decompilation will verbosely inform about the
/// decompilation process.
bool _verboseOutput = true;

/// Keep all functions in the decompiler's output.
/// Otherwise, only functions reachable from main are kept.
bool _keepAllFunctions = false;

/// Decode only parts selected through selective decompilation.
/// Otherwise, entire binary is decoded.
/// This speeds up decompilation, but usually produces lower-quality
/// results.
bool _selectedDecodeOnly = false;

std::string _ordinalNumbersDirectory;
std::string _inputFile;
std::string _inputPdbFile;
std::string _outputFile;
std::string _outputBitcodeFile;
std::string _outputAsmFile;
std::string _outputLlFile;
std::string _outputConfigFile;
std::string _outputUnpackedFile;
std::string _outputFormat;
std::string _logFile;
std::string _errFile;
uint64_t _maxMemoryLimit = 0;
bool _maxMemoryLimitHalfRam = true;
uint64_t _timeout = 0;

bool _detectStaticCode = true;
std::string _backendDisabledOpts;
std::string _backendEnabledOpts;
std::string _backendCallInfoObtainer = "optim";
std::string _backendVarRenamer = "readable";
bool _backendNoOpts = false;
bool _backendEmitCfg = false;
bool _backendEmitCg = false;
bool _backendKeepAllBrackets = false;
bool _backendKeepLibraryFuncs = false;
bool _backendNoTimeVaryingInfo = false;
bool _backendNoVarRenaming = false;
bool _backendNoCompoundOperators = false;
bool _backendNoSymbolicNames = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class has many boolean flags (e.g., _verboseOutput, _keepAllFunctions, _selectedDecodeOnly, etc.). Using an enum or a bitfield to manage these flags could improve performance and reduce memory usage. This would also make it easier to add or remove flags in the future.

Comment on lines +103 to 181

llvmir2hll::StringSet parseListOfOpts(
const std::string &opts) const;
llvmir2hll::StringVector getIdsOfPatternFindersToBeRun() const;
llvmir2hll::PatternFinderRunner::PatternFinders instantiatePatternFinders(
const llvmir2hll::StringVector &pfsIds);
ShPtr<llvmir2hll::PatternFinderRunner> instantiatePatternFinderRunner() const;
bool initialize(llvm::Module &m);
void createSemantics();
void createSemanticsFromParameter();
void createSemanticsFromLLVMIR();
bool loadConfig();
void saveConfig();
bool convertLLVMIRToBIR();
void removeLibraryFuncs();
void removeCodeUnreachableInCFG();
void fixSignedUnsignedTypes();
void convertLLVMIntrinsicFunctions();
void obtainDebugInfo();
void initAliasAnalysis();
void runOptimizations();
void renameVariables();
void convertConstantsToSymbolicNames();
void validateResultingModule();
void findPatterns();
void emitCFGs();
void emitCG();
void emitTargetHLLCode();
void finalize();
void cleanup();

llvmir2hll::StringSet parseListOfOpts(const std::string &opts) const;
llvmir2hll::StringVector getIdsOfPatternFindersToBeRun() const;
llvmir2hll::PatternFinderRunner::PatternFinders
instantiatePatternFinders(const llvmir2hll::StringVector &pfsIds);
ShPtr<llvmir2hll::PatternFinderRunner> instantiatePatternFinderRunner() const;

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

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

/// The used semantics.
ShPtr<llvmir2hll::Semantics> semantics;
/// The used semantics.
ShPtr<llvmir2hll::Semantics> semantics;

/// The used config.
config::Config* globalConfig = nullptr;
ShPtr<llvmir2hll::Config> config;
/// The used config.
config::Config *globalConfig = nullptr;
ShPtr<llvmir2hll::Config> config;

/// The used HLL writer.
ShPtr<llvmir2hll::HLLWriter> hllWriter;
/// The used HLL writer.
ShPtr<llvmir2hll::HLLWriter> hllWriter;

/// The used alias analysis.
ShPtr<llvmir2hll::AliasAnalysis> aliasAnalysis;
/// The used alias analysis.
ShPtr<llvmir2hll::AliasAnalysis> aliasAnalysis;

/// The used obtainer of information about function and function calls.
ShPtr<llvmir2hll::CallInfoObtainer> cio;
/// The used obtainer of information about function and function calls.
ShPtr<llvmir2hll::CallInfoObtainer> cio;

/// The used evaluator of arithmetical expressions.
ShPtr<llvmir2hll::ArithmExprEvaluator> arithmExprEvaluator;
/// The used evaluator of arithmetical expressions.
ShPtr<llvmir2hll::ArithmExprEvaluator> arithmExprEvaluator;

/// The used generator of variable names.
ShPtr<llvmir2hll::VarNameGen> varNameGen;
/// The used generator of variable names.
ShPtr<llvmir2hll::VarNameGen> varNameGen;

/// The used renamer of variables.
ShPtr<llvmir2hll::VarRenamer> varRenamer;
/// The used renamer of variables.
ShPtr<llvmir2hll::VarRenamer> varRenamer;

/// Output file stream.
std::unique_ptr<llvm::ToolOutputFile> outFile;
/// Output file stream.
std::unique_ptr<llvm::ToolOutputFile> outFile;

/// Output string stream.
std::unique_ptr<llvm::raw_string_ostream> outStringStream;
/// Output string stream.
std::unique_ptr<llvm::raw_string_ostream> outStringStream;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class LlvmIr2Hll has a large number of private member functions and member variables, which can make the class difficult to maintain and understand. This could be a sign that the class is trying to do too much and may benefit from being broken down into smaller, more focused classes or components.

Recommended Solution:
Consider refactoring the class to delegate some of its responsibilities to other classes. This will improve maintainability and readability by adhering to the Single Responsibility Principle (SRP).

/// Should we recover from out-of-memory errors during optimizations?
bool recoverFromOutOfMemory;
/// Should we recover from out-of-memory errors during optimizations?
bool recoverFromOutOfMemory;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The recoverFromOutOfMemory member variable is declared but never initialized in the constructor. This could lead to undefined behavior if the variable is accessed before being explicitly set.

Recommended Solution:
Initialize recoverFromOutOfMemory in the constructor to a default value, such as false, to ensure it has a defined state.

Copy link

@gitginie gitginie bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@restyled-io[bot]
Thank you for your contribution to this repository! We appreciate your effort in closing pull request.
Happy coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NO JIRA This PR does not have a Jira Ticket PR:size/XXL Denotes a Pull Request that changes 1000+ lines. size/XXL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant