[llvm] [TableGen] Emit Debug code for dynamic bits(eg: instruction operands) in DecoderEmitter (PR #194699)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 22 07:33:53 PDT 2026
================
@@ -683,6 +683,61 @@ static std::vector<EncodingIsland> getIslands(const KnownBits &EncodingBits,
return Islands;
}
+/// Emit:
+/// if (!Check(...)) {
+/// LLVM_DEBUG(<Helper>(<Args>));
+/// [DecodeComplete = false;]
+/// return MCDisassembler::Fail;
+/// }
+static void emitCheckWithDbgMsg(raw_ostream &OS, indent Indent,
+ const Twine &CheckCall, StringRef Helper,
+ const Twine &Args,
+ bool SetDecodeCompleteOnFail) {
+ OS << Indent << "if (!Check(S, " << CheckCall << ")) {\n";
+ OS << Indent << " LLVM_DEBUG(" << Helper << "(" << Args << "));\n";
+ if (SetDecodeCompleteOnFail)
+ OS << Indent << " DecodeComplete = false;\n";
+ OS << Indent << " return MCDisassembler::Fail;\n";
+ OS << Indent << "}\n";
+}
+
+/// Operand-level decoder (emitBinaryParser).
+static void emitDecoderCheckWithOpcDebug(raw_ostream &OS, indent Indent,
+ const OperandInfo &OpInfo,
+ const Twine &CheckCall) {
+ StringRef OpName = OpInfo.Name.empty() ? "opd" : OpInfo.Name;
+ StringRef DecoderName = OpInfo.Decoder;
+
+ std::string Args;
+ raw_string_ostream AS(Args);
+ if (OpInfo.Fields.empty()) {
+ const char *Desc = OpInfo.InitValue ? "imm" : "bits<0>";
+ AS << '"' << OpName << "\", \"" << Desc << "\", \"" << DecoderName << '"';
+ } else {
+ AS << '"' << OpName << "\", \"" << DecoderName << "\", {";
+ ListSeparator LS;
+ for (const EncodingField &EF : OpInfo.Fields)
+ AS << LS << EF.Base << ", " << EF.Width;
+ AS << '}';
+ }
+
+ emitCheckWithDbgMsg(OS, Indent, CheckCall, "reportOperandDecodeFailure", Args,
+ !OpInfo.HasCompleteDecoder);
+}
+
+/// Whole-instruction \p DecoderMethod. Used when the encoding
+/// has a custom \p DecoderMethod (whole-instruction decoder).
+static void emitDecoderMethodOpcDebug(raw_ostream &OS, indent Indent,
----------------
jurahul wrote:
nit: this function is called only once. Would it make sense to just inline it?
https://github.com/llvm/llvm-project/pull/194699
More information about the llvm-commits
mailing list