diff options
author | John Hodge <tpg@mutabah.net> | 2018-06-03 13:06:12 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2018-06-03 13:06:44 +0800 |
commit | ada4bdefc7da9c81e0006553f218efe56a4349ce (patch) | |
tree | 51809c1bf87d3f7543c499bade055bf0fd785c2d | |
parent | b635b94597796728194de0f8d2619f2c1f5ee542 (diff) | |
download | mrust-ada4bdefc7da9c81e0006553f218efe56a4349ce.tar.gz |
Standalone MIRI - Fix parse errors from mrustc changes, add recursion limit
-rwxr-xr-x | test_smiri.sh | 1 | ||||
-rw-r--r-- | tools/standalone_miri/debug.cpp | 3 | ||||
-rw-r--r-- | tools/standalone_miri/debug.hpp | 2 | ||||
-rw-r--r-- | tools/standalone_miri/lex.cpp | 25 | ||||
-rw-r--r-- | tools/standalone_miri/lex.hpp | 1 | ||||
-rw-r--r-- | tools/standalone_miri/main.cpp | 23 | ||||
-rw-r--r-- | tools/standalone_miri/miri.cpp | 22 | ||||
-rw-r--r-- | tools/standalone_miri/module_tree.cpp | 18 |
8 files changed, 83 insertions, 12 deletions
diff --git a/test_smiri.sh b/test_smiri.sh index 0dbad3fa..a275420a 100755 --- a/test_smiri.sh +++ b/test_smiri.sh @@ -2,6 +2,7 @@ set -e cd $(dirname $0) make -f minicargo.mk MMIR=1 LIBS +make -C tools/standalone_miri echo "--- mrustc -o output-mmir/hello" ./bin/mrustc rustc-1.19.0-src/src/test/run-pass/hello.rs -O -C codegen-type=monomir -o output-mmir/hello -L output-mmir/ > output-mmir/hello_dbg.txt echo "--- standalone_miri output-mmir/hello.mir" diff --git a/tools/standalone_miri/debug.cpp b/tools/standalone_miri/debug.cpp index f0476df7..c49df960 100644 --- a/tools/standalone_miri/debug.cpp +++ b/tools/standalone_miri/debug.cpp @@ -18,8 +18,9 @@ DebugSink::DebugSink(::std::ostream& inner): DebugSink::~DebugSink() { m_inner << "\n"; + m_inner.flush(); } -bool DebugSink::set_output_file(const ::std::string& s) +void DebugSink::set_output_file(const ::std::string& s) { s_out_file.reset(new ::std::ofstream(s)); } diff --git a/tools/standalone_miri/debug.hpp b/tools/standalone_miri/debug.hpp index 6b136ccb..b3b0d76f 100644 --- a/tools/standalone_miri/debug.hpp +++ b/tools/standalone_miri/debug.hpp @@ -33,7 +33,7 @@ public: template<typename T> ::std::ostream& operator<<(const T& v) { return m_inner << v; } - static bool set_output_file(const ::std::string& s); + static void set_output_file(const ::std::string& s); static bool enabled(const char* fcn_name); static DebugSink get(const char* fcn_name, const char* file, unsigned line, DebugLevel lvl); // TODO: Add a way to insert an annotation before/after an abort/warning/... that indicates what input location caused it. diff --git a/tools/standalone_miri/lex.cpp b/tools/standalone_miri/lex.cpp index 7cfe1a78..8fc77f7a 100644 --- a/tools/standalone_miri/lex.cpp +++ b/tools/standalone_miri/lex.cpp @@ -11,11 +11,11 @@ bool Token::operator==(TokenClass tc) const } bool Token::operator==(char c) const { - return this->strval.size() == 1 && this->strval[0] == c; + return (this->type == TokenClass::Ident || this->type == TokenClass::Symbol) && this->strval.size() == 1 && this->strval[0] == c; } bool Token::operator==(const char* s) const { - return this->strval == s; + return (this->type == TokenClass::Ident || this->type == TokenClass::Symbol) && this->strval == s; } uint64_t Token::integer() const @@ -56,6 +56,9 @@ double Token::real() const case TokenClass::ByteString: os << "b\"" << x.strval << "\""; break; + case TokenClass::Lifetime: + os << "'" << x.strval << "\""; + break; } return os; } @@ -95,6 +98,7 @@ Token Lexer::consume() auto rv = ::std::move(m_cur); advance(); + //::std::cout << *this << "Lexer::consume " << rv << " -> " << m_cur << ::std::endl; return rv; } @@ -349,6 +353,23 @@ void Lexer::advance() auto val = this->parse_string(); m_cur = Token { TokenClass::String, ::std::move(val) }; } + else if( ch == '\'') + { + ::std::string val; + ch = m_if.get(); + while( ch == '_' || ::std::isalnum(ch) ) + { + val += ch; + ch = m_if.get(); + } + m_if.unget(); + if( val == "" ) + { + ::std::cerr << *this << "Empty lifetime name"; + throw "ERROR"; + } + m_cur = Token { TokenClass::Lifetime, ::std::move(val) }; + } else { switch(ch) diff --git a/tools/standalone_miri/lex.hpp b/tools/standalone_miri/lex.hpp index 95130111..cc1429f7 100644 --- a/tools/standalone_miri/lex.hpp +++ b/tools/standalone_miri/lex.hpp @@ -14,6 +14,7 @@ enum class TokenClass Real, String, ByteString, + Lifetime, }; struct Token diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp index 90b5eff3..deed08be 100644 --- a/tools/standalone_miri/main.cpp +++ b/tools/standalone_miri/main.cpp @@ -48,7 +48,28 @@ int main(int argc, const char* argv[]) // Load HIR tree auto tree = ModuleTree {}; - tree.load_file(opts.infile); + try + { + tree.load_file(opts.infile); + } + catch(const DebugExceptionTodo& /*e*/) + { + ::std::cerr << "TODO Hit" << ::std::endl; + if(opts.logfile != "") + { + ::std::cerr << "- See '" << opts.logfile << "' for details" << ::std::endl; + } + return 1; + } + catch(const DebugExceptionError& /*e*/) + { + ::std::cerr << "Error encountered" << ::std::endl; + if(opts.logfile != "") + { + ::std::cerr << "- See '" << opts.logfile << "' for details" << ::std::endl; + } + return 1; + } // Create argc/argv based on input arguments auto argv_alloc = Allocation::new_alloc((1 + opts.args.size()) * POINTER_SIZE); diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp index 5f9c095f..f4179b5d 100644 --- a/tools/standalone_miri/miri.cpp +++ b/tools/standalone_miri/miri.cpp @@ -540,11 +540,19 @@ InterpreterThread::~InterpreterThread() for(size_t i = 0; i < m_stack.size(); i++) { const auto& frame = m_stack[m_stack.size() - 1 - i]; - ::std::cout << "#" << i << ": " << frame.fcn.my_path << " BB" << frame.bb_idx << "/"; - if( frame.stmt_idx == frame.fcn.m_mir.blocks.at(frame.bb_idx).statements.size() ) - ::std::cout << "TERM"; + ::std::cout << "#" << i << ": "; + if( frame.cb ) + { + ::std::cout << "WRAPPER"; + } else - ::std::cout << frame.stmt_idx; + { + ::std::cout << frame.fcn.my_path << " BB" << frame.bb_idx << "/"; + if( frame.stmt_idx == frame.fcn.m_mir.blocks.at(frame.bb_idx).statements.size() ) + ::std::cout << "TERM"; + else + ::std::cout << frame.stmt_idx; + } ::std::cout << ::std::endl; } } @@ -565,6 +573,12 @@ bool InterpreterThread::step_one(Value& out_thread_result) TRACE_FUNCTION_R(cur_frame.fcn.my_path, ""); const auto& bb = cur_frame.fcn.m_mir.blocks.at( cur_frame.bb_idx ); + const size_t MAX_STACK_DEPTH = 40; + if( this->m_stack.size() > MAX_STACK_DEPTH ) + { + LOG_ERROR("Maximum stack depth of " << MAX_STACK_DEPTH << " exceeded"); + } + MirHelpers state { *this, cur_frame }; if( cur_frame.stmt_idx < bb.statements.size() ) diff --git a/tools/standalone_miri/module_tree.cpp b/tools/standalone_miri/module_tree.cpp index db5fd495..8beba018 100644 --- a/tools/standalone_miri/module_tree.cpp +++ b/tools/standalone_miri/module_tree.cpp @@ -56,7 +56,7 @@ void ModuleTree::load_file(const ::std::string& path) bool Parser::parse_one() { //TRACE_FUNCTION_F(""); - if( lex.next() == "" ) // EOF? + if( lex.next() == TokenClass::Eof ) { return false; } @@ -1145,6 +1145,11 @@ RawType Parser::parse_core_type() } else if( lex.consume_if('&') ) { + if( lex.next() == TokenClass::Lifetime ) + { + // TODO: Handle lifetime names (require them?) + lex.consume(); + } auto bt = ::HIR::BorrowType::Shared; if( lex.consume_if("move") ) bt = ::HIR::BorrowType::Move; @@ -1240,8 +1245,15 @@ RawType Parser::parse_core_type() ::std::vector<::HIR::GenericPath> markers; while(lex.consume_if('+')) { - // TODO: Detect/parse lifetimes? - markers.push_back(parse_genericpath()); + if( lex.next() == TokenClass::Lifetime ) + { + // TODO: Include lifetimes in output? + lex.consume(); + } + else + { + markers.push_back(parse_genericpath()); + } } lex.consume_if(')'); |