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/compare.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
IntegerWithSign,
58
(int, sign)
59
(unsigned, value)
60
)
61
*/
62
BOOST_FUSION_ADAPT_STRUCT(
63
CompareInstruction,
64
(OpCode, opcode)
65
(std::vector<Expression>, arguments)
66
(std::vector<Instruction::Common::CompareOpType::Op>, ops)
67
)
68
69
template<>
70
CompareParser<ParserIterator>::CompareParser(const ParserContext& context)
71
: CompareParser::base_type(instruction),
72
common(context),
73
opcodes_compare(common.opcodes_compare),
74
expression(common.expression),
75
end_of_statement(common.end_of_statement),
76
diagnostics(common.diagnostics) {
77
78
// TODO: Will this properly match >= ?
79
compare_ops.add
80
( "==", CompareOp::Equal )
81
( "!=", CompareOp::NotEqual )
82
( "<", CompareOp::LessThan )
83
( "<=", CompareOp::LessEqual )
84
( ">", CompareOp::GreaterThan )
85
( ">=", CompareOp::GreaterEqual );
86
87
// Setup rules
88
89
auto comma_rule = qi::lit(',');
90
91
opcode = qi::no_case[qi::lexeme[opcodes_compare >> &ascii::space]];
92
compare_op = qi::lexeme[compare_ops];
93
94
// cmp src1, src2, op1, op2
95
// TODO: Also allow "cmp src1 op1 src2, src1 op2 src2"
96
two_ops = compare_op > comma_rule > compare_op;
97
two_expressions = expression > comma_rule > expression;
98
instr[0] = opcode > two_expressions > comma_rule > two_ops;
99
100
instruction = instr[0] > end_of_statement;
101
102
// Error handling
103
// BOOST_SPIRIT_DEBUG_NODE(instr[0]);
104
// BOOST_SPIRIT_DEBUG_NODE(instruction);
105
106
// qi::on_error<qi::fail>(instruction, error_handler(phoenix::ref(diagnostics), _1, _2, _3, _4));
107
}
108
109