summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-05-19 10:15:20 +0800
committerJohn Hodge <tpg@mutabah.net>2018-05-19 10:15:20 +0800
commitae177706bf0b4b2ff05e9102d1403c73799756b0 (patch)
tree9e525e69d7a16a7ad77d56c2c8c6c5de598977bf
parentaada4f2fe9be2f9bfadb4ef6ba057f36b9860aa8 (diff)
downloadmrust-ae177706bf0b4b2ff05e9102d1403c73799756b0.tar.gz
Standalone MIRI - Better logging (can redirect to a file, leaving stdout for the program)
-rwxr-xr-xtest_smiri.sh2
-rw-r--r--tools/standalone_miri/debug.cpp34
-rw-r--r--tools/standalone_miri/debug.hpp14
-rw-r--r--tools/standalone_miri/main.cpp61
-rw-r--r--tools/standalone_miri/miri.cpp10
-rw-r--r--tools/standalone_miri/module_tree.cpp96
-rw-r--r--tools/standalone_miri/value.cpp10
-rw-r--r--tools/standalone_miri/value.hpp15
8 files changed, 148 insertions, 94 deletions
diff --git a/test_smiri.sh b/test_smiri.sh
index 63c94fa2..5a7de4e4 100755
--- a/test_smiri.sh
+++ b/test_smiri.sh
@@ -3,4 +3,4 @@ set -e
cd $(dirname $0)
make -f minicargo.mk MMIR=1 LIBS
./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
-./tools/bin/standalone_miri output-mmir/hello.mir
+./tools/bin/standalone_miri output-mmir/hello.mir --logfile smiri_hello.log
diff --git a/tools/standalone_miri/debug.cpp b/tools/standalone_miri/debug.cpp
index 415bc5d5..f0476df7 100644
--- a/tools/standalone_miri/debug.cpp
+++ b/tools/standalone_miri/debug.cpp
@@ -1,6 +1,15 @@
+/*
+ * mrustc Standalone MIRI
+ * - by John Hodge (Mutabah)
+ *
+ * debug.cpp
+ * - Interpreter debug logging
+ */
#include "debug.hpp"
+#include <fstream>
unsigned DebugSink::s_indent = 0;
+::std::unique_ptr<std::ofstream> DebugSink::s_out_file;
DebugSink::DebugSink(::std::ostream& inner):
m_inner(inner)
@@ -10,39 +19,44 @@ DebugSink::~DebugSink()
{
m_inner << "\n";
}
+bool DebugSink::set_output_file(const ::std::string& s)
+{
+ s_out_file.reset(new ::std::ofstream(s));
+}
bool DebugSink::enabled(const char* fcn_name)
{
return true;
}
DebugSink DebugSink::get(const char* fcn_name, const char* file, unsigned line, DebugLevel lvl)
{
+ auto& sink = s_out_file ? *s_out_file : ::std::cout;
for(size_t i = s_indent; i--;)
- ::std::cout << " ";
+ sink << " ";
switch(lvl)
{
case DebugLevel::Trace:
- ::std::cout << "Trace: " << file << ":" << line << ": ";
+ sink << "Trace: " << file << ":" << line << ": ";
break;
case DebugLevel::Debug:
- ::std::cout << "DEBUG: " << fcn_name << ": ";
+ sink << "DEBUG: " << fcn_name << ": ";
break;
case DebugLevel::Notice:
- ::std::cout << "NOTE: ";
+ sink << "NOTE: ";
break;
case DebugLevel::Warn:
- ::std::cout << "WARN: ";
+ sink << "WARN: ";
break;
case DebugLevel::Error:
- ::std::cout << "ERROR: ";
+ sink << "ERROR: ";
break;
case DebugLevel::Fatal:
- ::std::cout << "FATAL: ";
+ sink << "FATAL: ";
break;
case DebugLevel::Bug:
- ::std::cout << "BUG: " << file << ":" << line << ": ";
+ sink << "BUG: " << file << ":" << line << ": ";
break;
}
- return DebugSink(::std::cout);
+ return DebugSink(sink);
}
void DebugSink::inc_indent()
{
@@ -51,4 +65,4 @@ void DebugSink::inc_indent()
void DebugSink::dec_indent()
{
s_indent --;
-} \ No newline at end of file
+}
diff --git a/tools/standalone_miri/debug.hpp b/tools/standalone_miri/debug.hpp
index f7d32fe5..6b136ccb 100644
--- a/tools/standalone_miri/debug.hpp
+++ b/tools/standalone_miri/debug.hpp
@@ -1,10 +1,15 @@
-//
-//
-//
+/*
+ * mrustc Standalone MIRI
+ * - by John Hodge (Mutabah)
+ *
+ * debug.hpp
+ * - Interpreter debug logging
+ */
#pragma once
#include <iostream>
#include <functional>
+#include <memory>
enum class DebugLevel {
Trace,
@@ -19,6 +24,7 @@ enum class DebugLevel {
class DebugSink
{
static unsigned s_indent;
+ static ::std::unique_ptr<std::ofstream> s_out_file;
::std::ostream& m_inner;
DebugSink(::std::ostream& inner);
public:
@@ -27,6 +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 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.
@@ -90,6 +97,7 @@ struct DebugExceptionError:
#define TRACE_FUNCTION_R(entry, exit) auto ftg##__LINE__ = FunctionTrace_d(__FUNCTION__,__FILE__,__LINE__,[&](DebugSink& FunctionTrace_ss){FunctionTrace_ss << entry;}, [&](DebugSink& FunctionTrace_ss) {FunctionTrace_ss << exit;} )
#define LOG_TRACE(strm) do { if(DebugSink::enabled(__FUNCTION__)) DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Trace) << strm; } while(0)
#define LOG_DEBUG(strm) do { if(DebugSink::enabled(__FUNCTION__)) DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Debug) << strm; } while(0)
+#define LOG_NOTICE(strm) do { DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Notice) << strm; } while(0)
#define LOG_ERROR(strm) do { DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Error) << strm; throw DebugExceptionError{}; } while(0)
#define LOG_FATAL(strm) do { DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Fatal) << strm; exit(1); } while(0)
#define LOG_TODO(strm) do { DebugSink::get(__FUNCTION__,__FILE__,__LINE__,DebugLevel::Bug) << "TODO: " << strm; throw DebugExceptionTodo{}; } while(0)
diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp
index 1755a9d7..c214676a 100644
--- a/tools/standalone_miri/main.cpp
+++ b/tools/standalone_miri/main.cpp
@@ -1,6 +1,10 @@
-//
-//
-//
+/*
+ * mrustc Standalone MIRI
+ * - by John Hodge (Mutabah)
+ *
+ * main.cpp
+ * - Program entrypoint
+ */
#include <iostream>
#include "module_tree.hpp"
#include "value.hpp"
@@ -17,8 +21,10 @@ struct ProgramOptions
//::std::string archname;
//TODO: Loadable FFI descriptions
//::std::vector<const char*> ffi_api_files;
- //TODO: Logfile
- //::std::string logfile;
+
+ // Output logfile
+ ::std::string logfile;
+ // Arguments for the program
::std::vector<const char*> args;
int parse(int argc, const char* argv[]);
@@ -34,10 +40,17 @@ int main(int argc, const char* argv[])
return 1;
}
- auto tree = ModuleTree {};
+ // Configure logging
+ if( opts.logfile != "" )
+ {
+ DebugSink::set_output_file(opts.logfile);
+ }
+ // Load HIR tree
+ auto tree = ModuleTree {};
tree.load_file(opts.infile);
+ // Construct argc/argv values
auto val_argc = Value( ::HIR::TypeRef{RawType::ISize} );
::HIR::TypeRef argv_ty { RawType::I8 };
argv_ty.wrappers.push_back(TypeWrapper { TypeWrapper::Ty::Pointer, 0 });
@@ -54,9 +67,11 @@ int main(int argc, const char* argv[])
argv_alloc->write_usize((1 + i) * POINTER_SIZE, 0);
argv_alloc->relocations.push_back({ (1 + i) * POINTER_SIZE, RelocationPtr::new_ffi({ "", (void*)(opts.args[0]), ::std::strlen(opts.args[0]) + 1 }) });
}
+ //val_argv.write_ptr(0, 0, RelocationPtr::new_alloc(argv_alloc));
val_argv.write_usize(0, 0);
val_argv.allocation->relocations.push_back({ 0 * POINTER_SIZE, RelocationPtr::new_alloc(argv_alloc) });
+ // Catch various exceptions from the interpreter
try
{
InterpreterThread root_thread(tree);
@@ -70,16 +85,24 @@ int main(int argc, const char* argv[])
{
}
- ::std::cout << rv << ::std::endl;
+ LOG_NOTICE("Return code: " << rv);
}
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;
}
@@ -89,26 +112,31 @@ int main(int argc, const char* argv[])
int ProgramOptions::parse(int argc, const char* argv[])
{
bool all_free = false;
+ // TODO: use getopt? POSIX only
for(int argidx = 1; argidx < argc; argidx ++)
{
const char* arg = argv[argidx];
if( arg[0] != '-' || all_free )
{
- // Free
+ // Free arguments
+ // - First is the input file
if( this->infile == "" )
{
this->infile = arg;
}
else
{
+ // Any subsequent arguments are passed to the taget
this->args.push_back(arg);
}
}
else if( arg[1] != '-' )
{
- // Short
+ // Short arguments
if( arg[2] != '\0' ) {
// Error?
+ ::std::cerr << "Unexpected option " << arg << ::std::endl;
+ return 1;
}
switch(arg[1])
{
@@ -116,8 +144,8 @@ int ProgramOptions::parse(int argc, const char* argv[])
this->show_help(argv[0]);
exit(0);
default:
- // TODO: Error
- break;
+ ::std::cerr << "Unexpected option -" << arg[1] << ::std::endl;
+ return 1;
}
}
else if( arg[2] != '\0' )
@@ -127,10 +155,19 @@ int ProgramOptions::parse(int argc, const char* argv[])
this->show_help(argv[0]);
exit(0);
}
+ else if( ::std::strcmp(arg, "--logfile") == 0 ) {
+ if( argidx + 1 == argc ) {
+ ::std::cerr << "Option " << arg << " requires an argument" << ::std::endl;
+ return 1;
+ }
+ const char* opt = argv[++argidx];
+ this->logfile = opt;
+ }
//else if( ::std::strcmp(arg, "--api") == 0 ) {
//}
else {
- // TODO: Error
+ ::std::cerr << "Unexpected option " << arg << ::std::endl;
+ return 1;
}
}
else
diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp
index eccc54c9..733aa8a3 100644
--- a/tools/standalone_miri/miri.cpp
+++ b/tools/standalone_miri/miri.cpp
@@ -1,6 +1,10 @@
-//
-//
-//
+/*
+ * mrustc Standalone MIRI
+ * - by John Hodge (Mutabah)
+ *
+ * miri.cpp
+ * - Interpreter core
+ */
#include <iostream>
#include "module_tree.hpp"
#include "value.hpp"
diff --git a/tools/standalone_miri/module_tree.cpp b/tools/standalone_miri/module_tree.cpp
index 6a7a0b5f..cb6f943d 100644
--- a/tools/standalone_miri/module_tree.cpp
+++ b/tools/standalone_miri/module_tree.cpp
@@ -40,12 +40,11 @@ void ModuleTree::load_file(const ::std::string& path)
{
if( !loaded_files.insert(path).second )
{
- ::std::cout << "DEBUG: load_file(" << path << ") - Already loaded" << ::std::endl;
+ LOG_DEBUG("load_file(" << path << ") - Already loaded");
return ;
}
- ::std::cout << "DEBUG: load_file(" << path << ")" << ::std::endl;
- //TRACE_FUNCTION_F(path);
+ TRACE_FUNCTION_R(path, "");
auto parse = Parser { *this, path };
while(parse.parse_one())
@@ -56,7 +55,7 @@ void ModuleTree::load_file(const ::std::string& path)
// Parse a single item from a .mir file
bool Parser::parse_one()
{
- //::std::cout << "DEBUG: parse_one" << ::std::endl;
+ //TRACE_FUNCTION_F("");
if( lex.next() == "" ) // EOF?
{
return false;
@@ -68,7 +67,7 @@ bool Parser::parse_one()
lex.check(TokenClass::String);
auto path = ::std::move(lex.next().strval);
lex.consume();
- //::std::cout << "DEBUG: parse_one - crate '" << path << "'" << ::std::endl;
+ //LOG_TRACE(lex << "crate '" << path << "'");
lex.check_consume(';');
@@ -78,7 +77,7 @@ bool Parser::parse_one()
else if( lex.consume_if("fn") )
{
auto p = parse_path();
- //::std::cout << "DEBUG: parse_one - fn " << p << ::std::endl;
+ //LOG_TRACE(lex << "fn " << p);
lex.check_consume('(');
::std::vector<::HIR::TypeRef> arg_tys;
@@ -94,7 +93,7 @@ bool Parser::parse_one()
{
rv_ty = parse_type();
}
-
+
if( lex.consume_if('=') )
{
auto link_name = ::std::move(lex.check_consume(TokenClass::String).strval);
@@ -102,7 +101,7 @@ bool Parser::parse_one()
auto abi = ::std::move(lex.check_consume(TokenClass::String).strval);
lex.check_consume(';');
- LOG_DEBUG("fn " << p);
+ LOG_DEBUG(lex << "extern fn " << p);
auto p2 = p;
tree.functions.insert( ::std::make_pair(::std::move(p), Function { ::std::move(p2), ::std::move(arg_tys), rv_ty, {link_name, abi}, {} }) );
}
@@ -110,7 +109,7 @@ bool Parser::parse_one()
{
auto body = parse_body();
- LOG_DEBUG("fn " << p);
+ LOG_DEBUG(lex << "fn " << p);
auto p2 = p;
tree.functions.insert( ::std::make_pair(::std::move(p), Function { ::std::move(p2), ::std::move(arg_tys), rv_ty, {}, ::std::move(body) }) );
}
@@ -118,7 +117,7 @@ bool Parser::parse_one()
else if( lex.consume_if("static") )
{
auto p = parse_path();
- //::std::cout << "DEBUG: parse_one - static " << p << ::std::endl;
+ //LOG_TRACE(lex << "static " << p);
lex.check_consume(':');
auto ty = parse_type();
// TODO: externs?
@@ -152,12 +151,12 @@ bool Parser::parse_one()
auto a = Allocation::new_alloc( reloc_str.size() );
//a.alloc().set_tag();
a->write_bytes(0, reloc_str.data(), reloc_str.size());
- s.val.allocation->relocations.push_back({ ofs, RelocationPtr::new_alloc(::std::move(a)) });
+ s.val.allocation->relocations.push_back({ ofs, /*size,*/ RelocationPtr::new_alloc(::std::move(a)) });
}
else if( lex.next() == "::" || lex.next() == "<" )
{
auto reloc_path = parse_path();
- s.val.allocation->relocations.push_back({ ofs, RelocationPtr::new_fcn(reloc_path) });
+ s.val.allocation->relocations.push_back({ ofs, /*size,*/ RelocationPtr::new_fcn(reloc_path) });
}
else
{
@@ -172,13 +171,13 @@ bool Parser::parse_one()
}
lex.check_consume(';');
- LOG_DEBUG("static " << p);
+ LOG_DEBUG(lex << "static " << p);
tree.statics.insert(::std::make_pair( ::std::move(p), ::std::move(s) ));
}
else if( lex.consume_if("type") )
{
auto p = (lex.consume_if('(')) ? parse_tuple() : parse_genericpath();
- //::std::cout << "DEBUG: parse_one - type " << p << ::std::endl;
+ //LOG_TRACE("type " << p);
auto rv = DataType {};
rv.my_path = p;
@@ -223,7 +222,7 @@ bool Parser::parse_one()
lex.check_consume('=');
auto ty = parse_type();
lex.check_consume(';');
- //::std::cout << ofs << " " << ty << ::std::endl;
+ //LOG_DEBUG(ofs << " " << ty);
rv.fields.push_back(::std::make_pair(ofs, ::std::move(ty)));
}
@@ -289,11 +288,10 @@ bool Parser::parse_one()
if( rv.alignment == 0 && rv.fields.size() != 0 )
{
- ::std::cerr << lex << "Alignment of zero with fields is invalid, " << p << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Alignment of zero with fields is invalid, " << p);
}
- LOG_DEBUG("type " << p);
+ LOG_DEBUG(lex << "type " << p);
auto it = this->tree.data_types.find(p);
if( it != this->tree.data_types.end() )
{
@@ -303,10 +301,7 @@ bool Parser::parse_one()
}
else
{
- //::std::cerr << lex << "Duplicate definition of " << p << ::std::endl;
-
- // Not really an error, can happen when loading crates
- //throw "ERROR";
+ //LOG_ERROR(lex << "Duplicate definition of " << p);
}
}
else
@@ -316,7 +311,7 @@ bool Parser::parse_one()
}
else
{
- ::std::cerr << lex << "Unexpected token at root - " << lex.next() << ::std::endl;
+ LOG_ERROR(lex << "Unexpected token at root - " << lex.next());
// Unknown item type
throw "ERROR";
@@ -360,8 +355,7 @@ bool Parser::parse_one()
lv = ::MIR::LValue::make_Argument({ idx });
}
catch(const ::std::exception& e) {
- ::std::cerr << lex << "Invalid argument name - " << name << " - " << e.what() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Invalid argument name - " << name << " - " << e.what());
}
}
// Hard-coded "RETURN" lvalue
@@ -372,8 +366,7 @@ bool Parser::parse_one()
else {
auto it = ::std::find(var_names.begin(), var_names.end(), name);
if( it == var_names.end() ) {
- ::std::cerr << lex << "Cannot find variable named '" << name << "'" << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Cannot find variable named '" << name << "'");
}
lv = ::MIR::LValue::make_Local(static_cast<unsigned>(it - var_names.begin()));
}
@@ -384,8 +377,7 @@ bool Parser::parse_one()
lv = ::MIR::LValue( ::std::move(path) );
}
else {
- ::std::cerr << lex << "Unexpected token in LValue - " << lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token in LValue - " << lex.next());
}
for(;;)
{
@@ -455,8 +447,7 @@ bool Parser::parse_one()
}
else
{
- ::std::cerr << p.lex << "Expected an integer or float, got " << p.lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(p.lex << "Expected an integer or float, got " << p.lex.next());
}
}
else if( p.lex.consume_if("true") ) {
@@ -471,8 +462,7 @@ bool Parser::parse_one()
return ::MIR::Constant::make_ItemAddr({ ::std::move(path) });
}
else {
- ::std::cerr << p.lex << "BUG? " << p.lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_BUG(p.lex << "BUG? " << p.lex.next());
}
}
@@ -653,8 +643,7 @@ bool Parser::parse_one()
op = ::MIR::eUniOp::NEG;
}
else {
- ::std::cerr << lex << "Unexpected token in uniop - " << lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token in uniop - " << lex.next());
}
auto lv = H::parse_lvalue(*this, var_names);
@@ -701,8 +690,7 @@ bool Parser::parse_one()
lex.check_consume('=');
break;
default:
- ::std::cerr << lex << "Unexpected token " << t << " in BINOP" << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token " << t << " in BINOP");
}
auto lv2 = H::parse_param(*this, var_names);
@@ -723,8 +711,7 @@ bool Parser::parse_one()
src_rval = ::MIR::RValue::make_DstMeta({ ::std::move(lv) });
}
else {
- ::std::cerr << lex << "Unexpected token in RValue - " << lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token in RValue - " << lex.next());
}
stmts.push_back(::MIR::Statement::make_Assign({ ::std::move(dst_val), ::std::move(src_rval) }));
@@ -735,8 +722,7 @@ bool Parser::parse_one()
auto name = ::std::move(lex.consume().strval);
auto df_it = ::std::find(drop_flag_names.begin(), drop_flag_names.end(), name);
if( df_it == drop_flag_names.end() ) {
- ::std::cerr << lex << "Unable to find drop flag '" << name << "'" << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unable to find drop flag '" << name << "'");
}
auto df_idx = static_cast<unsigned>( df_it - drop_flag_names.begin() );
lex.check_consume('=');
@@ -754,8 +740,7 @@ bool Parser::parse_one()
auto name = ::std::move(lex.consume().strval);
df_it = ::std::find(drop_flag_names.begin(), drop_flag_names.end(), name);
if( df_it == drop_flag_names.end() ) {
- ::std::cerr << lex << "Unable to find drop flag '" << name << "'" << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unable to find drop flag '" << name << "'");
}
auto other_idx = static_cast<unsigned>( df_it - drop_flag_names.begin() );
@@ -777,8 +762,7 @@ bool Parser::parse_one()
auto name = ::std::move(lex.consume().strval);
auto df_it = ::std::find(drop_flag_names.begin(), drop_flag_names.end(), name);
if( df_it == drop_flag_names.end() ) {
- ::std::cerr << lex << "Unable to find drop flag '" << name << "'" << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unable to find drop flag '" << name << "'");
}
flag_idx = static_cast<unsigned>( df_it - drop_flag_names.begin() );
}
@@ -842,7 +826,7 @@ bool Parser::parse_one()
break;
}
lex.check_consume(';');
- //::std::cout << stmts.back() << ::std::endl;
+ //LOG_TRACE(stmts.back());
}
lex.check(TokenClass::Ident);
@@ -928,8 +912,7 @@ bool Parser::parse_one()
vals = ::MIR::SwitchValues::make_String(::std::move(values));
}
else {
- ::std::cerr << lex << "Unexpected token for SWITCHVALUE value - " << lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token for SWITCHVALUE value - " << lex.next());
}
lex.check_consume('_');
lex.check_consume('=');
@@ -976,8 +959,7 @@ bool Parser::parse_one()
}
else
{
- ::std::cerr << lex << "Unexpected token at terminator - " << lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token at terminator - " << lex.next());
}
lex.check_consume('}');
@@ -1068,7 +1050,7 @@ bool Parser::parse_one()
}
RawType Parser::parse_core_type()
{
- //::std::cout << lex.next() << ::std::endl;
+ //LOG_TRACE(lex.next());
lex.check(TokenClass::Ident);
auto tok = lex.consume();
// Primitive type.
@@ -1124,8 +1106,7 @@ RawType Parser::parse_core_type()
return RawType::Str;
}
else {
- ::std::cerr << lex << "Unknown core type " << tok << "'" << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unknown core type " << tok << "'");
}
}
::HIR::TypeRef Parser::parse_type()
@@ -1285,8 +1266,7 @@ RawType Parser::parse_core_type()
}
else
{
- ::std::cerr << lex << "Unexpected token in type - " << lex.next() << ::std::endl;
- throw "ERROR";
+ LOG_ERROR(lex << "Unexpected token in type - " << lex.next());
}
}
const DataType* Parser::get_composite(::HIR::GenericPath gp)
@@ -1312,8 +1292,7 @@ const Function& ModuleTree::get_function(const ::HIR::Path& p) const
auto it = functions.find(p);
if(it == functions.end())
{
- ::std::cerr << "Unable to find function " << p << " for invoke" << ::std::endl;
- throw "";
+ LOG_ERROR("Unable to find function " << p << " for invoke");
}
return it->second;
}
@@ -1331,8 +1310,7 @@ Static& ModuleTree::get_static(const ::HIR::Path& p)
auto it = statics.find(p);
if(it == statics.end())
{
- ::std::cerr << "Unable to find static " << p << " for invoke" << ::std::endl;
- throw "";
+ LOG_ERROR("Unable to find static " << p << " for invoke");
}
return it->second;
}
diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp
index e9376ce6..c3db284a 100644
--- a/tools/standalone_miri/value.cpp
+++ b/tools/standalone_miri/value.cpp
@@ -1,6 +1,10 @@
-//
-//
-//
+/*
+ * mrustc Standalone MIRI
+ * - by John Hodge (Mutabah)
+ *
+ * value.cpp
+ * - Runtime values
+ */
#include "value.hpp"
#include "hir_sim.hpp"
#include "module_tree.hpp"
diff --git a/tools/standalone_miri/value.hpp b/tools/standalone_miri/value.hpp
index 4528b98f..81302e67 100644
--- a/tools/standalone_miri/value.hpp
+++ b/tools/standalone_miri/value.hpp
@@ -1,6 +1,10 @@
-//
-//
-//
+/*
+ * mrustc Standalone MIRI
+ * - by John Hodge (Mutabah)
+ *
+ * value.hpp
+ * - Runtime values
+ */
#pragma once
#include <vector>
@@ -257,9 +261,12 @@ struct Value:
Value();
Value(::HIR::TypeRef ty);
+
static Value with_size(size_t size, bool have_allocation);
static Value new_fnptr(const ::HIR::Path& fn_path);
static Value new_ffiptr(FFIPointer ffi);
+ //static Value new_usize(uint64_t v);
+ //static Value new_isize(int64_t v);
void create_allocation();
size_t size() const { return allocation ? allocation->size() : direct_data.size; }
@@ -281,6 +288,8 @@ struct Value:
void write_value(size_t ofs, Value v);
void write_bytes(size_t ofs, const void* src, size_t count) override;
+
+ //void write_ptr(size_t ofs, size_t ptr_ofs, RelocationPtr reloc);
};
extern ::std::ostream& operator<<(::std::ostream& os, const Value& v);