summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Parser/Token.cpp
diff options
context:
space:
mode:
authorChris Lattner <clattner@google.com>2018-07-04 20:45:39 -0700
committerjpienaar <jpienaar@google.com>2019-03-29 12:29:16 -0700
commitb0dabbd67f34966a72e41c1a8817756e07d50091 (patch)
tree1d77f0de0ab06d16587bd554bd39c7264463bf99 /mlir/lib/Parser/Token.cpp
parentccd8caee9eddbb1932184e78fbca7cea827b8b6f (diff)
downloadbcm5719-llvm-b0dabbd67f34966a72e41c1a8817756e07d50091.tar.gz
bcm5719-llvm-b0dabbd67f34966a72e41c1a8817756e07d50091.zip
Add parsing for attributes and attibutes on operations. Add IR representation
for attributes on operations. Split Operation out from OperationInst so it can be shared with OperationStmt one day. PiperOrigin-RevId: 203325366
Diffstat (limited to 'mlir/lib/Parser/Token.cpp')
-rw-r--r--mlir/lib/Parser/Token.cpp29
1 files changed, 25 insertions, 4 deletions
diff --git a/mlir/lib/Parser/Token.cpp b/mlir/lib/Parser/Token.cpp
index e1e4bedf28f..e6e0ebf0a2c 100644
--- a/mlir/lib/Parser/Token.cpp
+++ b/mlir/lib/Parser/Token.cpp
@@ -48,9 +48,21 @@ Optional<unsigned> Token::getUnsignedIntegerValue() const {
return result;
}
+/// For an integer token, return its value as a uint64_t. If it doesn't fit,
+/// return None.
+Optional<uint64_t> Token::getUInt64IntegerValue() const {
+ bool isHex = spelling.size() > 1 && spelling[1] == 'x';
+
+ uint64_t result = 0;
+ if (spelling.getAsInteger(isHex ? 0 : 10, result))
+ return None;
+ return result;
+}
+
+
/// For an inttype token, return its bitwidth.
Optional<unsigned> Token::getIntTypeBitwidth() const {
- unsigned result = 0;
+ unsigned result = 0;
if (spelling[1] == '0' ||
spelling.drop_front().getAsInteger(10, result) ||
// Arbitrary but large limit on bitwidth.
@@ -74,11 +86,20 @@ std::string Token::getStringValue() const {
/// token as a string. Warning: This will abort on markers, identifiers and
/// literal tokens since they have no fixed spelling.
StringRef Token::getTokenSpelling(Kind kind) {
- switch (kind) {
- default: assert(0 && "This token kind has no fixed spelling");
+ switch (kind) {
+ default: assert(0 && "This token kind has no fixed spelling");
#define TOK_PUNCTUATION(NAME, SPELLING) case NAME: return SPELLING;
#define TOK_OPERATOR(NAME, SPELLING) case NAME: return SPELLING;
#define TOK_KEYWORD(SPELLING) case kw_##SPELLING: return #SPELLING;
#include "TokenKinds.def"
- }
+ }
+}
+
+/// Return true if this is one of the keyword token kinds (e.g. kw_if).
+bool Token::isKeyword() const {
+ switch (kind) {
+ default: return false;
+#define TOK_KEYWORD(SPELLING) case kw_##SPELLING: return true;
+#include "TokenKinds.def"
+ }
}
OpenPOWER on IntegriCloud