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

Make vara-feature compatible to newer LLVM versions #129

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions include/vara/Feature/ConstraintParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ namespace vara::feature {
// ConstraintToken
//===----------------------------------------------------------------------===//

namespace legacy {
// NOLINTNEXTLINE(readability-identifier-naming)
[[nodiscard]] inline bool starts_with(llvm::StringRef Str,
llvm::StringRef Prefix) {
#if LLVM_VERSION_MAJOR <= 14
return Str.startswith(Prefix);
#else
return Str.starts_with(Prefix);
#endif
}
} // namespace legacy

class ConstraintToken {
public:
using PrecedenceTy = unsigned int;
Expand Down Expand Up @@ -187,38 +199,38 @@ class ConstraintLexer {
static ResultTy munchOperator(const llvm::StringRef &Str) {
switch (Str.front()) {
case '-':
if (Str.startswith("->")) {
if (legacy::starts_with(Str, "->")) {
return {ConstraintToken(ConstraintToken::ConstraintTokenKind::IMPLIES),
2};
}
return {ConstraintToken(ConstraintToken::ConstraintTokenKind::MINUS), 1};
case '!':
if (Str.startswith("!=")) {
if (legacy::starts_with(Str, "!=")) {
return {
ConstraintToken(ConstraintToken::ConstraintTokenKind::NOT_EQUAL),
2};
}
return {ConstraintToken(ConstraintToken::ConstraintTokenKind::NOT), 1};
case '=':
if (Str.startswith("=>")) {
if (legacy::starts_with(Str, "=>")) {
return {ConstraintToken(ConstraintToken::ConstraintTokenKind::IMPLIES),
2};
}
return {ConstraintToken(ConstraintToken::ConstraintTokenKind::EQUAL), 1};
case '>':
if (Str.startswith(">=")) {
if (legacy::starts_with(Str, ">=")) {
return {ConstraintToken(
ConstraintToken::ConstraintTokenKind::GREATER_EQUAL),
2};
}
return {ConstraintToken(ConstraintToken::ConstraintTokenKind::GREATER),
1};
case '<':
if (Str.startswith("<->") || Str.startswith("<=>")) {
if (legacy::starts_with(Str, "<->") || legacy::starts_with(Str, "<=>")) {
return {
ConstraintToken(ConstraintToken::ConstraintTokenKind::EQUIVALENT),
3};
} else if (Str.startswith("<=")) {
} else if (legacy::starts_with(Str, "<=")) {
return {
ConstraintToken(ConstraintToken::ConstraintTokenKind::LESS_EQUAL),
2};
Expand Down Expand Up @@ -282,7 +294,7 @@ static int64_t parseInteger(llvm::StringRef Str,
}

// If parsing failed, we return minimal or maximal value respectively.
if (Str.startswith("-")) {
if (legacy::starts_with(Str, "-")) {
return std::numeric_limits<int64_t>::min();
}
return std::numeric_limits<int64_t>::max();
Expand Down
3 changes: 0 additions & 3 deletions include/vara/Feature/FeatureSourceRange.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#ifndef VARA_FEATURE_FEATURESOURCERANGE_H
#define VARA_FEATURE_FEATURESOURCERANGE_H

#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Support/FormatVariadic.h"

Expand All @@ -17,7 +15,6 @@ namespace fs = std::experimental::filesystem;
#include <optional>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>

namespace vara::feature {
Expand Down
7 changes: 7 additions & 0 deletions tools/fm-viewer/FeatureModelViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Program.h"

#include <optional>

static llvm::cl::OptionCategory
FMViewerCategory("Feature model viewer options");

Expand Down Expand Up @@ -80,7 +82,12 @@ int main(int Argc, char **Argv) {
Viewer.empty() ? llvm::errc::invalid_argument
: llvm::sys::findProgramByName(Viewer)) {
llvm::errs() << "Trying '" << *P << "' program... \n";
#if __has_include("llvm/ADT/Optional.h")
// To stay compatible with older llvm versions
llvm::sys::ExecuteNoWait(*P, {*P, Filename}, llvm::None);
#else
llvm::sys::ExecuteNoWait(*P, {*P, Filename}, std::nullopt);
#endif
} else {
llvm::DisplayGraph(Filename);
}
Expand Down
Loading