CIRCT 22.0.0git
Loading...
Searching...
No Matches
InsertTestToFileMappingPass.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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
12#include "circt/Support/Path.h"
13#include "llvm/ADT/SmallString.h"
14
15namespace circt {
16namespace rtg {
17#define GEN_PASS_DEF_INSERTTESTTOFILEMAPPINGPASS
18#include "circt/Dialect/RTG/Transforms/RTGPasses.h.inc"
19} // namespace rtg
20} // namespace circt
21
22using namespace mlir;
23using namespace circt;
24using namespace circt::rtg;
25
26//===----------------------------------------------------------------------===//
27// Insert Test To File Mapping Pass
28//===----------------------------------------------------------------------===//
29
30namespace {
31struct InsertTestToFileMappingPass
32 : public rtg::impl::InsertTestToFileMappingPassBase<
33 InsertTestToFileMappingPass> {
34 using Base::Base;
35 void runOnOperation() override;
36};
37} // namespace
38
39void InsertTestToFileMappingPass::runOnOperation() {
40 SmallVector<TestOp> tests(getOperation().getOps<TestOp>());
41 auto loc = getOperation().getLoc();
42 if (!splitOutput) {
43 OpBuilder builder = OpBuilder::atBlockEnd(getOperation().getBody());
44 auto fileOp = emit::FileOp::create(builder, loc, path);
45 builder.setInsertionPointToStart(fileOp.getBody());
46 for (auto testOp : tests)
47 emit::RefOp::create(builder, loc, testOp.getSymNameAttr());
48
49 return;
50 }
51
52 if (path.empty() || path == "-") {
53 emitError(loc, "path must be specified when split-output is set");
54 return signalPassFailure();
55 }
56
57 for (auto testOp : tests) {
58 OpBuilder builder = OpBuilder::atBlockEnd(getOperation().getBody());
59 llvm::SmallString<128> filename(path.getValue());
60 appendPossiblyAbsolutePath(filename, testOp.getSymName() + ".s");
61 auto fileOp = emit::FileOp::create(builder, loc, filename);
62 OpBuilder::InsertionGuard guard(builder);
63 builder.setInsertionPointToStart(fileOp.getBody());
64 emit::RefOp::create(builder, loc, testOp.getSymNameAttr());
65 }
66}
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.
void appendPossiblyAbsolutePath(llvm::SmallVectorImpl< char > &base, const llvm::Twine &suffix)
Append a path to an existing path, replacing it if the other path is absolute.
Definition Path.cpp:26
Definition emit.py:1
Definition rtg.py:1