1 /*
2  * Copyright 2017, The Android Open Source Project
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 #ifndef CORE_DEFS_H
18 #define CORE_DEFS_H
19 
20 #include <string>
21 
22 namespace android {
23 namespace spirit {
24 
25 class Instruction;
26 
27 typedef int32_t LiteralInteger;
28 typedef std::string LiteralString;
29 typedef union {
30   int32_t intValue;
31   int64_t longValue;
32   float floatValue;
33   double doubleValue;
34 } LiteralContextDependentNumber;
35 typedef uint32_t LiteralExtInstInteger;
36 typedef uint32_t LiteralSpecConstantOpInteger;
37 typedef uint32_t IdResult;
38 
39 struct IdRef {
IdRefIdRef40   IdRef() : mId(0), mInstruction(nullptr) {}
41   IdRef(Instruction *inst);
42 
43   uint32_t mId;
44   mutable Instruction *mInstruction;
45 };
46 
47 // TODO: specialize these ref types
48 // TODO: should only reference type instructions
49 struct IdResultType : public IdRef {
IdResultTypeIdResultType50   IdResultType() : IdRef() {}
IdResultTypeIdResultType51   IdResultType(Instruction *inst) : IdRef(inst) {}
52 };
53 
54 // TODO: should only reference int representing memory semeantics
55 struct IdMemorySemantics : public IdRef {};
56 // TODO: should only reference int representing scopes
57 struct IdScope : public IdRef {};
58 
59 struct OpCodeAndWordCount {
OpCodeAndWordCountOpCodeAndWordCount60   OpCodeAndWordCount() : mOpCode(0) {}
OpCodeAndWordCountOpCodeAndWordCount61   OpCodeAndWordCount(uint32_t codeAndCount)
62       : mOpCode((uint16_t)codeAndCount),
63         mWordCount((uint32_t)(codeAndCount >> 16)) {}
OpCodeAndWordCountOpCodeAndWordCount64   OpCodeAndWordCount(uint32_t opcode, uint32_t wordCount)
65       : mOpCode((uint16_t)opcode), mWordCount((uint16_t)wordCount) {}
66 
uint32_tOpCodeAndWordCount67   operator uint32_t() const {
68     return ((uint32_t)mWordCount << 16) | (uint32_t)mOpCode;
69   }
70 
71   uint16_t mOpCode;
72   uint16_t mWordCount;
73 };
74 
75 } // namespace spirit
76 } // namespace android
77 
78 #endif // CORE_DEFS_H
79