7
7
// ===----------------------------------------------------------------------===//
8
8
9
9
#include " mlir/Tools/mlir-link/MlirLinkMain.h"
10
+ #include " mlir/IR/Builders.h"
11
+ #include " mlir/IR/BuiltinOps.h"
10
12
#include " mlir/IR/Dialect.h"
13
+ #include " mlir/IR/Location.h"
14
+ #include " mlir/IR/OwningOpRef.h"
15
+ #include " mlir/Support/FileUtilities.h"
11
16
#include " llvm/Support/CommandLine.h"
12
17
#include " llvm/Support/Error.h"
13
18
#include " llvm/Support/InitLLVM.h"
19
+ #include " llvm/Support/ToolOutputFile.h"
14
20
#include " llvm/Support/WithColor.h"
15
21
16
22
using namespace mlir ;
17
23
using namespace llvm ;
18
24
25
+ OwningOpRef<ModuleOp> makeCompositeModule (MLIRContext *context) {
26
+ OpBuilder builder (context);
27
+ ModuleOp op =
28
+ builder.create <ModuleOp>(FileLineColLoc::get (context, " mlir-link" , 0 , 0 ));
29
+ OwningOpRef<ModuleOp> composite (op);
30
+ return composite;
31
+ }
32
+
19
33
LogicalResult mlir::MlirLinkMain (int argc, char **argv,
20
34
DialectRegistry ®istry) {
21
35
static cl::OptionCategory linkCategory (" Link options" );
@@ -28,13 +42,33 @@ LogicalResult mlir::MlirLinkMain(int argc, char **argv,
28
42
" o" , cl::desc (" Override output filename" ), cl::init (" -" ),
29
43
cl::value_desc (" filename" ), cl::cat (linkCategory));
30
44
31
- static ExitOnError ExitOnErr;
45
+ static cl::opt<bool > verbose (
46
+ " v" , cl::desc (" Print information about actions taken" ),
47
+ cl::cat (linkCategory));
48
+
49
+ static ExitOnError exitOnErr;
32
50
33
51
InitLLVM y (argc, argv);
34
- ExitOnErr .setBanner (std::string (argv[0 ]) + " : " );
52
+ exitOnErr .setBanner (std::string (argv[0 ]) + " : " );
35
53
36
54
cl::HideUnrelatedOptions ({&linkCategory, &getColorCategory ()});
37
55
cl::ParseCommandLineOptions (argc, argv, " mlir linker\n " );
38
56
57
+ MLIRContext context (registry);
58
+ auto composite = makeCompositeModule (&context);
59
+
60
+ std::string errorMessage;
61
+
62
+ auto output = openOutputFile (outputFilename, &errorMessage);
63
+ if (!output) {
64
+ errs () << errorMessage;
65
+ return failure ();
66
+ }
67
+
68
+ if (verbose)
69
+ errs () << " Writing linked module to '" << outputFilename << " '\n " ;
70
+
71
+ composite.get ()->print (output->os ());
72
+ output->keep ();
39
73
return success ();
40
74
}
0 commit comments