diff options
author | Anton Staaf <robotboy@chromium.org> | 2011-09-09 12:16:30 -0700 |
---|---|---|
committer | Jon Loeliger <jdl@jdl.com> | 2011-09-22 09:24:31 -0500 |
commit | a4ea2fa9518ff0f4d7f4a08647599a727faac2e0 (patch) | |
tree | 1d51fe9f5d39c2beb168a20efb90cc51e6f46d52 /dtc-parser.y | |
parent | 83df28bd39979b32a75656cac291c36dbd4e5497 (diff) | |
download | dtc-a4ea2fa9518ff0f4d7f4a08647599a727faac2e0.tar.gz |
dtc: Support character literals in cell lists
With this patch the following property assignment:
property = <0x12345678 'a' '\r' 100>;
is equivalent to:
property = <0x12345678 0x00000061 0x0000000D 0x00000064>
Signed-off-by: Anton Staaf <robotboy@chromium.org>
Acked-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-parser.y')
-rw-r--r-- | dtc-parser.y | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/dtc-parser.y b/dtc-parser.y index 5e84a67..554f11a 100644 --- a/dtc-parser.y +++ b/dtc-parser.y @@ -34,6 +34,7 @@ extern struct boot_info *the_boot_info; extern int treesource_error; static unsigned long long eval_literal(const char *s, int base, int bits); +static unsigned char eval_char_literal(const char *s); %} %union { @@ -57,6 +58,7 @@ static unsigned long long eval_literal(const char *s, int base, int bits); %token DT_MEMRESERVE %token <propnodename> DT_PROPNODENAME %token <literal> DT_LITERAL +%token <literal> DT_CHAR_LITERAL %token <cbase> DT_BASE %token <byte> DT_BYTE %token <data> DT_STRING @@ -265,6 +267,10 @@ cellval: { $$ = eval_literal($1, 0, 32); } + | DT_CHAR_LITERAL + { + $$ = eval_char_literal($1); + } ; bytestring: @@ -343,3 +349,29 @@ static unsigned long long eval_literal(const char *s, int base, int bits) print_error("bad literal"); return val; } + +static unsigned char eval_char_literal(const char *s) +{ + int i = 1; + char c = s[0]; + + if (c == '\0') + { + print_error("empty character literal"); + return 0; + } + + /* + * If the first character in the character literal is a \ then process + * the remaining characters as an escape encoding. If the first + * character is neither an escape or a terminator it should be the only + * character in the literal and will be returned. + */ + if (c == '\\') + c = get_escape_char(s, &i); + + if (s[i] != '\0') + print_error("malformed character literal"); + + return c; +} |