MLLIF
a MLIR-based Language to Language Interoperability Flyover
Loading...
Searching...
No Matches
Decl.h
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#pragma once
18
19#include <vector>
20#include <memory>
21#include <rapidxml/rapidxml.hpp>
22
23namespace mllif {
24 class MLLIFContext;
25
26 class Type {
27 std::vector<std::string> _terms;
28 std::size_t _refs;
29 bool _builtin = false;
30
31 public:
32 Type() = default;
33 Type(MLLIFContext& context, std::string name);
34
35 const std::vector<std::string>& terms() const { return _terms; }
36 std::size_t refs() const { return _refs; }
37 bool builtin() const { return _builtin; }
38 };
39
40 class Decl {
41 std::string _name;
42 std::vector<std::shared_ptr<Decl>> _children;
43 std::shared_ptr<Decl> _parent;
44
45 public:
46 Decl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent);
47 virtual ~Decl() = default;
48
49 const std::string& name() const { return _name; }
50 const std::vector<std::shared_ptr<Decl>>& children() const { return _children; }
51 const std::shared_ptr<Decl>& parent() const { return _parent; }
52
53 static std::shared_ptr<Decl> Create(MLLIFContext& context, rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent);
54 };
55
56 class AssemblyDecl final : public Decl {
57 public:
58 AssemblyDecl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent) : Decl(context, node, parent) {};
59 };
60
61 class NamespaceDecl final : public Decl {
62 public:
63 NamespaceDecl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent) : Decl(context, node, parent) {};
64 };
65
66 class ObjectDecl final : public Decl {
67 std::string _size;
68 std::string _align;
69
70 public:
71 ObjectDecl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent);
72
73 const std::string& size() const { return _size; }
74 const std::string& align() const { return _align; }
75 };
76
77 class FunctionDecl : public Decl {
78 Type _returns;
79 std::string _symbol;
80
81 public:
82 FunctionDecl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent);
83
84 const Type& returns() const { return _returns; }
85 const std::string& symbol() const { return _symbol; }
86 };
87
88 class MethodDecl final : public FunctionDecl {
89 public:
90 MethodDecl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent) : FunctionDecl(context, node, parent) {};
91 };
92
93 class ParamDecl final : public Decl {
94 Type _type;
95
96 public:
97 ParamDecl(MLLIFContext& context, const rapidxml::xml_node<> *node, std::shared_ptr<Decl> parent);
98
99 const Type& type() const { return _type; }
100 };
101}
AssemblyDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.h:58
virtual ~Decl()=default
static std::shared_ptr< Decl > Create(MLLIFContext &context, rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.cxx:60
const std::shared_ptr< Decl > & parent() const
Definition Decl.h:51
const std::vector< std::shared_ptr< Decl > > & children() const
Definition Decl.h:50
Decl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.cxx:45
const std::string & name() const
Definition Decl.h:49
FunctionDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.cxx:99
const Type & returns() const
Definition Decl.h:84
const std::string & symbol() const
Definition Decl.h:85
MethodDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.h:90
NamespaceDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.h:63
ObjectDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.cxx:91
const std::string & align() const
Definition Decl.h:74
const std::string & size() const
Definition Decl.h:73
const Type & type() const
Definition Decl.h:99
ParamDecl(MLLIFContext &context, const rapidxml::xml_node<> *node, std::shared_ptr< Decl > parent)
Definition Decl.cxx:117
Type()=default
std::size_t refs() const
Definition Decl.h:36
const std::vector< std::string > & terms() const
Definition Decl.h:35
bool builtin() const
Definition Decl.h:37