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]

building CALL_EXPR's with string constants


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

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