public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: building CALL_EXPR's with string constants
@ 2000-06-08 14:01 Mike Stump
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Stump @ 2000-06-08 14:01 UTC (permalink / raw)
  To: gcc, mikenel

I generally do this by writting the code in C, running emacs, and then
gdb in emacs, and then cc1 in gdb, and watch to see what cc1 does with
the code.  Then I copy it.  It'll show you the routines to call, how
to call them, what you need to check for, and so on...  If you just
ask it.  It usually gives pretty good advice.

> From: Michael Nelson <mikenel@iapetus.com>
> To: "'gcc@gcc.gnu.org'" <gcc@gcc.gnu.org>
> Date: Thu, 8 Jun 2000 15:26:05 -0400 

> some difficulty figuring out how to call printf with a string
> constant.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* building CALL_EXPR's with string constants
@ 2000-06-08 12:22 Michael Nelson
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Nelson @ 2000-06-08 12:22 UTC (permalink / raw)
  To: 'gcc@gcc.gnu.org'

I am currently working on a language frontend for GCC (for an experimental
language), and am some difficulty figuring out how to call printf with a
string constant. The ratty code below crashes at expand_expr_stmt(). If I
change printf()'s parameter type to integer_type_node and pass an integer
constant, the compiler has no problem (though, obviously, the outputted code
is useless).

Any pointers?

        tree t;
        tree ftype;
        tree string_type_node, decl;
        string_type_node = build_pointer_type (char_type_node);

        ftype = build_function_type (integer_type_node, listify
(string_type_node));
        decl = build_decl (FUNCTION_DECL, get_identifier ("printf"), ftype);
        DECL_EXTERNAL (decl) = 1;
        TREE_PUBLIC (decl) = 1;
        make_decl_rtl (decl, (char *) NULL_PTR, 1);  
        assemble_external (decl);
        pushdecl (decl);

        ptr = build1 (ADDR_EXPR, build_pointer_type (ftype), decl);
        t = build (CALL_EXPR, integer_type_node, ptr, listify (build_string
(4, "test")), NULL_TREE);
        TREE_SIDE_EFFECTS (t) = 1;
        expand_expr_stmt (t);

Thanks,
-mike

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2000-06-08 14:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-08 14:01 building CALL_EXPR's with string constants Mike Stump
  -- strict thread matches above, loose matches on Subject: below --
2000-06-08 12:22 Michael Nelson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).