CIRCT 20.0.0git
Loading...
Searching...
No Matches
ESIAttributes.cpp
Go to the documentation of this file.
1//===- ESIAttributes.cpp - Implement ESI dialect attributes -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10
11#include "mlir/IR/Builders.h"
12#include "mlir/IR/BuiltinAttributes.h"
13#include "mlir/IR/DialectImplementation.h"
14#include "llvm/ADT/TypeSwitch.h"
15#include "llvm/Support/Base64.h"
16
17using namespace circt;
18using namespace esi;
19
20AppIDPathAttr AppIDPathAttr::getParent() {
21 ArrayRef<AppIDAttr> path = getPath();
22 if (path.empty())
23 return {};
24 return AppIDPathAttr::get(getContext(), getRoot(), path.drop_back());
25}
26
27Attribute BlobAttr::parse(AsmParser &odsParser, Type odsType) {
28 std::string base64;
29 if (odsParser.parseLess() || odsParser.parseString(&base64) ||
30 odsParser.parseGreater())
31 return {};
32 std::vector<char> data;
33 if (auto err = llvm::decodeBase64(base64, data)) {
34 llvm::handleAllErrors(std::move(err), [&](const llvm::ErrorInfoBase &eib) {
35 odsParser.emitError(odsParser.getNameLoc(), eib.message());
36 });
37 return {};
38 }
39 ArrayRef<uint8_t> unsignedData(reinterpret_cast<const uint8_t *>(data.data()),
40 data.size());
41 return BlobAttr::get(odsParser.getBuilder().getContext(), unsignedData);
42}
43void BlobAttr::print(AsmPrinter &odsPrinter) const {
44 odsPrinter << "<\"" << llvm::encodeBase64(getData()) << "\">";
45}
46
47#define GET_ATTRDEF_CLASSES
48#include "circt/Dialect/ESI/ESIAttributes.cpp.inc"
49
50void ESIDialect::registerAttributes() {
51 addAttributes<
52#define GET_ATTRDEF_LIST
53#include "circt/Dialect/ESI/ESIAttributes.cpp.inc"
54 >();
55}
Root class of the ESI type system.
Definition Types.h:27
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition esi.py:1