[Mlir-commits] [mlir] [mlir] Add support for DIGlobalVariable and DIGlobalVariableExpression (PR #73367)

Tobias Gysi llvmlistbot at llvm.org
Thu Nov 30 23:46:54 PST 2023


================
@@ -109,3 +122,71 @@ bool MemoryEffectsAttr::isReadWrite() {
     return false;
   return true;
 }
+
+//===----------------------------------------------------------------------===//
+// DIExpression
+//===----------------------------------------------------------------------===//
+
+DIExpressionAttr DIExpressionAttr::get(MLIRContext *context) {
+  return get(context, ArrayRef<DIExpressionElemAttr>({}));
+}
+
+/// Parse DWARF expression arguments with respect to the DWARF operation
+/// opcode. Some DWARF expression operations have a specific number of operands
+/// and may appear in a textual form.
+LogicalResult parseExpressionArg(AsmParser &parser, uint64_t opcode,
+                                 SmallVector<uint64_t> &args) {
+  auto operandParser = [&]() -> LogicalResult {
+    uint64_t operand = 0;
+    if (!args.empty() && opcode == llvm::dwarf::DW_OP_LLVM_convert) {
+      // Attempt to parse a keyword.
+      StringRef keyword;
+      if (succeeded(parser.parseOptionalKeyword(&keyword))) {
+        operand = llvm::dwarf::getAttributeEncoding(keyword);
+        if (operand == 0) {
+          // The keyword is invalid.
+          return parser.emitError(parser.getCurrentLocation())
+                 << "encountered unknown attribute encoding \"" << keyword
+                 << "\"";
+        }
+      }
+    }
+
+    // operand should be non-zero if a keyword was parsed. Otherwise, the
+    // operand MUST be an integer.
+    if (operand == 0) {
+      // Parse the next operand as an integer.
+      if (parser.parseInteger(operand)) {
+        return parser.emitError(parser.getCurrentLocation())
+               << "expected integer operand";
+      }
+    }
+
+    args.push_back(operand);
+    return success();
+  };
+
+  // Parse operands as a comma-separated list.
+  return parser.parseCommaSeparatedList(operandParser);
+}
+
+/// Print DWARF expression arguments with respect to the specific DWARF
+/// operation. Some operands are printed in their textual form.
----------------
gysit wrote:

```suggestion
/// Print DWARF expression arguments with respect to the specific DWARF
/// operation. Some operands are printed in their textual form.
```
nit: you can drop the comment here since it is already on the declaration.

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


More information about the Mlir-commits mailing list