CIRCT  20.0.0git
CHIRRTLTypes.cpp
Go to the documentation of this file.
1 //===- CHIRRTLTypes.cpp - Implement the CHIRRTL dialect -----------------===//
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 // This file implements the CHIRRTL dialect type system.
10 //
11 //===----------------------------------------------------------------------===//
12 
18 #include "circt/Support/LLVM.h"
19 #include "mlir/IR/DialectImplementation.h"
20 #include "mlir/IR/OpDefinition.h"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/TypeSwitch.h"
23 
24 using namespace mlir;
25 using namespace circt;
26 using namespace chirrtl;
27 using namespace firrtl;
28 
29 #define GET_TYPEDEF_CLASSES
30 #include "circt/Dialect/FIRRTL/CHIRRTLTypes.cpp.inc"
31 
32 //===----------------------------------------------------------------------===//
33 // CMemory Type
34 //===----------------------------------------------------------------------===//
35 
36 void CMemoryType::print(AsmPrinter &printer) const {
37  printer << "<";
38  // Don't print element types with "!firrtl.".
39  firrtl::printNestedType(getElementType(), printer);
40  printer << ", " << getNumElements() << ">";
41 }
42 
43 Type CMemoryType::parse(AsmParser &parser) {
45  uint64_t numElements;
46  if (parser.parseLess() || firrtl::parseNestedBaseType(elementType, parser) ||
47  parser.parseComma() || parser.parseInteger(numElements) ||
48  parser.parseGreater())
49  return {};
50  return parser.getChecked<CMemoryType>(elementType, numElements);
51 }
52 
53 LogicalResult CMemoryType::verify(function_ref<InFlightDiagnostic()> emitError,
55  uint64_t numElements) {
56  if (!elementType.isPassive()) {
57  return emitError() << "behavioral memory element type must be passive";
58  }
59  return success();
60 }
61 
62 //===----------------------------------------------------------------------===//
63 // CHIRRTLDialect
64 //===----------------------------------------------------------------------===//
65 
66 void CHIRRTLDialect::registerTypes() {
67  addTypes<
68 #define GET_TYPEDEF_LIST
69 #include "circt/Dialect/FIRRTL/CHIRRTLTypes.cpp.inc"
70  >();
71 }
MlirType uint64_t numElements
Definition: CHIRRTL.cpp:30
MlirType elementType
Definition: CHIRRTL.cpp:29
static LogicalResult verify(Value clock, bool eventExists, mlir::Location loc)
Definition: SVOps.cpp:2467
ParseResult parseNestedBaseType(FIRRTLBaseType &result, AsmParser &parser)
void printNestedType(Type type, AsmPrinter &os)
Print a type defined by this dialect.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
Definition: DebugAnalysis.h:21