This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating a global string constant node.


On Sat, Aug 4, 2012 at 12:52 PM, Matt Davis <mattdavis9@gmail.com> wrote:
> Hello,
> I need to create a global string constant node.  In the past, I have
> always been able to add global variables, but I have always left them
> uninitialized.  I know the trick is to build_decl() of VAR_DECL and, I
> guess in this case the type char_node_type.  However, I want the
> global decl initialized and referring to a string literal.  I know of
> build_string_literal()  but that does not create a decl node that I am
> aware of.  I am unsure as to how to set that literal to my VAR_DECL
> instance, so that it is in the read-only section of the resulting
> binary, and referred to by the identifier I pass to build_decl().  Is
> there an example in the code my grep-foo has failed me for this
> specific case?

After a bunch of tries, I have what I need.  I knew probability would
pay off, some call this persistence, I call it probability.   Anyways,
I had to set DECL_INITIAL for the VAR_DECL I created.  I set the decl
with the string literal from build_string_literal().  I then called
varpool_finalize_decl() on the decl instance and also marked the node
as "needed" via varpool_mark_needed_node().

-Matt


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]