[clang] [llvm] [clangd] Add support for the c2000 architecture (PR #125663)
James Nagurne via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 4 14:50:29 PST 2025
================
@@ -0,0 +1,356 @@
+#include "C2000.h"
+#include "Targets.h"
+#include "clang/Basic/Builtins.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/MacroBuilder.h"
+#include "clang/Basic/TargetBuiltins.h"
+
+using namespace clang;
+using namespace clang::targets;
+
+const char *const C2000TargetInfo::GCCRegNames[] = {
+ "ACC", "XAR0", "XAR1", "XAR2", "XAR3", "XAR4", "XAR5", "XAR6", "XAR7"};
+
+ArrayRef<const char *> C2000TargetInfo::getGCCRegNames() const {
+ return llvm::ArrayRef(GCCRegNames);
+}
+
+bool C2000TargetInfo::handleTargetFeatures(std::vector<std::string> &Features,
+ DiagnosticsEngine &Diags) {
+
+ for (const auto &Feature : Features) {
+ if (Feature == "+eabi") {
+ eabi = true;
+ continue;
+ }
+ if (Feature == "+strict_ansi") {
+ strict = true;
+ continue;
+ }
+ if (Feature == "+cla_support") {
+ cla_support = true;
+ }
+ if (Feature == "+cla0") {
+ cla0 = true;
+ continue;
+ }
+ if (Feature == "+cla1") {
+ cla1 = true;
+ continue;
+ }
+ if (Feature == "+cla2") {
+ cla2 = true;
+ continue;
+ }
+ if (Feature == "+relaxed") {
+ relaxed = true;
+ continue;
+ }
+ if (Feature == "+fpu64") {
+ fpu64 = true;
+ continue;
+ }
+ if (Feature == "+fpu32") {
+ fpu32 = true;
+ continue;
+ }
+ if (Feature == "+tmu_support") {
+ tmu_support = true;
+ }
+ if (Feature == "+tmu1") {
+ tmu1 = true;
+ continue;
+ }
+ if (Feature == "+idiv0") {
+ idiv0 = true;
+ continue;
+ }
+ if (Feature == "+vcu_support") {
+ vcu_support = true;
+ }
+ if (Feature == "+vcu2") {
+ vcu2 = true;
+ continue;
+ }
+ if (Feature == "+vcrc") {
+ vcrc = true;
+ continue;
+ }
+ if (Feature == "+opt_level") {
+ opt = true;
+ continue;
+ }
+ }
+ return true;
+}
+
+bool C2000TargetInfo::hasFeature(StringRef Feature) const {
+ return llvm::StringSwitch<bool>(Feature)
+ .Case("eabi", eabi)
+ .Case("strict_ansi", strict)
+ .Case("cla-support", cla_support)
+ .Case("cla0", cla0)
+ .Case("cla1", cla1)
+ .Case("cla2", cla2)
+ .Case("relaxed", relaxed)
+ .Case("fpu64", fpu64)
+ .Case("fpu32", fpu32)
+ .Case("tmu-support", tmu_support)
+ .Case("tmu1", tmu1)
+ .Case("vcu-support", vcu_support)
+ .Case("vcu2", vcu2)
+ .Case("vcrc", vcrc)
+ .Case("opt-level", opt)
+ .Default(false);
+}
+
+void C2000TargetInfo::getTargetDefines(const LangOptions &Opts,
+ MacroBuilder &Builder) const {
+ Builder.undefineMacro("__CHAR_BIT__"); // FIXME: Implement 16-bit char
----------------
DragonDisciple wrote:
This is my biggest red flag for this PR.
The clang frontend very explicitly disallows char width that is not 8 due to -some issue- that's not very well described.
This undefine/define is hacking around that assertion failure, leading to an 8-bit char but a __CHAR_BIT__ of 16.
https://github.com/llvm/llvm-project/pull/125663
More information about the llvm-commits
mailing list