CIRCT  18.0.0git
MIROps.cpp
Go to the documentation of this file.
1 //===- MIROps.cpp - Implement the Moore MIR operations --------------------===//
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 implement the Moore MIR ops.
10 //
11 //===----------------------------------------------------------------------===//
12 
14 #include "mlir/IR/Builders.h"
15 
16 using namespace circt;
17 using namespace circt::moore;
18 
19 //===----------------------------------------------------------------------===//
20 // Type Inference
21 //===----------------------------------------------------------------------===//
22 
23 LogicalResult ConcatOp::inferReturnTypes(
24  MLIRContext *context, std::optional<Location> loc, ValueRange operands,
25  DictionaryAttr attrs, mlir::OpaqueProperties properties,
26  mlir::RegionRange regions, SmallVectorImpl<Type> &results) {
27  Domain domain = Domain::TwoValued;
28  unsigned size = 0;
29  for (auto operand : operands) {
30  auto type = operand.getType().cast<UnpackedType>().getSimpleBitVector();
31  if (type.domain == Domain::FourValued)
32  domain = Domain::FourValued;
33  size += type.size;
34  }
35  results.push_back(
36  SimpleBitVectorType(domain, Sign::Unsigned, size).getType(context));
37  return success();
38 }
39 
40 //===----------------------------------------------------------------------===//
41 // Custom LValue parser and printer
42 //===----------------------------------------------------------------------===//
43 
44 static ParseResult parseLValueType(OpAsmParser &p, Type &lValueType) {
45  Type type;
46  if (p.parseType(type))
47  return p.emitError(p.getCurrentLocation(), "expected type");
48  lValueType = LValueType::get(type);
49  return success();
50 }
51 
52 static void printLValueType(OpAsmPrinter &p, Operation *, Type lValueType) {
53  p.printType(lValueType.cast<LValueType>().getNestedType());
54 }
55 
56 //===----------------------------------------------------------------------===//
57 // TableGen generated logic.
58 //===----------------------------------------------------------------------===//
59 
60 // Provide the autogenerated implementation guts for the Op classes.
61 #define GET_OP_CLASSES
62 #include "circt/Dialect/Moore/Moore.cpp.inc"
63 #include "circt/Dialect/Moore/MooreEnums.cpp.inc"
static ParseResult parseLValueType(OpAsmParser &p, Type &lValueType)
Definition: MIROps.cpp:44
static void printLValueType(OpAsmPrinter &p, Operation *, Type lValueType)
Definition: MIROps.cpp:52
An unpacked SystemVerilog type.
Definition: MooreTypes.h:282
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
Definition: CalyxOps.cpp:53
LogicalResult inferReturnTypes(MLIRContext *context, std::optional< Location > loc, ValueRange operands, DictionaryAttr attrs, mlir::OpaqueProperties properties, mlir::RegionRange regions, SmallVectorImpl< Type > &results, llvm::function_ref< FIRRTLType(ValueRange, ArrayRef< NamedAttribute >, std::optional< Location >)> callback)
Domain
The number of values each bit of a type can assume.
Definition: MooreTypes.h:27
@ FourValued
Four-valued types such as logic or integer.
@ TwoValued
Two-valued types such as bit or int.
@ Unsigned
An unsigned type.
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21
A simple bit vector type.
Definition: MooreTypes.h:134