diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-08-22 14:33:23 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-08-22 14:56:27 +0100 |
commit | cbfc0ee239fafc0dadaae314138410f9119c65fa (patch) | |
tree | 3b8d92a090ee0665df75c9b4e7c197d692e2d951 /gcc/rust/backend/rust-compile-item.h | |
parent | 79092784f20b99f26da847d2b921d3ea1ffc1a24 (diff) | |
download | gcc-cbfc0ee239fafc0dadaae314138410f9119c65fa.zip gcc-cbfc0ee239fafc0dadaae314138410f9119c65fa.tar.gz gcc-cbfc0ee239fafc0dadaae314138410f9119c65fa.tar.bz2 |
This allows for query based compilation
Rust can forward declare items to avoid the need for prototypes for
example. This means when a path resolved to a node we must look it up
and see if it is already compiled or go and compiler it. This also applies
to generics which are monomorphized and might have already been compiled.
This adds two new keyword arguments bool query_mode and ref_locus, these
say to the classes that this is query based mode and ICE when we get
error_mark_node when we fail to compile something. This will need to be
changed once we get to a certain level of maturity but this helps
diagnose bugs for now. The ref_locus refers to the location of the
reference to this item such that the compilation of an item can give us
a reference expression to this item with this ref_locus. For example:
call (123)
And call is query compiled and the ref_locus is this call_expression.
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index af0bc43..eb7d9ef 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -33,14 +33,28 @@ namespace Compile { class CompileItem : public HIRCompileBase { +protected: using Rust::Compile::HIRCompileBase::visit; public: - static void compile (HIR::Item *item, Context *ctx, bool compile_fns = true, - TyTy::BaseType *concrete = nullptr) + static Bexpression *compile (HIR::Item *item, Context *ctx, + bool compile_fns = true, + TyTy::BaseType *concrete = nullptr, + bool is_query_mode = false, + Location ref_locus = Location ()) { - CompileItem compiler (ctx, compile_fns, concrete); + CompileItem compiler (ctx, compile_fns, concrete, ref_locus); item->accept_vis (compiler); + + if (is_query_mode + && ctx->get_backend ()->is_error_expression (compiler.reference)) + { + rust_error_at (ref_locus, "failed to compile item: %s", + item->as_string ().c_str ()); + rust_assert ( + !ctx->get_backend ()->is_error_expression (compiler.reference)); + } + return compiler.reference; } void visit (HIR::StaticItem &var) override @@ -73,6 +87,8 @@ public: ctx->insert_var_decl (var.get_mappings ().get_hirid (), static_global); ctx->push_var (static_global); + + reference = ctx->get_backend ()->var_expression (static_global, ref_locus); } void visit (HIR::ConstantItem &constant) override @@ -98,6 +114,8 @@ public: ctx->push_const (const_expr); ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr); + + reference = const_expr; } void visit (HIR::Function &function) override @@ -139,8 +157,14 @@ public: { Bfunction *dummy = nullptr; if (!ctx->lookup_function_decl (fntype->get_ty_ref (), &dummy)) - ctx->insert_function_decl (fntype->get_ty_ref (), lookup, fntype); - + { + ctx->insert_function_decl (fntype->get_ty_ref (), lookup, + fntype); + } + + reference + = ctx->get_backend ()->function_code_expression (lookup, + ref_locus); return; } } @@ -287,6 +311,9 @@ public: ctx->pop_fn (); ctx->push_function (fndecl); + + reference + = ctx->get_backend ()->function_code_expression (fndecl, ref_locus); } void visit (HIR::ImplBlock &impl_block) override @@ -319,13 +346,18 @@ public: CompileItem::compile (item.get (), ctx, compile_fns); } -private: - CompileItem (Context *ctx, bool compile_fns, TyTy::BaseType *concrete) - : HIRCompileBase (ctx), compile_fns (compile_fns), concrete (concrete) +protected: + CompileItem (Context *ctx, bool compile_fns, TyTy::BaseType *concrete, + Location ref_locus) + : HIRCompileBase (ctx), compile_fns (compile_fns), concrete (concrete), + reference (ctx->get_backend ()->error_expression ()), + ref_locus (ref_locus) {} bool compile_fns; TyTy::BaseType *concrete; + Bexpression *reference; + Location ref_locus; }; } // namespace Compile |