[llvm] [RISCV][MC] Implement ISA mapping symbols (PR #67541)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 11 12:10:38 PST 2024


================
@@ -66,6 +86,69 @@ void RISCVTargetELFStreamer::emitAttribute(unsigned Attribute, unsigned Value) {
 void RISCVTargetELFStreamer::emitTextAttribute(unsigned Attribute,
                                                StringRef String) {
   getStreamer().setAttributeItem(Attribute, String, /*OverwriteExisting=*/true);
+  if (Attribute == RISCVAttrs::ARCH)
+    setArchString(String);
+}
+
+void RISCVTargetELFStreamer::emitDirectiveOptionArch(
+    ArrayRef<RISCVOptionArchArg> Args) {
+  if (Args.size() == 1) {
+    RISCVOptionArchArg Arg = Args[0];
+    if (Arg.Type == RISCVOptionArchArgType::Full) {
+      // If there is a full arch string, then just set the arch string and
+      // return. It is illegal to have more than one argument with this option.
+      setArchString(Arg.Value);
+      return;
+    }
+  }
+
+  auto ParseResult = RISCVISAInfo::parseArchString(ISAString, false);
+  if (!ParseResult) {
+    std::string Buffer;
+    raw_string_ostream OutputErrMsg(Buffer);
+    handleAllErrors(ParseResult.takeError(), [&](llvm::StringError &ErrMsg) {
+      OutputErrMsg << "invalid arch name '" << ISAString << "', "
+                   << ErrMsg.getMessage();
+    });
+    return;
+  }
+  auto &ISAInfo = *ParseResult;
+  std::vector<std::string> NewFeatures = ISAInfo->toFeatureVector();
+  for (RISCVOptionArchArg Arg : Args) {
----------------
topperc wrote:

Maybe `const RISCVOptionArchArg &Arg`?

https://github.com/llvm/llvm-project/pull/67541


More information about the llvm-commits mailing list