LILAC
Language to language Interop LAyer Compiler
Loading...
Searching...
No Matches
generatesubcommand.cxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Yeong-won Seo
3 *
4 * This file is part of LILAC.
5 *
6 * LILAC is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3, or (at your option) any later
9 * version.
10 *
11 * LILAC is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include "generatesubcommand.h"
21
22#include "utils.h"
23
24static std::vector<llvm::cl::OptionEnumValue> GetBackends()
25{
26 std::vector<llvm::cl::OptionEnumValue> values;
27 for (const auto registered: lilac::shared::BackendAction::GetRegistered())
28 values.emplace_back(registered->Name(), registered->Kind(), registered->Desc());
29 return values;
30}
31
33 : SubCommand("bind", "Generate binding-assembly from symbols"),
34 OutputPath{
35 "o",
36 llvm::cl::ValueRequired,
37 llvm::cl::init("."),
38 llvm::cl::cat(GetCategory()),
39 llvm::cl::sub(*this),
40 llvm::cl::value_desc("dir"),
41 llvm::cl::desc("Place the output into <dir>")
42 },
43 Language{
44 "to",
45 llvm::cl::Required,
46 llvm::cl::desc("Specify the language ID of the binding-assembly"),
47 llvm::cl::cat(GetCategory()),
48 llvm::cl::sub(*this),
49 llvm::cl::ValuesClass(GetInitializerList(GetBackends()))
50 },
51 SymbolFile{
52 "sym",
53 llvm::cl::Required,
54 llvm::cl::value_desc("file"),
55 llvm::cl::desc("Read symbols from <file>"),
56 llvm::cl::cat(GetCategory()),
57 llvm::cl::sub(*this)
58 },
59 ReferenceName{
60 "name",
61 llvm::cl::Required,
62 llvm::cl::desc("<library-name>"),
63 llvm::cl::cat(GetCategory()),
64 llvm::cl::sub(*this)
65 },
66 Argv{
67 llvm::cl::Sink,
68 llvm::cl::desc("<language-specific-args>..."),
69 llvm::cl::cat(GetCategory()),
70 llvm::cl::sub(*this)
71 }
72{
73}
74
76{
77 for (const auto registered: shared::BackendAction::GetRegistered())
78 {
79 if (registered->Kind() == Language.getValue())
80 return registered->Run(
81 SymbolFile.getValue(),
82 ReferenceName.getValue(),
83 OutputPath.getValue(),
84 Argv);
85 }
86
87 llvm::errs() << "No such language-id '" << Language.ValueStr << "'\n";
88 return -1;
89}
int Run() override
Runs a subcommand.
An abstraction class of llvm::cl::SubCommand
Definition subcommand.h:30
static const std::vector< BackendAction * > & GetRegistered()
Gets all registered actions.
Definition backend.cxx:49
std::initializer_list< T > GetInitializerList(std::vector< T > vector)
Definition utils.h:25