From a3a0c6437302c60bd6f521fc11e30c0a16bd79fc Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 11 Feb 2018 21:57:10 +0800 Subject: Standalone MIRI - Implementation sprint, statics in process. --- tools/standalone_miri/main.cpp | 156 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 149 insertions(+), 7 deletions(-) (limited to 'tools/standalone_miri/main.cpp') diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp index a6a58a91..c7069ed2 100644 --- a/tools/standalone_miri/main.cpp +++ b/tools/standalone_miri/main.cpp @@ -7,8 +7,6 @@ #include #include -#pragma warning( error : 4061) - struct ProgramOptions { ::std::string infile; @@ -16,7 +14,7 @@ struct ProgramOptions int parse(int argc, const char* argv[]); }; -Value MIRI_Invoke(const ModuleTree& modtree, ::HIR::Path path, ::std::vector args); +Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector args); int main(int argc, const char* argv[]) { @@ -31,15 +29,32 @@ int main(int argc, const char* argv[]) tree.load_file(opts.infile); - auto rv = MIRI_Invoke(tree, tree.find_lang_item("start"), {}); + auto val_argc = Value( ::HIR::TypeRef{RawType::I32} ); + ::HIR::TypeRef argv_ty { RawType::I8 }; + argv_ty.wrappers.push_back(TypeWrapper { TypeWrapper::Ty::Pointer, 0 }); + argv_ty.wrappers.push_back(TypeWrapper { TypeWrapper::Ty::Pointer, 0 }); + auto val_argv = Value(argv_ty); + val_argc.write_bytes(0, "\0\0\0", 4); + val_argv.write_bytes(0, "\0\0\0\0\0\0\0", argv_ty.get_size()); + + ::std::vector args; + args.push_back(::std::move(val_argc)); + args.push_back(::std::move(val_argv)); + auto rv = MIRI_Invoke( tree, tree.find_lang_item("start"), ::std::move(args) ); ::std::cout << rv << ::std::endl; return 0; } -Value MIRI_Invoke(const ModuleTree& modtree, ::HIR::Path path, ::std::vector args) +Value MIRI_Invoke(ModuleTree& modtree, ::HIR::Path path, ::std::vector args) { + //TRACE_FUNCTION_FR(path,path) const auto& fcn = modtree.get_function(path); + for(size_t i = 0; i < args.size(); i ++) + { + //DEBUG(a); + ::std::cout << "Argument(" << i << ") = " << args[i] << ::std::endl; + } ::std::vector drop_flags = fcn.m_mir.drop_flags; ::std::vector locals; locals.reserve( fcn.m_mir.locals.size() ); @@ -52,12 +67,14 @@ Value MIRI_Invoke(const ModuleTree& modtree, ::HIR::Path path, ::std::vector args; ::std::vector locals; - State(const Function& fcn, ::std::vector args): + State(ModuleTree& modtree, const Function& fcn, ::std::vector args): + modtree(modtree), fcn(fcn), ret(fcn.ret_ty), args(::std::move(args)) @@ -73,6 +90,7 @@ Value MIRI_Invoke(const ModuleTree& modtree, ::HIR::Path path, ::std::vector(ce.v); + val.write_bytes(0, &v, ::std::min(ty.get_size(), sizeof(v))); // TODO: Endian/format? + } + else { + throw ::std::runtime_error("BUG: Invalid type in Constant::Float"); + } + return val; + } break; + TU_ARM(c, Const, ce) { + throw ::std::runtime_error("BUG: Constant::Const in mmir"); + } break; + TU_ARM(c, Bytes, ce) { + throw ::std::runtime_error("TODO: Constant::Bytes"); + } break; + TU_ARM(c, StaticString, ce) { + throw ::std::runtime_error("TODO: Constant::StaticString"); + } break; + TU_ARM(c, ItemAddr, ce) { + // Create a value with a special backing allocation of zero size that references the specified item. + if( const auto* fn = modtree.get_function_opt(ce) ) { + return Value::new_fnptr(ce); + } + throw ::std::runtime_error("TODO: Constant::ItemAddr"); + } break; } throw ""; } @@ -186,6 +261,7 @@ Value MIRI_Invoke(const ModuleTree& modtree, ::HIR::Path path, ::std::vector(re.type) }); + Value new_val = Value(src_ty); + // ^ Pointer value + new_val.allocation.alloc().relocations.push_back(Relocation { 0, base_value.allocation }); + new_val.write_bytes(0, &ofs, src_ty.get_size()); + ::std::cerr << "TODO: RValue::Borrow - " << se.src << ::std::endl; + throw "TODO"; + } break; TU_ARM(se.src, SizedArray, re) { throw "TODO"; } break; @@ -272,17 +370,61 @@ Value MIRI_Invoke(const ModuleTree& modtree, ::HIR::Path path, ::std::vector sub_args; sub_args.reserve(te.args.size()); + for(const auto& a : te.args) + { + sub_args.push_back( state.param_to_value(a) ); + } + ::std::cout << "TODO: Call " << *fcn_p << ::std::endl; + MIRI_Invoke(modtree, *fcn_p, ::std::move(sub_args)); + } + throw ::std::runtime_error("TODO: Terminator::Call"); + } break; } throw ""; } -- cgit v1.2.3