summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f5b7351)
raw | patch | inline | side by side (parent: f5b7351)
author | Pete Cooper <peter_cooper@apple.com> | |
Thu, 7 Aug 2014 05:47:00 +0000 (05:47 +0000) | ||
committer | Pete Cooper <peter_cooper@apple.com> | |
Thu, 7 Aug 2014 05:47:00 +0000 (05:47 +0000) |
Instead of these becoming an integer literal internally, they now become bits<n> values.
Prior to this change, 0b001 was 1 bit long. This is confusing as clearly the user gave 3 bits.
This new type holds both the literal value and the size, and so can ensure sizes match on initializers.
For example, this used to be legal
bits<1> x = 0b00;
but now it must be written as
bits<2> x = 0b00;
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215084 91177308-0d34-0410-b5e6-96231b3b80d8
Prior to this change, 0b001 was 1 bit long. This is confusing as clearly the user gave 3 bits.
This new type holds both the literal value and the size, and so can ensure sizes match on initializers.
For example, this used to be legal
bits<1> x = 0b00;
but now it must be written as
bits<2> x = 0b00;
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215084 91177308-0d34-0410-b5e6-96231b3b80d8
lib/TableGen/TGLexer.cpp | patch | blob | history | |
lib/TableGen/TGLexer.h | patch | blob | history | |
lib/TableGen/TGParser.cpp | patch | blob | history | |
test/TableGen/BitsInit.td | patch | blob | history |
index cfcc119f82d3638adc4f436b892b26a3cc8fda78..63b85842d6a9e68910ecd32eb78be621abbb1ed7 100644 (file)
--- a/lib/TableGen/TGLexer.cpp
+++ b/lib/TableGen/TGLexer.cpp
if (CurPtr == NumStart)
return ReturnError(CurPtr-2, "Invalid binary number");
CurIntVal = strtoll(NumStart, nullptr, 2);
- return tgtok::IntVal;
+ return tgtok::BinaryIntVal;
}
}
diff --git a/lib/TableGen/TGLexer.h b/lib/TableGen/TGLexer.h
index c7f7306a1492e82a506ae0391069f1a99fd27804..9fb2e3536e0bf8a97cecd424660c2d3bc3cb7cd6 100644 (file)
--- a/lib/TableGen/TGLexer.h
+++ b/lib/TableGen/TGLexer.h
// Integer value.
IntVal,
+
+ // Binary constant. Note that these are sized according to the number of
+ // bits given.
+ BinaryIntVal,
// String valued tokens.
Id, StrVal, VarName, CodeFragment
assert(CurCode == tgtok::IntVal && "This token isn't an integer");
return CurIntVal;
}
+ std::pair<int64_t, unsigned> getCurBinaryIntVal() const {
+ assert(CurCode == tgtok::BinaryIntVal &&
+ "This token isn't a binary integer");
+ return std::make_pair(CurIntVal, (CurPtr - TokStart)-2);
+ }
SMLoc getLoc() const;
index d020a8bdc1a3f3ecfabd798083089f1cef841918..709c7a52b9f9fda327e1904a6db234b19f0ac1a5 100644 (file)
Lex.Lex(); // Skip '#'.
return ParseSimpleValue(CurRec, ItemType, Mode);
case tgtok::IntVal: R = IntInit::get(Lex.getCurIntVal()); Lex.Lex(); break;
+ case tgtok::BinaryIntVal: {
+ auto BinaryVal = Lex.getCurBinaryIntVal();
+ SmallVector<Init*, 16> Bits(BinaryVal.second);
+ for (unsigned i = 0, e = BinaryVal.second; i != e; ++i)
+ Bits[i] = BitInit::get(BinaryVal.first & (1 << i));
+ R = BitsInit::get(Bits);
+ Lex.Lex();
+ break;
+ }
case tgtok::StrVal: {
std::string Val = Lex.getCurStrVal();
Lex.Lex();
index 28fd3196fd0c394558b86d197f2aad8c9d45fb0b..c3d5113ebdb4ba736cf33d07bc1591a432d7c908 100644 (file)
// CHECK: bits<2> b = { 1, 0 };
// CHECK: bits<2> c = { 1, 1 };
// CHECK: }
+
+def {
+ bits<2> B1 = 0b011; // bitfield is too small, reject
+ bits<3> B2 = 0b011; // ok
+
+ bits<2> C1 = 0b111; // bitfield is too small, reject
+ bits<3> C2 = 0b111; // ok
+
+ bits<2> D1 = { 0, 0 }; // ok
+ bits<2> D2 = { 0b00 }; // ok
+ bits<3> D3 = { 0, 0 }; // type mismatch. RHS doesn't have enough bits
+ bits<3> D4 = { 0b00 }; // type mismatch. RHS doesn't have enough bits
+ bits<1> D5 = { 0 }; // ok
+ bits<1> D6 = { 1 }; // ok
+ bits<1> D7 = { 3 }; // type mismatch. LHS doesn't have enough bits
+ bits<2> D8 = { 0 }; // type mismatch. RHS doesn't have enough bits
+
+ bits<8> E;
+ let E{7-0} = {0,0,1,?,?,?,?,?};
+ let E{3-0} = 0b0010;
+}
+
+// CHECK: def {{.*}} {
+// CHECK: bits<2> B1;
+// CHECK: bits<3> B2 = { 0, 1, 1 };
+// CHECK: bits<2> C1;
+// CHECK: bits<3> C2 = { 1, 1, 1 };
+// CHECK: bits<2> D1 = { 0, 0 };
+// CHECK: bits<2> D2 = { 0, 0 };
+// CHECK: bits<3> D3;
+// CHECK: bits<3> D4;
+// CHECK: bits<1> D5 = { 0 };
+// CHECK: bits<1> D6 = { 1 };
+// CHECK: bits<1> D7 = { ? };
+// CHECK: bits<2> D8;
+// CHECK: bits<8> E = { 0, 0, 1, ?, 0, 0, 1, 0 };
+// CHECK: }