1 // -*- Mode: C++; tab-width:2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi:tw=80:et:ts=2:sts=2
3 //
4 // -----------------------------------------------------------------------
5 //
6 // This file is part of RLVM, a RealLive virtual machine clone.
7 //
8 // -----------------------------------------------------------------------
9 //
10 // Copyright (C) 2007 Elliot Glaysher
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
25 //
26 // -----------------------------------------------------------------------
27 
28 #ifndef SRC_LIBREALLIVE_INTMEMREF_H_
29 #define SRC_LIBREALLIVE_INTMEMREF_H_
30 
31 #include <iosfwd>
32 
33 namespace libreallive {
34 
35 const int INTA_LOCATION = 0;
36 const int INTB_LOCATION = 1;
37 const int INTC_LOCATION = 2;
38 const int INTD_LOCATION = 3;
39 const int INTE_LOCATION = 4;
40 const int INTF_LOCATION = 5;
41 const int INTG_LOCATION = 6;
42 
43 const int INTZ_LOCATION = 7;
44 const int INTL_LOCATION = 8;
45 
46 // -----------------------------------------------------------------------
47 
48 const int INTZ_LOCATION_IN_BYTECODE = 25;
49 const int INTL_LOCATION_IN_BYTECODE = 11;
50 
51 // -----------------------------------------------------------------------
52 
53 const int STRK_LOCATION = 0x0A;
54 const int STRM_LOCATION = 0x0C;
55 const int STRS_LOCATION = 0x12;
56 
57 // -----------------------------------------------------------------------
58 
is_string_location(const int type)59 inline bool is_string_location(const int type) {
60   return type == STRS_LOCATION || type == STRK_LOCATION ||
61       type == STRM_LOCATION;
62 }
63 
64 // -----------------------------------------------------------------------
65 
66 // References a piece of integer memory.
67 class IntMemRef {
68  public:
69   IntMemRef(int bytecode_rep, int location);
70   IntMemRef(int bank, int type, int location);
71 
72   IntMemRef(char bank_name, int location);
73   IntMemRef(char bank_name, const char* access_str, int location);
74   ~IntMemRef();
75 
bank()76   int bank() const { return memory_bank_; }
type()77   int type() const { return access_type_; }
location()78   int location() const { return location_; }
79 
80  private:
81   // Which piece of memory to operate on.
82   int memory_bank_;
83 
84   // How to access
85   int access_type_;
86 
87   // The memory location to
88   int location_;
89 };
90 
91 }  // namespace libreallive
92 
93 std::ostream& operator<<(std::ostream& oss,
94                          const libreallive::IntMemRef& memref);
95 
96 #endif  // SRC_LIBREALLIVE_INTMEMREF_H_
97