libcss
Loading...
Searching...
No Matches
bytecode.h
Go to the documentation of this file.
1/*
2 * This file is part of LibCSS.
3 * Licensed under the MIT License,
4 * http://www.opensource.org/licenses/mit-license.php
5 * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org>
6 */
7
8#ifndef css_bytecode_bytecode_h_
9#define css_bytecode_bytecode_h_
10
11#include <inttypes.h>
12#include <stdio.h>
13
14#include <libcss/types.h>
15#include <libcss/properties.h>
16
17#include "bytecode/opcodes.h"
18
19typedef uint32_t css_code_t;
20
22
30
38
48
49typedef enum unit {
50 UNIT_LENGTH = (1u << 8),
51 UNIT_PX = (1u << 8) + 0,
52 UNIT_EX = (1u << 8) + 1,
53 UNIT_EM = (1u << 8) + 2,
54 UNIT_IN = (1u << 8) + 3,
55 UNIT_CM = (1u << 8) + 4,
56 UNIT_MM = (1u << 8) + 5,
57 UNIT_PT = (1u << 8) + 6,
58 UNIT_PC = (1u << 8) + 7,
59 UNIT_CH = (1u << 8) + 8,
60 UNIT_REM = (1u << 8) + 9,
61 UNIT_LH = (1u << 8) + 10,
62 UNIT_VH = (1u << 8) + 11,
63 UNIT_VW = (1u << 8) + 12,
64 UNIT_VI = (1u << 8) + 13,
65 UNIT_VB = (1u << 8) + 14,
66 UNIT_VMIN = (1u << 8) + 15,
67 UNIT_VMAX = (1u << 8) + 16,
68 UNIT_Q = (1u << 8) + 17,
69
70 UNIT_PCT = (1 << 9),
71
72 UNIT_ANGLE = (1 << 10),
73 UNIT_DEG = (1 << 10) + 0,
74 UNIT_GRAD = (1 << 10) + 1,
75 UNIT_RAD = (1 << 10) + 2,
76 UNIT_TURN = (1 << 10) + 3,
77
78 UNIT_TIME = (1 << 11),
79 UNIT_MS = (1 << 11) + 0,
80 UNIT_S = (1 << 11) + 1,
81
82 UNIT_FREQ = (1 << 12),
83 UNIT_HZ = (1 << 12) + 0,
84 UNIT_KHZ = (1 << 12) + 1,
85
86 UNIT_RESOLUTION = (1 << 13),
87 UNIT_DPI = (1 << 13) + 0,
88 UNIT_DPCM = (1 << 13) + 1,
89 UNIT_DPPX = (1 << 13) + 2,
90
91 /* These are special only to the CALC bytecodes */
92 UNIT_CALC_ANY = (1 << 20),
93 UNIT_CALC_NUMBER = (1 << 20) + 1,
95
96typedef uint32_t colour;
97
98typedef enum shape {
99 SHAPE_RECT = 0
101
102static inline css_code_t buildOPV(opcode_t opcode, uint8_t flags, uint16_t value)
103{
104 return (opcode & 0x3ff) | (flags << 10) | ((value & 0x3fff) << 18);
105}
106
107static inline opcode_t getOpcode(css_code_t OPV)
108{
109 return (OPV & 0x3ff);
110}
111
112static inline uint8_t getFlags(css_code_t OPV)
113{
114 return ((OPV >> 10) & 0xff);
115}
116
117static inline uint16_t getValue(css_code_t OPV)
118{
119 return (OPV >> 18);
120}
121
122static inline bool isImportant(css_code_t OPV)
123{
124 return getFlags(OPV) & FLAG_IMPORTANT;
125}
126
127static inline enum flag_value getFlagValue(css_code_t OPV)
128{
129 return (getFlags(OPV) >> 1) & 0x7;
130}
131
132static inline bool hasFlagValue(css_code_t OPV)
133{
134 return getFlagValue(OPV) != FLAG_VALUE__NONE;
135}
136
137static inline bool isInherit(css_code_t OPV)
138{
139 return getFlagValue(OPV) == FLAG_VALUE_INHERIT;
140}
141
142static inline bool isCalc(css_code_t OPV)
143{
144 return getValue(OPV) == VALUE_IS_CALC;
145}
146
147#endif
148
149
150
uint32_t colour
Definition bytecode.h:96
unit
Definition bytecode.h:49
@ UNIT_VW
Definition bytecode.h:63
@ UNIT_DPPX
Definition bytecode.h:89
@ UNIT_CH
Definition bytecode.h:59
@ UNIT_GRAD
Definition bytecode.h:74
@ UNIT_PCT
Definition bytecode.h:70
@ UNIT_PT
Definition bytecode.h:57
@ UNIT_Q
Definition bytecode.h:68
@ UNIT_VB
Definition bytecode.h:65
@ UNIT_KHZ
Definition bytecode.h:84
@ UNIT_VMIN
Definition bytecode.h:66
@ UNIT_DPCM
Definition bytecode.h:88
@ UNIT_LENGTH
Definition bytecode.h:50
@ UNIT_CALC_NUMBER
Definition bytecode.h:93
@ UNIT_S
Definition bytecode.h:80
@ UNIT_CM
Definition bytecode.h:55
@ UNIT_REM
Definition bytecode.h:60
@ UNIT_TURN
Definition bytecode.h:76
@ UNIT_ANGLE
Definition bytecode.h:72
@ UNIT_IN
Definition bytecode.h:54
@ UNIT_RESOLUTION
Definition bytecode.h:86
@ UNIT_EX
Definition bytecode.h:52
@ UNIT_MM
Definition bytecode.h:56
@ UNIT_HZ
Definition bytecode.h:83
@ UNIT_VMAX
Definition bytecode.h:67
@ UNIT_CALC_ANY
Definition bytecode.h:92
@ UNIT_DEG
Definition bytecode.h:73
@ UNIT_PC
Definition bytecode.h:58
@ UNIT_EM
Definition bytecode.h:53
@ UNIT_TIME
Definition bytecode.h:78
@ UNIT_PX
Definition bytecode.h:51
@ UNIT_VI
Definition bytecode.h:64
@ UNIT_RAD
Definition bytecode.h:75
@ UNIT_FREQ
Definition bytecode.h:82
@ UNIT_DPI
Definition bytecode.h:87
@ UNIT_LH
Definition bytecode.h:61
@ UNIT_VH
Definition bytecode.h:62
@ UNIT_MS
Definition bytecode.h:79
shape
Definition bytecode.h:98
@ SHAPE_RECT
Definition bytecode.h:99
flag_value
Definition bytecode.h:23
@ FLAG_VALUE_INHERIT
Definition bytecode.h:25
@ FLAG_VALUE_REVERT
Definition bytecode.h:27
@ FLAG_VALUE_INITIAL
Definition bytecode.h:26
@ FLAG_VALUE_UNSET
Definition bytecode.h:28
@ FLAG_VALUE__NONE
Definition bytecode.h:24
uint32_t css_code_t
Definition bytecode.h:19
flag
Definition bytecode.h:31
@ FLAG_UNSET
Definition bytecode.h:36
@ FLAG_IMPORTANT
Definition bytecode.h:32
@ FLAG_REVERT
Definition bytecode.h:35
@ FLAG_INITIAL
Definition bytecode.h:34
@ FLAG_INHERIT
Definition bytecode.h:33
calc_opcodes
Definition bytecode.h:39
@ CALC_PUSH_VALUE
Definition bytecode.h:41
@ CALC_FINISH
Definition bytecode.h:46
@ CALC_ADD
Definition bytecode.h:42
@ CALC_MULTIPLY
Definition bytecode.h:44
@ CALC_DIVIDE
Definition bytecode.h:45
@ CALC_PUSH_NUMBER
Definition bytecode.h:40
@ CALC_SUBTRACT
Definition bytecode.h:43
enum css_properties_e opcode_t
Definition bytecode.h:21
css_properties_e
Definition properties.h:16
#define VALUE_IS_CALC
Definition opcodes.h:13