mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Parser.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <exception>
6
#include <memory>
7
#include <optional>
8
#include <string>
9
#include <utility>
10
#include <vector>
11
12
#include "
mini-llvm/ir/BasicBlock.h
"
13
#include "
mini-llvm/ir/Constant.h
"
14
#include "
mini-llvm/ir/Function.h
"
15
#include "
mini-llvm/ir/GlobalVar.h
"
16
#include "
mini-llvm/ir/Instruction.h
"
17
#include "
mini-llvm/ir/Module.h
"
18
#include "
mini-llvm/ir/Type.h
"
19
#include "
mini-llvm/ir/Value.h
"
20
#include "
mini-llvm/ir_reader/Symbol.h
"
21
#include "
mini-llvm/ir_reader/Token.h
"
22
#include "
mini-llvm/utils/Compiler.h
"
23
24
namespace
mini_llvm::ir
{
25
26
class
ParseException
:
public
std::exception {
27
public
:
28
ParseException
(std::string
message
, std::vector<Token>::const_iterator
location
)
29
: message_(std::move(
message
)), location_(
location
) {}
30
31
const
std::string &
message
() const & {
32
return
message_;
33
}
34
35
std::string &&
message
() && {
36
return
std::move(message_);
37
}
38
39
std::vector<Token>::const_iterator
location
()
const
{
40
return
location_;
41
}
42
43
const
char
*
what
() const noexcept
override
{
44
return
"ParseException"
;
45
}
46
47
private
:
48
std::string message_;
49
std::vector<Token>::const_iterator location_;
50
};
51
52
class
MINI_LLVM_EXPORT
Parser
{
53
public
:
54
explicit
Parser
(std::vector<Token>::const_iterator current);
55
56
~Parser
();
57
58
Parser
(
Parser
&&) noexcept;
59
Parser
&operator=(
Parser
&&) noexcept;
60
61
Module
parseModule
();
62
std::shared_ptr<
GlobalVar
>
parseGlobalVarHeader
(
bool
&isDeclaration);
63
void
parseGlobalVarInitializer
(
GlobalVar
&G);
64
std::shared_ptr<
Function
>
parseFunctionHeader
(
bool
&isDeclaration);
65
void
parseFunctionBody
(
Function
&F);
66
void
parseBasicBlock
(
BasicBlock
&B);
67
std::shared_ptr<
Instruction
>
parseInstruction
();
68
std::shared_ptr<
Value
>
parseValue
(const
Type
&type);
69
std::shared_ptr<
Value
>
parseIdentifier
(const
Type
&type);
70
std::shared_ptr<
Constant
>
parseConstant
(const
Type
&type);
71
std::unique_ptr<
Type
>
parseType
();
72
Symbol
parseSymbol
(std::optional<
Symbol
::Scope> scope = std::nullopt);
73
74
private:
75
class Impl;
76
77
std::unique_ptr<Impl> impl_;
78
};
79
80
MINI_LLVM_EXPORT
Module
parseModule
(const std::vector<
Token
> &tokens);
81
82
}
// namespace mini_llvm::ir
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
Token.h
Type.h
Value.h
mini_llvm::ir::BasicBlock
Definition
BasicBlock.h:28
mini_llvm::ir::Constant
Definition
Constant.h:13
mini_llvm::ir::Function
Definition
Function.h:34
mini_llvm::ir::GlobalVar
Definition
GlobalVar.h:20
mini_llvm::ir::Instruction
Definition
Instruction.h:22
mini_llvm::ir::Module
Definition
Module.h:22
mini_llvm::ir::ParseException::message
const std::string & message() const &
Definition
Parser.h:31
mini_llvm::ir::ParseException::message
std::string && message() &&
Definition
Parser.h:35
mini_llvm::ir::ParseException::ParseException
ParseException(std::string message, std::vector< Token >::const_iterator location)
Definition
Parser.h:28
mini_llvm::ir::ParseException::location
std::vector< Token >::const_iterator location() const
Definition
Parser.h:39
mini_llvm::ir::ParseException::what
const char * what() const noexcept override
Definition
Parser.h:43
mini_llvm::ir::Parser::parseModule
Module parseModule()
mini_llvm::ir::Parser::parseGlobalVarInitializer
void parseGlobalVarInitializer(GlobalVar &G)
mini_llvm::ir::Parser::~Parser
~Parser()
mini_llvm::ir::Parser::parseInstruction
std::shared_ptr< Instruction > parseInstruction()
mini_llvm::ir::Parser::Parser
Parser(Parser &&) noexcept
mini_llvm::ir::Parser::parseFunctionBody
void parseFunctionBody(Function &F)
mini_llvm::ir::Parser::parseType
std::unique_ptr< Type > parseType()
mini_llvm::ir::Parser::parseFunctionHeader
std::shared_ptr< Function > parseFunctionHeader(bool &isDeclaration)
mini_llvm::ir::Parser::parseGlobalVarHeader
std::shared_ptr< GlobalVar > parseGlobalVarHeader(bool &isDeclaration)
mini_llvm::ir::Parser::parseConstant
std::shared_ptr< Constant > parseConstant(const Type &type)
mini_llvm::ir::Parser::parseSymbol
Symbol parseSymbol(std::optional< Symbol::Scope > scope=std::nullopt)
mini_llvm::ir::Parser::parseBasicBlock
void parseBasicBlock(BasicBlock &B)
mini_llvm::ir::Parser::parseValue
std::shared_ptr< Value > parseValue(const Type &type)
mini_llvm::ir::Parser::parseIdentifier
std::shared_ptr< Value > parseIdentifier(const Type &type)
mini_llvm::ir::Parser::Parser
Parser(std::vector< Token >::const_iterator current)
mini_llvm::ir::Type
Definition
Type.h:18
mini_llvm::ir::Value
Definition
Value.h:24
BasicBlock.h
Constant.h
Function.h
GlobalVar.h
Instruction.h
Module.h
Symbol.h
mini_llvm::ir
Definition
Argument.h:13
mini_llvm::ir::parseModule
MINI_LLVM_EXPORT std::optional< Module > parseModule(const char *source)
mini_llvm::ir::Symbol
Definition
Symbol.h:13
mini_llvm::ir::Token
Definition
Token.h:15
include
mini-llvm
ir_reader
Parser.h
Generated by
1.17.0