aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gcc/elna1.cc57
-rw-r--r--gcc/gcc/gelna.texi12
-rw-r--r--gcc/lang-specs.h2
-rw-r--r--gcc/lang.opt4
4 files changed, 72 insertions, 3 deletions
diff --git a/gcc/gcc/elna1.cc b/gcc/gcc/elna1.cc
index c87d462..b9a9086 100644
--- a/gcc/gcc/elna1.cc
+++ b/gcc/gcc/elna1.cc
@@ -38,6 +38,7 @@ along with GCC; see the file COPYING3. If not see
tree elna_global_trees[ELNA_TI_MAX];
hash_map<nofree_string_hash, tree> *elna_global_decls = nullptr;
+std::vector<std::string> elna_include_dirs;
/* The resulting tree type. */
@@ -65,6 +66,33 @@ static bool elna_langhook_init(void)
using dependency_state = elna::boot::dependency_state<std::shared_ptr<elna::gcc::symbol_table>>;
+static std::vector<std::filesystem::path> find_module(const elna::boot::import_declaration* declaration)
+{
+ std::filesystem::path relative_path = elna::boot::build_path(declaration->segments);
+ std::vector<std::filesystem::path> found;
+
+ for (const auto& include_path : elna_include_dirs)
+ {
+ std::filesystem::path full_path = include_path / relative_path;
+
+ if (std::filesystem::exists(full_path))
+ {
+ found.push_back(std::move(full_path));
+ }
+ }
+ if (found.empty())
+ {
+ found.push_back(std::move(relative_path));
+ }
+ else if (found.size() > 1)
+ {
+ location_t gcc_location = elna::gcc::get_location(&declaration->position());
+ error_at(gcc_location, "Module %s was found in more than one include path",
+ relative_path.native().c_str());
+ }
+ return found;
+}
+
static elna::boot::dependency elna_parse_file(dependency_state& state, const char *filename)
{
std::ifstream entry_point{ filename, std::ios::in };
@@ -80,9 +108,9 @@ static elna::boot::dependency elna_parse_file(dependency_state& state, const cha
if (!outcome.has_errors())
{
- for (elna::boot::import_declaration const* sub_tree : outcome.tree->imports)
+ for (const elna::boot::import_declaration* sub_tree : outcome.tree->imports)
{
- std::filesystem::path sub_path = "source" / elna::boot::build_path(sub_tree->segments);
+ std::filesystem::path sub_path = find_module(sub_tree)[0];
dependency_state::const_iterator cached_import = state.find(sub_path);
if (cached_import == state.cend())
@@ -215,6 +243,28 @@ static unsigned int elna_langhook_option_lang_mask(void)
return CL_Elna;
}
+/* Handle a front end specific command-line option, in this case -I.
+ Return true if it was recognized/handled here, false to let the
+ common option handling machinery take over. */
+static bool elna_langhook_handle_option(
+ size_t scode, const char *arg,
+ HOST_WIDE_INT value ATTRIBUTE_UNUSED,
+ int kind ATTRIBUTE_UNUSED,
+ location_t loc ATTRIBUTE_UNUSED,
+ const struct cl_option_handlers * handlers ATTRIBUTE_UNUSED)
+{
+ opt_code code = static_cast<opt_code>(scode);
+
+ switch (code)
+ {
+ case OPT_I:
+ elna_include_dirs.push_back(arg);
+ return true;
+ default:
+ return true;
+ }
+}
+
/* 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)
@@ -254,6 +304,9 @@ tree convert(tree type, tree expr)
#undef LANG_HOOKS_OPTION_LANG_MASK
#define LANG_HOOKS_OPTION_LANG_MASK elna_langhook_option_lang_mask
+#undef LANG_HOOKS_HANDLE_OPTION
+#define LANG_HOOKS_HANDLE_OPTION elna_langhook_handle_option
+
struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
#include "gt-elna-elna1.h"
diff --git a/gcc/gcc/gelna.texi b/gcc/gcc/gelna.texi
index e4bc6ce..74eaecd 100644
--- a/gcc/gcc/gelna.texi
+++ b/gcc/gcc/gelna.texi
@@ -114,6 +114,18 @@ only documents the options specific to @command{gelna}.
@c man begin OPTIONS gelna
+@table @gcctabopt
+@item -I @var{dir}
+@opindex I
+Specify a directory to use when searching for imported modules at
+compile time. Multiple @option{-I} options can be used, and if a
+module of the same name is found in more than one searched directory,
+an error is reported.
+
+If a module is not found in any directory given with @option{-I}, the
+compiler falls back to looking for it in the current directory.
+@end table
+
@c man end
@node Option Index
diff --git a/gcc/lang-specs.h b/gcc/lang-specs.h
index ac3611d..5ef06e9 100644
--- a/gcc/lang-specs.h
+++ b/gcc/lang-specs.h
@@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see
"elna1 %i \
%{!Q:-quiet} " DUMPS_OPTIONS("") " %{m*} %{aux-info*} \
%{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs} \
- %{pg:-p} %{p} %{f*} %{undef} \
+ %{pg:-p} %{p} %{f*} %{undef} %{I*} \
%{!fsyntax-only:%{S:%W{o*}%{!o*:-o %w%b.s}}} \
%{fsyntax-only:-o %j} %{-param*} \
%{!fsyntax-only:%(invoke_as)}",
diff --git a/gcc/lang.opt b/gcc/lang.opt
index 1c8c95c..e8e5920 100644
--- a/gcc/lang.opt
+++ b/gcc/lang.opt
@@ -21,3 +21,7 @@
Language
Elna
+
+I
+Elna Joined Separate MissingArgError(missing path after %qs)
+-I <dir> Add <dir> to the end of the main include path.