Loading [MathJax]/extensions/tex2jax.js
CIRCT 21.0.0git
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RTGTestTypes.cpp
Go to the documentation of this file.
1//===- RTGTestTypes.cpp ---------------------------------------------------===//
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
14#include "mlir/IR/Builders.h"
15#include "mlir/IR/DialectImplementation.h"
16#include "llvm/ADT/TypeSwitch.h"
17
18using namespace circt;
19using namespace rtgtest;
20
21//===----------------------------------------------------------------------===//
22// TableGen generated logic.
23//===----------------------------------------------------------------------===//
24
25#define GET_TYPEDEF_CLASSES
26#include "circt/Dialect/RTGTest/IR/RTGTestTypes.cpp.inc"
27
28//===----------------------------------------------------------------------===//
29// IntegerRegisterType
30//===----------------------------------------------------------------------===//
31
32bool IntegerRegisterType::isValidContentType(Type type) const {
33 return llvm::isa<rtg::ImmediateType>(type);
34}
35
36Attribute IntegerRegisterType::parseContentValue(llvm::StringRef valueString,
37 Type contentType) const {
38 auto immType = dyn_cast<rtg::ImmediateType>(contentType);
39 if (!immType)
40 return {};
41
42 APInt intValue;
43 if (valueString.getAsInteger(16, intValue))
44 return {};
45
46 if (intValue.getBitWidth() < immType.getWidth()) {
47 intValue = intValue.zext(immType.getWidth());
48 } else {
49 if (!intValue.isIntN(immType.getWidth()))
50 return {};
51 intValue = intValue.trunc(immType.getWidth());
52 }
53
54 return rtg::ImmediateAttr::get(getContext(), intValue);
55}
56
57std::string IntegerRegisterType::getIntrinsicLabel(Attribute value,
58 llvm::StringRef id) const {
59 return "spike.pre.printreg.x" +
60 std::to_string(
61 cast<rtg::RegisterAttrInterface>(value).getClassIndex()) +
62 "." + id.str();
63}
64
65//===----------------------------------------------------------------------===//
66// Type registration
67//===----------------------------------------------------------------------===//
68
69void circt::rtgtest::RTGTestDialect::registerTypes() {
70 addTypes<
71#define GET_TYPEDEF_LIST
72#include "circt/Dialect/RTGTest/IR/RTGTestTypes.cpp.inc"
73 >();
74}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.