34 uint32_t
size(
void)
const {
return _args.size(); }
37 const char *
at(uint32_t nth)
const {
return _args.at(nth).c_str(); }
42 _args.emplace_back(arg);
47 std::vector<std::string> _args;
64 void append(
const std::string &arg) { _args.append(arg); }
80 FrontendFactory(
const std::string &path)
82 _handle = dlopen(path.c_str(), RTLD_LAZY);
83 assert(_handle !=
nullptr);
88 FrontendFactory(
const FrontendFactory &) =
delete;
89 FrontendFactory(FrontendFactory &&) =
delete;
92 ~FrontendFactory() { dlclose(_handle); }
95 using Entry = std::unique_ptr<enco::Frontend> (*)(
const cmdline::View &);
98 Entry
entry(
void)
const
100 auto entry =
reinterpret_cast<Entry
>(dlsym(_handle,
"make_frontend"));
101 assert(entry !=
nullptr);
106 std::unique_ptr<enco::Frontend> make(
const cmdline::View *args)
const
121class FrontendZone :
public Zone
124 FrontendZone(
const std::string &path) : _factory{path}
130 const FrontendFactory *factory(
void)
const {
return &_factory; }
133 FrontendFactory _factory;
144static int entry(
int argc,
char **argv)
148 std::unique_ptr<FrontendZone> frontend_zone;
152 std::map<std::string, std::function<void(
const std::string &arg)>> argparse;
154 argparse[
"--frontend"] = [&](
const std::string &path) {
155 frontend_zone = std::make_unique<FrontendZone>(path);
158 argparse[
"--frontend-arg"] = [&](
const std::string &
arg) { frontend_zone->append(arg); };
159 argparse[
"--backend-arg"] = [&](
const std::string &
arg) { backend_args.
append(arg); };
163 std::cerr <<
"Usage:" << std::endl;
164 std::cerr <<
"[Command] --frontend [.so path]" << std::endl;
165 std::cerr <<
" --frontend-arg [argument] ..." << std::endl;
166 std::cerr <<
" --backend-arg [argument] ..." << std::endl;
170 for (
int n = 1; n <
argc; n += 2)
172 const std::string tag{
argv[n]};
173 const std::string
arg{
argv[n + 1]};
175 auto it = argparse.find(tag);
177 if (it == argparse.end())
179 std::cerr <<
"Option '" << tag <<
"' is not supported" << std::endl;
186 assert(frontend_zone !=
nullptr);
188 auto frontend = frontend_zone->factory()->make(frontend_zone->args());
190 auto bundle = frontend->load();
194 backend->compile(bundle.module(), bundle.data());
200int main(
int argc,
char **argv)
204 return entry(argc, argv);
206 catch (
const std::exception &e)
208 std::cerr <<
"ERROR: " << e.what() << std::endl;
218 return entry(argc, argv);
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)
std::unique_ptr< enco::Backend > make_backend(const cmdline::View &)