gfx/graphite2/src/call_machine.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* GRAPHITE2 LICENSING
michael@0 2
michael@0 3 Copyright 2010, SIL International
michael@0 4 All rights reserved.
michael@0 5
michael@0 6 This library is free software; you can redistribute it and/or modify
michael@0 7 it under the terms of the GNU Lesser General Public License as published
michael@0 8 by the Free Software Foundation; either version 2.1 of License, or
michael@0 9 (at your option) any later version.
michael@0 10
michael@0 11 This program is distributed in the hope that it will be useful,
michael@0 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
michael@0 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
michael@0 14 Lesser General Public License for more details.
michael@0 15
michael@0 16 You should also have received a copy of the GNU Lesser General Public
michael@0 17 License along with this library in the file named "LICENSE".
michael@0 18 If not, write to the Free Software Foundation, 51 Franklin Street,
michael@0 19 Suite 500, Boston, MA 02110-1335, USA or visit their web page on the
michael@0 20 internet at http://www.fsf.org/licenses/lgpl.html.
michael@0 21
michael@0 22 Alternatively, the contents of this file may be used under the terms of the
michael@0 23 Mozilla Public License (http://mozilla.org/MPL) or the GNU General Public
michael@0 24 License, as published by the Free Software Foundation, either version 2
michael@0 25 of the License or (at your option) any later version.
michael@0 26 */
michael@0 27 // This call threaded interpreter implmentation for machine.h
michael@0 28 // Author: Tim Eves
michael@0 29
michael@0 30 // Build either this interpreter or the direct_machine implementation.
michael@0 31 // The call threaded interpreter is portable across compilers and
michael@0 32 // architectures as well as being useful to debug (you can set breakpoints on
michael@0 33 // opcodes) but is slower that the direct threaded interpreter by a factor of 2
michael@0 34
michael@0 35 #include <cassert>
michael@0 36 #include <cstring>
michael@0 37 #include <graphite2/Segment.h>
michael@0 38 #include "inc/Machine.h"
michael@0 39 #include "inc/Segment.h"
michael@0 40 #include "inc/Slot.h"
michael@0 41 #include "inc/Rule.h"
michael@0 42
michael@0 43 // Disable the unused parameter warning as th compiler is mistaken since dp
michael@0 44 // is always updated (even if by 0) on every opcode.
michael@0 45 #ifdef __GNUC__
michael@0 46 #pragma GCC diagnostic ignored "-Wunused-parameter"
michael@0 47 #endif
michael@0 48
michael@0 49 #define registers const byte * & dp, vm::Machine::stack_t * & sp, \
michael@0 50 vm::Machine::stack_t * const sb, regbank & reg
michael@0 51
michael@0 52 // These are required by opcodes.h and should not be changed
michael@0 53 #define STARTOP(name) bool name(registers) REGPARM(4);\
michael@0 54 bool name(registers) {
michael@0 55 #define ENDOP return (sp - sb)/Machine::STACK_MAX==0; \
michael@0 56 }
michael@0 57
michael@0 58 #define EXIT(status) { push(status); return false; }
michael@0 59
michael@0 60 // This is required by opcode_table.h
michael@0 61 #define do_(name) instr(name)
michael@0 62
michael@0 63
michael@0 64 using namespace graphite2;
michael@0 65 using namespace vm;
michael@0 66
michael@0 67 struct regbank {
michael@0 68 slotref is;
michael@0 69 slotref * map;
michael@0 70 SlotMap & smap;
michael@0 71 slotref * const map_base;
michael@0 72 const instr * & ip;
michael@0 73 int8 flags;
michael@0 74 };
michael@0 75
michael@0 76 typedef bool (* ip_t)(registers);
michael@0 77
michael@0 78 // Pull in the opcode definitions
michael@0 79 // We pull these into a private namespace so these otherwise common names dont
michael@0 80 // pollute the toplevel namespace.
michael@0 81 namespace {
michael@0 82 #define smap reg.smap
michael@0 83 #define seg smap.segment
michael@0 84 #define is reg.is
michael@0 85 #define ip reg.ip
michael@0 86 #define map reg.map
michael@0 87 #define mapb reg.map_base
michael@0 88 #define flags reg.flags
michael@0 89
michael@0 90 #include "inc/opcodes.h"
michael@0 91
michael@0 92 #undef smap
michael@0 93 #undef seg
michael@0 94 #undef is
michael@0 95 #undef ip
michael@0 96 #undef map
michael@0 97 #undef mapb
michael@0 98 #undef flags
michael@0 99 }
michael@0 100
michael@0 101 Machine::stack_t Machine::run(const instr * program,
michael@0 102 const byte * data,
michael@0 103 slotref * & map)
michael@0 104
michael@0 105 {
michael@0 106 assert(program != 0);
michael@0 107
michael@0 108 // Declare virtual machine registers
michael@0 109 const instr * ip = program-1;
michael@0 110 const byte * dp = data;
michael@0 111 stack_t * sp = _stack + Machine::STACK_GUARD,
michael@0 112 * const sb = sp;
michael@0 113 regbank reg = {*map, map, _map, _map.begin()+_map.context(), ip, 0};
michael@0 114
michael@0 115 // Run the program
michael@0 116 while ((reinterpret_cast<ip_t>(*++ip))(dp, sp, sb, reg)) {}
michael@0 117 const stack_t ret = sp == _stack+STACK_GUARD+1 ? *sp-- : 0;
michael@0 118
michael@0 119 check_final_stack(sp);
michael@0 120 map = reg.map;
michael@0 121 *map = reg.is;
michael@0 122 return ret;
michael@0 123 }
michael@0 124
michael@0 125 // Pull in the opcode table
michael@0 126 namespace {
michael@0 127 #include "inc/opcode_table.h"
michael@0 128 }
michael@0 129
michael@0 130 const opcode_t * Machine::getOpcodeTable() throw()
michael@0 131 {
michael@0 132 return opcode_table;
michael@0 133 }
michael@0 134
michael@0 135

mercurial