summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/standalone_miri/Makefile43
-rw-r--r--tools/standalone_miri/debug.hpp4
-rw-r--r--tools/standalone_miri/lex.cpp4
-rw-r--r--tools/standalone_miri/main.cpp49
-rw-r--r--tools/standalone_miri/mir.cpp1
-rw-r--r--tools/standalone_miri/module_tree.cpp3
-rw-r--r--tools/standalone_miri/value.hpp1
7 files changed, 101 insertions, 4 deletions
diff --git a/tools/standalone_miri/Makefile b/tools/standalone_miri/Makefile
new file mode 100644
index 00000000..94c89452
--- /dev/null
+++ b/tools/standalone_miri/Makefile
@@ -0,0 +1,43 @@
+#
+# Standalone MIR Interpreter
+#
+ifeq ($(OS),Windows_NT)
+ EXESUF ?= .exe
+endif
+EXESUF ?=
+
+V ?= @
+
+OBJDIR := .obj/
+
+BIN := ../bin/standalone_miri$(EXESUF)
+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 .
+
+OBJS := $(OBJS:%=$(OBJDIR)%)
+
+.PHONY: all clean
+
+all: $(BIN)
+
+clean:
+ rm $(BIN) $(OBJS)
+
+$(BIN): $(OBJS) ../bin/common_lib.a
+ @mkdir -p $(dir $@)
+ @echo [CXX] -o $@
+ $V$(CXX) -o $@ $(OBJS) ../bin/common_lib.a $(LINKFLAGS)
+
+$(OBJDIR)%.o: %.cpp
+ @mkdir -p $(dir $@)
+ @echo [CXX] $<
+ $V$(CXX) -o $@ -c $< $(CXXFLAGS) -MMD -MP -MF $@.dep
+
+../bin/common_lib.a:
+ make -C ../common
+
+-include $(OBJS:%.o=%.o.dep)
+
diff --git a/tools/standalone_miri/debug.hpp b/tools/standalone_miri/debug.hpp
index 5afad96e..f7d32fe5 100644
--- a/tools/standalone_miri/debug.hpp
+++ b/tools/standalone_miri/debug.hpp
@@ -75,14 +75,14 @@ FunctionTrace<T,U> FunctionTrace_d(const char* fname, const char* file, unsigned
struct DebugExceptionTodo:
public ::std::exception
{
- const char* what() const {
+ const char* what() const noexcept override {
return "TODO hit";
}
};
struct DebugExceptionError:
public ::std::exception
{
- const char* what() const {
+ const char* what() const noexcept override {
return "error";
}
};
diff --git a/tools/standalone_miri/lex.cpp b/tools/standalone_miri/lex.cpp
index 48a9e0cd..7cfe1a78 100644
--- a/tools/standalone_miri/lex.cpp
+++ b/tools/standalone_miri/lex.cpp
@@ -390,6 +390,10 @@ void Lexer::advance()
{
m_cur = Token { TokenClass::Symbol, "<<" };
}
+ else if( ch == '=' )
+ {
+ m_cur = Token { TokenClass::Symbol, "<=" };
+ }
else
{
m_if.unget();
diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp
index a75e753f..384bc79e 100644
--- a/tools/standalone_miri/main.cpp
+++ b/tools/standalone_miri/main.cpp
@@ -353,6 +353,21 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
ret.write_i32(0, 120); // ERROR_CALL_NOT_IMPLEMENTED
return ret;
}
+
+ // - No guard page needed
+ if( path == ::HIR::SimplePath { "std", {"sys", "imp", "thread", "guard", "init" } } )
+ {
+ ret = Value::with_size(16, false);
+ ret.write_u64(0, 0);
+ ret.write_u64(8, 0);
+ return ret;
+ }
+
+ // - No stack overflow handling needed
+ if( path == ::HIR::SimplePath { "std", { "sys", "imp", "stack_overflow", "imp", "init" } } )
+ {
+ return ret;
+ }
}
if( fcn.external.link_name != "" )
@@ -1162,6 +1177,9 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
case RawType::USize:
new_val.write_usize( 0, Ops::do_bitwise(v_l.read_usize(0), v_r.read_usize(0), re.op) );
break;
+ case RawType::I32:
+ new_val.write_i32( 0, static_cast<int32_t>(Ops::do_bitwise(v_l.read_i32(0), v_r.read_i32(0), re.op)) );
+ break;
default:
LOG_TODO("BinOp bitwise - " << se.src << " w/ " << ty_l);
}
@@ -1497,7 +1515,7 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
assert(v.read_usize(v.m_offset) == 0);
auto& alloc_ptr = v.m_alloc ? v.m_alloc : v.m_value->allocation;
LOG_ASSERT(alloc_ptr, "Calling value that can't be a pointer (no allocation)");
- auto& fcn_alloc_ptr = alloc_ptr.alloc().get_relocation(v.m_offset);
+ const auto& fcn_alloc_ptr = alloc_ptr.alloc().get_relocation(v.m_offset);
LOG_ASSERT(fcn_alloc_ptr, "Calling value with no relocation");
LOG_ASSERT(fcn_alloc_ptr.get_ty() == AllocationPtr::Ty::Function, "Calling value that isn't a function pointer");
fcn_p = &fcn_alloc_ptr.fcn();
@@ -1516,6 +1534,11 @@ Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector<Value> ar
throw "";
}
+
+extern "C" {
+ long sysconf(int);
+}
+
Value MIRI_Invoke_Extern(const ::std::string& link_name, const ::std::string& abi, ::std::vector<Value> args)
{
if( link_name == "__rust_allocate" )
@@ -1631,6 +1654,25 @@ Value MIRI_Invoke_Extern(const ::std::string& link_name, const ::std::string& ab
return rv;
}
}
+#else
+ // std C
+ else if( link_name == "signal" )
+ {
+ LOG_DEBUG("Call `signal` - Ignoring and returning SIG_IGN");
+ auto rv = Value(::HIR::TypeRef(RawType::USize));
+ rv.write_usize(0, 1);
+ return rv;
+ }
+ // 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
// Allocators!
else
@@ -1728,6 +1770,11 @@ Value MIRI_Invoke_Intrinsic(ModuleTree& modtree, const ::std::string& name, cons
{
rv = Value(ty_params.tys.at(0));
}
+ else if( name == "init" )
+ {
+ rv = Value(ty_params.tys.at(0));
+ rv.mark_bytes_valid(0, rv.size());
+ }
// - Unsized stuff
else if( name == "size_of_val" )
{
diff --git a/tools/standalone_miri/mir.cpp b/tools/standalone_miri/mir.cpp
index 4593fb44..a0601823 100644
--- a/tools/standalone_miri/mir.cpp
+++ b/tools/standalone_miri/mir.cpp
@@ -7,6 +7,7 @@
*/
#include "../../src/mir/mir.hpp"
#include "hir_sim.hpp"
+#include <iostream>
namespace std {
template <typename T>
diff --git a/tools/standalone_miri/module_tree.cpp b/tools/standalone_miri/module_tree.cpp
index 2513140a..d62695d1 100644
--- a/tools/standalone_miri/module_tree.cpp
+++ b/tools/standalone_miri/module_tree.cpp
@@ -5,6 +5,7 @@
#include "lex.hpp"
#include "value.hpp"
#include <iostream>
+#include <algorithm> // std::find
#include "debug.hpp"
ModuleTree::ModuleTree()
@@ -1328,4 +1329,4 @@ Value* ModuleTree::get_static_opt(const ::HIR::Path& p)
return nullptr;
}
return &it->second;
-} \ No newline at end of file
+}
diff --git a/tools/standalone_miri/value.hpp b/tools/standalone_miri/value.hpp
index 8b103210..fb5cc5ae 100644
--- a/tools/standalone_miri/value.hpp
+++ b/tools/standalone_miri/value.hpp
@@ -6,6 +6,7 @@
#include <vector>
#include <memory>
#include <cstdint>
+#include <cstring> // memcpy
#include <cassert>
namespace HIR {