summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-02-24 20:57:11 +0800
committerJohn Hodge <tpg@mutabah.net>2018-02-24 20:57:11 +0800
commitcec5b32e9918c97b0b044ff30b86892d974c82f4 (patch)
tree7c593b476db80574cecd948724e294c958dd047d /tools
parentef3009113058aa6b0a723c292b38a92baa87b0af (diff)
downloadmrust-cec5b32e9918c97b0b044ff30b86892d974c82f4.tar.gz
Standalone MIRI + Codegen MMIR - Drop support
Diffstat (limited to 'tools')
-rw-r--r--tools/standalone_miri/hir_sim.hpp3
-rw-r--r--tools/standalone_miri/main.cpp66
-rw-r--r--tools/standalone_miri/module_tree.cpp19
-rw-r--r--tools/standalone_miri/module_tree.hpp6
4 files changed, 82 insertions, 12 deletions
diff --git a/tools/standalone_miri/hir_sim.hpp b/tools/standalone_miri/hir_sim.hpp
index 93d5569c..4b111d3e 100644
--- a/tools/standalone_miri/hir_sim.hpp
+++ b/tools/standalone_miri/hir_sim.hpp
@@ -210,6 +210,9 @@ namespace HIR {
::std::string m_name; // if empty, the path is Generic in m_trait
PathParams m_params;
+ Path()
+ {
+ }
Path(SimplePath sp):
Path(GenericPath(sp))
{
diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp
index f060fef0..0d372991 100644
--- a/tools/standalone_miri/main.cpp
+++ b/tools/standalone_miri/main.cpp
@@ -97,8 +97,6 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
return MIRI_Invoke_Extern(fcn.external.link_name, fcn.external.link_abi, ::std::move(args));
}
- ::std::vector<bool> drop_flags = fcn.m_mir.drop_flags;
-
struct State
{
ModuleTree& modtree;
@@ -106,12 +104,14 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
Value ret;
::std::vector<Value> args;
::std::vector<Value> locals;
+ ::std::vector<bool> drop_flags;
State(ModuleTree& modtree, const Function& fcn, ::std::vector<Value> args):
modtree(modtree),
fcn(fcn),
ret(fcn.ret_ty),
- args(::std::move(args))
+ args(::std::move(args)),
+ drop_flags(fcn.m_mir.drop_flags)
{
locals.reserve(fcn.m_mir.locals.size());
for(const auto& ty : fcn.m_mir.locals)
@@ -906,7 +906,7 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
}
} break;
TU_ARM(se.src, Struct, re) {
- throw "TODO";
+ LOG_TODO(stmt);
} break;
}
LOG_DEBUG("- " << new_val);
@@ -915,9 +915,41 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
case ::MIR::Statement::TAG_Asm:
LOG_TODO(stmt);
break;
- case ::MIR::Statement::TAG_Drop:
- LOG_TODO(stmt);
- break;
+ TU_ARM(stmt, Drop, se) {
+ if( se.flag_idx == ~0u || state.drop_flags.at(se.flag_idx) )
+ {
+ ::HIR::TypeRef ty;
+ auto v = state.get_value_and_type(se.slot, ty);
+ // If an owned borrow, deref to inner
+ // If an array, drop all inners
+ if( !ty.wrappers.empty() )
+ LOG_TODO(stmt << " - " << ty);
+
+ // If a composite, check for drop glue and drop if present
+ if( ty.wrappers.empty() )
+ {
+ if( ty.inner_type == RawType::Composite )
+ {
+ if( ty.composite_type->drop_glue != ::HIR::Path() )
+ {
+ LOG_TODO(stmt << " - " << ty);
+ }
+ else
+ {
+ // No drop glue
+ }
+ }
+ else if( ty.inner_type == RawType::TraitObject )
+ {
+ LOG_TODO(stmt << " - " << ty);
+ }
+ else
+ {
+ // No destructor
+ }
+ }
+ }
+ } break;
case ::MIR::Statement::TAG_SetDropFlag:
LOG_TODO(stmt);
break;
@@ -1098,9 +1130,27 @@ Value MIRI_Invoke_Intrinsic(const ::std::string& name, const ::HIR::PathParams&
{
// Assume is a no-op which returns unit
}
+ else if( name == "offset" )
+ {
+ auto ptr_val = ::std::move(args.at(0));
+ auto& ofs_val = args.at(1);
+
+ auto r = ptr_val.allocation.alloc().get_relocation(0);
+ auto orig_ofs = ptr_val.read_usize(0);
+ auto delta_ofs = ptr_val.read_usize(0);
+ auto new_ofs = orig_ofs + delta_ofs;
+ if(POINTER_SIZE != 8) {
+ new_ofs &= 0xFFFFFFFF;
+ }
+
+
+ ptr_val.write_usize(0, new_ofs);
+ ptr_val.allocation.alloc().relocations.push_back({ 0, r });
+ return ptr_val;
+ }
else
{
- LOG_TODO("Call itrinsic \"" << name << "\"");
+ LOG_TODO("Call intrinsic \"" << name << "\"");
}
return rv;
}
diff --git a/tools/standalone_miri/module_tree.cpp b/tools/standalone_miri/module_tree.cpp
index a457db8e..2fc99bc4 100644
--- a/tools/standalone_miri/module_tree.cpp
+++ b/tools/standalone_miri/module_tree.cpp
@@ -173,16 +173,27 @@ bool Parser::parse_one()
rv.alignment = lex.consume().integer();
lex.check_consume(';');
- // TODO: DST Meta
+ // Drop glue (if present)
+ if( lex.consume_if("DROP") )
+ {
+ rv.drop_glue = parse_path();
+ lex.check_consume(';');
+ }
+ else
+ {
+ // No drop glue
+ }
+
+ // DST Meta type
if( lex.consume_if("DSTMETA") )
{
- //rv->dst_meta = parse_type();
+ rv.dst_meta = parse_type();
lex.check_consume(';');
- throw "TODO";
}
else
{
- //rv->dst_meta = ::HIR::TypeRef::diverge();
+ // Using ! as the metadata type means that the type is Sized (meanwhile, `()` means unsized with no meta)
+ rv.dst_meta = ::HIR::TypeRef::diverge();
}
while( lex.next() != '}' )
diff --git a/tools/standalone_miri/module_tree.hpp b/tools/standalone_miri/module_tree.hpp
index 3489e77e..20e37a51 100644
--- a/tools/standalone_miri/module_tree.hpp
+++ b/tools/standalone_miri/module_tree.hpp
@@ -58,11 +58,17 @@ public:
// struct/union/enum
struct DataType
{
+ // TODO: Store the name of this type for logging?
+
// TODO: Metadata type! (indicates an unsized wrapper)
// TODO: Drop glue
size_t alignment;
size_t size;
+
+ ::HIR::Path drop_glue;
+ ::HIR::TypeRef dst_meta;
+
// Offset and datatype
::std::vector<::std::pair<size_t, ::HIR::TypeRef>> fields;
// Values for variants