LILAC
Language to language Interop LAyer Compiler
Loading...
Searching...
No Matches
compilesymbolsubcommand.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
21
22#include "utils.h"
23#include "shared/frontend.h"
24
25static std::vector<llvm::cl::OptionEnumValue> GetFrontends()
26{
27 std::vector<llvm::cl::OptionEnumValue> values;
28 for (const auto registered: lilac::shared::FrontendAction::GetRegistered())
29 values.emplace_back(registered->Name(), registered->Kind(), registered->Desc());
30 return values;
31}
32
34 : SubCommand("sym", "Compile target-assembly into symbols"),
35 Language{
36 "from",
37 llvm::cl::Required,
38 llvm::cl::ValuesClass(GetInitializerList(GetFrontends())),
39 llvm::cl::desc("<langauge id>"),
40 llvm::cl::cat(GetCategory()),
41 llvm::cl::sub(*this),
42 },
43 OutputFile{
44 "o",
45 llvm::cl::Required,
46 llvm::cl::desc("<output file>"),
47 llvm::cl::cat(GetCategory()),
48 llvm::cl::sub(*this),
49 },
50 Argv{
51 llvm::cl::Sink,
52 llvm::cl::desc("<language-specific args>..."),
53 llvm::cl::cat(GetCategory()),
54 llvm::cl::sub(*this)
55 }
56{
57}
58
60{
61 for (const auto registered: shared::FrontendAction::GetRegistered())
62 {
63 if (registered->Kind() == Language.getValue())
64 return registered->Run(OutputFile.getValue(), Argv);
65 }
66
67 llvm::errs() << "No such language-id '" << Language.ValueStr << "'\n";
68 return -1;
69}
int Run() override
Runs a subcommand.
An abstraction class of llvm::cl::SubCommand
Definition subcommand.h:30
static const std::vector< FrontendAction * > & GetRegistered()
Gets all registered actions.
Definition frontend.cxx:46
std::initializer_list< T > GetInitializerList(std::vector< T > vector)
Definition utils.h:25