MLLIF
a MLIR-based Language to Language Interoperability Flyover
Loading...
Searching...
No Matches
main.cxx
Go to the documentation of this file.
1/*
2 * Copyright 2025 Yeong-won Seo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "pch.h"
18
19#include <cstring>
20#include <memory>
23#include <mllif/Backend/Decl.h>
24#include <mllif/Backend/Stdin.h>
25
26static void PrintErrors(const mllif::MLLIFContext &context) {
27 for (auto error : context.errors()) {
28 std::cerr << "\x1b[0;31merror\x1b[0m: " << error.what() << std::endl;
29 }
30}
31
32static void PrintHelp() {
33 std::cout << "syntax: mllif-cs <library-name>"
34 << "usage: mllif-cs mylib.so < mylib.msm > mylib.cs";
35}
36
37auto main(int argc, char *argv[]) -> int {
38 mllif::MLLIFContext context;
39 std::vector<char> msm;
40 rapidxml::xml_document<> doc;
41 std::shared_ptr<mllif::Decl> root;
42
43 if (argc < 2) {
44 context.error("missing library name; see help");
45 goto ERROR;
46 }
47
48 if (strcmp(argv[1], "--help") == 0 ||
49 strcmp(argv[1], "-h") == 0) {
50 PrintHelp();
51 return EXIT_SUCCESS;
52 }
53
55 doc.parse<0>(msm.data());
56
57 root = mllif::Decl::Create(context, doc.first_node(), nullptr);
58
59 if (!context) {
60 goto ERROR;
61 }
62
63 {
64 mllif::cs::CsBridgeGen wrapperGen(argv[1]);
65 wrapperGen.handleDecl(context, root, std::cout, 0);
66
67 if (!context) {
68 goto ERROR;
69 }
70 }
71
72 return EXIT_SUCCESS;
73
74 ERROR:
75 PrintErrors(context);
76 return EXIT_FAILURE;
77}
auto main() -> int
Definition main.cxx:33
bool handleDecl(MLLIFContext &context, const std::shared_ptr< Decl > &node, std::ostream &out, std::size_t indent)
Definition BridgeGen.cxx:20
static std::shared_ptr< Decl > Create(MLLIFContext &context, rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.cxx:60
const std::vector< Error > & errors() const
Definition Context.h:33
void error(const std::string &what)
Definition Context.h:35
static std::vector< char > ReadToEnd()
Reads stdin until EOF.
Definition Stdin.cxx:20