36 uint32_t
size(
void)
const {
return _args.size(); }
39 const char *
at(uint32_t nth)
const {
return _args.at(nth).c_str(); }
44 _args.emplace_back(arg);
49 std::vector<std::string> _args;
66 void append(
const std::string &arg) { _args.append(arg); }
82 FrontendFactory(
const std::string &path)
84 _handle = dlopen(path.c_str(), RTLD_LAZY);
85 assert(_handle !=
nullptr);
90 FrontendFactory(
const FrontendFactory &) =
delete;
91 FrontendFactory(FrontendFactory &&) =
delete;
94 ~FrontendFactory() { dlclose(_handle); }
97 using Entry = std::unique_ptr<enco::Frontend> (*)(
const cmdline::View &);
100 Entry
entry(
void)
const
102 auto entry =
reinterpret_cast<Entry
>(dlsym(_handle,
"make_frontend"));
103 assert(entry !=
nullptr);
108 std::unique_ptr<enco::Frontend> make(
const cmdline::View *args)
const
123class FrontendZone :
public Zone
126 FrontendZone(
const std::string &path) : _factory{path}
132 const FrontendFactory *factory(
void)
const {
return &_factory; }
135 FrontendFactory _factory;
159 std::unique_ptr<FrontendZone> frontend_zone;
162 std::map<std::string, std::function<void(
const std::string &arg)>> argparse;
164 argparse[
"--frontend"] = [&](
const std::string &path) {
165 frontend_zone = std::make_unique<FrontendZone>(path);
168 argparse[
"--frontend-arg"] = [&](
const std::string &arg) { frontend_zone->append(arg); };
172 std::cerr <<
"Usage:" << std::endl;
173 std::cerr <<
"[Command] --frontend [.so path]" << std::endl;
174 std::cerr <<
" --frontend-arg [argument] ..." << std::endl;
178 for (
int n = 1; n < argc; n += 2)
180 const std::string tag{argv[n]};
181 const std::string arg{argv[n + 1]};
183 auto it = argparse.find(tag);
185 if (it == argparse.end())
187 std::cerr <<
"Option '" << tag <<
"' is not supported" << std::endl;
194 assert(frontend_zone !=
nullptr);
196 auto frontend = frontend_zone->factory()->make(frontend_zone->args());
198 auto bundle = frontend->load();
201 dump(bundle.module());
Vector & append(const std::string &arg)
uint32_t size(void) const
const char * at(uint32_t nth) const
int entry(const int argc, char **argv)
int entry(int argc, char **argv)
void dump(const coco::Op *op, int indent)