8 typedef unsigned char BYTE;
13 typedef struct _code_buf_t {
14 BYTE *next; /**< next byte to be written */
15 int len; /**< length of current string */
19 VLC_7BIT = 0x00, /**< 8 bit code, carrying 7 bits payload */
20 VLC_14BIT = 0x80, /**< 16 bit code, carrying 14 bits payload */
21 VLC_21BIT = 0xC0, /**< 24 bit code, carrying 21 bits payload */
22 VLC_28BIT = 0xE0, /**< 32 bit code, carrying 28 bits payload */
23 VLC_32BIT = 0xF0, /**< 40 bit code, carrying 32 bits payload */
25 VLC_TAG_FIRST = 0xF1, /**< first possible tag value */
26 VLC_TAG_REF = 0xFE, /**< special tag, next code is an ID */
27 VLC_TAG_END = 0xFF, /**< end tag */
31 * put a byte into the buffer
33 static INLINE void put_byte(CODE_BUFFER *buf, BYTE byte)
40 * returns the next byte from the buffer WITHOUT dropping
42 static INLINE BYTE look_byte(CODE_BUFFER *buf)
48 * returns the next byte from the buffer WITH dropping
50 static INLINE BYTE get_byte(CODE_BUFFER *buf)
55 #define BITS(n) (1 << (n))
58 * put a 32bit value into the buffer
60 static void put_code(CODE_BUFFER *buf, unsigned code)
63 put_byte(buf, VLC_7BIT | code);
65 else if (code < BITS(6 + 8)) {
66 put_byte(buf, VLC_14BIT | (code >> 8));
69 else if (code < BITS(5 + 8 + 8)) {
70 put_byte(buf, VLC_21BIT | (code >> 16));
71 put_byte(buf, code >> 8);
74 else if (code < BITS(4 + 8 + 8 + 8)) {
75 put_byte(buf, VLC_28BIT | (code >> 24));
76 put_byte(buf, code >> 16);
77 put_byte(buf, code >> 8);
81 put_byte(buf, VLC_32BIT);
82 put_byte(buf, code >> 24);
83 put_byte(buf, code >> 16);
84 put_byte(buf, code >> 8);
90 * put a tag into the buffer
92 static void put_tag(CODE_BUFFER *buf, BYTE tag)
94 assert(tag >= VLC_TAG_FIRST && "invalid tag");
100 * returns the next tag or zero if the next code isn't a tag
102 static BYTE next_tag(CODE_BUFFER *buf)
104 BYTE b = look_byte(buf);
106 if (b >= VLC_TAG_FIRST)
112 * encodes an IR-node, recursive worker
114 static void _encode_node(ir_node *node, CODE_BUFFER *buf, int max_depth)
119 code = get_irn_opcode(node);
124 if (max_depth <= 0) {
129 preds = get_irn_arity(node);
130 put_code(buf, preds);
132 for (i = 0; i < preds; ++i) {
133 ir_node *n = get_irn_n(node, i);
135 _encode_node(n, buf, max_depth);
142 static void encode_node(ir_node *node, CODE_BUFFER *buf, int max_depth)
144 _encode_node(node, buf, max_depth);
145 put_code(buf, VLC_TAG_END);