building CALL_EXPR's with string constants
Michael Nelson
mikenel@iapetus.com
Thu Jun 8 12:22:00 GMT 2000
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
More information about the Gcc
mailing list