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 <memory>
24#include <mllif/Backend/Decl.h>
25#include <mllif/Backend/Stdin.h>
26
27static void PrintErrors(const mllif::MLLIFContext &context) {
28 for (auto error : context.errors()) {
29 std::cerr << "\x1b[0;31merror\x1b[0m: " << error.what() << std::endl;
30 }
31}
32
33auto main() -> int {
34 auto msm = mllif::Stdin::ReadToEnd();
35
36 rapidxml::xml_document<> doc;
37 doc.parse<0>(msm.data());
38
39 mllif::MLLIFContext context;
40 const auto root = mllif::Decl::Create(context, doc.first_node(), nullptr);
41
42 if (!context) {
43 goto ERROR;
44 }
45
46 {
48 declGen.handleDecl(context, root, std::cout, 0);
49
50 if (!context) {
51 goto ERROR;
52 }
53 }
54
55 {
56 mllif::cxx::CxxBridgeGen wrapperGen;
57 wrapperGen.handleDecl(context, root, std::cout, 0);
58
59 if (!context) {
60 goto ERROR;
61 }
62 }
63
64 return EXIT_SUCCESS;
65
66ERROR:
67 PrintErrors(context);
68 return EXIT_FAILURE;
69}
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
static std::vector< char > ReadToEnd()
Reads stdin until EOF.
Definition Stdin.cxx:20