summaryrefslogtreecommitdiff
path: root/dtc-lexer.l
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2009-12-08 14:24:42 +1100
committerJon Loeliger <jdl@jdl.com>2010-01-14 07:52:25 -0600
commitd68cb36b0bebc7711ada9b750f3c19398c44efb7 (patch)
tree16caaff272f32c7d3179a96dcdc444c8c620565c /dtc-lexer.l
parentd75b33af676d0beac8398651a7f09037555a550b (diff)
downloaddtc-d68cb36b0bebc7711ada9b750f3c19398c44efb7.tar.gz
dtc: Simpler interface to source file management
This patch cleans up our handling of input files, particularly dts source files, but also (to an extent) other input files such as those used by /incbin/ and those used in -I dtb and -I fs modes. We eliminate the current clunky mechanism which combines search paths (which we don't actually use at present) with the open relative to current source file behaviour, which we do. Instead there's a single srcfile_relative_open() entry point for callers which opens a new input file relative to the current source file (which the srcpos code tracks internally). It doesn't currently do search paths, but we can add that later without messing with the callers, by drawing the search path from a global (which makes sense anyway, rather than shuffling it around the rest of the processing code). That suffices for non-dts input files. For the actual dts files, srcfile_push() and srcfile_pop() wrappers open the file while also keeping track of it as the current source file for future opens. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'dtc-lexer.l')
-rw-r--r--dtc-lexer.l91
1 files changed, 10 insertions, 81 deletions
diff --git a/dtc-lexer.l b/dtc-lexer.l
index d142de5..12467c0 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -40,7 +40,7 @@ LINECOMMENT "//".*\n
#define YY_USER_ACTION \
{ \
- yylloc.file = srcpos_file; \
+ yylloc.file = current_srcfile; \
yylloc.first_line = yylineno; \
}
@@ -165,100 +165,29 @@ static int pop_input_file(void);
%%
-
-/*
- * Stack of nested include file contexts.
- */
-
-struct incl_file {
- struct dtc_file *file;
- YY_BUFFER_STATE yy_prev_buf;
- int yy_prev_lineno;
- struct incl_file *prev;
-};
-
-static struct incl_file *incl_file_stack;
-
-
-/*
- * Detect infinite include recursion.
- */
-#define MAX_INCLUDE_DEPTH (100)
-
-static int incl_depth = 0;
-
-
static void push_input_file(const char *filename)
{
- struct incl_file *incl_file;
- struct dtc_file *newfile;
- struct search_path search, *searchptr = NULL;
-
assert(filename);
- if (incl_depth++ >= MAX_INCLUDE_DEPTH)
- die("Includes nested too deeply");
-
- if (srcpos_file) {
- search.dir = srcpos_file->dir;
- search.next = NULL;
- search.prev = NULL;
- searchptr = &search;
- }
-
- newfile = dtc_open_file(filename, searchptr);
-
- incl_file = xmalloc(sizeof(struct incl_file));
-
- /*
- * Save current context.
- */
- incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
- incl_file->yy_prev_lineno = yylineno;
- incl_file->file = srcpos_file;
- incl_file->prev = incl_file_stack;
+ current_srcfile->lineno = yylineno;
- incl_file_stack = incl_file;
+ srcfile_push(filename);
- /*
- * Establish new context.
- */
- srcpos_file = newfile;
+ yyin = current_srcfile->f;
yylineno = 1;
- yyin = newfile->file;
- yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
+
+ yypush_buffer_state(yy_create_buffer(yyin, YY_BUF_SIZE));
}
static int pop_input_file(void)
{
- struct incl_file *incl_file;
-
- if (incl_file_stack == 0)
+ if (srcfile_pop() == 0)
return 0;
- dtc_close_file(srcpos_file);
-
- /*
- * Pop.
- */
- --incl_depth;
- incl_file = incl_file_stack;
- incl_file_stack = incl_file->prev;
-
- /*
- * Recover old context.
- */
- yy_delete_buffer(YY_CURRENT_BUFFER);
- yy_switch_to_buffer(incl_file->yy_prev_buf);
- yylineno = incl_file->yy_prev_lineno;
- srcpos_file = incl_file->file;
- yyin = incl_file->file ? incl_file->file->file : NULL;
-
- /*
- * Free old state.
- */
- free(incl_file);
+ yypop_buffer_state();
+ yylineno = current_srcfile->lineno;
+ yyin = current_srcfile->f;
return 1;
}