Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: src/IceMemoryRegion.h

Issue 476323004: Start adding an integrated assembler. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: make fixups part of address Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceInstX8632.def ('k') | src/IceOperand.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Modified by the Subzero authors.
6 //
7 //===- subzero/src/IceMemoryRegion.h - Memory region ------------*- C++ -*-===//
8 //
9 // The Subzero Code Generator
10 //
11 // This file is distributed under the University of Illinois Open Source
12 // License. See LICENSE.TXT for details.
13 //
14 //===----------------------------------------------------------------------===//
15 //
16 // This file declares/defines the MemoryRegion class. It tracks a pointer
17 // plus its bounds for bounds-checking in debug mode.
18 //===----------------------------------------------------------------------===//
19
20 #ifndef SUBZERO_SRC_ICE_MEMORY_REGION_H_
21 #define SUBZERO_SRC_ICE_MEMORY_REGION_H_
22
23 #include "IceDefs.h"
24 #include "IceUtils.h"
25
26 namespace Ice {
27
28 // Memory regions are useful for accessing memory with bounds check in
29 // debug mode. They can be safely passed by value and do not assume ownership
30 // of the region.
31 // This is essentially like LLVM's ArrayRef, except for the interface.
32 class MemoryRegion {
33 public:
34 MemoryRegion() : pointer_(NULL), size_(0) {}
35 MemoryRegion(void *pointer, size_t size) : pointer_(pointer), size_(size) {}
36 MemoryRegion(const MemoryRegion &other) { *this = other; }
37 MemoryRegion &operator=(const MemoryRegion &other) {
38 pointer_ = other.pointer_;
39 size_ = other.size_;
40 return *this;
41 }
42
43 void *pointer() const { return pointer_; }
44 size_t size() const { return size_; }
45
46 size_t start() const { return reinterpret_cast<size_t>(pointer_); }
47 size_t end() const { return start() + size_; }
48
49 template <typename T> T Load(size_t offset) const {
50 return *ComputeInternalPointer<T>(offset);
51 }
52
53 template <typename T> void Store(size_t offset, T value) const {
54 *ComputeInternalPointer<T>(offset) = value;
55 }
56
57 template <typename T> T *PointerTo(size_t offset) const {
58 return ComputeInternalPointer<T>(offset);
59 }
60
61 bool Contains(size_t address) const {
62 return (address >= start()) && (address < end());
63 }
64
65 void CopyFrom(size_t offset, const MemoryRegion &from) const {
66 assert(from.pointer() != NULL && from.size() > 0);
67 assert(this->size() >= from.size());
68 assert(offset <= this->size() - from.size());
69 memmove(reinterpret_cast<void *>(start() + offset), from.pointer(),
70 from.size());
71 }
72
73 // Compute a sub memory region based on an existing one.
74 void Subregion(const MemoryRegion &from, size_t offset, size_t size) {
75 assert(from.size() >= size);
76 assert(offset <= (from.size() - size));
77 pointer_ = reinterpret_cast<void *>(from.start() + offset);
78 size_ = size;
79 }
80
81 // Compute an extended memory region based on an existing one.
82 void Extend(const MemoryRegion &region, size_t extra) {
83 pointer_ = region.pointer();
84 size_ = (region.size() + extra);
85 }
86
87 private:
88 template <typename T> T *ComputeInternalPointer(size_t offset) const {
89 assert(size() >= sizeof(T));
90 assert(offset <= size() - sizeof(T));
91 return reinterpret_cast<T *>(start() + offset);
92 }
93
94 void *pointer_;
95 size_t size_;
96 };
97
98 } // end of namespace Ice
99
100 #endif // SUBZERO_SRC_ICE_MEMORY_REGION_H
OLDNEW
« no previous file with comments | « src/IceInstX8632.def ('k') | src/IceOperand.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698