From 4a8198baca2cfcee17f83978ab71422a04d53b1a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 15 Sep 2018 12:03:28 +0800 Subject: minicargo.mk - Random test target --- minicargo.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/minicargo.mk b/minicargo.mk index 6c9962a6..49d24ff3 100644 --- a/minicargo.mk +++ b/minicargo.mk @@ -114,6 +114,8 @@ $(RUSTCSRC)build/Makefile: $(RUSTCSRC)src/llvm/CMakeLists.txt # # Developement-only targets # +$(OUTDIR)rustc-build/librustc_trans.hir: $(MRUSTC) LIBS $(LLVM_CONFIG) + $(MINICARGO) $(RUSTCSRC)src/librustc_trans --vendor-dir $(RUSTCSRC)src/vendor --output-dir $(dir $@) -L $(OUTDIR) $(MINICARGO_FLAGS) $(OUTDIR)rustc-build/librustdoc.hir: $(MRUSTC) LIBS $(MINICARGO) $(RUSTCSRC)src/librustdoc --vendor-dir $(RUSTCSRC)src/vendor --output-dir $(dir $@) -L $(OUTDIR) $(MINICARGO_FLAGS) #$(OUTDIR)cargo-build/libserde-1_0_6.hir: $(MRUSTC) LIBS -- cgit v1.2.3 From f5168113b6dcdfc8e9713dcf122b99ca6e26a4fc Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 19 Oct 2018 07:40:53 +0800 Subject: Codegen C - Fix incorrect use of ZST in enum constructor shim (fixes #86) --- src/trans/codegen_c.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 0ced3150..b578c09b 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1538,7 +1538,7 @@ namespace { { if( this->type_is_bad_zst(repr->fields[var_idx].ty) ) { - m_of << " .DATA = { /* ZST Variant */ }"; + //m_of << " .DATA = { /* ZST Variant */ }"; } else { -- cgit v1.2.3 From 96d23305473e71bc6fdfca0fca4d6a22983801be Mon Sep 17 00:00:00 2001 From: John Hodge Date: Fri, 19 Oct 2018 17:19:29 +0800 Subject: Add a few new tests, one for #86, the other for #77 (eventually) --- samples/test/issue-mrustc-77.rs | 14 ++++++++++++++ samples/test/zst_use.rs | 12 ++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 samples/test/issue-mrustc-77.rs create mode 100644 samples/test/zst_use.rs diff --git a/samples/test/issue-mrustc-77.rs b/samples/test/issue-mrustc-77.rs new file mode 100644 index 00000000..ba916822 --- /dev/null +++ b/samples/test/issue-mrustc-77.rs @@ -0,0 +1,14 @@ +// ignore-test + +#[repr(C)] +#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +pub struct __BindgenBitfieldUnit +where + Storage: AsRef<[u8]> + AsMut<[u8]>, +{ + storage: Storage, + align: [Align; 0], +} + +fn main() { +} diff --git a/samples/test/zst_use.rs b/samples/test/zst_use.rs new file mode 100644 index 00000000..17e75919 --- /dev/null +++ b/samples/test/zst_use.rs @@ -0,0 +1,12 @@ +// compile-flags: --test + +#[test] +fn zst_enum_variant() { + #[inline(never)] + fn takes_fn Option<()>>(f: F) { + f( () ); + } + + takes_fn( Option::Some ); +} + -- cgit v1.2.3 From 9dd5e5364bacf75e8b7f034e61a7f536d0a6344c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 21 Oct 2018 09:53:43 +0800 Subject: Windows build fixes --- src/hir/expr_ptr.hpp | 2 +- src/mir/cleanup.cpp | 2 +- vsproject/mrustc.vcxproj | 1 - vsproject/mrustc.vcxproj.filters | 3 --- 4 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/hir/expr_ptr.hpp b/src/hir/expr_ptr.hpp index b510e737..2f0f30e4 100644 --- a/src/hir/expr_ptr.hpp +++ b/src/hir/expr_ptr.hpp @@ -12,7 +12,7 @@ #include -class Span; +struct Span; namespace HIR { diff --git a/src/mir/cleanup.cpp b/src/mir/cleanup.cpp index 37d256df..eae24031 100644 --- a/src/mir/cleanup.cpp +++ b/src/mir/cleanup.cpp @@ -1218,7 +1218,7 @@ void MIR_Cleanup(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path, void MIR_CleanupCrate(::HIR::Crate& crate) { - ::MIR::OuterVisitor ov { crate, [&](const auto& res, const auto& p, auto& expr_ptr, const auto& args, const auto& ty){ + ::MIR::OuterVisitor ov { crate, [&](const auto& res, const auto& p, ::HIR::ExprPtr& expr_ptr, const auto& args, const auto& ty){ MIR_Cleanup(res, p, expr_ptr.get_mir_or_error_mut(Span()), args, ty); } }; ov.visit_crate(crate); diff --git a/vsproject/mrustc.vcxproj b/vsproject/mrustc.vcxproj index 13c4a23e..234ce37b 100644 --- a/vsproject/mrustc.vcxproj +++ b/vsproject/mrustc.vcxproj @@ -206,7 +206,6 @@ - diff --git a/vsproject/mrustc.vcxproj.filters b/vsproject/mrustc.vcxproj.filters index 755013af..cedc5fd1 100644 --- a/vsproject/mrustc.vcxproj.filters +++ b/vsproject/mrustc.vcxproj.filters @@ -98,9 +98,6 @@ Source Files\hir_expand - - Source Files\hir_expand - Source Files\hir_conv -- cgit v1.2.3 From 4d6aa119e76862ba57acc7f99ebf68d1ee71adbd Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 21 Oct 2018 12:55:31 +0800 Subject: VS - Make target paths consistent (fixes build error in Win32 target) --- vsproject/common_lib/common_lib.vcxproj | 9 ++++++++- vsproject/minicargo/minicargo.vcxproj | 9 ++++++++- vsproject/standalone_miri/standalone_miri.vcxproj | 4 ++++ vsproject/testrunner/testrunner.vcxproj | 9 ++++++++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/vsproject/common_lib/common_lib.vcxproj b/vsproject/common_lib/common_lib.vcxproj index 09789501..4f861999 100644 --- a/vsproject/common_lib/common_lib.vcxproj +++ b/vsproject/common_lib/common_lib.vcxproj @@ -69,7 +69,14 @@ - + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + Level3 diff --git a/vsproject/minicargo/minicargo.vcxproj b/vsproject/minicargo/minicargo.vcxproj index 25ffbe03..8694bc11 100644 --- a/vsproject/minicargo/minicargo.vcxproj +++ b/vsproject/minicargo/minicargo.vcxproj @@ -68,7 +68,14 @@ - + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + Level3 diff --git a/vsproject/standalone_miri/standalone_miri.vcxproj b/vsproject/standalone_miri/standalone_miri.vcxproj index 5c235353..af8c8154 100644 --- a/vsproject/standalone_miri/standalone_miri.vcxproj +++ b/vsproject/standalone_miri/standalone_miri.vcxproj @@ -71,12 +71,16 @@ true + $(Platform)\$(Configuration)\ + $(SolutionDir)$(Platform)\$(Configuration)\ true false + $(Platform)\$(Configuration)\ + $(SolutionDir)$(Platform)\$(Configuration)\ false diff --git a/vsproject/testrunner/testrunner.vcxproj b/vsproject/testrunner/testrunner.vcxproj index 94d365f0..550614ac 100644 --- a/vsproject/testrunner/testrunner.vcxproj +++ b/vsproject/testrunner/testrunner.vcxproj @@ -68,7 +68,14 @@ - + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(Platform)\$(Configuration)\ + Level3 -- cgit v1.2.3 From ba553fd63c3f88a0eb62dbebe010e50b72fbe8b5 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 21 Oct 2018 12:55:58 +0800 Subject: Standalone MIRI - Compilation fixes for 32-bit msvc --- tools/standalone_miri/miri.cpp | 9 +++++++-- tools/standalone_miri/module_tree.cpp | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp index 8231f2c5..14958c45 100644 --- a/tools/standalone_miri/miri.cpp +++ b/tools/standalone_miri/miri.cpp @@ -290,7 +290,12 @@ struct MirHelpers else if( wrapper->type == TypeWrapper::Ty::Array ) { ty = array_ty.get_inner(); - base_val.m_offset += ty.get_size() * idx; + // Check index against array size + if( idx >= wrapper->size ) { + LOG_ERROR("Index out of bounds on array " << array_ty << ", idx=" << idx); + throw "ERROR"; + } + base_val.m_offset += static_cast(ty.get_size() * idx); return base_val; } else if( wrapper->type == TypeWrapper::Ty::Slice ) @@ -335,7 +340,7 @@ struct MirHelpers LOG_DEBUG("val = " << val << ", (inner) ty=" << ty); LOG_ASSERT(val.m_size >= POINTER_SIZE, "Deref of a value that doesn't fit a pointer - " << ty); - size_t ofs = val.read_usize(0); + size_t ofs = static_cast( val.read_usize(0) ); // TODO: Limits? // There MUST be a relocation at this point with a valid allocation. auto alloc = val.get_relocation(val.m_offset); diff --git a/tools/standalone_miri/module_tree.cpp b/tools/standalone_miri/module_tree.cpp index eb6b6b9e..8e0a231a 100644 --- a/tools/standalone_miri/module_tree.cpp +++ b/tools/standalone_miri/module_tree.cpp @@ -156,12 +156,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, /*size,*/ RelocationPtr::new_alloc(::std::move(a)) }); + s.val.allocation->relocations.push_back({ static_cast(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, /*size,*/ RelocationPtr::new_fcn(reloc_path) }); + s.val.allocation->relocations.push_back({ static_cast(ofs), /*size,*/ RelocationPtr::new_fcn(reloc_path) }); } else { -- cgit v1.2.3 From bd32801622229ba3ac02924852f2835bed9debc3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 3 Nov 2018 22:09:14 +0800 Subject: HIR Typecheck - Fix mixup between assignment SHR/SHL operator traits --- src/hir_typeck/expr_check.cpp | 4 ++-- src/hir_typeck/expr_cs.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hir_typeck/expr_check.cpp b/src/hir_typeck/expr_check.cpp index 985fe15f..319124ad 100644 --- a/src/hir_typeck/expr_check.cpp +++ b/src/hir_typeck/expr_check.cpp @@ -177,8 +177,8 @@ namespace { case ::HIR::ExprNode_Assign::Op::And: lang_item = "bitand_assign"; break; case ::HIR::ExprNode_Assign::Op::Or : lang_item = "bitor_assign" ; break; case ::HIR::ExprNode_Assign::Op::Xor: lang_item = "bitxor_assign"; break; - case ::HIR::ExprNode_Assign::Op::Shr: lang_item = "shl_assign"; break; - case ::HIR::ExprNode_Assign::Op::Shl: lang_item = "shr_assign"; break; + case ::HIR::ExprNode_Assign::Op::Shr: lang_item = "shr_assign"; break; + case ::HIR::ExprNode_Assign::Op::Shl: lang_item = "shl_assign"; break; } assert(lang_item); const auto& trait_path = this->get_lang_item_path(node.span(), lang_item); diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 62f50ed9..b62ea1cc 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -846,8 +846,8 @@ namespace { case ::HIR::ExprNode_Assign::Op::And: lang_item = "bitand_assign"; break; case ::HIR::ExprNode_Assign::Op::Or : lang_item = "bitor_assign" ; break; case ::HIR::ExprNode_Assign::Op::Xor: lang_item = "bitxor_assign"; break; - case ::HIR::ExprNode_Assign::Op::Shr: lang_item = "shl_assign"; break; - case ::HIR::ExprNode_Assign::Op::Shl: lang_item = "shr_assign"; break; + case ::HIR::ExprNode_Assign::Op::Shr: lang_item = "shr_assign"; break; + case ::HIR::ExprNode_Assign::Op::Shl: lang_item = "shl_assign"; break; } assert(lang_item); const auto& trait_path = this->context.m_crate.get_lang_item_path(node.span(), lang_item); -- cgit v1.2.3 From a51eea542ae086687ea2c4cb09321785f5cc6269 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 4 Nov 2018 08:22:18 +0800 Subject: Typecheck Expressions - Fix a use-after-free, impacts #85 --- src/hir_typeck/expr_cs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index b62ea1cc..554fea69 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -5204,7 +5204,7 @@ namespace { DEBUG("- Magic inferrence link for binops on numerics"); context.equate_types(sp, res, left); } - context.equate_types_to_shadow(sp, right); + context.equate_types_to_shadow(sp, /*right*/v.params.m_types.at(0)); // RHS, can't use `right` because it might be freed by the above equate. } else { -- cgit v1.2.3 From 9afb96ccf062961c663e4c84f803e3a01054ea7a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 4 Nov 2018 08:24:41 +0800 Subject: Typecheck Expressions - (minor) Slight cleanup --- src/hir_typeck/helpers.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hir_typeck/helpers.cpp b/src/hir_typeck/helpers.cpp index 22291123..0a56e9cb 100644 --- a/src/hir_typeck/helpers.cpp +++ b/src/hir_typeck/helpers.cpp @@ -622,7 +622,7 @@ void HMTypeInferrence::set_ivar_to(unsigned int slot, ::HIR::TypeRef type) ) else #endif - root_ivar.type = box$( mv$(type) ); + root_ivar.type = box$( type ); } this->mark_change(); @@ -1544,7 +1544,7 @@ bool TraitResolution::has_associated_type(const ::HIR::TypeRef& input) const //TRACE_FUNCTION_F(input); TU_MATCH(::HIR::TypeRef::Data, (input.m_data), (e), (Infer, - auto& ty = this->m_ivars.get_type(input); + const auto& ty = this->m_ivars.get_type(input); if( ty != input ) { return this->has_associated_type(ty); } -- cgit v1.2.3 From 17be046b4ea045118664d1420cf3263770921a4f Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 4 Nov 2018 08:26:39 +0800 Subject: Standalone MIRI - Fix some warnings/todos --- tools/standalone_miri/miri.cpp | 2 +- tools/standalone_miri/value.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp index 14958c45..53783420 100644 --- a/tools/standalone_miri/miri.cpp +++ b/tools/standalone_miri/miri.cpp @@ -1036,7 +1036,7 @@ bool InterpreterThread::step_one(Value& out_thread_result) LOG_ASSERT(ty_r.get_wrapper() == nullptr, "Bitwise operator with non-primitive - " << ty_r); size_t max_bits = ty_r.get_size() * 8; uint8_t shift; - auto check_cast = [&](auto v){ LOG_ASSERT(0 <= v && v <= max_bits, "Shift out of range - " << v); return static_cast(v); }; + auto check_cast = [&](auto v){ LOG_ASSERT(0 <= v && v <= static_cast(max_bits), "Shift out of range - " << v); return static_cast(v); }; switch(ty_r.inner_type) { case RawType::U64: shift = check_cast(v_r.read_u64(0)); break; diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp index 849d3a64..39b3b906 100644 --- a/tools/standalone_miri/value.cpp +++ b/tools/standalone_miri/value.cpp @@ -586,7 +586,7 @@ Value Value::new_fnptr(const ::HIR::Path& fn_path) assert(rv.allocation); rv.allocation->relocations.push_back(Relocation { 0, RelocationPtr::new_fcn(fn_path) }); rv.allocation->data.at(0) = 0; - rv.allocation->mask.at(0) = 0xFF; // TODO: Get pointer size and make that much valid instead of 8 bytes + rv.allocation->mask.at(0) = (1 << POINTER_SIZE)-1; return rv; } Value Value::new_ffiptr(FFIPointer ffi) @@ -595,7 +595,7 @@ Value Value::new_ffiptr(FFIPointer ffi) rv.create_allocation(); rv.allocation->relocations.push_back(Relocation { 0, RelocationPtr::new_ffi(ffi) }); rv.allocation->data.at(0) = 0; - rv.allocation->mask.at(0) = 0xFF; // TODO: Get pointer size and make that much valid instead of 8 bytes + rv.allocation->mask.at(0) = (1 << POINTER_SIZE)-1; return rv; } Value Value::new_pointer(::HIR::TypeRef ty, uint64_t v, RelocationPtr r) { -- cgit v1.2.3 From 1726886913173c2828e962d7c5d384e3915d0ae3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 4 Nov 2018 20:28:32 +0800 Subject: All - Cleaning up some memory leaks --- src/include/rc_string.hpp | 37 +++++++++---------------- src/include/span.hpp | 6 ++++- src/macro_rules/macro_rules_ptr.hpp | 2 +- src/macro_rules/mod.cpp | 6 +++++ src/parse/pattern.cpp | 54 ++++++++++++++++++------------------- src/parse/root.cpp | 22 +++++++-------- src/parse/token.cpp | 1 + src/parse/tokenstream.cpp | 2 +- src/parse/types.cpp | 26 +++++++++--------- src/rc_string.cpp | 14 +++++++++- src/span.cpp | 9 ------- 11 files changed, 90 insertions(+), 89 deletions(-) diff --git a/src/include/rc_string.hpp b/src/include/rc_string.hpp index eec47d80..914228c6 100644 --- a/src/include/rc_string.hpp +++ b/src/include/rc_string.hpp @@ -29,12 +29,7 @@ public: { } - RcString(const RcString& x): - m_ptr(x.m_ptr), - m_len(x.m_len) - { - if( m_ptr ) *m_ptr += 1; - } + RcString(const RcString& x); RcString(RcString&& x): m_ptr(x.m_ptr), m_len(x.m_len) @@ -47,36 +42,28 @@ public: RcString& operator=(const RcString& x) { - if( &x != this ) - { - this->~RcString(); - m_ptr = x.m_ptr; - m_len = x.m_len; - if( m_ptr ) *m_ptr += 1; - } + if( !(&x != this) ) throw ""; + + this->~RcString(); + new (this) RcString(x); + return *this; } RcString& operator=(RcString&& x) { - if( &x != this ) - { - this->~RcString(); - m_ptr = x.m_ptr; - m_len = x.m_len; - x.m_ptr = nullptr; - x.m_len = 0; - } + if( !(&x != this) ) throw ""; + + this->~RcString(); + new (this) RcString( ::std::move(x) ); return *this; } const char* c_str() const { - if( m_len > 0 ) - { + if( m_len > 0 ) { return reinterpret_cast(m_ptr + 1); } - else - { + else { return ""; } } diff --git a/src/include/span.hpp b/src/include/span.hpp index 68d6bfdf..d41fa81e 100644 --- a/src/include/span.hpp +++ b/src/include/span.hpp @@ -46,10 +46,14 @@ struct Span end_line(end_line), end_ofs(end_ofs) {} - Span(const Span& x); + Span(const Span& x) = default; + Span(Span&& x) = default; Span(const Position& position); Span(); + Span& operator=(const Span& x) = default; + Span& operator=(Span&& x) = default; + void bug(::std::function msg) const; void error(ErrorType tag, ::std::function msg) const; void warning(WarningType tag, ::std::function msg) const; diff --git a/src/macro_rules/macro_rules_ptr.hpp b/src/macro_rules/macro_rules_ptr.hpp index fdb01fbe..5dbfd032 100644 --- a/src/macro_rules/macro_rules_ptr.hpp +++ b/src/macro_rules/macro_rules_ptr.hpp @@ -14,7 +14,7 @@ class MacroRulesPtr MacroRules* m_ptr; public: MacroRulesPtr(): m_ptr(nullptr) {} - MacroRulesPtr(MacroRules* p): m_ptr(p) {} + MacroRulesPtr(MacroRules* p); MacroRulesPtr(MacroRulesPtr&& x): m_ptr(x.m_ptr) { diff --git a/src/macro_rules/mod.cpp b/src/macro_rules/mod.cpp index 6410d334..f9754286 100644 --- a/src/macro_rules/mod.cpp +++ b/src/macro_rules/mod.cpp @@ -157,10 +157,16 @@ bool is_token_item(eTokenType tt) { } } +MacroRulesPtr::MacroRulesPtr(MacroRules* p): + m_ptr(p) +{ + //::std::cout << "MRP new " << m_ptr << ::std::endl; +} MacroRulesPtr::~MacroRulesPtr() { if(m_ptr) { + //::std::cout << "MRP delete " << m_ptr << ::std::endl; delete m_ptr; m_ptr = nullptr; } diff --git a/src/parse/pattern.cpp b/src/parse/pattern.cpp index f6d61728..e2949a63 100644 --- a/src/parse/pattern.cpp +++ b/src/parse/pattern.cpp @@ -92,7 +92,7 @@ AST::Pattern Parse_Pattern(TokenStream& lex, bool is_refutable) if( GET_TOK(tok, lex) != TOK_AT ) { PUTBACK(tok, lex); - return AST::Pattern(AST::Pattern::TagBind(), lex.end_span(ps), mv$(bind_name), bind_type, is_mut); + return AST::Pattern(AST::Pattern::TagBind(), lex.end_span(mv$(ps)), mv$(bind_name), bind_type, is_mut); } binding = AST::PatternBinding( mv$(bind_name), bind_type, is_mut ); @@ -126,11 +126,11 @@ AST::Pattern Parse_Pattern(TokenStream& lex, bool is_refutable) if( is_refutable ) { assert(bind_type == ::AST::PatternBinding::Type::MOVE); assert(is_mut == false); - return AST::Pattern(AST::Pattern::TagMaybeBind(), lex.end_span(ps), mv$(name)); + return AST::Pattern(AST::Pattern::TagMaybeBind(), lex.end_span(mv$(ps)), mv$(name)); } // Otherwise, it IS a binding else { - return AST::Pattern(AST::Pattern::TagBind(), lex.end_span(ps), mv$(name), bind_type, is_mut); + return AST::Pattern(AST::Pattern::TagBind(), lex.end_span(mv$(ps)), mv$(name), bind_type, is_mut); } break;} } @@ -188,11 +188,11 @@ AST::Pattern Parse_PatternReal1(TokenStream& lex, bool is_refutable) switch( GET_TOK(tok, lex) ) { case TOK_UNDERSCORE: - return AST::Pattern( lex.end_span(ps), AST::Pattern::Data() ); + return AST::Pattern( lex.end_span(mv$(ps)), AST::Pattern::Data() ); //case TOK_DOUBLE_DOT: // return AST::Pattern( AST::Pattern::TagWildcard() ); case TOK_RWORD_BOX: - return AST::Pattern( AST::Pattern::TagBox(), lex.end_span(ps), Parse_Pattern(lex, is_refutable) ); + return AST::Pattern( AST::Pattern::TagBox(), lex.end_span(mv$(ps)), Parse_Pattern(lex, is_refutable) ); case TOK_DOUBLE_AMP: lex.putback(TOK_AMP); case TOK_AMP: { @@ -203,7 +203,7 @@ AST::Pattern Parse_PatternReal1(TokenStream& lex, bool is_refutable) is_mut = true; else PUTBACK(tok, lex); - return AST::Pattern( AST::Pattern::TagReference(), lex.end_span(ps), is_mut, Parse_Pattern(lex, is_refutable) ); + return AST::Pattern( AST::Pattern::TagReference(), lex.end_span(mv$(ps)), is_mut, Parse_Pattern(lex, is_refutable) ); } case TOK_RWORD_SELF: case TOK_RWORD_SUPER: @@ -221,44 +221,44 @@ AST::Pattern Parse_PatternReal1(TokenStream& lex, bool is_refutable) { auto dt = tok.datatype(); // TODO: Ensure that the type is ANY or a signed integer - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Integer({dt, -tok.intval()}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Integer({dt, -tok.intval()}) ); } else if( tok.type() == TOK_FLOAT ) { - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Float({tok.datatype(), -tok.floatval()}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Float({tok.datatype(), -tok.floatval()}) ); } else { throw ParseError::Unexpected(lex, tok, {TOK_INTEGER, TOK_FLOAT}); } case TOK_FLOAT: - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Float({tok.datatype(), tok.floatval()}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Float({tok.datatype(), tok.floatval()}) ); case TOK_INTEGER: - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Integer({tok.datatype(), tok.intval()}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Integer({tok.datatype(), tok.intval()}) ); case TOK_RWORD_TRUE: - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Integer({CORETYPE_BOOL, 1}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Integer({CORETYPE_BOOL, 1}) ); case TOK_RWORD_FALSE: - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Integer({CORETYPE_BOOL, 0}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Integer({CORETYPE_BOOL, 0}) ); case TOK_STRING: - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_String( mv$(tok.str()) ) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_String( mv$(tok.str()) ) ); case TOK_BYTESTRING: - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_ByteString({ mv$(tok.str()) }) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_ByteString({ mv$(tok.str()) }) ); case TOK_INTERPOLATED_EXPR: { auto e = tok.take_frag_node(); if( auto* n = dynamic_cast(e.get()) ) { - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_String( mv$(n->m_value) ) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_String( mv$(n->m_value) ) ); } //else if( auto* n = dynamic_cast(e.get()) ) { - // return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_ByteString( mv$(n->m_value) ) ); + // return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_ByteString( mv$(n->m_value) ) ); //} else if( auto* n = dynamic_cast(e.get()) ) { - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Integer({CORETYPE_BOOL, n->m_value}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Integer({CORETYPE_BOOL, n->m_value}) ); } else if( auto* n = dynamic_cast(e.get()) ) { - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Integer({n->m_datatype, n->m_value}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Integer({n->m_datatype, n->m_value}) ); } else if( auto* n = dynamic_cast(e.get()) ) { - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Float({n->m_datatype, n->m_value}) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Float({n->m_datatype, n->m_value}) ); } else { TODO(lex.point_span(), "Convert :expr into a pattern value - " << *e); @@ -266,7 +266,7 @@ AST::Pattern Parse_PatternReal1(TokenStream& lex, bool is_refutable) } break; case TOK_PAREN_OPEN: - return AST::Pattern( AST::Pattern::TagTuple(), lex.end_span(ps), Parse_PatternTuple(lex, is_refutable) ); + return AST::Pattern( AST::Pattern::TagTuple(), lex.end_span(mv$(ps)), Parse_PatternTuple(lex, is_refutable) ); case TOK_SQUARE_OPEN: return Parse_PatternReal_Slice(lex, is_refutable); default: @@ -280,12 +280,12 @@ AST::Pattern Parse_PatternReal_Path(TokenStream& lex, ProtoSpan ps, AST::Path pa switch( GET_TOK(tok, lex) ) { case TOK_PAREN_OPEN: - return AST::Pattern( AST::Pattern::TagNamedTuple(), lex.end_span(ps), mv$(path), Parse_PatternTuple(lex, is_refutable) ); + return AST::Pattern( AST::Pattern::TagNamedTuple(), lex.end_span(mv$(ps)), mv$(path), Parse_PatternTuple(lex, is_refutable) ); case TOK_BRACE_OPEN: return Parse_PatternStruct(lex, ps, mv$(path), is_refutable); default: PUTBACK(tok, lex); - return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(ps), AST::Pattern::Value::make_Named(mv$(path)) ); + return AST::Pattern( AST::Pattern::TagValue(), lex.end_span(mv$(ps)), AST::Pattern::Value::make_Named(mv$(path)) ); } } @@ -323,7 +323,7 @@ AST::Pattern Parse_PatternReal_Slice(TokenStream& lex, bool is_refutable) if( has_binding ) { if(is_split) - ERROR(lex.end_span(ps), E0000, "Multiple instances of .. in a slice pattern"); + ERROR(lex.end_span(mv$(ps)), E0000, "Multiple instances of .. in a slice pattern"); inner_binding = mv$(binding); is_split = true; @@ -346,13 +346,13 @@ AST::Pattern Parse_PatternReal_Slice(TokenStream& lex, bool is_refutable) if( is_split ) { - return ::AST::Pattern( lex.end_span(ps), ::AST::Pattern::Data::make_SplitSlice({ mv$(leading), mv$(inner_binding), mv$(trailing) }) ); + return ::AST::Pattern( lex.end_span(mv$(ps)), ::AST::Pattern::Data::make_SplitSlice({ mv$(leading), mv$(inner_binding), mv$(trailing) }) ); } else { assert( !inner_binding.is_valid() ); assert( trailing.empty() ); - return ::AST::Pattern( lex.end_span(ps), ::AST::Pattern::Data::make_Slice({ mv$(leading) }) ); + return ::AST::Pattern( lex.end_span(mv$(ps)), ::AST::Pattern::Data::make_Slice({ mv$(leading) }) ); } } @@ -452,7 +452,7 @@ AST::Pattern Parse_PatternStruct(TokenStream& lex, ProtoSpan ps, AST::Path path, i ++; } - return AST::Pattern(AST::Pattern::TagNamedTuple(), lex.end_span(ps), mv$(path), AST::Pattern::TuplePat { mv$(leading), has_split, mv$(trailing) }); + return AST::Pattern(AST::Pattern::TagNamedTuple(), lex.end_span(mv$(ps)), mv$(path), AST::Pattern::TuplePat { mv$(leading), has_split, mv$(trailing) }); } bool is_exhaustive = true; @@ -521,6 +521,6 @@ AST::Pattern Parse_PatternStruct(TokenStream& lex, ProtoSpan ps, AST::Path path, } while( GET_TOK(tok, lex) == TOK_COMMA ); CHECK_TOK(tok, TOK_BRACE_CLOSE); - return AST::Pattern(AST::Pattern::TagStruct(), lex.end_span(ps), ::std::move(path), ::std::move(subpats), is_exhaustive); + return AST::Pattern(AST::Pattern::TagStruct(), lex.end_span(mv$(ps)), ::std::move(path), ::std::move(subpats), is_exhaustive); } diff --git a/src/parse/root.cpp b/src/parse/root.cpp index 68ad570b..bc001c99 100644 --- a/src/parse/root.cpp +++ b/src/parse/root.cpp @@ -25,7 +25,7 @@ Spanned get_spanned(TokenStream& lex, ::std::function f) { auto ps = lex.start_span(); auto v = f(); return Spanned { - lex.end_span(ps), + lex.end_span( mv$(ps) ), mv$(v) }; } @@ -499,7 +499,7 @@ AST::Function Parse_FunctionDef(TokenStream& lex, ::std::string abi, bool allow_ PUTBACK(tok, lex); } - return AST::Function(lex.end_span(ps), mv$(params), mv$(abi), is_unsafe, is_const, is_variadic, mv$(ret_type), mv$(args)); + return AST::Function(lex.end_span( mv$(ps) ), mv$(params), mv$(abi), is_unsafe, is_const, is_variadic, mv$(ret_type), mv$(args)); } AST::Function Parse_FunctionDefWithCode(TokenStream& lex, ::std::string abi, bool allow_self, bool is_unsafe, bool is_const) @@ -1003,12 +1003,12 @@ AST::Attribute Parse_MetaItem(TokenStream& lex) switch(GET_TOK(tok, lex)) { case TOK_STRING: - return AST::Attribute(lex.end_span(ps), name, tok.str()); + return AST::Attribute(lex.end_span(mv$(ps)), name, tok.str()); case TOK_INTERPOLATED_EXPR: { auto n = tok.take_frag_node(); if( auto* v = dynamic_cast<::AST::ExprNode_String*>(&*n) ) { - return AST::Attribute(lex.end_span(ps), name, mv$(v->m_value)); + return AST::Attribute(lex.end_span(mv$(ps)), name, mv$(v->m_value)); } else { @@ -1031,10 +1031,10 @@ AST::Attribute Parse_MetaItem(TokenStream& lex) items.push_back(Parse_MetaItem(lex)); } while(GET_TOK(tok, lex) == TOK_COMMA); CHECK_TOK(tok, TOK_PAREN_CLOSE); - return AST::Attribute(lex.end_span(ps), name, mv$(items)); } + return AST::Attribute(lex.end_span(mv$(ps)), name, mv$(items)); } default: PUTBACK(tok, lex); - return AST::Attribute(lex.end_span(ps), name); + return AST::Attribute(lex.end_span(mv$(ps)), name); } } @@ -1229,7 +1229,7 @@ void Parse_Impl_Item(TokenStream& lex, AST::Impl& impl) throw ParseError::Unexpected(lex, tok); } - impl.items().back().data->span = lex.end_span(ps); + impl.items().back().data->span = lex.end_span(mv$(ps)); impl.items().back().data->attrs = mv$(item_attrs); // Empty for functions } @@ -1262,7 +1262,7 @@ AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::A GET_CHECK_TOK(tok, lex, TOK_SEMICOLON); i.attrs = mv$(meta_items); - i.span = lex.end_span(ps); + i.span = lex.end_span(mv$(ps)); rv.add_item( AST::Named { mv$(name), mv$(i), is_public } ); break; } @@ -1280,7 +1280,7 @@ AST::ExternBlock Parse_ExternBlock(TokenStream& lex, ::std::string abi, ::AST::A auto i = ::AST::Item(::AST::Static( (is_mut ? ::AST::Static::MUT : ::AST::Static::STATIC), mv$(type), ::AST::Expr() )); i.attrs = mv$(meta_items); - i.span = lex.end_span(ps); + i.span = lex.end_span(mv$(ps)); rv.add_item( AST::Named { mv$(name), mv$(i), is_public } ); break; } default: @@ -1504,7 +1504,7 @@ bool Parse_MacroInvocation_Opt(TokenStream& lex, AST::MacroInvocation& out_inv) { item_data = ::AST::Item( mv$(inv) ); item_data.attrs = mv$(meta_items); - item_data.span = lex.end_span(ps); + item_data.span = lex.end_span(mv$(ps)); return ::AST::Named< ::AST::Item> { "", mv$(item_data), false }; } @@ -1875,7 +1875,7 @@ bool Parse_MacroInvocation_Opt(TokenStream& lex, AST::MacroInvocation& out_inv) } item_data.attrs = mv$(meta_items); - item_data.span = lex.end_span(ps); + item_data.span = lex.end_span(mv$(ps)); return ::AST::Named< ::AST::Item> { mv$(item_name), mv$(item_data), is_public }; } diff --git a/src/parse/token.cpp b/src/parse/token.cpp index 115df135..2e5a61d4 100644 --- a/src/parse/token.cpp +++ b/src/parse/token.cpp @@ -207,6 +207,7 @@ Token Token::clone() const BUG(m_pos, "Fragment with invalid token type (" << *this << ")"); break; } + assert(rv.m_data.is_Fragment()); ) ) return rv; diff --git a/src/parse/tokenstream.cpp b/src/parse/tokenstream.cpp index 611df2ff..889c626c 100644 --- a/src/parse/tokenstream.cpp +++ b/src/parse/tokenstream.cpp @@ -125,7 +125,7 @@ ProtoSpan TokenStream::start_span() const Span TokenStream::end_span(ProtoSpan ps) const { auto p = this->getPosition(); - auto rv = Span( ps.filename, ps.start_line, ps.start_ofs, p.line, p.ofs ); + auto rv = Span( ::std::move(ps.filename), ps.start_line, ps.start_ofs, p.line, p.ofs ); rv.outer_span = this->outerSpan(); return rv; } diff --git a/src/parse/types.cpp b/src/parse/types.cpp index a07e66f8..ca5b7892 100644 --- a/src/parse/types.cpp +++ b/src/parse/types.cpp @@ -61,7 +61,7 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) case TOK_DOUBLE_LT: { PUTBACK(tok, lex); auto path = Parse_Path(lex, PATH_GENERIC_TYPE); - return TypeRef(TypeRef::TagPath(), lex.end_span(ps), mv$(path)); + return TypeRef(TypeRef::TagPath(), lex.end_span(mv$(ps)), mv$(path)); } // case TOK_RWORD_FOR: { @@ -122,7 +122,7 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) else { PUTBACK(tok, lex); } - return TypeRef(TypeRef::TagReference(), lex.end_span(ps), ::std::move(lifetime), is_mut, Parse_Type(lex, false)); + return TypeRef(TypeRef::TagReference(), lex.end_span(mv$(ps)), ::std::move(lifetime), is_mut, Parse_Type(lex, false)); } // '*' - Raw pointer case TOK_STAR: @@ -131,10 +131,10 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) { case TOK_RWORD_MUT: // Mutable pointer - return TypeRef(TypeRef::TagPointer(), lex.end_span(ps), true, Parse_Type(lex, false)); + return TypeRef(TypeRef::TagPointer(), lex.end_span(mv$(ps)), true, Parse_Type(lex, false)); case TOK_RWORD_CONST: // Immutable pointer - return TypeRef(TypeRef::TagPointer(), lex.end_span(ps), false, Parse_Type(lex, false)); + return TypeRef(TypeRef::TagPointer(), lex.end_span(mv$(ps)), false, Parse_Type(lex, false)); default: throw ParseError::Unexpected(lex, tok, {TOK_RWORD_CONST, TOK_RWORD_MUT}); } @@ -147,11 +147,11 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) // Sized array AST::Expr array_size = Parse_Expr(lex); GET_CHECK_TOK(tok, lex, TOK_SQUARE_CLOSE); - return TypeRef(TypeRef::TagSizedArray(), lex.end_span(ps), mv$(inner), array_size.take_node()); + return TypeRef(TypeRef::TagSizedArray(), lex.end_span(mv$(ps)), mv$(inner), array_size.take_node()); } else if( tok.type() == TOK_SQUARE_CLOSE ) { - return TypeRef(TypeRef::TagUnsizedArray(), lex.end_span(ps), mv$(inner)); + return TypeRef(TypeRef::TagUnsizedArray(), lex.end_span(mv$(ps)), mv$(inner)); } else { throw ParseError::Unexpected(lex, tok/*, "; or ]"*/); @@ -162,7 +162,7 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) case TOK_PAREN_OPEN: { DEBUG("Tuple"); if( GET_TOK(tok, lex) == TOK_PAREN_CLOSE ) - return TypeRef(TypeRef::TagTuple(), lex.end_span(ps), {}); + return TypeRef(TypeRef::TagTuple(), lex.end_span(mv$(ps)), {}); PUTBACK(tok, lex); TypeRef inner = Parse_Type(lex, true); @@ -185,7 +185,7 @@ TypeRef Parse_Type_Int(TokenStream& lex, bool allow_trait_list) types.push_back( Parse_Type(lex) ); } CHECK_TOK(tok, TOK_PAREN_CLOSE); - return TypeRef(TypeRef::TagTuple(), lex.end_span(ps), mv$(types)); } + return TypeRef(TypeRef::TagTuple(), lex.end_span(mv$(ps)), mv$(types)); } } default: throw ParseError::Unexpected(lex, tok); @@ -259,7 +259,7 @@ TypeRef Parse_Type_Fn(TokenStream& lex, ::AST::HigherRankedBounds hrbs) PUTBACK(tok, lex); } - return TypeRef(TypeRef::TagFunction(), lex.end_span(ps), mv$(hrbs), is_unsafe, mv$(abi), mv$(args), is_variadic, mv$(ret_type)); + return TypeRef(TypeRef::TagFunction(), lex.end_span(mv$(ps)), mv$(hrbs), is_unsafe, mv$(abi), mv$(args), is_variadic, mv$(ret_type)); } TypeRef Parse_Type_Path(TokenStream& lex, ::AST::HigherRankedBounds hrbs, bool allow_trait_list) @@ -270,7 +270,7 @@ TypeRef Parse_Type_Path(TokenStream& lex, ::AST::HigherRankedBounds hrbs, bool a if( hrbs.empty() && !allow_trait_list ) { - return TypeRef(TypeRef::TagPath(), lex.end_span(ps), Parse_Path(lex, PATH_GENERIC_TYPE)); + return TypeRef(TypeRef::TagPath(), lex.end_span(mv$(ps)), Parse_Path(lex, PATH_GENERIC_TYPE)); } else { @@ -303,11 +303,11 @@ TypeRef Parse_Type_Path(TokenStream& lex, ::AST::HigherRankedBounds hrbs, bool a { if( lifetimes.empty()) lifetimes.push_back(AST::LifetimeRef()); - return TypeRef(lex.end_span(ps), mv$(traits), mv$(lifetimes)); + return TypeRef(lex.end_span(mv$(ps)), mv$(traits), mv$(lifetimes)); } else { - return TypeRef(TypeRef::TagPath(), lex.end_span(ps), mv$(traits.at(0).path)); + return TypeRef(TypeRef::TagPath(), lex.end_span(mv$(ps)), mv$(traits.at(0).path)); } } } @@ -335,6 +335,6 @@ TypeRef Parse_Type_ErasedType(TokenStream& lex, bool allow_trait_list) } while( GET_TOK(tok, lex) == TOK_PLUS ); PUTBACK(tok, lex); - return TypeRef(lex.end_span(ps), TypeData::make_ErasedType({ mv$(traits), mv$(lifetimes) })); + return TypeRef(lex.end_span(mv$(ps)), TypeData::make_ErasedType({ mv$(traits), mv$(lifetimes) })); } diff --git a/src/rc_string.cpp b/src/rc_string.cpp index 46f36923..4025d8c8 100644 --- a/src/rc_string.cpp +++ b/src/rc_string.cpp @@ -21,6 +21,18 @@ RcString::RcString(const char* s, unsigned int len): for(unsigned int j = 0; j < len; j ++ ) data_mut[j] = s[j]; data_mut[len] = '\0'; + + //::std::cout << "RcString(" << m_ptr << " \"" << *this << "\") - " << *m_ptr << " (creation)" << ::std::endl; + } +} +RcString::RcString(const RcString& x): + m_ptr(x.m_ptr), + m_len(x.m_len) +{ + if( m_ptr ) + { + *m_ptr += 1; + //::std::cout << "RcString(" << m_ptr << " \"" << *this << "\") - " << *m_ptr << " refs present (copy)" << ::std::endl; } } RcString::~RcString() @@ -28,7 +40,7 @@ RcString::~RcString() if(m_ptr) { *m_ptr -= 1; - //::std::cout << "RcString(\"" << *this << "\") - " << *m_ptr << " refs left" << ::std::endl; + //::std::cout << "RcString(" << m_ptr << " \"" << *this << "\") - " << *m_ptr << " refs left (drop)" << ::std::endl; if( *m_ptr == 0 ) { delete[] m_ptr; diff --git a/src/span.cpp b/src/span.cpp index eacdc7aa..34f2637e 100644 --- a/src/span.cpp +++ b/src/span.cpp @@ -11,15 +11,6 @@ #include #include -Span::Span(const Span& x): - outer_span(x.outer_span), - filename(x.filename), - start_line(x.start_line), - start_ofs(x.start_ofs), - end_line(x.end_line), - end_ofs(x.end_ofs) -{ -} Span::Span(const Position& pos): outer_span(), filename(pos.filename), -- cgit v1.2.3 From 16e05c582c39e0aa4f0ef6dd70756fded6516d25 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 4 Nov 2018 22:09:28 +0800 Subject: Codegen C - Fix minor OOB string read --- src/trans/codegen_c.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index b578c09b..55b3ea1a 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -1975,9 +1975,8 @@ namespace { m_of << "\\x0" << (unsigned int)static_cast(v); else m_of << "\\x" << (unsigned int)static_cast(v); - // If the next character is a hex digit, - // close/reopen the string. - if( isxdigit(*(&v+1)) ) + // If the next character is a hex digit, close/reopen the string. + if( &v < &s.back() && isxdigit(*(&v+1)) ) m_of << "\"\""; } } -- cgit v1.2.3 From ad1cec3df31470a1b97f1c672a45ae57495945a5 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Wed, 14 Nov 2018 12:33:24 +0100 Subject: Trans - Add initial support for m68k --- src/trans/target.cpp | 16 ++++++++++++++++ tools/common/target_detect.h | 2 ++ 2 files changed, 18 insertions(+) diff --git a/src/trans/target.cpp b/src/trans/target.cpp index f91b679a..64cf19c6 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -34,6 +34,11 @@ const TargetArch ARCH_ARM32 = { 32, false, { /*atomic(u8)=*/true, false, true, false, true } }; +const TargetArch ARCH_M68K = { + "m68k", + 32, true, + { /*atomic(u8)=*/true, false, true, false, true } +}; TargetSpec g_target; @@ -108,6 +113,10 @@ namespace { rv.m_arch = ARCH_X86_64; } + else if( key_val.value.as_string() == ARCH_M68K.m_name ) + { + rv.m_arch = ARCH_M68K; + } else { // Error. @@ -332,6 +341,13 @@ namespace ARCH_ARM64 }; } + else if(target_name == "m68k-linux-gnu") + { + return TargetSpec { + "unix", "linux", "gnu", {CodegenMode::Gnu11, "m68k-linux-gnu", BACKEND_C_OPTS_GNU}, + ARCH_M68K + }; + } else if(target_name == "i586-windows-gnu") { return TargetSpec { diff --git a/tools/common/target_detect.h b/tools/common/target_detect.h index a4c44ba4..0812c363 100644 --- a/tools/common/target_detect.h +++ b/tools/common/target_detect.h @@ -24,6 +24,8 @@ # define DEFAULT_TARGET_NAME "arm-linux-gnu" # elif defined(__i386__) # define DEFAULT_TARGET_NAME "i586-linux-gnu" +# elif defined(__m68k__) +# define DEFAULT_TARGET_NAME "m68k-linux-gnu" # else # warning "Unable to detect a suitable default target (linux-gnu)" # endif -- cgit v1.2.3 From a56ce2ac8c99f8622da26bf3677286400c4bbec4 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 18 Nov 2018 11:34:52 +0800 Subject: vsproject - Remove error on C4061 (errors even with `default`) --- vsproject/standalone_miri/standalone_miri.vcxproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vsproject/standalone_miri/standalone_miri.vcxproj b/vsproject/standalone_miri/standalone_miri.vcxproj index af8c8154..ad97ff69 100644 --- a/vsproject/standalone_miri/standalone_miri.vcxproj +++ b/vsproject/standalone_miri/standalone_miri.vcxproj @@ -94,7 +94,7 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true $(SolutionDir)..\src\include;$(SolutionDir)..\tools\standalone_miri;%(AdditionalIncludeDirectories) - 4062;4061;%(TreatSpecificWarningsAsErrors) + 4062;%(TreatSpecificWarningsAsErrors) Console @@ -110,7 +110,7 @@ _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true $(SolutionDir)..\src\include;$(SolutionDir)..\tools\standalone_miri;%(AdditionalIncludeDirectories) - 4062;4061;%(TreatSpecificWarningsAsErrors) + 4062;%(TreatSpecificWarningsAsErrors) Console @@ -181,4 +181,4 @@ - \ No newline at end of file + -- cgit v1.2.3 From 3ed852f30e6b039050b44e2b89010215332b7bac Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 24 Nov 2018 14:48:37 +0800 Subject: standalone_miri - Fix MSVC ice and clean up some warnings --- tools/standalone_miri/miri.cpp | 4 ++-- tools/standalone_miri/value.cpp | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/standalone_miri/miri.cpp b/tools/standalone_miri/miri.cpp index 53783420..fd4d45d8 100644 --- a/tools/standalone_miri/miri.cpp +++ b/tools/standalone_miri/miri.cpp @@ -363,7 +363,7 @@ struct MirHelpers size_t slice_inner_size; if( ty.has_slice_meta(slice_inner_size) ) { - size = (ty.get_wrapper() == nullptr ? ty.get_size() : 0) + meta_val->read_usize(0) * slice_inner_size; + size = (ty.get_wrapper() == nullptr ? ty.get_size() : 0) + static_cast(meta_val->read_usize(0)) * slice_inner_size; } //else if( ty == RawType::TraitObject) { // // NOTE: Getting the size from the allocation is semi-valid, as you can't sub-slice trait objects @@ -1036,7 +1036,7 @@ bool InterpreterThread::step_one(Value& out_thread_result) LOG_ASSERT(ty_r.get_wrapper() == nullptr, "Bitwise operator with non-primitive - " << ty_r); size_t max_bits = ty_r.get_size() * 8; uint8_t shift; - auto check_cast = [&](auto v){ LOG_ASSERT(0 <= v && v <= static_cast(max_bits), "Shift out of range - " << v); return static_cast(v); }; + auto check_cast = [&](uint64_t v){ LOG_ASSERT(0 <= v && v <= static_cast(max_bits), "Shift out of range - " << v); return static_cast(v); }; switch(ty_r.inner_type) { case RawType::U64: shift = check_cast(v_r.read_u64(0)); break; diff --git a/tools/standalone_miri/value.cpp b/tools/standalone_miri/value.cpp index 39b3b906..5974a172 100644 --- a/tools/standalone_miri/value.cpp +++ b/tools/standalone_miri/value.cpp @@ -214,8 +214,8 @@ void* ValueCommonRead::read_pointer_unsafe(size_t rd_ofs, size_t req_valid, size LOG_FATAL("Out-of-bounds pointer"); if( ofs + req_valid > a.size() ) LOG_FATAL("Out-of-bounds pointer (" << ofs << " + " << req_valid << " > " << a.size()); - a.check_bytes_valid( ofs, req_valid ); - out_size = a.size() - ofs; + a.check_bytes_valid( static_cast(ofs), req_valid ); + out_size = a.size() - static_cast(ofs); out_is_mut = true; return a.data_ptr() + ofs; } @@ -225,7 +225,7 @@ void* ValueCommonRead::read_pointer_unsafe(size_t rd_ofs, size_t req_valid, size LOG_FATAL("Out-of-bounds pointer"); if( ofs + req_valid > s.size() ) LOG_FATAL("Out-of-bounds pointer (" << ofs << " + " << req_valid << " > " << s.size()); - out_size = s.size() - ofs; + out_size = s.size() - static_cast(ofs); out_is_mut = false; return const_cast( static_cast(s.data() + ofs) ); } @@ -237,7 +237,7 @@ void* ValueCommonRead::read_pointer_unsafe(size_t rd_ofs, size_t req_valid, size //if( req_valid ) // LOG_FATAL("Can't request valid data from a FFI pointer"); // TODO: Have an idea of mutability and available size from FFI - out_size = f.size - ofs; + out_size = f.size - static_cast(ofs); out_is_mut = false; return reinterpret_cast(reloc.ffi().ptr_value) + ofs; } @@ -256,7 +256,7 @@ ValueRef ValueCommonRead::read_pointer_valref_mut(size_t rd_ofs, size_t size) else { // TODO: Validate size - return ValueRef(reloc, ofs, size); + return ValueRef(reloc, static_cast(ofs), size); } } -- cgit v1.2.3 From c2f9278596a4f1eec3e611d3425edd10e0d15c83 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 24 Nov 2018 14:48:58 +0800 Subject: HIR - Fix struct/class mismatch --- src/hir/expr_state.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hir/expr_state.hpp b/src/hir/expr_state.hpp index 5491b4d3..11fffe67 100644 --- a/src/hir/expr_state.hpp +++ b/src/hir/expr_state.hpp @@ -10,8 +10,9 @@ namespace HIR { -struct ExprState +class ExprState { +public: ::HIR::SimplePath m_mod_path; const ::HIR::Module& m_module; -- cgit v1.2.3 From 146483f00b7e8014b7abd2a382d993daabaf3359 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 24 Nov 2018 14:50:12 +0800 Subject: minicargo - (minor) #include <> to "" --- tools/minicargo/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/minicargo/main.cpp b/tools/minicargo/main.cpp index d7312d48..ec6b8b45 100644 --- a/tools/minicargo/main.cpp +++ b/tools/minicargo/main.cpp @@ -9,9 +9,9 @@ #include #include // strcmp #include -#include "debug.h" +#include #include "manifest.h" -#include "helpers.h" +#include #include "repository.h" #include "build.h" -- cgit v1.2.3 From c4939c4e12ac66aa3ac92470169abca16bb9ce5b Mon Sep 17 00:00:00 2001 From: Arlie Davis Date: Wed, 28 Nov 2018 13:53:38 -0800 Subject: Mark destructors in base classes as virtual. This is required for correctness, and when using -fsized-deallocation the previous code fails. --- src/ast/expr.hpp | 1 + src/expand/derive.cpp | 1 + src/hir/expr.hpp | 1 + src/hir_typeck/expr_cs.cpp | 1 + src/include/synext_decorator.hpp | 1 + src/include/synext_macro.hpp | 1 + 6 files changed, 6 insertions(+) diff --git a/src/ast/expr.hpp b/src/ast/expr.hpp index f3981db5..264b37e9 100644 --- a/src/ast/expr.hpp +++ b/src/ast/expr.hpp @@ -623,6 +623,7 @@ struct ExprNode_UniOp: class NodeVisitor { public: + virtual ~NodeVisitor() = default; inline void visit(const unique_ptr& cnode) { if(cnode.get()) cnode->visit(*this); diff --git a/src/expand/derive.cpp b/src/expand/derive.cpp index 5e97c888..5bbef62c 100644 --- a/src/expand/derive.cpp +++ b/src/expand/derive.cpp @@ -72,6 +72,7 @@ struct DeriveOpts /// Interface for derive handlers struct Deriver { + virtual ~Deriver() = default; virtual const char* trait_name() const = 0; virtual AST::Impl handle_item(Span sp, const DeriveOpts& opts, const AST::GenericParams& p, const TypeRef& type, const AST::Struct& str) const = 0; virtual AST::Impl handle_item(Span sp, const DeriveOpts& opts, const AST::GenericParams& p, const TypeRef& type, const AST::Enum& enm) const = 0; diff --git a/src/hir/expr.hpp b/src/hir/expr.hpp index 55a4eaf2..00d22c00 100644 --- a/src/hir/expr.hpp +++ b/src/hir/expr.hpp @@ -815,6 +815,7 @@ struct ExprNode_Closure: class ExprVisitor { public: + virtual ~ExprVisitor() = default; virtual void visit_node_ptr(::std::unique_ptr& node_ptr); virtual void visit_node(ExprNode& node); #define NV(nt) virtual void visit(nt& n) = 0; diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp index 554fea69..363dfeeb 100644 --- a/src/hir_typeck/expr_cs.cpp +++ b/src/hir_typeck/expr_cs.cpp @@ -25,6 +25,7 @@ struct Context class Revisitor { public: + virtual ~Revisitor() = default; virtual void fmt(::std::ostream& os) const = 0; virtual bool revisit(Context& context) = 0; }; diff --git a/src/include/synext_decorator.hpp b/src/include/synext_decorator.hpp index eaed3154..1e16ce09 100644 --- a/src/include/synext_decorator.hpp +++ b/src/include/synext_decorator.hpp @@ -45,6 +45,7 @@ class ExpandDecorator { void unexpected(const Span& sp, const AST::Attribute& mi, const char* loc_str) const; public: + virtual ~ExpandDecorator() = default; virtual AttrStage stage() const = 0; virtual void handle(const Span& sp, const AST::Attribute& mi, AST::Crate& crate) const { unexpected(sp, mi, "crate"); } diff --git a/src/include/synext_macro.hpp b/src/include/synext_macro.hpp index d414ceb0..60b52d89 100644 --- a/src/include/synext_macro.hpp +++ b/src/include/synext_macro.hpp @@ -27,6 +27,7 @@ class TokenStream; class ExpandProcMacro { public: + virtual ~ExpandProcMacro() = default; virtual ::std::unique_ptr expand(const Span& sp, const AST::Crate& crate, const ::std::string& ident, const TokenTree& tt, AST::Module& mod) = 0; }; -- cgit v1.2.3 From f6209dce15ce863e15dc3063d78e43eeb0db25ee Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 15 Dec 2018 14:47:08 +0800 Subject: Targets - Add alignment to the target specs, along with a saveback test. --- Makefile | 9 ++- samples/target_stress_test.toml | 22 +++++++ src/main.cpp | 32 ++++++++-- src/trans/codegen_c.cpp | 11 ++-- src/trans/target.cpp | 137 ++++++++++++++++++++++++++++------------ src/trans/target.hpp | 28 +++++--- tools/common/toml.cpp | 85 ++++++++++++++++--------- tools/common/toml.h | 21 +++++- 8 files changed, 252 insertions(+), 93 deletions(-) create mode 100644 samples/target_stress_test.toml diff --git a/Makefile b/Makefile index 1eda93dd..23c799d2 100644 --- a/Makefile +++ b/Makefile @@ -276,7 +276,14 @@ output/rust/test_run-pass_hello_out.txt: output/rust/test_run-pass_hello # # TEST: Rust standard library and the "hello, world" run-pass test # -test: output/libstd.hir output/rust/test_run-pass_hello_out.txt $(BIN) +test: output/libstd.hir output/rust/test_run-pass_hello_out.txt $(BIN) TEST_targetsaveback + +.PHONY: TEST_targetsaveback +TEST_targetsaveback: + $(BIN) --target ./samples/target_stress_test.toml --dump-target-spec TMP-dump-target_stress_test.toml + $(BIN) --target ./TMP-dump-target_stress_test.toml --dump-target-spec TMP-dump-target_stress_test-2.toml + diff ./samples/target_stress_test.toml TMP-dump-target_stress_test.toml + diff TMP-dump-target_stress_test.toml TMP-dump-target_stress_test-2.toml # # TEST: Attempt to compile rust_os (Tifflin) from ../rust_os diff --git a/samples/target_stress_test.toml b/samples/target_stress_test.toml new file mode 100644 index 00000000..c7630567 --- /dev/null +++ b/samples/target_stress_test.toml @@ -0,0 +1,22 @@ +[target] +family = "fake" +os-name = "fakest" +env-name = "faker" + +[backend.c] +variant = "msvc" +target = "x86_64-linux-msvc" +compiler-opts = ["/W:1234",] +linker-opts = ["/K",] + +[arch] +name = "fubar" +pointer-bits = 128 +is-big-endian = true +has-atomic-u8 = false +has-atomic-u16 = false +has-atomic-u32 = false +has-atomic-u64 = false +has-atomic-ptr = false +alignments = { u16 = 1, u32 = 2, u64 = 4, u128 = 8, f32 = 3, f64 = 5, ptr = 16 } + diff --git a/src/main.cpp b/src/main.cpp index 2dd05a05..a50fe095 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,7 @@ bool g_debug_enabled = true; void init_debug_list() { + g_debug_disable_map.insert( "Target Load" ); g_debug_disable_map.insert( "Parse" ); g_debug_disable_map.insert( "LoadCrates" ); g_debug_disable_map.insert( "Expand" ); @@ -156,6 +157,9 @@ struct ProgramParams bool test_harness = false; + // NOTE: If populated, nothing happens except for loading the target + ::std::string target_saveback; + ::std::vector lib_search_dirs; ::std::vector libraries; ::std::map<::std::string, ::std::string> crate_overrides; // --extern name=path @@ -214,8 +218,21 @@ int main(int argc, char *argv[]) Cfg_SetValueCb("feature", [¶ms](const ::std::string& s) { return params.features.count(s) != 0; }); - Target_SetCfg(params.target); + CompilePhaseV("Target Load", [&]() { + Target_SetCfg(params.target); + }); + if( params.target_saveback != "") + { + Target_ExportCurSpec(params.target_saveback); + return 0; + } + + if( params.infile == "" ) + { + ::std::cerr << "No input file passed" << ::std::endl; + return 1; + } if( params.test_harness ) { @@ -1060,6 +1077,13 @@ ProgramParams::ProgramParams(int argc, char *argv[]) } this->target = argv[++i]; } + else if( strcmp(arg, "--dump-target-spec") == 0 ) { + if (i == argc - 1) { + ::std::cerr << "Flag " << arg << " requires an argument" << ::std::endl; + exit(1); + } + this->target_saveback = argv[++i]; + } else if( strcmp(arg, "--test") == 0 ) { this->test_harness = true; } @@ -1070,12 +1094,6 @@ ProgramParams::ProgramParams(int argc, char *argv[]) } } - if (this->infile == "") - { - ::std::cerr << "No input file passed" << ::std::endl; - exit(1); - } - if( const auto* a = getenv("MRUSTC_DUMP") ) { while( a[0] ) diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 55b3ea1a..84a538d5 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -205,20 +205,23 @@ namespace { m_outfile_path_c(outfile + ".c"), m_of(m_outfile_path_c) { + m_options.emulated_i128 = Target_GetCurSpec().m_backend_c.m_emulated_i128; switch(Target_GetCurSpec().m_backend_c.m_codegen_mode) { case CodegenMode::Gnu11: m_compiler = Compiler::Gcc; - m_options.emulated_i128 = false; - if( Target_GetCurSpec().m_arch.m_pointer_bits < 64 ) + if( Target_GetCurSpec().m_arch.m_pointer_bits < 64 && !m_options.emulated_i128 ) { - m_options.emulated_i128 = true; + WARNING(Span(), W0000, "Potentially misconfigured target, 32-bit targets require i128 emulation"); } m_options.disallow_empty_structs = true; break; case CodegenMode::Msvc: m_compiler = Compiler::Msvc; - m_options.emulated_i128 = true; + if( !m_options.emulated_i128 ) + { + WARNING(Span(), W0000, "Potentially misconfigured target, MSVC requires i128 emulation"); + } m_options.disallow_empty_structs = true; break; } diff --git a/src/trans/target.cpp b/src/trans/target.cpp index 64cf19c6..332a7e04 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -17,27 +17,32 @@ const TargetArch ARCH_X86_64 = { "x86_64", 64, false, - { /*atomic(u8)=*/true, false, true, true, true } + { /*atomic(u8)=*/true, false, true, true, true }, + { 2, 4, 8, 16, 4, 8, 8 }, }; const TargetArch ARCH_X86 = { "x86", 32, false, - { /*atomic(u8)=*/true, false, true, false, true } + { /*atomic(u8)=*/true, false, true, false, true }, + { 2, 4, /*u64*/4, /*u128*/4, 4, 4, /*ptr*/4 } // u128 has the same alignment as u64, which is u32's alignment. And f64 is 4 byte aligned }; const TargetArch ARCH_ARM64 = { "aarch64", 64, false, - { /*atomic(u8)=*/true, true, true, true, true } + { /*atomic(u8)=*/true, true, true, true, true }, + { 2, 4, 8, 16, 4, 8, 8 }, }; const TargetArch ARCH_ARM32 = { "arm", 32, false, - { /*atomic(u8)=*/true, false, true, false, true } + { /*atomic(u8)=*/true, false, true, false, true }, + { 2, 4, 8, 16, 4, 8, 4 } // Note, all types are natively aligned (but i128 will be emulated) }; const TargetArch ARCH_M68K = { "m68k", 32, true, - { /*atomic(u8)=*/true, false, true, false, true } + { /*atomic(u8)=*/true, false, true, false, true }, + { 2, 4, 8, 16, 4, 8, 4 } // TODO: Does m68k have lower alignments? }; TargetSpec g_target; @@ -159,6 +164,11 @@ namespace check_path_length(key_val, 3); rv.m_backend_c.m_c_compiler = key_val.value.as_string(); } + else if( key_val.path[2] == "emulate-i128" ) + { + check_path_length(key_val, 3); + rv.m_backend_c.m_emulated_i128 = key_val.value.as_bool(); + } else if( key_val.path[2] == "compiler-opts" ) { check_path_length(key_val, 3); @@ -233,6 +243,42 @@ namespace check_path_length(key_val, 2); rv.m_arch.m_atomics.ptr = key_val.value.as_bool(); } + else if( key_val.path[1] == "alignments" ) + { + check_path_length(key_val, 3); + if( key_val.path[2] == "u16" ) + { + rv.m_arch.m_alignments.u16 = key_val.value.as_int(); + } + else if( key_val.path[2] == "u32" ) + { + rv.m_arch.m_alignments.u32 = key_val.value.as_int(); + } + else if( key_val.path[2] == "u64" ) + { + rv.m_arch.m_alignments.u64 = key_val.value.as_int(); + } + else if( key_val.path[2] == "u128" ) + { + rv.m_arch.m_alignments.u128 = key_val.value.as_int(); + } + else if( key_val.path[2] == "f32" ) + { + rv.m_arch.m_alignments.f32 = key_val.value.as_int(); + } + else if( key_val.path[2] == "f64" ) + { + rv.m_arch.m_alignments.f64 = key_val.value.as_int(); + } + else if( key_val.path[2] == "ptr" ) + { + rv.m_arch.m_alignments.ptr = key_val.value.as_int(); + } + else + { + ::std::cerr << "WARNING: Unknown field arch.alignments." << key_val.path[1] << " in " << filename << ::std::endl; + } + } else { ::std::cerr << "WARNING: Unknown field arch." << key_val.path[1] << " in " << filename << ::std::endl; @@ -290,10 +336,10 @@ namespace << "[backend.c]\n" << "variant = \"" << H::c_variant_name(spec.m_backend_c.m_codegen_mode) << "\"\n" << "target = \"" << spec.m_backend_c.m_c_compiler << "\"\n" - << "compiler-opts = [" << spec.m_backend_c.m_compiler_opts << "]\n" - << "linker-opts = [" << spec.m_backend_c.m_linker_opts << "]\n" + << "compiler-opts = ["; for(const auto& s : spec.m_backend_c.m_compiler_opts) of << "\"" << s << "\","; of << "]\n" + << "linker-opts = ["; for(const auto& s : spec.m_backend_c.m_linker_opts) of << "\"" << s << "\","; of << "]\n" << "\n" - << "[arch]" + << "[arch]\n" << "name = \"" << spec.m_arch.m_name << "\"\n" << "pointer-bits = " << spec.m_arch.m_pointer_bits << "\n" << "is-big-endian = " << H::tfstr(spec.m_arch.m_big_endian) << "\n" @@ -302,6 +348,16 @@ namespace << "has-atomic-u32 = " << H::tfstr(spec.m_arch.m_atomics.u32) << "\n" << "has-atomic-u64 = " << H::tfstr(spec.m_arch.m_atomics.u64) << "\n" << "has-atomic-ptr = " << H::tfstr(spec.m_arch.m_atomics.ptr) << "\n" + << "alignments = {" + << " u16 = " << static_cast(spec.m_arch.m_alignments.u16 ) << "," + << " u32 = " << static_cast(spec.m_arch.m_alignments.u32 ) << "," + << " u64 = " << static_cast(spec.m_arch.m_alignments.u64 ) << "," + << " u128 = " << static_cast(spec.m_arch.m_alignments.u128) << "," + << " f32 = " << static_cast(spec.m_arch.m_alignments.f32 ) << "," + << " f64 = " << static_cast(spec.m_arch.m_alignments.f64 ) << "," + << " ptr = " << static_cast(spec.m_arch.m_alignments.ptr ) + << " }\n" + << "\n" ; } TargetSpec init_from_spec_name(const ::std::string& target_name) @@ -316,49 +372,49 @@ namespace else if(target_name == "i586-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", {CodegenMode::Gnu11, "i586-linux-gnu", BACKEND_C_OPTS_GNU}, + "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "i586-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", {CodegenMode::Gnu11, "x86_64-linux-gnu", BACKEND_C_OPTS_GNU}, + "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "x86_64-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "arm-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", {CodegenMode::Gnu11, "arm-elf-eabi", BACKEND_C_OPTS_GNU}, + "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "arm-elf-eabi", BACKEND_C_OPTS_GNU}, ARCH_ARM32 }; } else if(target_name == "aarch64-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", {CodegenMode::Gnu11, "aarch64-linux-gnu", BACKEND_C_OPTS_GNU}, + "unix", "linux", "gnu", {CodegenMode::Gnu11, false, "aarch64-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_ARM64 }; } else if(target_name == "m68k-linux-gnu") { return TargetSpec { - "unix", "linux", "gnu", {CodegenMode::Gnu11, "m68k-linux-gnu", BACKEND_C_OPTS_GNU}, + "unix", "linux", "gnu", {CodegenMode::Gnu11, true, "m68k-linux-gnu", BACKEND_C_OPTS_GNU}, ARCH_M68K }; } else if(target_name == "i586-windows-gnu") { return TargetSpec { - "windows", "windows", "gnu", {CodegenMode::Gnu11, "mingw32", BACKEND_C_OPTS_GNU}, + "windows", "windows", "gnu", {CodegenMode::Gnu11, true, "mingw32", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-windows-gnu") { return TargetSpec { - "windows", "windows", "gnu", {CodegenMode::Gnu11, "x86_64-w64-mingw32", BACKEND_C_OPTS_GNU}, + "windows", "windows", "gnu", {CodegenMode::Gnu11, false, "x86_64-w64-mingw32", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } @@ -366,84 +422,84 @@ namespace { // TODO: Should this include the "kernel32.lib" inclusion? return TargetSpec { - "windows", "windows", "msvc", {CodegenMode::Msvc, "x86", {}, {}}, + "windows", "windows", "msvc", {CodegenMode::Msvc, true, "x86", {}, {}}, ARCH_X86 }; } else if (target_name == "x86_64-windows-msvc") { return TargetSpec { - "windows", "windows", "msvc", {CodegenMode::Msvc, "amd64", {}, {}}, + "windows", "windows", "msvc", {CodegenMode::Msvc, true, "amd64", {}, {}}, ARCH_X86_64 }; } else if(target_name == "i686-unknown-freebsd") { return TargetSpec { - "unix", "freebsd", "gnu", {CodegenMode::Gnu11, "i686-unknown-freebsd", BACKEND_C_OPTS_GNU}, + "unix", "freebsd", "gnu", {CodegenMode::Gnu11, true, "i686-unknown-freebsd", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-unknown-freebsd") { return TargetSpec { - "unix", "freebsd", "gnu", {CodegenMode::Gnu11, "x86_64-unknown-freebsd", BACKEND_C_OPTS_GNU}, + "unix", "freebsd", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-freebsd", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "arm-unknown-freebsd") { return TargetSpec { - "unix", "freebsd", "gnu", {CodegenMode::Gnu11, "arm-unknown-freebsd", BACKEND_C_OPTS_GNU}, + "unix", "freebsd", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-freebsd", BACKEND_C_OPTS_GNU}, ARCH_ARM32 }; } else if(target_name == "aarch64-unknown-freebsd") { return TargetSpec { - "unix", "freebsd", "gnu", {CodegenMode::Gnu11, "aarch64-unknown-freebsd", BACKEND_C_OPTS_GNU}, + "unix", "freebsd", "gnu", {CodegenMode::Gnu11, false, "aarch64-unknown-freebsd", BACKEND_C_OPTS_GNU}, ARCH_ARM64 }; } else if(target_name == "x86_64-unknown-netbsd") { return TargetSpec { - "unix", "netbsd", "gnu", {CodegenMode::Gnu11, "x86_64-unknown-netbsd", BACKEND_C_OPTS_GNU}, + "unix", "netbsd", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-netbsd", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "i686-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "i686-unknown-openbsd", BACKEND_C_OPTS_GNU}, + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, true, "i686-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_X86 }; } else if(target_name == "x86_64-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "x86_64-unknown-openbsd", BACKEND_C_OPTS_GNU}, + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } else if(target_name == "arm-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "arm-unknown-openbsd", BACKEND_C_OPTS_GNU}, + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_ARM32 }; } else if(target_name == "aarch64-unknown-openbsd") { return TargetSpec { - "unix", "openbsd", "gnu", {CodegenMode::Gnu11, "aarch64-unknown-openbsd", BACKEND_C_OPTS_GNU}, + "unix", "openbsd", "gnu", {CodegenMode::Gnu11, false, "aarch64-unknown-openbsd", BACKEND_C_OPTS_GNU}, ARCH_ARM64 }; } else if(target_name == "x86_64-unknown-dragonfly") { return TargetSpec { - "unix", "dragonfly", "gnu", {CodegenMode::Gnu11, "x86_64-unknown-dragonfly", BACKEND_C_OPTS_GNU}, + "unix", "dragonfly", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-dragonfly", BACKEND_C_OPTS_GNU}, ARCH_X86_64 }; } @@ -451,7 +507,7 @@ namespace { // NOTE: OSX uses Mach-O binaries, which don't fully support the defaults used for GNU targets return TargetSpec { - "unix", "macos", "gnu", {CodegenMode::Gnu11, "x86_64-apple-darwin", {}, {}}, + "unix", "macos", "gnu", {CodegenMode::Gnu11, false, "x86_64-apple-darwin", {}, {}}, ARCH_X86_64 }; } @@ -684,48 +740,45 @@ bool Target_GetSizeAndAlignOf(const Span& sp, const StaticTraitResolve& resolve, case ::HIR::CoreType::U8: case ::HIR::CoreType::I8: out_size = 1; - out_align = 1; + out_align = 1; // u8 is always 1 aligned return true; case ::HIR::CoreType::U16: case ::HIR::CoreType::I16: out_size = 2; - out_align = 2; + out_align = g_target.m_arch.m_alignments.u16; return true; case ::HIR::CoreType::U32: case ::HIR::CoreType::I32: case ::HIR::CoreType::Char: out_size = 4; - out_align = 4; + out_align = g_target.m_arch.m_alignments.u32; return true; case ::HIR::CoreType::U64: case ::HIR::CoreType::I64: out_size = 8; - // TODO: on x86, u64/i64 has an alignment of 4, while x86_64 has 8. What do other platforms have? - out_align = g_target.m_arch.m_name == "x86" ? 4 : 8; + out_align = g_target.m_arch.m_alignments.u64; return true; case ::HIR::CoreType::U128: 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) - 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; + if( g_target.m_backend_c.m_emulated_i128 ) + out_align = g_target.m_arch.m_alignments.u64; + else + out_align = g_target.m_arch.m_alignments.u128; return true; case ::HIR::CoreType::Usize: case ::HIR::CoreType::Isize: out_size = g_target.m_arch.m_pointer_bits / 8; - out_align = g_target.m_arch.m_pointer_bits / 8; + out_align = g_target.m_arch.m_alignments.ptr; return true; case ::HIR::CoreType::F32: out_size = 4; - out_align = 4; + out_align = g_target.m_arch.m_alignments.f32; return true; case ::HIR::CoreType::F64: out_size = 8; - out_align = g_target.m_arch.m_name == "x86" ? 4 : 8; + out_align = g_target.m_arch.m_alignments.f64; return true; case ::HIR::CoreType::Str: DEBUG("sizeof on a `str` - unsized"); diff --git a/src/trans/target.hpp b/src/trans/target.hpp index b1ed9456..b6f04a42 100644 --- a/src/trans/target.hpp +++ b/src/trans/target.hpp @@ -17,23 +17,35 @@ enum class CodegenMode Msvc, }; +// NOTE: The default architecture is an unnamed 32-bit little-endian arch with all types natively aligned struct TargetArch { - ::std::string m_name; - unsigned m_pointer_bits; - bool m_big_endian; + ::std::string m_name = ""; + unsigned m_pointer_bits = 32; + bool m_big_endian = false; struct { - bool u8; - bool u16; - bool u32; - bool u64; - bool ptr; + bool u8 = true; + bool u16 = true; + bool u32 = true; + bool u64 = false; + bool ptr = true; } m_atomics; + + struct { + uint8_t u16 = 2; + uint8_t u32 = 4; + uint8_t u64 = 8; + uint8_t u128 = 16; + uint8_t f32 = 4; + uint8_t f64 = 8; + uint8_t ptr = 4; + } m_alignments; }; struct BackendOptsC { CodegenMode m_codegen_mode; + bool m_emulated_i128; // Influences the chosen alignment for i128/u128 ::std::string m_c_compiler; // MSVC arch / GNU triplet ::std::vector< ::std::string> m_compiler_opts; ::std::vector< ::std::string> m_linker_opts; diff --git a/tools/common/toml.cpp b/tools/common/toml.cpp index 489f32b6..285d22a4 100644 --- a/tools/common/toml.cpp +++ b/tools/common/toml.cpp @@ -80,11 +80,8 @@ struct Token }; TomlFile::TomlFile(const ::std::string& filename): - m_if(filename) + m_lexer(filename) { - if( !m_if.is_open() ) { - throw ::std::runtime_error("Unable to open file '" + filename + "'"); - } } TomlFileIter TomlFile::begin() { @@ -99,12 +96,14 @@ TomlFileIter TomlFile::end() TomlKeyValue TomlFile::get_next_value() { - auto t = Token::lex_from(m_if); + auto t = m_lexer.get_token(); if(m_current_composite.empty()) { while( t.m_type == Token::Type::Newline ) - t = Token::lex_from(m_if); + { + t = m_lexer.get_token(); + } // Expect '[', a string, or an identifier switch(t.m_type) @@ -116,32 +115,32 @@ TomlKeyValue TomlFile::get_next_value() m_current_block.clear(); do { - t = Token::lex_from(m_if); + t = m_lexer.get_token(); bool is_array = false; if(t.m_type == Token::Type::SquareOpen) { is_array = true; - t = Token::lex_from(m_if); + t = m_lexer.get_token(); } assert(t.m_type == Token::Type::Ident || t.m_type == Token::Type::String); m_current_block.push_back(t.as_string()); if(is_array) { m_current_block.push_back(::format(m_array_counts[t.as_string()]++)); - t = Token::lex_from(m_if); + t = m_lexer.get_token(); assert(t.m_type == Token::Type::SquareClose); } - t = Token::lex_from(m_if); + t = m_lexer.get_token(); } while(t.m_type == Token::Type::Dot); if( t.m_type != Token::Type::SquareClose ) { - throw ::std::runtime_error(::format("Unexpected token in block header - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token in block header - ", t)); } - t = Token::lex_from(m_if); + t = m_lexer.get_token(); if (t.m_type != Token::Type::Newline) { - throw ::std::runtime_error(::format("Unexpected token after block block - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token after block block - ", t)); } DEBUG("Start block " << m_current_block); // Recurse! @@ -156,7 +155,7 @@ TomlKeyValue TomlFile::get_next_value() if( t.m_type == Token::Type::Eof ) { // EOF isn't allowed here - throw ::std::runtime_error(::format("Unexpected EOF in composite")); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected EOF in composite")); } } switch (t.m_type) @@ -165,14 +164,14 @@ TomlKeyValue TomlFile::get_next_value() case Token::Type::Ident: break; default: - throw ::std::runtime_error(::format("Unexpected token for key - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token for key - ", t)); } ::std::string key_name = t.as_string(); - t = Token::lex_from(m_if); + t = m_lexer.get_token(); if(t.m_type != Token::Type::Assign) - throw ::std::runtime_error(::format("Unexpected token after key - ", t)); - t = Token::lex_from(m_if); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token after key - ", t)); + t = m_lexer.get_token(); // --- Value --- TomlKeyValue rv; @@ -193,10 +192,12 @@ TomlKeyValue TomlFile::get_next_value() rv.path.push_back(key_name); rv.value.m_type = TomlValue::Type::List; - while( (t = Token::lex_from(m_if)).m_type != Token::Type::SquareClose ) + while( (t = m_lexer.get_token()).m_type != Token::Type::SquareClose ) { while( t.m_type == Token::Type::Newline ) - t = Token::lex_from(m_if); + { + t = m_lexer.get_token(); + } if( t.m_type == Token::Type::SquareClose ) break; @@ -208,15 +209,15 @@ TomlKeyValue TomlFile::get_next_value() rv.value.m_sub_values.push_back(TomlValue { t.as_string() }); break; default: - throw ::std::runtime_error(::format("Unexpected token in array value position - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token in array value position - ", t)); } - t = Token::lex_from(m_if); + t = m_lexer.get_token(); if(t.m_type != Token::Type::Comma) break; } if(t.m_type != Token::Type::SquareClose) - throw ::std::runtime_error(::format("Unexpected token after array - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token after array - ", t)); break; case Token::Type::BraceOpen: m_current_composite.push_back(key_name); @@ -228,7 +229,7 @@ TomlKeyValue TomlFile::get_next_value() rv.path.insert(rv.path.end(), m_current_composite.begin(), m_current_composite.end()); rv.path.push_back(key_name); rv.value = TomlValue { t.m_intval }; - return rv; + break; case Token::Type::Ident: if( t.m_data == "true" ) { @@ -247,34 +248,58 @@ TomlKeyValue TomlFile::get_next_value() } else { - throw ::std::runtime_error(::format("Unexpected identifier in value position - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected identifier in value position - ", t)); } break; default: - throw ::std::runtime_error(::format("Unexpected token in value position - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token in value position - ", t)); } - t = Token::lex_from(m_if); + t = m_lexer.get_token(); while (!m_current_composite.empty() && t.m_type == Token::Type::BraceClose) { DEBUG("Leave composite block " << m_current_block << ", " << m_current_composite); m_current_composite.pop_back(); - t = Token::lex_from(m_if); + t = m_lexer.get_token(); } if( m_current_composite.empty() ) { // TODO: Allow EOF? if(t.m_type != Token::Type::Newline) - throw ::std::runtime_error(::format("Unexpected token in TOML file after entry - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token in TOML file after entry - ", t)); } else { if( t.m_type != Token::Type::Comma ) - throw ::std::runtime_error(::format("Unexpected token in TOML file after composite entry - ", t)); + throw ::std::runtime_error(::format(m_lexer, ": Unexpected token in TOML file after composite entry - ", t)); } return rv; } +TomlLexer::TomlLexer(const ::std::string& filename) + :m_if(filename) + ,m_filename(filename) + ,m_line(1) +{ + if( !m_if.is_open() ) { + throw ::std::runtime_error("Unable to open file '" + filename + "'"); + } +} +Token TomlLexer::get_token() +{ + auto rv = Token::lex_from(m_if); + if( rv.m_type == Token::Type::Newline ) + { + m_line ++; + } + return rv; +} +::std::ostream& operator<<(::std::ostream& os, const TomlLexer& x) +{ + os << x.m_filename << ":" << x.m_line; + return os; +} + Token Token::lex_from(::std::ifstream& is) { auto rv = Token::lex_from_inner(is); diff --git a/tools/common/toml.h b/tools/common/toml.h index 4c97e7f2..17e05142 100644 --- a/tools/common/toml.h +++ b/tools/common/toml.h @@ -15,11 +15,28 @@ class TomlFileIter; struct TomlKeyValue; -class TomlFile +struct Token; +class TomlLexer { + friend class TomlFile; /// Input file stream ::std::ifstream m_if; + ::std::string m_filename; + unsigned m_line; +protected: + TomlLexer(const ::std::string& filename); + Token get_token(); + +public: + friend ::std::ostream& operator<<(::std::ostream& os, const TomlLexer& x); +}; + +class TomlFile +{ + /// Input file stream + TomlLexer m_lexer; + /// Name of the current `[]` block ::std::vector<::std::string> m_current_block; @@ -40,6 +57,8 @@ public: // Obtain the next value in the file TomlKeyValue get_next_value(); + + const TomlLexer& lexer() const; }; struct TomlValue -- cgit v1.2.3 From f893005e2b0a207826d56782afcd456754adb643 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 15 Dec 2018 15:40:54 +0800 Subject: Trans Target - Fix MSVC build --- src/trans/target.cpp | 12 ++++++------ src/trans/target.hpp | 42 ++++++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/src/trans/target.cpp b/src/trans/target.cpp index 332a7e04..53d84030 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -17,32 +17,32 @@ const TargetArch ARCH_X86_64 = { "x86_64", 64, false, - { /*atomic(u8)=*/true, false, true, true, true }, - { 2, 4, 8, 16, 4, 8, 8 }, + TargetArch::Atomics(/*atomic(u8)=*/true, false, true, true, true), + TargetArch::Alignments(2, 4, 8, 16, 4, 8, 8) }; const TargetArch ARCH_X86 = { "x86", 32, false, { /*atomic(u8)=*/true, false, true, false, true }, - { 2, 4, /*u64*/4, /*u128*/4, 4, 4, /*ptr*/4 } // u128 has the same alignment as u64, which is u32's alignment. And f64 is 4 byte aligned + TargetArch::Alignments(2, 4, /*u64*/4, /*u128*/4, 4, 4, /*ptr*/4) // u128 has the same alignment as u64, which is u32's alignment. And f64 is 4 byte aligned }; const TargetArch ARCH_ARM64 = { "aarch64", 64, false, { /*atomic(u8)=*/true, true, true, true, true }, - { 2, 4, 8, 16, 4, 8, 8 }, + TargetArch::Alignments(2, 4, 8, 16, 4, 8, 8) }; const TargetArch ARCH_ARM32 = { "arm", 32, false, { /*atomic(u8)=*/true, false, true, false, true }, - { 2, 4, 8, 16, 4, 8, 4 } // Note, all types are natively aligned (but i128 will be emulated) + TargetArch::Alignments(2, 4, 8, 16, 4, 8, 4) // Note, all types are natively aligned (but i128 will be emulated) }; const TargetArch ARCH_M68K = { "m68k", 32, true, { /*atomic(u8)=*/true, false, true, false, true }, - { 2, 4, 8, 16, 4, 8, 4 } // TODO: Does m68k have lower alignments? + TargetArch::Alignments(2, 4, 8, 16, 4, 8, 4) // TODO: Does m68k have lower alignments? }; TargetSpec g_target; diff --git a/src/trans/target.hpp b/src/trans/target.hpp index b6f04a42..4e0309dd 100644 --- a/src/trans/target.hpp +++ b/src/trans/target.hpp @@ -20,26 +20,44 @@ enum class CodegenMode // NOTE: The default architecture is an unnamed 32-bit little-endian arch with all types natively aligned struct TargetArch { - ::std::string m_name = ""; - unsigned m_pointer_bits = 32; - bool m_big_endian = false; + ::std::string m_name; + unsigned m_pointer_bits; + bool m_big_endian; - struct { + struct Atomics { bool u8 = true; bool u16 = true; bool u32 = true; bool u64 = false; bool ptr = true; + Atomics(bool u8 = true, bool u16 = true, bool u32 = true, bool u64 = false, bool ptr = true) + :u8(u8) + ,u16(u16) + ,u32(u32) + ,u64(u64) + ,ptr(ptr) + { + } } m_atomics; - struct { - uint8_t u16 = 2; - uint8_t u32 = 4; - uint8_t u64 = 8; - uint8_t u128 = 16; - uint8_t f32 = 4; - uint8_t f64 = 8; - uint8_t ptr = 4; + struct Alignments { + uint8_t u16; + uint8_t u32; + uint8_t u64; + uint8_t u128; + uint8_t f32; + uint8_t f64; + uint8_t ptr; + Alignments(uint8_t u16 = 2, uint8_t u32 = 4, uint8_t u64 = 8, uint8_t u128 = 16, uint8_t f32 = 4, uint8_t f64 = 8, uint8_t ptr = 4) + :u16 (u16) + ,u32 (u32 ) + ,u64 (u64 ) + ,u128(u128) + ,f32 (f32 ) + ,f64 (f64 ) + ,ptr (ptr ) + { + } } m_alignments; }; struct BackendOptsC -- cgit v1.2.3 From c16b84b5784865bdb37bbb4b26dc22cec588ffd8 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 13:04:36 +0800 Subject: Minicargo - Fix #98 by moving chdir into `spawn_process` (and protect it with a lock) --- tools/common/path.h | 7 +++++++ tools/minicargo/build.cpp | 48 ++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/tools/common/path.h b/tools/common/path.h index eae4951f..1ad6f506 100644 --- a/tools/common/path.h +++ b/tools/common/path.h @@ -38,6 +38,13 @@ public: return m_str != ""; } + bool operator==(const path& p) const { + return m_str == p.m_str; + } + bool operator!=(const path& p) const { + return m_str != p.m_str; + } + path& operator/=(const path& p) { if(!p.is_valid()) diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 35c64f3b..d3f3ae45 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -62,6 +62,9 @@ class Builder { BuildOptions m_opts; ::helpers::path m_compiler_path; +#ifndef _WIN32 + mutable ::std::mutex chdir_mutex; +#endif public: Builder(BuildOptions opts); @@ -73,7 +76,7 @@ public: private: ::helpers::path get_crate_path(const PackageManifest& manifest, const PackageTarget& target, bool is_for_host, const char** crate_type, ::std::string* out_crate_suffix) const; bool spawn_process_mrustc(const StringList& args, StringListKV env, const ::helpers::path& logfile) const; - bool spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile) const; + bool spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile, const ::helpers::path& working_directory={}) const; ::helpers::path build_and_run_script(const PackageManifest& manifest, bool is_for_host) const; @@ -537,6 +540,11 @@ bool BuildList::build(BuildOptions opts, unsigned num_jobs) Builder::Builder(BuildOptions opts): m_opts(::std::move(opts)) { + if( const char* override_path = getenv("MRUSTC_PATH") ) { + m_compiler_path = override_path; + return ; + } + // TODO: Clean this stuff up #ifdef _WIN32 char buf[1024]; size_t s = GetModuleFileName(NULL, buf, sizeof(buf)-1); @@ -882,23 +890,14 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& } //auto _ = ScopedChdir { manifest.directory() }; - #if _WIN32 - #else - auto fd_cwd = open(".", O_DIRECTORY); - chdir(manifest.directory().str().c_str()); - #endif - if( !this->spawn_process(script_exe_abs.str().c_str(), {}, env, out_file) ) + if( !this->spawn_process(script_exe_abs.str().c_str(), {}, env, out_file, /*working_directory=*/manifest.directory()) ) { rename(out_file.str().c_str(), (out_file+"_failed").str().c_str()); // Build failed, return an invalid path return ::helpers::path();; } - #if _WIN32 - #else - fchdir(fd_cwd); - #endif } - + return out_file; } bool Builder::build_library(const PackageManifest& manifest, bool is_for_host) const @@ -934,7 +933,7 @@ bool Builder::spawn_process_mrustc(const StringList& args, StringListKV env, con //env.push_back("MRUSTC_DEBUG", ""); return spawn_process(m_compiler_path.str().c_str(), args, env, logfile); } -bool Builder::spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile) const +bool Builder::spawn_process(const char* exe_name, const StringList& args, const StringListKV& env, const ::helpers::path& logfile, const ::helpers::path& working_directory/*={}*/) const { #ifdef _WIN32 ::std::stringstream cmdline; @@ -986,7 +985,7 @@ bool Builder::spawn_process(const char* exe_name, const StringList& args, const WriteFile(si.hStdOutput, "\n", 1, &tmp, NULL); } PROCESS_INFORMATION pi = { 0 }; - CreateProcessA(exe_name, (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi); + CreateProcessA(exe_name, (LPSTR)cmdline_str.c_str(), NULL, NULL, TRUE, 0, NULL, (working_directory != ::helpers::path() ? working_directory.str().c_str() : NULL), &si, &pi); CloseHandle(si.hStdOutput); WaitForSingleObject(pi.hProcess, INFINITE); DWORD status = 1; @@ -1050,12 +1049,23 @@ bool Builder::spawn_process(const char* exe_name, const StringList& args, const // }); envp.push_back(nullptr); - if( posix_spawn(&pid, exe_name, &fa, /*attr=*/nullptr, (char* const*)argv.data(), (char* const*)envp.get_vec().data()) != 0 ) + // TODO: Acquire a lock { - ::std::cerr << "Unable to run process '" << exe_name << "' - " << strerror(errno) << ::std::endl; - DEBUG("Unable to spawn executable"); - posix_spawn_file_actions_destroy(&fa); - return false; + ::std::lock_guard<::std::mutex> lh { this->chdir_mutex }; + auto fd_cwd = open(".", O_DIRECTORY); + if( working_directory != ::helpers::path() ) { + chdir(working_directory.str().c_str()); + } + if( posix_spawn(&pid, exe_name, &fa, /*attr=*/nullptr, (char* const*)argv.data(), (char* const*)envp.get_vec().data()) != 0 ) + { + ::std::cerr << "Unable to run process '" << exe_name << "' - " << strerror(errno) << ::std::endl; + DEBUG("Unable to spawn executable"); + posix_spawn_file_actions_destroy(&fa); + return false; + } + if( working_directory != ::helpers::path() ) { + fchdir(fd_cwd); + } } posix_spawn_file_actions_destroy(&fa); int status = -1; -- cgit v1.2.3 From c31bc22c461e22ff1c26c7c32ccb26d8841dc566 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 14:05:22 +0800 Subject: Appveyor - Initial config file (to override UI settings) --- appveyor.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..116c15c6 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,12 @@ +version: 1.0.{build} + +before_build: +- cmd: nuget restore vsproject/mrustc.sln + +build: + project: vsproject/mrustc.sln + verbosity: minimal + +test_script: +- ps: cd vsproject # Use powershell to change to the vsproject directory +- cmd: build_std.cmd -- cgit v1.2.3 From 749ded0351148846af5b2f9e7475504831cbf34b Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 14:17:59 +0800 Subject: Add Travis/Appveyor badges, tweak appveyor config --- README.md | 3 +++ appveyor.yml | 3 +-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bbc34fb6..d17ef42b 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ Mutabah's Rust Compiler _In-progress_ alternative rust compiler. Capable of building a fully-working copy of rustc, but not yet suitable for everyday use. +[![Build Status: windows](https://ci.appveyor.com/api/projects/status/96y4ui20pl8xjm2h/branch/master?svg=true)](https://ci.appveyor.com/project/thepowersgang/mrustc/branch/master) +[![Build Status: Linux/OSX](https://travis-ci.org/thepowersgang/mrustc.svg?branch=master)](https://travis-ci.org/thepowersgang/mrustc) + Intro === This project is an attempt at creating a simple rust compiler in C++, with the ultimate goal of being a separate re-implementation. diff --git a/appveyor.yml b/appveyor.yml index 116c15c6..8cc7bd87 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,5 +8,4 @@ build: verbosity: minimal test_script: -- ps: cd vsproject # Use powershell to change to the vsproject directory -- cmd: build_std.cmd +- cmd: cd vsproject & build_std.cmd -- cgit v1.2.3 From b8e2907cd4a5f9efa17718008ecdfb560ad61674 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 14:34:55 +0800 Subject: Appveyor - twiddling --- appveyor.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 8cc7bd87..3f3f52f0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,5 +1,8 @@ version: 1.0.{build} +configuration: Release +platform: x64 + before_build: - cmd: nuget restore vsproject/mrustc.sln @@ -8,4 +11,9 @@ build: verbosity: minimal test_script: -- cmd: cd vsproject & build_std.cmd +# - Download/extract rust 1.19.0 +- appveyor DownloadFile https://static.rust-lang.org/dist/rustc-1.19.0-src.tar.gz +- tar xzf rustc-1.19.0-src.tar.gz +- cmd: cd vsproject +- cmd: call build_std.cmd +- cmd: call run_hello.cmd -- cgit v1.2.3 From efc95784c83cc054ed5a0f2d71ff0c66e3dfb2cf Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 18:40:23 +0800 Subject: Codegen MMIR - Remove places where assert body needs to be evaluated (ref #97) --- src/trans/codegen_mmir.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp index b2c5282a..a7d47c0e 100644 --- a/src/trans/codegen_mmir.cpp +++ b/src/trans/codegen_mmir.cpp @@ -18,6 +18,14 @@ namespace { + size_t Target_GetSizeOf_Required(const Span& sp, const StaticTraitResolve& resolve, const ::HIR::TypeRef& ty) + { + size_t size; + bool type_has_size = Target_GetSizeOf(sp, resolve, ty, size); + ASSERT_BUG(sp, type_has_size, "Attempting to get the size of a unsized type"); + return size; + } + template struct Fmt { @@ -779,8 +787,7 @@ namespace cur_ofs ++; } emit_literal_as_bytes(le[i], repr->fields[i].ty, out_relocations, base_ofs + cur_ofs); - size_t size; - assert(Target_GetSizeOf(sp, m_resolve, repr->fields[i].ty, size)); + size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[i].ty); cur_ofs += size; } while(cur_ofs < repr->size) @@ -803,8 +810,7 @@ namespace emit_literal_as_bytes(*le.val, repr->fields[le.idx].ty, out_relocations, base_ofs + cur_ofs); - size_t size; - assert(Target_GetSizeOf(sp, m_resolve, repr->fields[le.idx].ty, size)); + size_t size = Target_GetSizeOf(sp, m_resolve, repr->fields[le.idx].ty); cur_ofs += size; } @@ -819,8 +825,7 @@ namespace auto v = ::HIR::Literal::make_Integer(le.idx); emit_literal_as_bytes(v, repr->fields[ve->field.index].ty, out_relocations, base_ofs + cur_ofs); - size_t size; - assert(Target_GetSizeOf(sp, m_resolve, repr->fields[ve->field.index].ty, size)); + size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[ve->field.index].ty) cur_ofs += size; } // TODO: Nonzero? @@ -888,8 +893,7 @@ namespace for(const auto& v : lit.as_List()) { emit_literal_as_bytes(v, *te.inner, out_relocations, base_ofs); - size_t size; - assert(Target_GetSizeOf(sp, m_resolve, *te.inner, size)); + size_t size = Target_GetSizeOf(sp, m_resolve, *te.inner, size); base_ofs += size; } } break; -- cgit v1.2.3 From ad5d36e85a25d1addb4c854114102bef696d4472 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 18:41:23 +0800 Subject: (minor) Whitespace cleaup --- src/trans/codegen_mmir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp index a7d47c0e..4c17fe47 100644 --- a/src/trans/codegen_mmir.cpp +++ b/src/trans/codegen_mmir.cpp @@ -332,7 +332,7 @@ namespace else if( t.m_data.is_Slice() ) { return ::HIR::CoreType::Usize; } - else if( t.m_data.is_TraitObject() ) { + else if( t.m_data.is_TraitObject() ) { const auto& te = t.m_data.as_TraitObject(); //auto vtp = t.m_data.as_TraitObject().m_trait.m_path; @@ -389,7 +389,7 @@ namespace { m_of << "fn " << drop_glue_path << "(&move " << ty << ") {\n"; m_of << "\tlet unit: ();\n"; - + if( const auto* ity = m_resolve.is_type_owned_box(ty) ) { m_of << "\t0: {\n"; -- cgit v1.2.3 From 8e8e51ac1b04c7cc85a4a81d9c1906fb9f5a4d58 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Dec 2018 18:42:50 +0800 Subject: Codegen MMIR - Forgot to compile before commit, fix syntax errors. --- src/trans/codegen_mmir.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/trans/codegen_mmir.cpp b/src/trans/codegen_mmir.cpp index 4c17fe47..73de19d3 100644 --- a/src/trans/codegen_mmir.cpp +++ b/src/trans/codegen_mmir.cpp @@ -810,7 +810,7 @@ namespace emit_literal_as_bytes(*le.val, repr->fields[le.idx].ty, out_relocations, base_ofs + cur_ofs); - size_t size = Target_GetSizeOf(sp, m_resolve, repr->fields[le.idx].ty); + size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[le.idx].ty); cur_ofs += size; } @@ -825,7 +825,7 @@ namespace auto v = ::HIR::Literal::make_Integer(le.idx); emit_literal_as_bytes(v, repr->fields[ve->field.index].ty, out_relocations, base_ofs + cur_ofs); - size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[ve->field.index].ty) + size_t size = Target_GetSizeOf_Required(sp, m_resolve, repr->fields[ve->field.index].ty); cur_ofs += size; } // TODO: Nonzero? -- cgit v1.2.3 From 17f910e871e70a5edbf32ea05ef8f68bc71003c9 Mon Sep 17 00:00:00 2001 From: John Paul Adrian Glaubitz Date: Sat, 22 Dec 2018 15:49:16 +0100 Subject: Trans - Fix alignment values for m68k --- src/trans/target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/trans/target.cpp b/src/trans/target.cpp index 53d84030..316749be 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -42,7 +42,7 @@ const TargetArch ARCH_M68K = { "m68k", 32, true, { /*atomic(u8)=*/true, false, true, false, true }, - TargetArch::Alignments(2, 4, 8, 16, 4, 8, 4) // TODO: Does m68k have lower alignments? + TargetArch::Alignments(2, 2, 2, 2, 2, 2, 2) }; TargetSpec g_target; -- cgit v1.2.3 From 1579cd7f8eb592fdc24bfa87917ce85239fd3eb3 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Tue, 15 Jan 2019 19:12:12 +0800 Subject: Minicargo - Auto-detect bin targets (fixes #101) --- tools/minicargo/manifest.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/minicargo/manifest.cpp b/tools/minicargo/manifest.cpp index bbaa24f6..e47da1bc 100644 --- a/tools/minicargo/manifest.cpp +++ b/tools/minicargo/manifest.cpp @@ -484,6 +484,20 @@ PackageManifest PackageManifest::load_from_toml(const ::std::string& path) rv.m_targets.push_back(PackageTarget { PackageTarget::Type::Lib }); } } + // - If there's no binary section, but src/main.rs exists, add as a binary + if( ! ::std::any_of(rv.m_targets.begin(), rv.m_targets.end(), [](const auto& x){ return x.m_type == PackageTarget::Type::Bin; }) ) + { + // No library, add one pointing to lib.rs + if( ::std::ifstream(package_dir / "src" / "main.rs").good() ) + { + DEBUG("- Implicit binary"); + rv.m_targets.push_back(PackageTarget { PackageTarget::Type::Bin }); + } + } + if( rv.m_targets.empty() ) + { + throw ::std::runtime_error(format("Manifest file ", path, " didn't specify any targets (and src/{main,lib}.rs doesn't exist)")); + } // Default target names for(auto& tgt : rv.m_targets) -- cgit v1.2.3 From cbed0d2930168ef15bfdeb02c6f12991094b1480 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Mon, 21 Jan 2019 23:30:06 +0000 Subject: targets: Add x86_64 and arm targets for Haiku --- src/trans/target.cpp | 14 ++++++++++++++ tools/common/target_detect.h | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/src/trans/target.cpp b/src/trans/target.cpp index 316749be..70996fb0 100644 --- a/src/trans/target.cpp +++ b/src/trans/target.cpp @@ -511,6 +511,20 @@ namespace ARCH_X86_64 }; } + else if(target_name == "arm-unknown-haiku") + { + return TargetSpec { + "unix", "haiku", "gnu", {CodegenMode::Gnu11, true, "arm-unknown-haiku", {}, {}}, + ARCH_ARM32 + }; + } + else if(target_name == "x86_64-unknown-haiku") + { + return TargetSpec { + "unix", "haiku", "gnu", {CodegenMode::Gnu11, false, "x86_64-unknown-haiku", {}, {}}, + ARCH_X86_64 + }; + } else { ::std::cerr << "Unknown target name '" << target_name << "'" << ::std::endl; diff --git a/tools/common/target_detect.h b/tools/common/target_detect.h index 0812c363..1bfc7dd9 100644 --- a/tools/common/target_detect.h +++ b/tools/common/target_detect.h @@ -75,6 +75,15 @@ // - Apple devices #elif defined(__APPLE__) # define DEFAULT_TARGET_NAME "x86_64-apple-macosx" +// - Haiku +#elif defined(__HAIKU__) +# if defined(__x86_64__) +# define DEFAULT_TARGET_NAME "x86_64-unknown-haiku" +# elif defined(__arm__) +# define DEFAULT_TARGET_NAME "arm-unknown-haiku" +# else +# warning "Unable to detect a suitable default target (Haiku)" +# endif // - Unknown #else # warning "Unable to detect a suitable default target" -- cgit v1.2.3 From 3108cf9eea6dfd801136987568c072f4105b9b7a Mon Sep 17 00:00:00 2001 From: Danny Milosavljevic Date: Mon, 4 Feb 2019 18:16:58 +0100 Subject: Fix recv_v128u procedural macro plugin decoder --- src/expand/proc_macro.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp index d34a91a5..be0b4ce6 100644 --- a/src/expand/proc_macro.cpp +++ b/src/expand/proc_macro.cpp @@ -970,7 +970,7 @@ uint64_t ProcMacroInv::recv_v128u() for(;;) { auto b = recv_u8(); - v |= static_cast(b) << ofs; + v |= static_cast(b & 0x7F) << ofs; if( (b & 0x80) == 0 ) break; ofs += 7; -- cgit v1.2.3 From 0992c4af5242fc95e8cc028c5af7fb86424e624c Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 6 Oct 2018 18:11:40 +0800 Subject: HIR - (minor) Handle equal function pointers when doing fuzzy --- src/hir/hir.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/hir/hir.cpp b/src/hir/hir.cpp index 9f9bc1c3..5d67ac5f 100644 --- a/src/hir/hir.cpp +++ b/src/hir/hir.cpp @@ -450,7 +450,9 @@ namespace { ), (Function, TU_IFLET(::HIR::TypeRef::Data, right.m_data, Function, re, - TODO(sp, "Function"); + if( left == right ) + return ::OrdEqual; + TODO(sp, "Function - " << left << " and " << right); //return typelist_ord_specific(sp, le.arg_types, re.arg_types); ) else { -- cgit v1.2.3 From 7d728e447d70d79e93c01a7c51efbd61be09d68f Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 6 Oct 2018 18:12:24 +0800 Subject: Makefile - Add libcore-test --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 23c799d2..2ef88f9e 100644 --- a/Makefile +++ b/Makefile @@ -236,6 +236,7 @@ LIB_TESTS := collections #std rust_tests-libs: $(patsubst %,output/lib%-test_out.txt, $(LIB_TESTS)) RUNTIME_ARGS_output/libcollections-test := --test-threads 1 +#RUNTIME_ARGS_output/libcore-test := --test-threads 1 RUNTIME_ARGS_output/libstd-test := --test-threads 1 RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::test_index_nonexistent RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::test_drops @@ -243,6 +244,13 @@ RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::te RUNTIME_ARGS_output/libstd-test += --skip ::collections::hash::map::test_map::test_placement_panic RUNTIME_ARGS_output/libstd-test += --skip ::io::stdio::tests::panic_doesnt_poison # Unbounded execution +output/libcore-test: $(RUSTCSRC)src/libcore/tests/lib.rs $(TEST_DEPS) + @echo "--- [MRUSTC] --test -o $@" + @mkdir -p output/ + @rm -f $@ + $(DBG) $(ENV_$@) $(BIN) --test $< -o $@ $(RUST_FLAGS) $(ARGS_$@) $(PIPECMD) +# # HACK: Work around gdb returning success even if the program crashed + @test -e $@ output/lib%-test: $(RUSTCSRC)src/lib%/lib.rs $(TEST_DEPS) @echo "--- [MRUSTC] --test -o $@" @mkdir -p output/ -- cgit v1.2.3 From 80c2add7b04e6e202d9a4f3b3c25ec498e3b5893 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 23 Feb 2019 12:33:15 +0800 Subject: minicargo - Improved error reporting for failed build scripts --- tools/minicargo/build.cpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index 35c64f3b..6d586893 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -30,6 +30,7 @@ extern int _putenv_s(const char*, const char*); # include # include #endif +#include #include #include #ifdef _WIN32 @@ -889,9 +890,24 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& #endif if( !this->spawn_process(script_exe_abs.str().c_str(), {}, env, out_file) ) { - rename(out_file.str().c_str(), (out_file+"_failed").str().c_str()); + ::std::cerr << "Calling " << script_exe_abs << " failed" << ::std::endl; + { + ::std::ifstream ifs(out_file); + char linebuf[512]; + while( !ifs.getline(linebuf, sizeof(linebuf)-1).eof() ) + { + if( strncmp(linebuf, "cargo:", 6) == 0 ) { + continue; + } + ::std::cerr << linebuf << ::std::endl; + } + } + + auto failed_filename = out_file+"_failed.txt"; + remove(failed_filename.str().c_str()); + rename(out_file.str().c_str(), failed_filename.str().c_str()); // Build failed, return an invalid path - return ::helpers::path();; + return ::helpers::path(); } #if _WIN32 #else @@ -993,7 +1009,7 @@ bool Builder::spawn_process(const char* exe_name, const StringList& args, const GetExitCodeProcess(pi.hProcess, &status); if (status != 0) { - DEBUG("Compiler exited with non-zero exit status " << status); + DEBUG("Process exited with non-zero exit status " << status); return false; } #else -- cgit v1.2.3 From 9b706e3beaa59db561008fd5ad13f2674da12861 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 23 Feb 2019 13:53:12 +0800 Subject: Codegen C - Fix msvc clz/ctz --- src/trans/codegen_c.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 84a538d5..56b03f9c 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -305,7 +305,7 @@ namespace { // 64-bit bit ops (gcc intrinsics) m_of << "static inline uint64_t __builtin_clz64(uint64_t v) {\n" - << "\treturn (v >> 32 != 0 ? __builtin_clz(v>>32) : 32 + __builtin_clz(v));\n" + << "\treturn ( (v >> 32) != 0 ? __builtin_clz(v>>32) : 32 + __builtin_clz(v));\n" << "}\n" << "static inline uint64_t __builtin_ctz64(uint64_t v) {\n" << "\treturn ((v&0xFFFFFFFF) == 0 ? __builtin_ctz(v>>32) + 32 : __builtin_ctz(v));\n" @@ -317,10 +317,10 @@ namespace { << "static inline uint64_t __builtin_popcount(uint64_t v) {\n" << "\treturn (v >> 32 != 0 ? __popcnt64(v>>32) : 32 + __popcnt64(v));\n" << "}\n" - << "static inline int __builtin_ctz(uint32_t v) { int rv; _BitScanReverse(&rv, v); return rv; }\n" - << "static inline int __builtin_clz(uint32_t v) { int rv; _BitScanForward(&rv, v); return rv; }\n" + << "static inline int __builtin_ctz(uint32_t v) { int rv; _BitScanForward(&rv, v); return rv; }\n" + << "static inline int __builtin_clz(uint32_t v) { int rv; _BitScanReverse(&rv, v); return 31 - rv; }\n" << "static inline uint64_t __builtin_clz64(uint64_t v) {\n" - << "\treturn (v >> 32 != 0 ? __builtin_clz(v>>32) : 32 + __builtin_clz(v));\n" + << "\treturn ( (v >> 32) != 0 ? __builtin_clz(v>>32) : 32 + __builtin_clz(v) );\n" << "}\n" << "static inline uint64_t __builtin_ctz64(uint64_t v) {\n" << "\treturn ((v&0xFFFFFFFF) == 0 ? __builtin_ctz(v>>32) + 32 : __builtin_ctz(v));\n" @@ -1935,7 +1935,11 @@ namespace { (String, m_of << "{ "; this->print_escaped_string(e); - m_of << ", " << e.size() << "}"; + // TODO: Better type checking? + if( !ty.m_data.is_Array() ) { + m_of << ", " << e.size(); + } + m_of << "}"; ) ) } -- cgit v1.2.3 From a7868c927d1776d7c2570c95deae1cbd77483938 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 23 Feb 2019 13:53:45 +0800 Subject: vsproject scripts - Add libproc_macro --- vsproject/build_std.cmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vsproject/build_std.cmd b/vsproject/build_std.cmd index a9d6b45d..0a360614 100644 --- a/vsproject/build_std.cmd +++ b/vsproject/build_std.cmd @@ -5,3 +5,5 @@ x64\Release\minicargo.exe ..\rustc-1.19.0-src\src\libpanic_unwind --script-overr if %errorlevel% neq 0 exit /b %errorlevel% x64\Release\minicargo.exe ..\rustc-1.19.0-src\src\libtest --script-overrides ..\script-overrides\stable-1.19.0 if %errorlevel% neq 0 exit /b %errorlevel% +x64\Release\minicargo.exe ..\lib\libproc_macro +if %errorlevel% neq 0 exit /b %errorlevel% -- cgit v1.2.3 From a2f952ba6fe355a804c2b5cb33deebbc07ac2462 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 23 Feb 2019 14:17:47 +0800 Subject: minicargo - Fix infinite printing in build script error reporting if an over-long line is hit. --- tools/minicargo/build.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tools/minicargo/build.cpp b/tools/minicargo/build.cpp index d074525c..53fa1a16 100644 --- a/tools/minicargo/build.cpp +++ b/tools/minicargo/build.cpp @@ -794,6 +794,10 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& args.push_back("--crate-type"); args.push_back("bin"); args.push_back("-o"); args.push_back(outfile); args.push_back("-L"); args.push_back(this->get_output_dir(true).str()); // NOTE: Forces `is_for_host` to true here. + if( true ) + { + args.push_back("-g"); + } for(const auto& d : m_opts.lib_search_dirs) { args.push_back("-L"); @@ -893,22 +897,24 @@ bool Builder::build_target(const PackageManifest& manifest, const PackageTarget& //auto _ = ScopedChdir { manifest.directory() }; if( !this->spawn_process(script_exe_abs.str().c_str(), {}, env, out_file, /*working_directory=*/manifest.directory()) ) { + auto failed_filename = out_file+"_failed.txt"; + remove(failed_filename.str().c_str()); + rename(out_file.str().c_str(), failed_filename.str().c_str()); + ::std::cerr << "Calling " << script_exe_abs << " failed" << ::std::endl; { - ::std::ifstream ifs(out_file); - char linebuf[512]; - while( !ifs.getline(linebuf, sizeof(linebuf)-1).eof() ) + ::std::ifstream ifs(failed_filename); + char linebuf[1024]; + while( ifs.good() && !ifs.eof() ) { + ifs.getline(linebuf, sizeof(linebuf)-1); if( strncmp(linebuf, "cargo:", 6) == 0 ) { continue; } - ::std::cerr << linebuf << ::std::endl; + ::std::cerr << "> " << linebuf << ::std::endl; } } - auto failed_filename = out_file+"_failed.txt"; - remove(failed_filename.str().c_str()); - rename(out_file.str().c_str(), failed_filename.str().c_str()); // Build failed, return an invalid path return ::helpers::path(); } -- cgit v1.2.3 From 5ecf83cb46c08532b541416b571effe0dfe2831a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 24 Feb 2019 14:23:46 +0100 Subject: Implement compiler check TODO. (#112) Checks if `-gcc` exists before trying to call it, and does so before trying $CC --- src/trans/codegen_c.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp index 56b03f9c..538c3bb2 100644 --- a/src/trans/codegen_c.cpp +++ b/src/trans/codegen_c.cpp @@ -648,13 +648,14 @@ namespace { if( getenv(varname.c_str()) ) { args.push_back( getenv(varname.c_str()) ); } + else if (system(("which " + Target_GetCurSpec().m_backend_c.m_c_compiler + "-gcc" + " >/dev/null 2>&1").c_str()) == 0) { + args.push_back( Target_GetCurSpec().m_backend_c.m_c_compiler + "-gcc" ); + } else if( getenv("CC") ) { args.push_back( getenv("CC") ); } else { - // TODO: Determine if the compiler can't be found, and fall back to `gcc` if that's the case - args.push_back( Target_GetCurSpec().m_backend_c.m_c_compiler + "-gcc" ); - //args.push_back( "gcc" ); + args.push_back("gcc"); } } for( const auto& a : Target_GetCurSpec().m_backend_c.m_compiler_opts ) @@ -1324,7 +1325,7 @@ 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 - // TODO: + // 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 << "\tunion {\n"; @@ -3667,7 +3668,7 @@ namespace { m_of << "("; for(unsigned int j = 0; j < e.args.size(); j ++) { if(j != 0) m_of << ","; - m_of << " "; + m_of << " "; if( m_options.disallow_empty_structs && TU_TEST1(e.args[j], LValue, .is_Field()) ) { ::HIR::TypeRef tmp; @@ -3916,7 +3917,7 @@ namespace { void emit_intrinsic_call(const ::std::string& name, const ::HIR::PathParams& params, const ::MIR::Terminator::Data_Call& e) { const auto& mir_res = *m_mir_res; - enum class Ordering + enum class Ordering { SeqCst, Acquire, @@ -4081,7 +4082,7 @@ namespace { m_of << "*(volatile uint8_t*)"; else m_of << "*(volatile int8_t*)"; - emit_param(e.args.at(0)); + emit_param(e.args.at(0)); switch(op) { case AtomicOp::Add: m_of << " += "; break; -- cgit v1.2.3 From 3f44cece3931baccea9835b08bd5ad11aa59dab0 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 24 Feb 2019 21:41:38 +0800 Subject: Travis - Set compiler for generated code --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 864d973d..04d7ea11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ matrix: - os: linux before_install: - export CC=gcc-6 + - export CC-x86_64-linux-gnu=gcc-6 - export CXX=g++-6 addons: apt: -- cgit v1.2.3 From f41f2197456be87c7c63582dbeee4667bfae35e8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 28 May 2019 14:42:59 -0700 Subject: Allow square brackets in macro definitions Fixes #103 --- samples/test/issue-mrustc-103.rs | 9 +++++++++ src/macro_rules/parse.cpp | 1 + 2 files changed, 10 insertions(+) create mode 100644 samples/test/issue-mrustc-103.rs diff --git a/samples/test/issue-mrustc-103.rs b/samples/test/issue-mrustc-103.rs new file mode 100644 index 00000000..f27fe6de --- /dev/null +++ b/samples/test/issue-mrustc-103.rs @@ -0,0 +1,9 @@ +macro_rules! pat { + [$a:expr;$b:expr] => ( + println!("{} {}", $a, $b); + ) +} +fn main() { + pat![4;5]; +} + diff --git a/src/macro_rules/parse.cpp b/src/macro_rules/parse.cpp index b3b1014e..0cc7b3a8 100644 --- a/src/macro_rules/parse.cpp +++ b/src/macro_rules/parse.cpp @@ -254,6 +254,7 @@ MacroRule Parse_MacroRules_Var(TokenStream& lex) { case TOK_BRACE_OPEN: close = TOK_BRACE_CLOSE; break; case TOK_PAREN_OPEN: close = TOK_PAREN_CLOSE; break; + case TOK_SQUARE_OPEN: close = TOK_SQUARE_CLOSE; break; default: throw ParseError::Unexpected(lex, tok); } -- cgit v1.2.3