This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Ada, treelang needs to be converted to --enable-mapped-location
- From: Per Bothner <per at bothner dot com>
- To: Richard Kenner <kenner at vlsi1 dot ultra dot nyu dot edu>
- Cc: gcc at gcc dot gnu dot org
- Date: Mon, 04 Oct 2004 00:28:11 -0700
- Subject: Re: Ada, treelang needs to be converted to --enable-mapped-location
- References: <10410022053.AA16576@vlsi1.ultra.nyu.edu>
Richard Kenner wrote:
To summarize: you can create the Source_Ptr -> source_location
mapping in two basic ways: interleaved with lexing, or as a
mapping when the Source_Buffer is read in. Whichever you prefer.
I guess the question is what does "read" mean in the context of a
compiler that doesn't call the lexer library.
I'm confused. What is "the lexer library"? It certainly seems that
Ada calls a lexer library - it appears to be the Scans package. If you
mean libcpp (except for line-map.[hc]), that's not a lexer library,
that's a pre-processor library. It is not used for Java or Fortran
either.
Don't get confused by line-map.[hc] being in libcpp. That's mainly
because some people wanted to put libcpp in a separate top-level
library, and because libcpp depends on line-map[hc]. Logically,
line-map.[hc] is a separate library, but that seemed overkill.
My intention by the word "read" was when when the character of the
source file are read into the compiler's Source_Buffer, which from
what I gather happens *before* lexing.
My suggestion that one option is to create thr Source_Ptr ->
source_location mapping (i.e. data structures to make the mapping
reasonably efficient) be done more-or-less at the same time as the
source file is read into a Source_Buffer and Source_Ptr mapping is
updated.
Alternatively, you can so it using call-backs to line-map.[hc] while the
Ada front-end is scanning the Source_buffer. That is my recommendation.
It's tricky to make calls from the Ada part of the code since, as Geert
pointed out, that code is also used wiht non-GCC back-ends.
Yes, but that doesn't preclude using the line_map structure, even
with non-GCC back-ends. There is no reason why the Ada front-end
can't use line_map for a program that say just does analysis and
never touches a tree or an rtx.
The Source_Ptr type appears to be an abstract source position encoded
as a int. I see no reason why you can't change its *implementation*
to be the source_location type defined in line-map.h. You can do this
*regardless* of whether "back-end" you use. True, it's a non-trivial
change, and since I obviously don't know all the ramifications and
features of your current implementation, it's not my place to suggest
you make such a pervasive change. However, my instinct is that would
be the best long-term solution.
Moreover, it's quite common for the Ada front-end to read a file and
no item in the file is in the produced tree.
Like C, C++, and Java.
So I'd interpret "read" as meaning "being asked to convert the first
GNAT tree node using this file into a GCC node".
You can certainly do that. It's not what I would have suggested, but
it may be a reasonable solution.
Is there a way to find
out if a filename has been seen already or do we need a separate hash table
just for that purpose?
Whether a filename has been seen is a front-end issue.
You clearly don't need a separate hash table, if you're willing to add a
boolean field to the Source_Buffer type.
Alternatively, the (relatively new) TRANSLATION_UNIT_DECL may be a
reasonably place to hang per-source-file data.
--
--Per Bothner
per@bothner.com http://per.bothner.com/