1 /* memoryword.h
2 
3    Copyright 2009-2010 Taco Hoekwater <taco@luatex.org>
4 
5    This file is part of LuaTeX.
6 
7    LuaTeX is free software; you can redistribute it and/or modify it under
8    the terms of the GNU General Public License as published by the Free
9    Software Foundation; either version 2 of the License, or (at your
10    option) any later version.
11 
12    LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
15    License for more details.
16 
17    You should have received a copy of the GNU General Public License along
18    with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
19 
20 
21 /* This header file is extra special because it is read in from
22    within the pascal source */
23 
24 #ifndef MEMORYWORD_H
25 #  define MEMORYWORD_H
26 
27 /* texmfmem.h: the memory_word type, which is too hard to translate
28    automatically from Pascal.  We have to make sure the byte-swapping
29    that the (un)dumping routines do suffices to put things in the right
30    place in memory.
31 
32    A memory_word can be broken up into a `twohalves' or a
33    `fourquarters', and a `twohalves' can be further broken up.  Here is
34    a picture.  ..._M = most significant byte, ..._L = least significant
35    byte.
36 
37 
38    BigEndian:
39    twohalves.v:  RH_MM RH_ML RH_LM RH_LL LH_MM LH_ML LH_LM LH_LL
40    twohalves.u:  ---------JUNK---------- ----B0----- ----B1-----
41    fourquarters: ----B0----- ----B1----- ----B2----- ----B3-----
42    twoints:      ---------CINT0--------- ---------CINT1---------
43 
44    LittleEndian:
45    twohalves.v:  LH_LL LH_LM LH_ML LH_MM RH_LL RH_LM RH_ML RH_MM
46    twohalves.u:  ----B1----- ----B0-----
47    fourquarters: ----B3----- ----B2----- ----B1----- ----B0-----
48    twoints:      ---------CINT1--------- ---------CINT0---------
49 
50 */
51 
52 
53 typedef union {
54     struct {
55 #  ifdef WORDS_BIGENDIAN
56         halfword RH, LH;
57 #  else
58         halfword LH, RH;
59 #  endif
60     } v;
61 
62     struct {                    /* Make B0,B1 overlap the most significant bytes of LH.  */
63 #  ifdef WORDS_BIGENDIAN
64         halfword junk;
65         quarterword B0, B1;
66 #  else                         /* not WORDS_BIGENDIAN */
67         /* If 32-bit memory words, have to do something.  */
68         quarterword B1, B0;
69 #  endif                        /* LittleEndian */
70     } u;
71 } two_halves;
72 
73 typedef struct {
74     struct {
75 #  ifdef WORDS_BIGENDIAN
76         quarterword B0, B1, B2, B3;
77 #  else
78         quarterword B3, B2, B1, B0;
79 #  endif
80     } u;
81 } four_quarters;
82 
83 typedef struct {
84 #  ifdef WORDS_BIGENDIAN
85     int CINT0, CINT1;
86 #  else
87     int CINT1, CINT0;
88 #  endif
89 } two_ints;
90 
91 typedef struct {
92     glue_ratio GLUE;
93 } glues;
94 
95 typedef union {
96     two_halves hh;
97     four_quarters qqqq;
98     two_ints ii;
99     glues gg;
100 } memory_word;
101 
102 #  define b0 u.B0
103 #  define b1 u.B1
104 #  define b2 u.B2
105 #  define b3 u.B3
106 
107 #  define rh v.RH
108 #  define lhfield v.LH
109 
110 #  define cint ii.CINT0
111 #  define cint1 ii.CINT1
112 
113 #  define gr gg.GLUE
114 
115 /* the next five defines are needed for the prototypes in web2c's coerce.h */
116 
117 #  define memoryword memory_word
118 #  define strnumber str_number
119 #  define packedASCIIcode packed_ASCII_code
120 #  define poolpointer pool_pointer
121 
122 typedef FILE *word_file;
123 
124 #  ifdef DEBUG
125 extern void print_word(memory_word w);
126 #  endif
127 
128 #endif
129