llvm.org GIT mirror llvm / a034e07
AsmWriter/Bitcode: MDExpression git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229023 91177308-0d34-0410-b5e6-96231b3b80d8 Duncan P. N. Exon Smith 4 years ago
11 changed file(s) with 123 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
162162 METADATA_TEMPLATE_TYPE = 25, // [distinct, scope, name, type, ...]
163163 METADATA_TEMPLATE_VALUE= 26, // [distinct, scope, name, type, value, ...]
164164 METADATA_GLOBAL_VAR = 27, // [distinct, ...]
165 METADATA_LOCAL_VAR = 28 // [distinct, ...]
165 METADATA_LOCAL_VAR = 28, // [distinct, ...]
166 METADATA_EXPRESSION = 29 // [distinct, n x element]
166167 };
167168
168169 // The constants block (CONSTANTS_BLOCK_ID) describes emission for each
747747 DWKEYWORD(ATE, DwarfAttEncoding);
748748 DWKEYWORD(VIRTUALITY, DwarfVirtuality);
749749 DWKEYWORD(LANG, DwarfLang);
750 DWKEYWORD(OP, DwarfOp);
750751 #undef DWKEYWORD
751752
752753 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
35983598 return false;
35993599 }
36003600
3601 /// ParseMDExpression:
3602 /// ::= !MDExpression(0, 7, -1)
36013603 bool LLParser::ParseMDExpression(MDNode *&Result, bool IsDistinct) {
3602 return TokError("unimplemented parser");
3603 }
3604 assert(Lex.getKind() == lltok::MetadataVar && "Expected metadata type name");
3605 Lex.Lex();
3606
3607 if (ParseToken(lltok::lparen, "expected '(' here"))
3608 return true;
3609
3610 SmallVector Elements;
3611 if (Lex.getKind() != lltok::rparen)
3612 do {
3613 if (Lex.getKind() == lltok::DwarfOp) {
3614 if (unsigned Op = dwarf::getOperationEncoding(Lex.getStrVal())) {
3615 Lex.Lex();
3616 Elements.push_back(Op);
3617 continue;
3618 }
3619 return TokError(Twine("invalid DWARF op '") + Lex.getStrVal() + "'");
3620 }
3621
3622 if (Lex.getKind() != lltok::APSInt || Lex.getAPSIntVal().isSigned())
3623 return TokError("expected unsigned integer");
3624
3625 auto &U = Lex.getAPSIntVal();
3626 if (U.ugt(UINT64_MAX))
3627 return TokError("element too large, limit is " + Twine(UINT64_MAX));
3628 Elements.push_back(U.getZExtValue());
3629 Lex.Lex();
3630 } while (EatIfPresent(lltok::comma));
3631
3632 if (ParseToken(lltok::rparen, "expected ')' here"))
3633 return true;
3634
3635 Result = GET_OR_DISTINCT(MDExpression, (Context, Elements));
3636 return false;
3637 }
3638
36043639 bool LLParser::ParseMDObjCProperty(MDNode *&Result, bool IsDistinct) {
36053640 return TokError("unimplemented parser");
36063641 }
197197 LocalVar, // %foo %"foo"
198198 MetadataVar, // !foo
199199 StringConstant, // "foo"
200 DwarfTag, // DW_TAG_foo (includes "DW_TAG_")
201 DwarfAttEncoding, // DW_ATE_foo (includes "DW_ATE_")
202 DwarfVirtuality, // DW_VIRTUALITY_foo (includes "DW_VIRTUALITY_")
203 DwarfLang, // DW_LANG_foo (includes "DW_LANG_")
200 DwarfTag, // DW_TAG_foo
201 DwarfAttEncoding, // DW_ATE_foo
202 DwarfVirtuality, // DW_VIRTUALITY_foo
203 DwarfLang, // DW_LANG_foo
204 DwarfOp, // DW_OP_foo
204205
205206 // Type valued tokens (TyVal).
206207 Type,
15511551 NextMDValueNo++);
15521552 break;
15531553 }
1554 case bitc::METADATA_EXPRESSION: {
1555 if (Record.size() < 1)
1556 return Error("Invalid record");
1557
1558 MDValueList.AssignValue(
1559 GET_OR_DISTINCT(MDExpression, Record[0],
1560 (Context, makeArrayRef(Record).slice(1))),
1561 NextMDValueNo++);
1562 break;
1563 }
15541564 case bitc::METADATA_STRING: {
15551565 std::string String(Record.begin(), Record.end());
15561566 llvm::UpgradeMDStringConstant(String);
10911091 Record.clear();
10921092 }
10931093
1094 static void WriteMDExpression(const MDExpression *, const ValueEnumerator &,
1095 BitstreamWriter &, SmallVectorImpl &,
1096 unsigned) {
1097 llvm_unreachable("write not implemented");
1098 }
1094 static void WriteMDExpression(const MDExpression *N, const ValueEnumerator &,
1095 BitstreamWriter &Stream,
1096 SmallVectorImpl &Record,
1097 unsigned Abbrev) {
1098 Record.reserve(N->getElements().size() + 1);
1099
1100 Record.push_back(N->isDistinct());
1101 for (uint64_t I : N->getElements())
1102 Record.push_back(I);
1103
1104 Stream.EmitRecord(bitc::METADATA_EXPRESSION, Record, Abbrev);
1105 Record.clear();
1106 }
1107
10991108 static void WriteMDObjCProperty(const MDObjCProperty *, const ValueEnumerator &,
11001109 BitstreamWriter &, SmallVectorImpl &,
11011110 unsigned) {
17801780 Out << ")";
17811781 }
17821782
1783 static void writeMDExpression(raw_ostream &, const MDExpression *,
1784 TypePrinting *, SlotTracker *, const Module *) {
1785 llvm_unreachable("write not implemented");
1786 }
1783 static void writeMDExpression(raw_ostream &Out, const MDExpression *N,
1784 TypePrinting *TypePrinter, SlotTracker *Machine,
1785 const Module *Context) {
1786 Out << "!MDExpression(";
1787 FieldSeparator FS;
1788 if (N->isValid()) {
1789 for (auto I = N->expr_op_begin(), E = N->expr_op_end(); I != E; ++I) {
1790 const char *OpStr = dwarf::OperationEncodingString(I->getOp());
1791 assert(OpStr && "Expected valid opcode");
1792
1793 Out << FS << OpStr;
1794 for (unsigned A = 0, AE = I->getNumArgs(); A != AE; ++A)
1795 Out << FS << I->getArg(A);
1796 }
1797 } else {
1798 for (const auto &I : N->getElements())
1799 Out << FS << I;
1800 }
1801 Out << ")";
1802 }
1803
17871804 static void writeMDObjCProperty(raw_ostream &, const MDObjCProperty *,
17881805 TypePrinting *, SlotTracker *, const Module *) {
17891806 llvm_unreachable("write not implemented");
0 ; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
1
2 ; CHECK-NOT: error
3 !0 = !MDExpression(18446744073709551615)
4
5 ; CHECK: :[[@LINE+1]]:20: error: element too large, limit is 18446744073709551615
6 !1 = !MDExpression(18446744073709551616)
0 ; RUN: not llvm-as -disable-output < %s 2>&1 | FileCheck -check-prefix VERIFY %s
1 ; RUN: llvm-as -disable-verify < %s | llvm-dis | FileCheck -check-prefix NOVERIFY %s
2
3 ; NOVERIFY: !named = !{!0}
4 !named = !{!0}
5
6 ; NOVERIFY: !0 = !MDExpression(0, 1, 9, 7, 2)
7 ; VERIFY: assembly parsed, but does not verify
8 !0 = !MDExpression(0, 1, 9, 7, 2)
0 ; RUN: llvm-as < %s | llvm-dis | llvm-as | llvm-dis | FileCheck %s
1 ; RUN: verify-uselistorder %s
2
3 ; CHECK: !named = !{!0, !1, !2, !3, !4}
4 !named = !{!0, !1, !2, !3, !4}
5
6 ; CHECK: !0 = !MDExpression()
7 ; CHECK-NEXT: !1 = !MDExpression(DW_OP_deref)
8 ; CHECK-NEXT: !2 = !MDExpression(DW_OP_plus, 3)
9 ; CHECK-NEXT: !3 = !MDExpression(DW_OP_bit_piece, 3, 7)
10 ; CHECK-NEXT: !4 = !MDExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
11 !0 = !MDExpression()
12 !1 = !MDExpression(DW_OP_deref)
13 !2 = !MDExpression(DW_OP_plus, 3)
14 !3 = !MDExpression(DW_OP_bit_piece, 3, 7)
15 !4 = !MDExpression(DW_OP_deref, DW_OP_plus, 3, DW_OP_bit_piece, 3, 7)
7878 syn match llvmType /!\zs\a\+\ze\s*(/
7979 syn match llvmConstant /\/
8080 syn match llvmConstant /\/
81 syn match llvmConstant /\/
8182 syn match llvmConstant /\/
8283 syn match llvmConstant /\/
8384