CIRCT 24.0.0git
Loading...
Searching...
No Matches
LLHDTypes.cpp
Go to the documentation of this file.
1//===- LLHDTypes.cpp - LLHD types and attributes code defs ----------------===//
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//
9// Implementation for LLHD data types.
10//
11//===----------------------------------------------------------------------===//
12
16#include "mlir/IR/Builders.h"
17#include "mlir/IR/DialectImplementation.h"
18#include "llvm/ADT/TypeSwitch.h"
19
20using namespace circt::llhd;
21using namespace mlir;
22
23#define GET_TYPEDEF_CLASSES
24#include "circt/Dialect/LLHD/LLHDTypes.cpp.inc"
25
26#define GET_ATTRDEF_CLASSES
27#include "circt/Dialect/LLHD/LLHDAttributes.cpp.inc"
28
29//===----------------------------------------------------------------------===//
30// Wrapper Type
31//===----------------------------------------------------------------------===//
32
34 return TypeSwitch<WrapperType, Type>(*this).Case<RefType, NetType>(
35 [](auto type) { return type.getNestedType(); });
36}
37
38//===----------------------------------------------------------------------===//
39// Time Attribute
40//===----------------------------------------------------------------------===//
41
42/// Parse a time attribute.
43/// Syntax: timeattr ::= #llhd.time<[time][timeUnit], [delta]d>
44Attribute TimeAttr::parse(AsmParser &p, Type type) {
45 llvm::StringRef timeUnit;
46 uint64_t time = 0;
47 unsigned delta = 0;
48
49 // parse the time value
50 if (p.parseLess() || p.parseInteger(time) || p.parseKeyword(&timeUnit))
51 return {};
52
53 // parse the delta step value
54 if (p.parseComma() || p.parseInteger(delta) || p.parseKeyword("d") ||
55 p.parseGreater())
56 return {};
57
58 // return a new instance of time attribute
59 auto loc = p.getEncodedSourceLoc(p.getCurrentLocation());
60 return getChecked(mlir::detail::getDefaultDiagnosticEmitFn(loc),
61 p.getContext(), time, timeUnit, delta);
62}
63
64void TimeAttr::print(AsmPrinter &p) const {
65 p << "<" << getTime() << getTimeUnit() << ", " << getDelta() << "d>";
66}
67
68LogicalResult TimeAttr::verify(function_ref<InFlightDiagnostic()> emitError,
69 TimeType type, uint64_t time,
70 llvm::StringRef timeUnit, unsigned delta) {
71 // Check the time unit is a legal SI unit
72 std::vector<std::string> legalUnits{"ys", "zs", "as", "fs", "ps",
73 "ns", "us", "ms", "s"};
74 if (llvm::find(legalUnits, timeUnit) == legalUnits.end())
75 return emitError() << "Illegal time unit.";
76
77 return success();
78}
79
80//===----------------------------------------------------------------------===//
81// Register attributes and types to the LLHD Dialect
82//===----------------------------------------------------------------------===//
83
84void LLHDDialect::registerTypes() {
85 addTypes<
86#define GET_TYPEDEF_LIST
87#include "circt/Dialect/LLHD/LLHDTypes.cpp.inc"
88 >();
89}
90
91void LLHDDialect::registerAttributes() {
92 addAttributes<
93#define GET_ATTRDEF_LIST
94#include "circt/Dialect/LLHD/LLHDAttributes.cpp.inc"
95 >();
96}
return success()
mlir::Type getNestedType() const
Get the wrapped type.
Definition LLHDTypes.cpp:33