#include "config.h" #include "system.h" #include "coretypes.h" #include "target.h" #include "tree.h" #include "tree-iterator.h" #include "gimple-expr.h" #include "diagnostic.h" #include "opts.h" #include "fold-const.h" #include "cgraph.h" #include "gimplify.h" #include "stor-layout.h" #include "debug.h" #include "convert.h" #include "langhooks.h" #include "langhooks-def.h" #include "common/common-target.h" /* Language-dependent contents of a type. */ struct GTY (()) lang_type { char dummy; }; /* Language-dependent contents of a decl. */ struct GTY (()) lang_decl { char dummy; }; /* Language-dependent contents of an identifier. This must include a tree_identifier. */ struct GTY (()) lang_identifier { struct tree_identifier common; }; /* The resulting tree type. */ union GTY ((desc ("TREE_CODE (&%h.generic) == IDENTIFIER_NODE"), chain_next ("CODE_CONTAINS_STRUCT (TREE_CODE (&%h.generic), " "TS_COMMON) ? ((union lang_tree_node *) TREE_CHAIN " "(&%h.generic)) : NULL"))) lang_tree_node { union tree_node GTY ((tag ("0"), desc ("tree_node_structure (&%h)"))) generic; struct lang_identifier GTY ((tag ("1"))) identifier; }; /* We don't use language_function. */ struct GTY (()) language_function { int dummy; }; /* Creates an expression whose value is that of EXPR, converted to type TYPE. This function implements all reasonable scalar conversions. */ tree convert (tree type, tree expr) { return expr; } /* Language hooks. */ static bool elna_langhook_init (void) { /* NOTE: Newer versions of GCC use only: build_common_tree_nodes (false); See Eugene's comment in the comments section. */ build_common_tree_nodes (false); /* I don't know why this has to be done explicitly. */ void_list_node = build_tree_list (NULL_TREE, void_type_node); build_common_builtin_nodes (); return true; } static void elna_parse_file (const char *filename) { FILE *file = fopen (filename, "r"); if (file == NULL) { fatal_error (UNKNOWN_LOCATION, "cannot open filename %s: %m", filename); } tree main_fndecl_type_param[] = { integer_type_node, build_pointer_type (build_pointer_type (char_type_node)) }; tree main_fndecl_type = build_function_type_array (integer_type_node, 2, main_fndecl_type_param); tree main_fndecl = build_fn_decl ("main", main_fndecl_type); tree resdecl = build_decl (UNKNOWN_LOCATION, RESULT_DECL, NULL_TREE, integer_type_node); DECL_RESULT (main_fndecl) = resdecl; tree set_result = build2 (INIT_EXPR, void_type_node, DECL_RESULT (main_fndecl), build_int_cst_type (integer_type_node, 3)); tree return_stmt = build1 (RETURN_EXPR, void_type_node, set_result); tree list = alloc_stmt_list (); append_to_statement_list (return_stmt, &list); tree new_block = build_block (NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE); tree bind_expr = build3 (BIND_EXPR, void_type_node, NULL_TREE, list, new_block); BLOCK_SUPERCONTEXT (new_block) = main_fndecl; DECL_INITIAL (main_fndecl) = new_block; DECL_SAVED_TREE (main_fndecl) = bind_expr; DECL_EXTERNAL (main_fndecl) = 0; DECL_PRESERVE_P (main_fndecl) = 1; gimplify_function_tree (main_fndecl); cgraph_node::finalize_function (main_fndecl, true); fclose(file); } static void elna_langhook_parse_file (void) { for (int i = 0; i < num_in_fnames; i++) { elna_parse_file (in_fnames[i]); } } static tree elna_langhook_type_for_mode (enum machine_mode mode, int unsignedp) { if (mode == TYPE_MODE (float_type_node)) return float_type_node; if (mode == TYPE_MODE (double_type_node)) return double_type_node; if (mode == TYPE_MODE (intQI_type_node)) return unsignedp ? unsigned_intQI_type_node : intQI_type_node; if (mode == TYPE_MODE (intHI_type_node)) return unsignedp ? unsigned_intHI_type_node : intHI_type_node; if (mode == TYPE_MODE (intSI_type_node)) return unsignedp ? unsigned_intSI_type_node : intSI_type_node; if (mode == TYPE_MODE (intDI_type_node)) return unsignedp ? unsigned_intDI_type_node : intDI_type_node; if (mode == TYPE_MODE (intTI_type_node)) return unsignedp ? unsigned_intTI_type_node : intTI_type_node; if (mode == TYPE_MODE (integer_type_node)) return unsignedp ? unsigned_type_node : integer_type_node; if (mode == TYPE_MODE (long_integer_type_node)) return unsignedp ? long_unsigned_type_node : long_integer_type_node; if (mode == TYPE_MODE (long_long_integer_type_node)) return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node; if (COMPLEX_MODE_P (mode)) { if (mode == TYPE_MODE (complex_float_type_node)) return complex_float_type_node; if (mode == TYPE_MODE (complex_double_type_node)) return complex_double_type_node; if (mode == TYPE_MODE (complex_long_double_type_node)) return complex_long_double_type_node; if (mode == TYPE_MODE (complex_integer_type_node) && !unsignedp) return complex_integer_type_node; } /* gcc_unreachable */ return NULL; } static tree elna_langhook_type_for_size (unsigned int bits ATTRIBUTE_UNUSED, int unsignedp ATTRIBUTE_UNUSED) { gcc_unreachable (); return NULL; } /* Record a builtin function. We just ignore builtin functions. */ static tree elna_langhook_builtin_function (tree decl) { return decl; } static bool elna_langhook_global_bindings_p (void) { gcc_unreachable (); return true; } static tree elna_langhook_pushdecl (tree decl ATTRIBUTE_UNUSED) { gcc_unreachable (); } static tree elna_langhook_getdecls (void) { return NULL; } #undef LANG_HOOKS_NAME #define LANG_HOOKS_NAME "Tiny" #undef LANG_HOOKS_INIT #define LANG_HOOKS_INIT elna_langhook_init #undef LANG_HOOKS_PARSE_FILE #define LANG_HOOKS_PARSE_FILE elna_langhook_parse_file #undef LANG_HOOKS_TYPE_FOR_MODE #define LANG_HOOKS_TYPE_FOR_MODE elna_langhook_type_for_mode #undef LANG_HOOKS_TYPE_FOR_SIZE #define LANG_HOOKS_TYPE_FOR_SIZE elna_langhook_type_for_size #undef LANG_HOOKS_BUILTIN_FUNCTION #define LANG_HOOKS_BUILTIN_FUNCTION elna_langhook_builtin_function #undef LANG_HOOKS_GLOBAL_BINDINGS_P #define LANG_HOOKS_GLOBAL_BINDINGS_P elna_langhook_global_bindings_p #undef LANG_HOOKS_PUSHDECL #define LANG_HOOKS_PUSHDECL elna_langhook_pushdecl #undef LANG_HOOKS_GETDECLS #define LANG_HOOKS_GETDECLS elna_langhook_getdecls struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER; #include "gt-tiny-tiny1.h" #include "gtype-tiny.h"