OSDN Git Service

Implement pointer arithmetic.
[android-x86/external-swiftshader.git] / src / Reactor / Main.cpp
1 // Copyright 2016 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "Reactor.hpp"
16
17 #include <cassert>
18
19 using namespace sw;
20
21 int reference(int *p, int y)
22 {
23         int x = p[-1];
24         int z = 4;
25
26         for(int i = 0; i < 10; i++)
27         {
28                 z += (2 << i) - (i / 3);
29         }
30
31         int sum = x + y + z;
32    
33         return sum;
34 }
35
36 int main()
37 {
38         Routine *routine = nullptr;
39
40         {
41                 Function<Int(Pointer<Int>, Int)> function;
42                 {
43                         Pointer<Int> p = function.Arg<0>();
44                         Int x = p[-1];
45                         Int y = function.Arg<1>();
46                         Int z = 4;
47
48                         For(Int i = 0, i < 10, i++)
49                         {
50                                 z += (2 << i) - (i / 3);
51                         }
52
53                         Int sum = x + y + z;
54    
55                         Return(sum);
56                 }
57
58                 routine = function(L"one");
59
60                 if(routine)
61                 {
62                         int (*callable)(int*, int) = (int(*)(int*,int))routine->getEntry();
63                         int one[2] = {1, 0};
64                         int result = callable(&one[1], 2);
65                         assert(result == reference(&one[1], 2));
66                 }
67         }
68
69         delete routine;
70
71         return 0;
72 }