diff options
author | John Hodge <tpg@mutabah.net> | 2017-07-08 18:09:35 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2017-07-08 18:09:35 +0800 |
commit | 4a954d768f5d314133e85629546fdb4a4f587d2d (patch) | |
tree | 2e498bc166b5809fe1d8afc879b92033760ff86b /src/hir | |
parent | 029dd3f14422f0587b63e33781afe072bafc094a (diff) | |
download | mrust-4a954d768f5d314133e85629546fdb4a4f587d2d.tar.gz |
Codegen+Loading - MSVC support draft (libcore compiles, doesn't load)
Diffstat (limited to 'src/hir')
-rw-r--r-- | src/hir/deserialise.cpp | 13 | ||||
-rw-r--r-- | src/hir/serialise_lowlevel.cpp | 10 |
2 files changed, 16 insertions, 7 deletions
diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 3cb58a2e..2e05cac1 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -5,7 +5,7 @@ * hir/serialise.cpp * - HIR (De)Serialisation for crate metadata */ -#define DISABLE_DEBUG // Disable debug for this function - too hot +//#define DISABLE_DEBUG // Disable debug for this function - too hot #include "hir.hpp" #include "main_bindings.hpp" #include <serialiser_texttree.hpp> @@ -1132,17 +1132,22 @@ namespace { ::HIR::CratePtr HIR_Deserialise(const ::std::string& filename, const ::std::string& loaded_name) { - ::HIR::serialise::Reader in { filename }; - HirDeserialiser s { loaded_name, in }; - try { + ::HIR::serialise::Reader in{ filename }; + HirDeserialiser s { loaded_name, in }; + ::HIR::Crate rv = s.deserialise_crate(); return ::HIR::CratePtr( mv$(rv) ); } catch(int) { ::std::abort(); } + catch(const ::std::runtime_error& e) + { + ::std::cerr << "Unable to deserialise crate metadata from " << filename << ": " << e.what() << ::std::endl; + ::std::abort(); + } #if 0 catch(const char*) { diff --git a/src/hir/serialise_lowlevel.cpp b/src/hir/serialise_lowlevel.cpp index a3bb3870..19e8c6b4 100644 --- a/src/hir/serialise_lowlevel.cpp +++ b/src/hir/serialise_lowlevel.cpp @@ -43,7 +43,7 @@ void Writer::write(const void* buf, size_t len) WriterInner::WriterInner(const ::std::string& filename): - m_backing( filename ), + m_backing( filename, ::std::ios_base::out | ::std::ios_base::binary), m_zstream(), m_buffer( 16*1024 ) //m_buffer( 4*1024 ) @@ -177,7 +177,7 @@ size_t ReadBuffer::read(void* dst, size_t len) void ReadBuffer::populate(ReaderInner& is) { m_backing.resize( m_backing.capacity(), 0 ); - auto len = is.read(m_backing.data(), m_backing.capacity()); + auto len = is.read(m_backing.data(), m_backing.size()); m_backing.resize( len ); m_ofs = 0; } @@ -217,10 +217,14 @@ void Reader::read(void* buf, size_t len) ReaderInner::ReaderInner(const ::std::string& filename): - m_backing(filename), + m_backing(filename, ::std::ios_base::in|::std::ios_base::binary), m_zstream(), m_buffer(16*1024) { + ::std::memset(&m_zstream, 0, sizeof m_zstream); + if( !m_backing.is_open() ) + throw ::std::runtime_error("Unable to open file"); + m_zstream.zalloc = Z_NULL; m_zstream.zfree = Z_NULL; m_zstream.opaque = Z_NULL; |