Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/SharedDependencies/Sources/nihstro/parser_assembly/floatop.cpp
2 views
1
// Copyright 2014 Tony Wasserka
2
// All rights reserved.
3
//
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
6
//
7
// * Redistributions of source code must retain the above copyright
8
// notice, this list of conditions and the following disclaimer.
9
// * Redistributions in binary form must reproduce the above copyright
10
// notice, this list of conditions and the following disclaimer in the
11
// documentation and/or other materials provided with the distribution.
12
// * Neither the name of the owner nor the names of its contributors may
13
// be used to endorse or promote products derived from this software
14
// without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28
29
// Enable this for detailed XML overview of parser results
30
// #define BOOST_SPIRIT_DEBUG
31
32
#include <boost/fusion/include/adapt_struct.hpp>
33
#include <boost/phoenix/core/reference.hpp>
34
#include <boost/spirit/include/qi.hpp>
35
36
#include "nihstro/parser_assembly.h"
37
#include "nihstro/parser_assembly_private.h"
38
39
#include "nihstro/shader_binary.h"
40
#include "nihstro/shader_bytecode.h"
41
42
namespace spirit = boost::spirit;
43
namespace qi = boost::spirit::qi;
44
namespace ascii = boost::spirit::qi::ascii;
45
namespace phoenix = boost::phoenix;
46
47
using spirit::_1;
48
using spirit::_2;
49
using spirit::_3;
50
using spirit::_4;
51
52
using namespace nihstro;
53
54
// Adapt parser data structures for use with boost::spirit
55
56
BOOST_FUSION_ADAPT_STRUCT(
57
StatementInstruction,
58
(OpCode, opcode)
59
(std::vector<Expression>, expressions)
60
)
61
62
template<>
63
FloatOpParser<ParserIterator>::FloatOpParser(const ParserContext& context)
64
: FloatOpParser::base_type(float_instruction),
65
common(context),
66
opcodes_float(common.opcodes_float),
67
expression(common.expression),
68
end_of_statement(common.end_of_statement),
69
diagnostics(common.diagnostics) {
70
71
// Setup rules
72
73
auto comma_rule = qi::lit(',');
74
75
for (int i = 0; i < 4; ++i) {
76
// Make sure that a mnemonic is always followed by a space (such that e.g. "addbla" fails to match)
77
opcode[i] = qi::no_case[qi::lexeme[opcodes_float[i] >> &ascii::space]];
78
}
79
80
// chain of arguments for each group of opcodes
81
expression_chain[0] = expression;
82
for (int i = 1; i < 4; ++i) {
83
expression_chain[i] = (expression_chain[i - 1] >> comma_rule) > expression;
84
}
85
86
// e.g. "add o1, t2, t5"
87
float_instr[0] = opcode[0] > expression_chain[0];
88
float_instr[1] = opcode[1] > expression_chain[1];
89
float_instr[2] = opcode[2] > expression_chain[2];
90
float_instr[3] = opcode[3] > expression_chain[3];
91
92
float_instruction %= (float_instr[0] | float_instr[1] | float_instr[2] | float_instr[3]) > end_of_statement;
93
94
// Error handling
95
// BOOST_SPIRIT_DEBUG_NODE(opcode[0]);
96
// BOOST_SPIRIT_DEBUG_NODE(opcode[1]);
97
// BOOST_SPIRIT_DEBUG_NODE(opcode[2]);
98
// BOOST_SPIRIT_DEBUG_NODE(opcode[3]);
99
100
// BOOST_SPIRIT_DEBUG_NODE(expression_chain[0]);
101
// BOOST_SPIRIT_DEBUG_NODE(expression_chain[1]);
102
// BOOST_SPIRIT_DEBUG_NODE(expression_chain[2]);
103
// BOOST_SPIRIT_DEBUG_NODE(expression_chain[3]);
104
105
// BOOST_SPIRIT_DEBUG_NODE(float_instr[0]);
106
// BOOST_SPIRIT_DEBUG_NODE(float_instr[1]);
107
// BOOST_SPIRIT_DEBUG_NODE(float_instr[2]);
108
// BOOST_SPIRIT_DEBUG_NODE(float_instr[3]);
109
// BOOST_SPIRIT_DEBUG_NODE(float_instruction);
110
111
diagnostics.Add(expression_chain[0].name(), "one argument");
112
diagnostics.Add(expression_chain[1].name(), "two arguments");
113
diagnostics.Add(expression_chain[2].name(), "three arguments");
114
diagnostics.Add(expression_chain[3].name(), "four arguments");
115
116
// qi::on_error<qi::fail>(float_instruction, error_handler(phoenix::ref(diagnostics), _1, _2, _3, _4));
117
}
118
119