Add support for decimal, octal and binary based cell values.

New syntax d#, b#, o# and h# allow for an explicit prefix
on cell values to specify their base.  Eg: <d# 123>

Signed-off-by: Jon Loeliger <jdl@freescale.com>
This commit is contained in:
Jon Loeliger 2007-02-15 10:59:27 -06:00
parent c226ddcabc
commit af0278a3a0
4 changed files with 51 additions and 8 deletions

21
data.c
View file

@ -19,6 +19,7 @@
*/
#include "dtc.h"
#include "dtc-parser.tab.h"
void fixup_free(struct fixup *f)
{
@ -224,6 +225,26 @@ struct data data_merge(struct data d1, struct data d2)
return d;
}
/*
* Convert a string representation of a numberic cell
* in the given base into a cell.
*/
cell_t data_convert_cell(char *s, unsigned int base)
{
cell_t c;
extern YYLTYPE yylloc;
c = strtoul(s, NULL, base);
if (errno == EINVAL || errno == ERANGE) {
fprintf(stderr,
"Line %d: Invalid cell value '%s'; %d assumed\n",
yylloc.first_line, s, c);
}
return c;
}
struct data data_append_cell(struct data d, cell_t word)
{
cell_t beword = cpu_to_be32(word);