diff options
Diffstat (limited to 'src/bytecode')
-rw-r--r-- | src/bytecode/Makefile | 49 | ||||
-rw-r--r-- | src/bytecode/bytecode.h | 3 | ||||
-rw-r--r-- | src/bytecode/dump.c | 229 |
3 files changed, 281 insertions, 0 deletions
diff --git a/src/bytecode/Makefile b/src/bytecode/Makefile new file mode 100644 index 0000000..db4d922 --- /dev/null +++ b/src/bytecode/Makefile @@ -0,0 +1,49 @@ +# Child makefile fragment +# +# Toolchain is provided by top-level makefile +# +# Variables provided by top-level makefile +# +# COMPONENT The name of the component +# EXPORT The location of the export directory +# TOP The location of the source tree root +# RELEASEDIR The place to put release objects +# DEBUGDIR The place to put debug objects +# +# do_include Canned command sequence to include a child makefile +# +# Variables provided by parent makefile: +# +# DIR The name of the directory we're in, relative to $(TOP) +# +# Variables we can manipulate: +# +# ITEMS_CLEAN The list of items to remove for "make clean" +# ITEMS_DISTCLEAN The list of items to remove for "make distclean" +# TARGET_TESTS The list of target names to run for "make test" +# +# SOURCES The list of sources to build for $(COMPONENT) +# +# Plus anything from the toolchain + +# Push parent directory onto the directory stack +sp := $(sp).x +dirstack_$(sp) := $(d) +d := $(DIR) + +# Manipulate include paths +CFLAGS := $(CFLAGS) -I$(d) + +# Sources +SRCS_$(d) := dump.c + +# Append to sources for component +SOURCES += $(addprefix $(d), $(SRCS_$(d))) + +# Now include any children we may have +MAKE_INCLUDES := $(wildcard $(d)*/Makefile) +$(eval $(foreach INC, $(MAKE_INCLUDES), $(call do_include,$(INC)))) + +# Finally, pop off the directory stack +d := $(dirstack_$(sp)) +sp := $(basename $(sp)) diff --git a/src/bytecode/bytecode.h b/src/bytecode/bytecode.h index 2db3138..86019d1 100644 --- a/src/bytecode/bytecode.h +++ b/src/bytecode/bytecode.h @@ -9,6 +9,7 @@ #define css_bytecode_bytecode_h_ #include <inttypes.h> +#include <stdio.h> #include <libcss/types.h> @@ -163,6 +164,8 @@ static inline bool isInherit(uint32_t OPV) return getFlags(OPV) & 0x2; } +void css_bytecode_dump(void *bytecode, uint32_t length, FILE *fp); + #endif diff --git a/src/bytecode/dump.c b/src/bytecode/dump.c new file mode 100644 index 0000000..05213ee --- /dev/null +++ b/src/bytecode/dump.c @@ -0,0 +1,229 @@ +/* + * This file is part of LibCSS. + * Licensed under the MIT License, + * http://www.opensource.org/licenses/mit-license.php + * Copyright 2008 John-Mark Bell <jmb@netsurf-browser.org> + */ + +#include "bytecode/bytecode.h" +#include "bytecode/opcodes.h" + +/** + * Opcode names, indexed by opcode + */ +static const char *opcode_names[] = { + "azimuth", + "background-attachment", + "background-color", + "background-image", + "background-position", + "background-repeat", + "border-collapse", + "border-spacing", + "border-trbl-color", + "border-trbl-style", + "border-trbl-width", + "bottom", + "caption-side", + "clear", + "clip", + "color", + "content", + "counter-increment", + "counter-reset", + "cue-after", + "cue-before", + "cursor", + "direction", + "display", + "elevation", + "empty-cells", + "float", + "font-family", + "font-size", + "font-style", + "font-variant", + "font-weight", + "height", + "left", + "letter-spacing", + "line-height", + "list-style-image", + "list-style-position", + "list-style-type", + "margin-trbl", + "max-height", + "max-width", + "min-height", + "min-width", + "orphans", + "outline-color", + "outline-style", + "outline-width", + "overflow", + "padding-trbl", + "page-break-after", + "page-break-before", + "page-break-inside", + "pause-after", + "pause-before", + "pitch-range", + "pitch", + "play-during", + "position", + "quotes", + "richness", + "right", + "speak-header", + "speak-numeral", + "speak-punctuation", + "speak", + "speech-rate", + "stress", + "table-layout", + "text-align", + "text-decoration", + "text-indent", + "text-transform", + "top", + "unicode-bidi", + "vertical-align", + "visibility", + "voice-family", + "volume", + "white-space", + "widows", + "width", + "word-spacing", + "z-index", +}; + +/** + * Dump a CSS bytecode stream to the given file handle + * + * \param bytecode The stream to dump + * \param length Length, in bytes, of bytecode + * \param fp File handle to output to + */ +void css_bytecode_dump(void *bytecode, uint32_t length, FILE *fp) +{ + uint32_t offset = 0; + +#define ADVANCE(n) do { \ + offset += (n); \ + bytecode = ((uint8_t *) bytecode) + (n); \ +} while(0) + + while (offset < length) { + opcode op; + uint8_t flags; + uint16_t value; + uint32_t opv = *((uint32_t *) bytecode); + + ADVANCE(sizeof(opv)); + + op = getOpcode(opv); + + fprintf(fp, "%s: ", opcode_names[op]); + + flags = getFlags(opv); + + if (flags & FLAG_INHERIT) { + fprintf(fp, "inherit"); + } else { + value = getValue(opv); + + switch (op) { + case OP_BACKGROUND_ATTACHMENT: + switch (value) { + case BACKGROUND_ATTACHMENT_FIXED: + fprintf(fp, "fixed"); + break; + case BACKGROUND_ATTACHMENT_SCROLL: + fprintf(fp, "scroll"); + break; + } + break; + case OP_BACKGROUND_COLOR: + switch (value) { + case BACKGROUND_COLOR_TRANSPARENT: + fprintf(fp, "transparent"); + break; + case BACKGROUND_COLOR_SET: + { + uint32_t colour = + *((uint32_t *) bytecode); + ADVANCE(sizeof(colour)); + fprintf(fp, "#%08x", colour); + } + break; + } + break; + case OP_BACKGROUND_IMAGE: + switch (value) { + case BACKGROUND_IMAGE_NONE: + fprintf(fp, "none"); + break; + case BACKGROUND_IMAGE_URI: + { + uint8_t *ptr = + *((uint8_t **) bytecode); + ADVANCE(sizeof(ptr)); + size_t len = + *((size_t *) bytecode); + ADVANCE(sizeof(len)); + fprintf(fp, "url('%.*s')", (int) len, + (char *) ptr); + } + break; + } + break; + case OP_BACKGROUND_REPEAT: + switch (value) { + case BACKGROUND_REPEAT_NO_REPEAT: + fprintf(fp, "no-repeat"); + break; + case BACKGROUND_REPEAT_REPEAT_X: + fprintf(fp, "repeat-x"); + break; + case BACKGROUND_REPEAT_REPEAT_Y: + fprintf(fp, "repeat-y"); + break; + case BACKGROUND_REPEAT_REPEAT: + fprintf(fp, "repeat"); + break; + } + break; + case OP_CLEAR: + switch (value) { + case CLEAR_NONE: + fprintf(fp, "none"); + break; + case CLEAR_LEFT: + fprintf(fp, "left"); + break; + case CLEAR_RIGHT: + fprintf(fp, "right"); + break; + case CLEAR_BOTH: + fprintf(fp, "both"); + break; + } + break; + default: + fprintf(fp, "Unknown opcode %x", op); + break; + } + } + + if (flags & FLAG_IMPORTANT) + fprintf(fp, " !important"); + + fprintf(fp, "; "); + } + +#undef ADVANCE + +} + + |