13#include "mlir/Bindings/Python/NanobindAdaptors.h"
15#include <nanobind/nanobind.h>
22class PyRtgToolOptions {
25 bool verifyPasses,
bool verbosePassExecution,
26 const std::vector<std::string> &unsupportedInstructions,
27 const std::string &unsupportedInstructionsFile,
28 bool splitOutput,
const std::string &outputPath,
29 bool memoriesAsImmediates)
31 setOutputFormat(outputFormat);
32 setVerifyPasses(verifyPasses);
33 setVerbosePassExecution(verbosePassExecution);
34 setUnsupportedInstructions(unsupportedInstructions);
35 setUnsupportedInstructionsFile(unsupportedInstructionsFile);
36 setSplitOutput(splitOutput);
37 setOutputPath(outputPath);
38 setMemoriesAsImmediates(memoriesAsImmediates);
42 operator CirctRtgToolOptions()
const {
return options; }
43 CirctRtgToolOptions
get()
const {
return options; }
51 void setVerifyPasses(
bool enable) {
55 void setVerbosePassExecution(
bool enable) {
60 setUnsupportedInstructions(
const std::vector<std::string> &instructions) {
62 options, instructions.size(),
63 reinterpret_cast<const void **
>(
64 const_cast<std::string *
>(instructions.data())));
67 void addUnsupportedInstruction(
const std::string &instruction) {
71 void setUnsupportedInstructionsFile(
const std::string &filename) {
76 void setSplitOutput(
bool enable) {
80 void setOutputPath(
const std::string &path) {
84 void setMemoriesAsImmediates(
bool enable) {
89 CirctRtgToolOptions options;
95 m.doc() =
"RTGTool Python native extension";
97 nb::enum_<CirctRtgToolOutputFormat>(m,
"OutputFormat")
102 nb::class_<PyRtgToolOptions>(m,
"Options")
104 const std::vector<std::string> &,
const std::string &,
bool,
105 const std::string &,
bool>(),
108 nb::arg(
"verify_passes") =
true,
109 nb::arg(
"verbose_pass_execution") =
false,
110 nb::arg(
"unsupported_instructions") = std::vector<const char *>(),
111 nb::arg(
"unsupported_instructions_file") =
"",
112 nb::arg(
"split_output") =
false, nb::arg(
"output_path") =
"",
113 nb::arg(
"memories_as_immediates") =
true)
114 .def(
"set_output_format", &PyRtgToolOptions::setOutputFormat,
115 "Specify the output format of the tool", nb::arg(
"format"))
116 .def(
"set_seed", &PyRtgToolOptions::setSeed,
117 "Specify the seed for all RNGs used in the tool", nb::arg(
"seed"))
118 .def(
"set_verify_passes", &PyRtgToolOptions::setVerifyPasses,
119 "Specify whether the verifiers should be run after each pass",
121 .def(
"set_verbose_pass_execution",
122 &PyRtgToolOptions::setVerbosePassExecution,
123 "Specify whether passes should run in verbose mode",
125 .def(
"set_unsupported_instructions",
126 &PyRtgToolOptions::setUnsupportedInstructions,
127 "Set the list of of instructions unsupported by the assembler",
128 nb::arg(
"instructions"))
129 .def(
"add_unsupported_instruction",
130 &PyRtgToolOptions::addUnsupportedInstruction,
131 "Add the instruction given by name to the list of instructions not "
132 "supported by the assembler",
133 nb::arg(
"instruction_name"))
134 .def(
"set_unsupported_instructions_file",
135 &PyRtgToolOptions::setUnsupportedInstructionsFile,
136 "Register a file containing a comma-separated list of instruction "
137 "names which are not supported by the assembler.",
139 .def(
"set_split_output", &PyRtgToolOptions::setSplitOutput,
140 "Determines whether each test should be emitted to a separate file.",
142 .def(
"output_path", &PyRtgToolOptions::setOutputPath,
143 "The path of a file to be emitted to or a directory if "
144 "'split_output' is enabled.",
146 .def(
"set_memories_as_immediates",
147 &PyRtgToolOptions::setMemoriesAsImmediates,
148 "Determines whether memories are lowered to immediates or labels.",
151 m.def(
"populate_randomizer_pipeline",
152 [](MlirPassManager pm,
const PyRtgToolOptions &options) {
Direction get(bool isOutput)
Returns an output direction if isOutput is true, otherwise returns an input direction.
void populateDialectRTGToolSubmodule(nanobind::module_ &m)
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.