elna/gcc/elna1.cc

244 lines
5.8 KiB
C++
Raw Normal View History

2024-12-23 13:54:11 +01:00
#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 "stor-layout.h"
#include "debug.h"
#include "langhooks.h"
#include "langhooks-def.h"
#include "common/common-target.h"
#include <fstream>
#include <elna/source/driver.h>
2024-12-29 22:28:53 +01:00
#include "elna/gcc/elna-tree.h"
2024-12-27 23:38:25 +01:00
#include "elna/gcc/elna-generic.h"
#include "elna/gcc/elna-diagnostic.h"
2024-12-23 13:54:11 +01:00
#include "parser.hh"
/* Language-dependent contents of a type. */
struct GTY (()) lang_type
{
2025-01-03 22:18:35 +01:00
char dummy;
2024-12-23 13:54:11 +01:00
};
/* Language-dependent contents of a decl. */
struct GTY (()) lang_decl
{
2025-01-03 22:18:35 +01:00
char dummy;
2024-12-23 13:54:11 +01:00
};
/* Language-dependent contents of an identifier. This must include a
tree_identifier. */
struct GTY (()) lang_identifier
{
2025-01-03 22:18:35 +01:00
struct tree_identifier common;
2024-12-23 13:54:11 +01:00
};
/* 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
{
2025-01-03 22:18:35 +01:00
union tree_node GTY ((tag ("0"), desc ("tree_node_structure (&%h)"))) generic;
struct lang_identifier GTY ((tag ("1"))) identifier;
2024-12-23 13:54:11 +01:00
};
/* We don't use language_function. */
struct GTY (()) language_function
{
2025-01-03 22:18:35 +01:00
int dummy;
2024-12-23 13:54:11 +01:00
};
/* Language hooks. */
2024-12-27 23:38:25 +01:00
static bool elna_langhook_init(void)
2024-12-23 13:54:11 +01:00
{
2024-12-29 22:28:53 +01:00
build_common_tree_nodes(false);
2025-01-03 22:18:35 +01:00
elna::gcc::init_ttree();
2024-12-23 13:54:11 +01:00
2024-12-29 22:28:53 +01:00
void_list_node = build_tree_list(NULL_TREE, void_type_node);
2024-12-23 13:54:11 +01:00
2024-12-29 22:28:53 +01:00
build_common_builtin_nodes();
2024-12-23 13:54:11 +01:00
2024-12-27 23:38:25 +01:00
return true;
2024-12-23 13:54:11 +01:00
}
2024-12-29 22:28:53 +01:00
static void elna_parse_file(const char *filename)
2024-12-23 13:54:11 +01:00
{
2024-12-27 23:38:25 +01:00
std::ifstream file{ filename, std::ios::in };
2024-12-23 13:54:11 +01:00
2024-12-27 23:38:25 +01:00
if (!file)
2024-12-23 13:54:11 +01:00
{
2025-01-03 22:18:35 +01:00
fatal_error(UNKNOWN_LOCATION, "cannot open filename %s: %m", filename);
2024-12-23 13:54:11 +01:00
}
2024-12-27 23:38:25 +01:00
elna::source::driver driver{ filename };
elna::source::lexer lexer(file);
yy::parser parser(lexer, driver);
2024-12-23 13:54:11 +01:00
2024-12-27 23:38:25 +01:00
linemap_add(line_table, LC_ENTER, 0, filename, 1);
2025-01-03 22:18:35 +01:00
if (parser())
2024-12-23 13:54:11 +01:00
{
2024-12-27 23:38:25 +01:00
for (const auto& error : driver.errors())
2024-12-23 13:54:11 +01:00
{
2024-12-28 14:33:35 +01:00
auto gcc_location = elna::gcc::get_location(&error->position);
2024-12-23 13:54:11 +01:00
2024-12-27 23:38:25 +01:00
error_at(gcc_location, error->what().c_str());
2024-12-23 13:54:11 +01:00
}
}
2024-12-27 23:38:25 +01:00
else
{
elna::gcc::generic_visitor generic_visitor;
generic_visitor.visit(driver.tree.get());
}
linemap_add(line_table, LC_LEAVE, 0, NULL, 0);
2024-12-23 13:54:11 +01:00
}
2024-12-29 22:28:53 +01:00
static void elna_langhook_parse_file(void)
2024-12-23 13:54:11 +01:00
{
2025-01-03 22:18:35 +01:00
for (unsigned int i = 0; i < num_in_fnames; i++)
2024-12-23 13:54:11 +01:00
{
2025-01-03 22:18:35 +01:00
elna_parse_file(in_fnames[i]);
2024-12-23 13:54:11 +01:00
}
}
2025-01-03 22:18:35 +01:00
static tree elna_langhook_type_for_mode(enum machine_mode mode, int unsignedp)
2024-12-23 13:54:11 +01:00
{
2025-01-03 22:18:35 +01:00
if (mode == TYPE_MODE(float_type_node))
2024-12-23 13:54:11 +01:00
{
2025-01-03 22:18:35 +01:00
return float_type_node;
2024-12-23 13:54:11 +01:00
}
2025-01-03 22:18:35 +01:00
else 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;
}
else if (mode == TYPE_MODE(intHI_type_node))
{
return unsignedp ? unsigned_intHI_type_node : intHI_type_node;
}
else if (mode == TYPE_MODE(intSI_type_node))
{
return unsignedp ? unsigned_intSI_type_node : intSI_type_node;
}
else if (mode == TYPE_MODE(intDI_type_node))
{
return unsignedp ? unsigned_intDI_type_node : intDI_type_node;
}
else if (mode == TYPE_MODE(intTI_type_node))
{
return unsignedp ? unsigned_intTI_type_node : intTI_type_node;
}
else if (mode == TYPE_MODE(integer_type_node))
{
return unsignedp ? unsigned_type_node : integer_type_node;
}
else if (mode == TYPE_MODE(long_integer_type_node))
{
return unsignedp ? long_unsigned_type_node : long_integer_type_node;
}
else 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 nullptr;
2024-12-23 13:54:11 +01:00
}
2024-12-29 22:28:53 +01:00
static tree elna_langhook_type_for_size(unsigned int bits ATTRIBUTE_UNUSED,
int unsignedp ATTRIBUTE_UNUSED)
2024-12-23 13:54:11 +01:00
{
2024-12-29 22:28:53 +01:00
gcc_unreachable();
2024-12-23 13:54:11 +01:00
}
/* Record a builtin function. We just ignore builtin functions. */
2024-12-29 22:28:53 +01:00
static tree elna_langhook_builtin_function(tree decl)
2024-12-23 13:54:11 +01:00
{
2024-12-29 22:28:53 +01:00
return decl;
2024-12-23 13:54:11 +01:00
}
2024-12-29 22:28:53 +01:00
static bool elna_langhook_global_bindings_p(void)
2024-12-23 13:54:11 +01:00
{
2025-01-07 14:37:30 +01:00
return false;
2024-12-23 13:54:11 +01:00
}
2024-12-29 22:28:53 +01:00
static tree elna_langhook_pushdecl(tree decl ATTRIBUTE_UNUSED)
2024-12-23 13:54:11 +01:00
{
2024-12-29 22:28:53 +01:00
gcc_unreachable();
2024-12-23 13:54:11 +01:00
}
2024-12-29 22:28:53 +01:00
static tree elna_langhook_getdecls(void)
2024-12-23 13:54:11 +01:00
{
2024-12-29 22:28:53 +01:00
return NULL;
2024-12-23 13:54:11 +01:00
}
#undef LANG_HOOKS_NAME
#define LANG_HOOKS_NAME "Elna"
#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-elna-elna1.h"
#include "gtype-elna.h"