blob: 7b634cf1d3d9e8d0573f98982116b092a8d2200f [file] [log] [blame]
Shih-wei Liao21d28f52012-06-12 05:55:00 -07001/*
2 * Copyright (C) 2012 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 ART_SRC_GREENLAND_TARGET_DATA_LAYOUT_H_
18#define ART_SRC_GREENLAND_TARGET_DATA_LAYOUT_H_
19
20#include "lir.h"
21
22#include "logging.h"
23
24namespace art {
25namespace greenland {
26
27class TargetDataLayout {
28 private:
29 // Size of pointer in bytes
30 unsigned pointer_size_;
31
32 // Stack alignment in bytes
33 unsigned stack_alignment_;
34
35 public:
36 TargetDataLayout(unsigned pointer_size, unsigned stack_alignment)
37 : pointer_size_(pointer_size), stack_alignment_(stack_alignment) { }
38
39 unsigned GetPointerSize() const {
40 return pointer_size_;
41 }
42 unsigned GetPointerSizeInBits() const {
43 return (pointer_size_ << 3);
44 }
45
46 unsigned GetStackAlignment() const {
47 return stack_alignment_;
48 }
49
50 unsigned GetOpTypeSize(LIR::OperationType op_type) const {
51 switch (op_type) {
52 case LIR::kUInt8TypeOp: return 1; break;
53 case LIR::kSInt8TypeOp: return 1; break;
54 case LIR::kUInt16TypeOp: return 2; break;
55 case LIR::kSInt16TypeOp: return 2; break;
56 case LIR::kInt32TypeOp: return 4; break;
57 case LIR::kInt64TypeOp: return 8; break;
58 case LIR::kFloatTypeOp: return 4; break;
59 case LIR::kDoubleTypeOp: return 8; break;
60 case LIR::kPointerTypeOp: return pointer_size_; break;
61 case LIR::kUnknownTypeOp:
62 default: {
63 LOG(FATAL) << "Unknown operation type: " << op_type;
64 return 0;
65 }
66 }
67 // unreachable
68 }
69};
70
71} // namespace greenland
72} // namespace art
73
74#endif // ART_SRC_GREENLAND_TARGET_DATA_LAYOUT_H_