w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

Machine.h
Go to the documentation of this file.
1 /* GRAPHITE2 LICENSING
2 
3  Copyright 2010, SIL International
4  All rights reserved.
5 
6  This library is free software; you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published
8  by the Free Software Foundation; either version 2.1 of License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should also have received a copy of the GNU Lesser General Public
17  License along with this library in the file named "LICENSE".
18  If not, write to the Free Software Foundation, 51 Franklin Street,
19  Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
20  internet at http://www.fsf.org/licenses/lgpl.html.
21 
22 Alternatively, the contents of this file may be used under the terms of the
23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
24 License, as published by the Free Software Foundation, either version 2
25 of the License or (at your option) any later version.
26 */
27 // This general interpreter interface.
28 // Author: Tim Eves
29 
30 // Build one of direct_machine.cpp or call_machine.cpp to implement this
31 // interface.
32 
33 #pragma once
34 #include <cstring>
35 #include <limits>
36 #include <graphite2/Types.h>
37 #include "inc/Main.h"
38 
39 #if defined(__GNUC__)
40 #if defined(__clang__) || (__GNUC__ * 100 + __GNUC_MINOR__ * 10) < 430
41 #define HOT
42 #if defined(__x86_64)
43 #define REGPARM(n) __attribute__((regparm(n)))
44 #else
45 #define REGPARM(n)
46 #endif
47 #else
48 #define HOT __attribute__((hot))
49 #if defined(__x86_64)
50 #define REGPARM(n) __attribute__((hot, regparm(n)))
51 #else
52 #define REGPARM(n)
53 #endif
54 #endif
55 #else
56 #define HOT
57 #define REGPARM(n)
58 #endif
59 
60 #if defined(__MINGW32__)
61 // MinGW's <limits> at some point includes winnt.h which #define's a
62 // DELETE macro, which conflicts with enum opcode below, so we undefine
63 // it here.
64 #undef DELETE
65 #endif
66 
67 namespace graphite2 {
68 
69 // Forward declarations
70 class Segment;
71 class Slot;
72 class SlotMap;
73 
74 
75 namespace vm
76 {
77 
78 
79 typedef void * instr;
80 typedef Slot * slotref;
81 
82 enum {VARARGS = 0xff, MAX_NAME_LEN=32};
83 
84 enum opcode {
85  NOP = 0,
86 
88 
89  ADD, SUB, MUL, DIV,
91  NEG,
93 
95 
96  AND, OR, NOT,
99 
105 
113 
114  PUSH_IGLYPH_ATTR, // not implemented
115 
124  // private opcodes for internal use only, comes after all other on disk opcodes
126 };
127 
128 struct opcode_t
129 {
133 };
134 
135 
136 class Machine
137 {
138 public:
139  typedef int32 stack_t;
140  static size_t const STACK_ORDER = 10,
143 
144  class Code;
145 
146  enum status_t {
147  finished = 0,
152  died_early
153  };
154 
155  Machine(SlotMap &) throw();
156  static const opcode_t * getOpcodeTable() throw();
157 
159 
160  SlotMap & slotMap() const throw();
161  status_t status() const throw();
162 // operator bool () const throw();
163 
164 private:
167  slotref * & map) HOT;
168 
172 };
173 
176 {
177  // Initialise stack guard +1 entries as the stack pointer points to the
178  // current top of stack, hence the first push will never write entry 0.
179  // Initialising the guard space like this is unnecessary and is only
180  // done to keep valgrind happy during fuzz testing. Hopefully loop
181  // unrolling will flatten this.
182  for (size_t n = STACK_GUARD + 1; n; --n) _stack[n-1] = 0;
183 }
184 
185 inline SlotMap& Machine::slotMap() const throw()
186 {
187  return _map;
188 }
189 
190 inline Machine::status_t Machine::status() const throw()
191 {
192  return _status;
193 }
194 
195 inline void Machine::check_final_stack(const stack_t * const sp)
196 {
197  if (_status != finished) return;
198 
199  stack_t const * const base = _stack + STACK_GUARD,
200  * const limit = base + STACK_MAX;
201  if (sp < base) _status = stack_underflow; // This should be impossible now.
202  else if (sp >= limit) _status = stack_overflow; // So should this.
203  else if (sp != base) _status = stack_not_empty;
204 }
205 
206 } // namespace vm
207 } // namespace graphite2
static size_t const STACK_GUARD
Definition: Machine.h:142
static size_t const STACK_ORDER
Definition: Machine.h:140
static const opcode_t * getOpcodeTable()
status_t status() const
Definition: Machine.h:190
stack_t _stack[STACK_MAX+2 *STACK_GUARD]
Definition: Machine.h:170
Machine(SlotMap &)
Definition: Machine.h:174
SlotMap & slotMap() const
Definition: Machine.h:185
void check_final_stack(const stack_t *const sp)
Definition: Machine.h:195
static size_t const STACK_MAX
Definition: Machine.h:141
#define n
Definition: t4ht.c:1290
const char * program
Definition: dv2dt.c:152
struct rect data
Definition: dvipdfm.c:64
int base
Definition: gsftopk.c:1502
#define const
Definition: ftzconf.h:91
#define inline
Definition: config.h:132
void * instr
Definition: Machine.h:79
@ PUSH_GLYPH_METRIC
Definition: Machine.h:110
@ PUT_SUBS_8BIT_OBS
Definition: Machine.h:101
@ PUSH_GLYPH_ATTR
Definition: Machine.h:120
@ IATTR_SET_SLOT
Definition: Machine.h:108
@ PUSH_ATT_TO_GLYPH_ATTR
Definition: Machine.h:120
@ PUT_GLYPH_8BIT_OBS
Definition: Machine.h:101
@ PUSH_ATT_TO_GLYPH_METRIC
Definition: Machine.h:111
@ PUSH_ATT_TO_GATTR_OBS
Definition: Machine.h:111
@ PUSH_IGLYPH_ATTR
Definition: Machine.h:114
@ PUSH_GLYPH_ATTR_OBS
Definition: Machine.h:109
@ PUSH_SLOT_ATTR
Definition: Machine.h:109
@ PUSH_ISLOT_ATTR
Definition: Machine.h:112
@ PUSH_PROC_STATE
Definition: Machine.h:118
@ MAX_NAME_LEN
Definition: Machine.h:82
Slot * slotref
Definition: Machine.h:80
Definition: bits.h:30
gr_uint8 uint8
Definition: Main.h:38
gr_int32 int32
Definition: Main.h:44
Machine::Code Code
Definition: Pass.cpp:43
#define map
#define HOT
Definition: Machine.h:56
char name[MAX_NAME_LEN]
Definition: Machine.h:132
Definition: psfont.h:67
#define sp
Definition: stack.c:11
#define limit(x)
Definition: yuvsplittoppm.c:26