Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/Dialect/HW/HWDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ Operation *HWDialect::materializeConstant(OpBuilder &builder, Attribute value,
}

// Parameter expressions materialize into hw.param.value.
auto parentOp = builder.getBlock()->getParentOp();
Block *block = builder.getBlock();
if (!block)
return nullptr;
auto parentOp = block->getParentOp();
auto curModule = dyn_cast<HWModuleOp>(parentOp);
if (!curModule)
curModule = parentOp->getParentOfType<HWModuleOp>();
Expand Down
1 change: 1 addition & 0 deletions unittests/Dialect/HW/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ add_circt_unittest(CIRCTHWTests
HWModuleTest.cpp
InstanceGraphTest.cpp
InstancePathTest.cpp
MaterializerTest.cpp
)

target_link_libraries(CIRCTHWTests
Expand Down
31 changes: 31 additions & 0 deletions unittests/Dialect/HW/MaterializerTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "circt/Dialect/HW/HWDialect.h"
#include "mlir/IR/Builders.h"
#include "gtest/gtest.h"

using namespace circt;
using namespace hw;

namespace {

TEST(MaterializerTest, ImmediateAttr) {
MLIRContext context;
context.loadDialect<HWDialect>();
Location loc(UnknownLoc::get(&context));
OpBuilder builder(&context);

// Check that we don't crash on non-sensical materializations.
auto attr = builder.getI8IntegerAttr(42);
auto type = builder.getF64Type();
context.getLoadedDialect<HWDialect>()->materializeConstant(builder, attr,
type, loc);
}

} // namespace