summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ast/attrs.hpp2
-rw-r--r--src/hir/deserialise.cpp4
-rw-r--r--src/span.cpp4
-rw-r--r--src/trans/codegen_c.cpp70
-rw-r--r--src/trans/target.cpp7
-rw-r--r--src/version.cpp8
-rw-r--r--tools/minicargo/build.cpp2
-rw-r--r--tools/minicargo/main.cpp1
-rw-r--r--tools/standalone_miri/miri.cpp34
-rw-r--r--tools/standalone_miri/value.cpp10
-rw-r--r--tools/testrunner/main.cpp6
-rw-r--r--vsproject/mrustc.vcxproj2
-rw-r--r--vsproject/mrustc.vcxproj.filters6
-rw-r--r--vsproject/standalone_miri/standalone_miri.vcxproj1
-rw-r--r--vsproject/standalone_miri/standalone_miri.vcxproj.filters3
15 files changed, 105 insertions, 55 deletions
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<uint32_t>(m_in.read_count()) };
+ ::HIR::LifetimeRef rv;
+ rv.binding = static_cast<uint32_t>(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<void(::std::ostream&)> 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<void(::std::ostream&)> 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 <iostream>
#include <cstring> // strcmp
#include <map>
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 <iomanip>
#include "debug.hpp"
#include "miri.hpp"
+#include <cstring> // memrchr
#ifdef _WIN32
# define NOMINMAX
# include <Windows.h>
@@ -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<const char*>(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<Value> 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<const char*>(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<char*>(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<const c
STARTUPINFO si = { 0 };
si.cb = sizeof(si);
- si.dwFlags = STARTF_USESTDHANDLES;
+ si.dwFlags = STARTF_USESTDHANDLES|STARTF_FORCEOFFFEEDBACK;
si.hStdInput = NULL;
- si.hStdError = GetStdHandle(STD_ERROR_HANDLE);
{
SECURITY_ATTRIBUTES sa = { 0 };
sa.nLength = sizeof(sa);
@@ -532,8 +531,11 @@ bool run_executable(const ::helpers::path& exe_name, const ::std::vector<const c
//WriteFile(si.hStdOutput, cmdline_str.data(), static_cast<DWORD>(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 @@
<ClCompile Include="..\src\resolve\absolute.cpp" />
<ClCompile Include="..\src\resolve\index.cpp" />
<ClCompile Include="..\src\resolve\use.cpp" />
- <ClCompile Include="..\src\serialise.cpp" />
<ClCompile Include="..\src\span.cpp" />
<ClCompile Include="..\src\trans\allocator.cpp" />
<ClCompile Include="..\src\trans\codegen.cpp" />
@@ -264,6 +263,7 @@
<ClCompile Include="..\src\trans\monomorphise.cpp" />
<ClCompile Include="..\src\trans\target.cpp" />
<ClCompile Include="..\src\trans\trans_list.cpp" />
+ <ClCompile Include="..\src\version.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\ast\ast.hpp" />
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 @@
<ClCompile Include="..\src\rc_string.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="..\src\serialise.cpp">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="..\src\span.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -392,6 +389,9 @@
<ClCompile Include="..\src\trans\codegen_mmir.cpp">
<Filter>Source Files\trans</Filter>
</ClCompile>
+ <ClCompile Include="..\src\version.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\src\common.hpp">
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 @@
<ClCompile Include="..\..\tools\standalone_miri\lex.cpp" />
<ClCompile Include="..\..\tools\standalone_miri\main.cpp" />
<ClCompile Include="..\..\tools\standalone_miri\mir.cpp" />
+ <ClCompile Include="..\..\tools\standalone_miri\miri.cpp" />
<ClCompile Include="..\..\tools\standalone_miri\module_tree.cpp" />
<ClCompile Include="..\..\tools\standalone_miri\value.cpp" />
</ItemGroup>
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 @@
<ClCompile Include="..\..\tools\standalone_miri\debug.cpp">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="..\..\tools\standalone_miri\miri.cpp">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
</Project> \ No newline at end of file