diff options
author | John Hodge <tpg@mutabah.net> | 2018-05-12 13:55:04 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-05-12 13:55:04 +0800 |
commit | f2ba1740cf1570bc06ddf5472a7319fdbb5ff827 (patch) | |
tree | 5a0dbdab275a0976e8da82a80b6cd31d87d393a3 /tools | |
parent | 2165fa41d051a4ce3fc1cddfe68a25fa65445706 (diff) | |
download | mrust-f2ba1740cf1570bc06ddf5472a7319fdbb5ff827.tar.gz |
Standalone Miri - More implementation work
Diffstat (limited to 'tools')
-rw-r--r-- | tools/standalone_miri/Makefile | 1 | ||||
-rw-r--r-- | tools/standalone_miri/main.cpp | 51 |
2 files changed, 43 insertions, 9 deletions
diff --git a/tools/standalone_miri/Makefile b/tools/standalone_miri/Makefile index 94c89452..95e99c75 100644 --- a/tools/standalone_miri/Makefile +++ b/tools/standalone_miri/Makefile @@ -16,6 +16,7 @@ OBJS := main.o debug.o mir.o lex.o value.o module_tree.o hir_sim.o LINKFLAGS := -g -lpthread CXXFLAGS := -Wall -std=c++14 -g -O2 CXXFLAGS += -I ../common -I ../../src/include -I . +CXXFLAGS += -Wno-misleading-indentation # Gets REALLY confused by the TU_ARM macro OBJS := $(OBJS:%=$(OBJDIR)%) diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp index 384bc79e..86a213dd 100644 --- a/tools/standalone_miri/main.cpp +++ b/tools/standalone_miri/main.cpp @@ -1266,10 +1266,16 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar } } break; TU_ARM(se.src, DstMeta, re) { - LOG_TODO(stmt); + auto ptr = state.get_value_ref(re.val); + + ::HIR::TypeRef dst_ty; + state.get_value_and_type(se.dst, dst_ty); + new_val = ptr.read_value(POINTER_SIZE, dst_ty.get_size()); } break; TU_ARM(se.src, DstPtr, re) { - LOG_TODO(stmt); + auto ptr = state.get_value_ref(re.val); + + new_val = ptr.read_value(0, POINTER_SIZE); } break; TU_ARM(se.src, MakeDst, re) { // - Get target type, just for some assertions @@ -1655,6 +1661,17 @@ Value MIRI_Invoke_Extern(const ::std::string& link_name, const ::std::string& ab } } #else + // POSIX + else if( link_name == "sysconf" ) + { + auto name = args.at(0).read_i32(0); + LOG_DEBUG("FFI sysconf(" << name << ")"); + long val = sysconf(name); + auto rv = Value(::HIR::TypeRef(RawType::USize)); + rv.write_usize(0, val); + return rv; + } +#endif // std C else if( link_name == "signal" ) { @@ -1663,17 +1680,33 @@ Value MIRI_Invoke_Extern(const ::std::string& link_name, const ::std::string& ab rv.write_usize(0, 1); return rv; } - // POSIX - else if( link_name == "sysconf" ) + // - `void *memchr(const void *s, int c, size_t n);` + else if( link_name == "memchr" ) { - auto name = args.at(0).read_i32(0); - LOG_DEBUG("FFI sysconf(" << name << ")"); - long val = sysconf(name); + LOG_ASSERT(args.at(0).allocation.is_alloc(), ""); + //size_t ptr_space; + //void* ptr = args.at(0).read_pointer(0, ptr_space); + auto ptr_alloc = args.at(0).allocation.alloc().get_relocation(0); + void* ptr = ptr_alloc.alloc().data_ptr() + args.at(0).read_usize(0); + auto c = args.at(1).read_i32(0); + auto n = args.at(2).read_usize(0); + // TODO: Check range of `n` + + void* ret = memchr(ptr, c, n); + auto rv = Value(::HIR::TypeRef(RawType::USize)); - rv.write_usize(0, val); + rv.create_allocation(); + if( ret ) + { + rv.write_usize(0, args.at(0).read_usize(0) + ( static_cast<const uint8_t*>(ret) - static_cast<const uint8_t*>(ptr) )); + rv.allocation.alloc().relocations.push_back({ 0, ptr_alloc }); + } + else + { + rv.write_usize(0, 0); + } return rv; } -#endif // Allocators! else { |