forked from rust-lang/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SOL][BPF] Enable Solana BPF extensions as subtarget feature
- Loading branch information
Showing
44 changed files
with
302 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
//===--- BPF.cpp - Tools Implementations ------------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "BPF.h" | ||
#include "clang/Driver/Driver.h" | ||
#include "clang/Driver/DriverDiagnostic.h" | ||
#include "clang/Driver/Options.h" | ||
#include "llvm/ADT/StringSwitch.h" | ||
#include "llvm/Option/ArgList.h" | ||
|
||
using namespace clang::driver; | ||
using namespace clang::driver::tools; | ||
using namespace clang; | ||
using namespace llvm::opt; | ||
|
||
// Decode AArch64 features from string like +[no]featureA+[no]featureB+... | ||
static bool DecodeBPFFeatures(const Driver &D, StringRef text, | ||
std::vector<StringRef> &Features) { | ||
SmallVector<StringRef, 8> Split; | ||
text.split(Split, StringRef("+"), -1, false); | ||
|
||
for (StringRef Feature : Split) { | ||
if (Feature == "solana") | ||
Features.push_back("+solana"); | ||
else | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
static bool | ||
getBPFArchFeaturesFromMarch(const Driver &D, StringRef March, | ||
const ArgList &Args, | ||
std::vector<StringRef> &Features) { | ||
std::string MarchLowerCase = March.lower(); | ||
std::pair<StringRef, StringRef> Split = StringRef(MarchLowerCase).split("+"); | ||
|
||
return (Split.first == "bpfel" || Split.first == "bpfeb") && | ||
(Split.second.size() == 0 || DecodeBPFFeatures(D, Split.second, Features)); | ||
} | ||
|
||
void bpf::getBPFTargetFeatures(const Driver &D, const ArgList &Args, | ||
std::vector<StringRef> &Features) { | ||
printf("CHECK BPF FEATURES\n"); | ||
Arg *A; | ||
bool success = true; | ||
if ((A = Args.getLastArg(options::OPT_march_EQ))) | ||
success = getBPFArchFeaturesFromMarch(D, A->getValue(), Args, Features); | ||
if (!success) | ||
D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
//===--- BPF.h - BPF-specific Tool Helpers ----------------------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_BPF_H | ||
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_BPF_H | ||
|
||
#include "clang/Driver/Driver.h" | ||
#include "llvm/ADT/StringRef.h" | ||
#include "llvm/Option/Option.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
namespace clang { | ||
namespace driver { | ||
namespace tools { | ||
namespace bpf { | ||
|
||
void getBPFTargetFeatures(const Driver &D, const llvm::opt::ArgList &Args, | ||
std::vector<llvm::StringRef> &Features); | ||
|
||
} // end namespace bpf | ||
} // namespace tools | ||
} // end namespace driver | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_ARCH_BPF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.