From ec907f56199c495db061f2712a5be3977bcb11e8 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 5 Aug 2018 00:10:39 +0800 Subject: Add version number (0.8 for now, because altough not stable, it works...) --- src/version.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/version.cpp (limited to 'src/version.cpp') diff --git a/src/version.cpp b/src/version.cpp new file mode 100644 index 00000000..d6307618 --- /dev/null +++ b/src/version.cpp @@ -0,0 +1,29 @@ +/* + * MRustC - Rust Compiler + * - By John Hodge (Mutabah/thePowersGang) + * + * version.cpp + * - Compiler version number + */ +#include +#include + +#define VERSION_MAJOR 0 +#define VERSION_MINOR 8 +#define VERSION_PATCH 0 + +unsigned int giVersion_Major = VERSION_MAJOR; +unsigned int giVersion_Minor = VERSION_MINOR; +unsigned int giVersion_Patch = VERSION_PATCH; +bool gbVersion_GitDirty = VERSION_GIT_ISDIRTY; +const char* gsVersion_GitHash = VERSION_GIT_FULLHASH; +const char* gsVersion_GitShortHash = VERSION_GIT_SHORTHASH; +const char* gsVersion_BuildTime = VERSION_BUILDTIME; + + +::std::string Version_GetString() +{ + ::std::stringstream ss; + ss << "v" << VERSION_MAJOR << "." << VERSION_MINOR << "." << VERSION_PATCH << " " << VERSION_GIT_BRANCH << ":" << VERSION_GIT_SHORTHASH; + return ss.str(); +} -- cgit v1.2.3 From d85ac84278fa0322f1df0b16a45a1cdde83cba57 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 9 Sep 2018 22:19:40 +0800 Subject: Msvc compile fixes --- src/ast/attrs.hpp | 2 +- src/hir/deserialise.cpp | 4 +- src/span.cpp | 4 ++ src/trans/codegen_c.cpp | 70 +++++++++++++--------- src/trans/target.cpp | 7 ++- src/version.cpp | 8 +++ tools/minicargo/build.cpp | 2 +- tools/minicargo/main.cpp | 1 + tools/standalone_miri/miri.cpp | 34 +++++++---- tools/standalone_miri/value.cpp | 10 ++-- tools/testrunner/main.cpp | 6 +- vsproject/mrustc.vcxproj | 2 +- vsproject/mrustc.vcxproj.filters | 6 +- vsproject/standalone_miri/standalone_miri.vcxproj | 1 + .../standalone_miri.vcxproj.filters | 3 + 15 files changed, 105 insertions(+), 55 deletions(-) (limited to 'src/version.cpp') diff --git a/src/ast/attrs.hpp b/src/ast/attrs.hpp index 1926e96a..0e1c8149 100644 --- a/src/ast/attrs.hpp +++ b/src/ast/attrs.hpp @@ -113,7 +113,7 @@ public: ) ) } - Attribute& operator=(const Attribute&& ) = delete; + Attribute& operator=(const Attribute& ) = delete; Attribute(Attribute&& ) = default; Attribute& operator=(Attribute&& ) = default; Attribute clone() const; diff --git a/src/hir/deserialise.cpp b/src/hir/deserialise.cpp index 17a93730..afce2fe4 100644 --- a/src/hir/deserialise.cpp +++ b/src/hir/deserialise.cpp @@ -734,7 +734,9 @@ ::HIR::LifetimeRef HirDeserialiser::deserialise_lifetimeref() { - return { static_cast(m_in.read_count()) }; + ::HIR::LifetimeRef rv; + rv.binding = static_cast(m_in.read_count()); + return rv; } ::HIR::TypeRef HirDeserialiser::deserialise_type() diff --git a/src/span.cpp b/src/span.cpp index 3d4d1ceb..eacdc7aa 100644 --- a/src/span.cpp +++ b/src/span.cpp @@ -59,7 +59,11 @@ namespace { void Span::bug(::std::function msg) const { print_span_message(*this, [](auto& os){os << "BUG";}, msg); +#ifndef _WIN32 abort(); +#else + exit(1); +#endif } void Span::error(ErrorType tag, ::std::function msg) const { diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index ca038230..322846e8 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -955,6 +955,7 @@ namespace { if( te.size() > 0 ) { m_of << "typedef struct "; emit_ctype(ty); m_of << " {\n"; + unsigned n_fields = 0; for(unsigned int i = 0; i < te.size(); i++) { m_of << "\t"; @@ -967,8 +968,13 @@ namespace { else { emit_ctype(te[i], FMT_CB(ss, ss << "_" << i;)); m_of << ";\n"; + n_fields += 1; } } + if( n_fields == 0 && m_options.disallow_empty_structs ) + { + m_of << "\tchar _d;\n"; + } m_of << "} "; emit_ctype(ty); m_of << ";\n"; } @@ -1315,36 +1321,40 @@ namespace { assert(1 + union_fields.size() + 1 >= repr->fields.size()); // Make the union! // NOTE: The way the structure generation works is that enum variants are always first, so the field index = the variant index - m_of << "\tunion {\n"; - // > First field + // TODO: + if( !this->type_is_bad_zst(repr->fields[0].ty) || ::std::any_of(union_fields.begin(), union_fields.end(), [this,repr](auto x){ return !this->type_is_bad_zst(repr->fields[x].ty); }) ) { - m_of << "\t\t"; - const auto& ty = repr->fields[0].ty; - if( this->type_is_bad_zst(ty) ) { - m_of << "// ZST: " << ty << "\n"; - } - else { - emit_ctype( ty, FMT_CB(ss, ss << "var_0") ); - m_of << ";\n"; - //sized_fields ++; + m_of << "\tunion {\n"; + // > First field + { + m_of << "\t\t"; + const auto& ty = repr->fields[0].ty; + if( this->type_is_bad_zst(ty) ) { + m_of << "// ZST: " << ty << "\n"; + } + else { + emit_ctype( ty, FMT_CB(ss, ss << "var_0") ); + m_of << ";\n"; + //sized_fields ++; + } } - } - // > All others - for(auto idx : union_fields) - { - m_of << "\t\t"; + // > All others + for(auto idx : union_fields) + { + m_of << "\t\t"; - const auto& ty = repr->fields[idx].ty; - if( this->type_is_bad_zst(ty) ) { - m_of << "// ZST: " << ty << "\n"; - } - else { - emit_ctype( ty, FMT_CB(ss, ss << "var_" << idx) ); - m_of << ";\n"; - //sized_fields ++; + const auto& ty = repr->fields[idx].ty; + if( this->type_is_bad_zst(ty) ) { + m_of << "// ZST: " << ty << "\n"; + } + else { + emit_ctype( ty, FMT_CB(ss, ss << "var_" << idx) ); + m_of << ";\n"; + //sized_fields ++; + } } + m_of << "\t} DATA;\n"; } - m_of << "\t} DATA;\n"; if( repr->fields.size() == 1 + union_fields.size() ) { @@ -1791,14 +1801,14 @@ namespace { m_of << "{"; const auto& ity = get_inner_type(e.idx, 0); if( this->type_is_bad_zst(ity) ) { - m_of << " {}"; + //m_of << " {}"; } else { m_of << " { .var_" << e.idx << " = "; emit_literal(ity, *e.val, params); - m_of << " }"; + m_of << " }, "; } - m_of << ", .TAG = "; emit_enum_variant_val(repr, e.idx); + m_of << ".TAG = "; emit_enum_variant_val(repr, e.idx); m_of << "}"; } ), @@ -3991,13 +4001,15 @@ namespace { m_of << name << o_before << "8" << o_after << "("; break; case ::HIR::CoreType::U16: + case ::HIR::CoreType::I16: m_of << name << o_before << "16" << o_after << "("; break; case ::HIR::CoreType::U32: + case ::HIR::CoreType::I32: m_of << name << o_before << o_after << "("; break; case ::HIR::CoreType::U64: - //case ::HIR::CoreType::I64: + case ::HIR::CoreType::I64: m_of << name << o_before << "64" << o_after << "("; break; case ::HIR::CoreType::Usize: diff --git a/src/trans/target.cpp b/src/trans/target.cpp index ea850937..f91b679a 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -691,7 +691,12 @@ bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, case ::HIR::CoreType::I128: out_size = 16; // TODO: If i128 is emulated, this can be 8 (as it is on x86, where it's actually 4 due to the above comment) - out_align = g_target.m_arch.m_name == "x86" ? 4 : 16; + if( g_target.m_arch.m_name == "x86" ) + out_align = 4; + else if( /*g_target.m_arch.m_name == "x86_64" && */g_target.m_backend_c.m_codegen_mode == CodegenMode::Msvc ) + out_align = 8; + else + out_align = 16; return true; case ::HIR::CoreType::Usize: case ::HIR::CoreType::Isize: diff --git a/src/version.cpp b/src/version.cpp index d6307618..b40196ff 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -12,6 +12,14 @@ #define VERSION_MINOR 8 #define VERSION_PATCH 0 +#ifdef _WIN32 +# define VERSION_GIT_ISDIRTY 1 +# define VERSION_GIT_FULLHASH "" +# define VERSION_GIT_SHORTHASH "" +# define VERSION_BUILDTIME "" +# define VERSION_GIT_BRANCH "" +#endif + unsigned int giVersion_Major = VERSION_MAJOR; unsigned int giVersion_Minor = VERSION_MINOR; unsigned int giVersion_Patch = VERSION_PATCH; diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 2f8fafe4..35c64f3b 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -945,7 +945,7 @@ bool Builder::spawn_process(const char* exe_name, const StringList& args, const auto cmdline_str = cmdline.str(); if(true) { - ::std::cout << "> " << cmdline_str << ::std::end;; + ::std::cout << "> " << cmdline_str << ::std::endl; } else { diff --git a/tools/minicargo/main.cpp b/tools/minicargo/main.cpp index b96a8a03..d7312d48 100644 --- a/tools/minicargo/main.cpp +++ b/tools/minicargo/main.cpp @@ -5,6 +5,7 @@ * main.cpp * - Entrypoint */ +#define _CRT_SECURE_NO_WARNINGS #include #include // strcmp #include diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp index f4179b5d..8231f2c5 100644 --- a/tools/standalone_miri/miri.cpp +++ b/tools/standalone_miri/miri.cpp @@ -12,6 +12,7 @@ #include #include "debug.hpp" #include "miri.hpp" +#include // memrchr #ifdef _WIN32 # define NOMINMAX # include @@ -953,10 +954,10 @@ bool InterpreterThread::step_one(Value& out_thread_result) int res = 0; // TODO: Handle comparison of the relocations too - const auto& alloc_l = v_l.m_value ? v_l.m_value->allocation : v_l.m_alloc; - const auto& alloc_r = v_r.m_value ? v_r.m_value->allocation : v_r.m_alloc; - auto reloc_l = alloc_l ? v_l.get_relocation(v_l.m_offset) : RelocationPtr(); - auto reloc_r = alloc_r ? v_r.get_relocation(v_r.m_offset) : RelocationPtr(); + //const auto& alloc_l = v_l.m_value ? v_l.m_value->allocation : v_l.m_alloc; + //const auto& alloc_r = v_r.m_value ? v_r.m_value->allocation : v_r.m_alloc; + auto reloc_l = /*alloc_l ? */v_l.get_relocation(v_l.m_offset)/* : RelocationPtr()*/; + auto reloc_r = /*alloc_r ? */v_r.get_relocation(v_r.m_offset)/* : RelocationPtr()*/; if( reloc_l != reloc_r ) { @@ -1578,10 +1579,23 @@ bool InterpreterThread::call_path(Value& ret, const ::HIR::Path& path, ::std::ve return false; } +#ifdef _WIN32 +const char* memrchr(const void* p, int c, size_t s) { + const char* p2 = reinterpret_cast(p); + while( s > 0 ) + { + s -= 1; + if( p2[s] == c ) + return &p2[s]; + } + return nullptr; +} +#else extern "C" { long sysconf(int); ssize_t write(int, const void*, size_t); } +#endif bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, const ::std::string& abi, ::std::vector args) { if( link_name == "__rust_allocate" ) @@ -1673,8 +1687,8 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c } else if( link_name == "GetModuleHandleW" ) { - LOG_ASSERT(args.at(0).allocation.is_alloc(), ""); - const auto& tgt_alloc = args.at(0).allocation.alloc().get_relocation(0); + LOG_ASSERT(args.at(0).allocation, ""); + const auto& tgt_alloc = args.at(0).get_relocation(0); const void* arg0 = (tgt_alloc ? tgt_alloc.alloc().data_ptr() : nullptr); //extern void* GetModuleHandleW(const void* s); if(arg0) { @@ -1698,10 +1712,8 @@ bool InterpreterThread::call_extern(Value& rv, const ::std::string& link_name, c } else if( link_name == "GetProcAddress" ) { - LOG_ASSERT(args.at(0).allocation.is_alloc(), ""); - const auto& handle_alloc = args.at(0).allocation.alloc().get_relocation(0); - LOG_ASSERT(args.at(1).allocation.is_alloc(), ""); - const auto& sym_alloc = args.at(1).allocation.alloc().get_relocation(0); + const auto& handle_alloc = args.at(0).get_relocation(0); + const auto& sym_alloc = args.at(1).get_relocation(0); // TODO: Ensure that first arg is a FFI pointer with offset+size of zero void* handle = handle_alloc.ffi().ptr_value; @@ -2204,7 +2216,7 @@ bool InterpreterThread::call_intrinsic(Value& rv, const ::std::string& name, con LOG_ASSERT(src_ofs <= src_alloc.ffi().size, ""); LOG_ASSERT(byte_count <= src_alloc.ffi().size, ""); LOG_ASSERT(src_ofs + byte_count <= src_alloc.ffi().size, ""); - dst_alloc.alloc().write_bytes(dst_ofs, src_alloc.ffi().ptr_value + src_ofs, byte_count); + dst_alloc.alloc().write_bytes(dst_ofs, reinterpret_cast(src_alloc.ffi().ptr_value) + src_ofs, byte_count); break; } } diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp index cf378077..849d3a64 100644 --- a/tools/standalone_miri/value.cpp +++ b/tools/standalone_miri/value.cpp @@ -239,7 +239,7 @@ void* ValueCommonRead::read_pointer_unsafe(size_t rd_ofs, size_t req_valid, size // TODO: Have an idea of mutability and available size from FFI out_size = f.size - ofs; out_is_mut = false; - return reloc.ffi().ptr_value + ofs; + return reinterpret_cast(reloc.ffi().ptr_value) + ofs; } } throw ""; @@ -607,22 +607,22 @@ Value Value::new_pointer(::HIR::TypeRef ty, uint64_t v, RelocationPtr r) { return rv; } Value Value::new_usize(uint64_t v) { - Value rv( ::HIR::TypeRef(RawType::USize) ); + auto rv = Value( ::HIR::TypeRef(RawType::USize) ); rv.write_usize(0, v); return rv; } Value Value::new_isize(int64_t v) { - Value rv( ::HIR::TypeRef(RawType::ISize) ); + auto rv = Value( ::HIR::TypeRef(RawType::ISize) ); rv.write_isize(0, v); return rv; } Value Value::new_u32(uint32_t v) { - Value rv( ::HIR::TypeRef(RawType::U32) ); + auto rv = Value( ::HIR::TypeRef(RawType::U32) ); rv.write_u32(0, v); return rv; } Value Value::new_i32(int32_t v) { - Value rv( ::HIR::TypeRef(RawType::I32) ); + auto rv = Value( ::HIR::TypeRef(RawType::I32) ); rv.write_i32(0, v); return rv; } diff --git a/tools/testrunner/main.cpp b/tools/testrunner/main.cpp index 4dafe508..5c21937d 100644 --- a/tools/testrunner/main.cpp +++ b/tools/testrunner/main.cpp @@ -520,9 +520,8 @@ bool run_executable(const ::helpers::path& exe_name, const ::std::vector(cmdline_str.size()), &tmp, NULL); //WriteFile(si.hStdOutput, "\n", 1, &tmp, NULL); } + DuplicateHandle(NULL, si.hStdOutput, NULL, &si.hStdError, GENERIC_WRITE, FALSE, FILE_SHARE_READ); PROCESS_INFORMATION pi = { 0 }; + auto em = SetErrorMode(SEM_NOGPFAULTERRORBOX); CreateProcessA(exe_name.str().c_str(), (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); + SetErrorMode(em); CloseHandle(si.hStdOutput); WaitForSingleObject(pi.hProcess, INFINITE); DWORD status = 1; diff --git a/vsproject/mrustc.vcxproj b/vsproject/mrustc.vcxproj index 2096266a..13c4a23e 100644 --- a/vsproject/mrustc.vcxproj +++ b/vsproject/mrustc.vcxproj @@ -252,7 +252,6 @@ - @@ -264,6 +263,7 @@ + diff --git a/vsproject/mrustc.vcxproj.filters b/vsproject/mrustc.vcxproj.filters index 997e4849..755013af 100644 --- a/vsproject/mrustc.vcxproj.filters +++ b/vsproject/mrustc.vcxproj.filters @@ -80,9 +80,6 @@ Source Files - - Source Files - Source Files @@ -392,6 +389,9 @@ Source Files\trans + + Source Files + diff --git a/vsproject/standalone_miri/standalone_miri.vcxproj b/vsproject/standalone_miri/standalone_miri.vcxproj index 66f33ebd..5c235353 100644 --- a/vsproject/standalone_miri/standalone_miri.vcxproj +++ b/vsproject/standalone_miri/standalone_miri.vcxproj @@ -170,6 +170,7 @@ + diff --git a/vsproject/standalone_miri/standalone_miri.vcxproj.filters b/vsproject/standalone_miri/standalone_miri.vcxproj.filters index e26bbee5..3b25bbfb 100644 --- a/vsproject/standalone_miri/standalone_miri.vcxproj.filters +++ b/vsproject/standalone_miri/standalone_miri.vcxproj.filters @@ -59,5 +59,8 @@ Source Files + + Source Files + \ No newline at end of file -- cgit v1.2.3