summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/trans/codegen.cpp1
-rw-r--r--src/trans/codegen_c.cpp12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/trans/codegen.cpp b/src/trans/codegen.cpp
index 0141497f..043e9b43 100644
--- a/src/trans/codegen.cpp
+++ b/src/trans/codegen.cpp
@@ -129,6 +129,7 @@ void Trans_Codegen(const ::std::string& outfile, const ::HIR::Crate& crate, cons
MIR_Validate(resolve, ::HIR::ItemPath(""), *mir, args, ret_type);
codegen->emit_function_code(path, fcn, ent.second->pp, mir);
}
+ // TODO: Detect if the function was a #[inline] function from another crate, and don't emit if that is the case?
else {
codegen->emit_function_code(path, fcn, pp, fcn.m_code.m_mir);
}
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index 12c80a88..4ea2e54d 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -894,6 +894,7 @@ namespace {
(Variant,
MIR_ASSERT(*m_mir_res, ty.m_data.is_Path(), "");
MIR_ASSERT(*m_mir_res, ty.m_data.as_Path().binding.is_Enum(), "");
+ const auto& enm = *ty.m_data.as_Path().binding.as_Enum();
auto it = m_enum_repr_cache.find(ty.m_data.as_Path().path.m_data.as_Generic());
if( it != m_enum_repr_cache.end() )
{
@@ -906,6 +907,11 @@ namespace {
m_of << "}";
}
}
+ else if( enm.m_repr != ::HIR::Enum::Repr::Rust || ::std::all_of(enm.m_variants.begin(), enm.m_variants.end(), [](const auto& x){return x.second.is_Unit() || x.second.is_Value();}) )
+ {
+ MIR_ASSERT(*m_mir_res, e.vals.empty(), "Value-only enum with fields");
+ m_of << "{" << e.idx << "}";
+ }
else
{
m_of << "{" << e.idx << ", { .var_" << e.idx << " = {";
@@ -2631,6 +2637,7 @@ namespace {
(Variant,
MIR_ASSERT(*m_mir_res, ty.m_data.is_Path(), "");
MIR_ASSERT(*m_mir_res, ty.m_data.as_Path().binding.is_Enum(), "");
+ const auto& enm = *ty.m_data.as_Path().binding.as_Enum();
auto it = m_enum_repr_cache.find(ty.m_data.as_Path().path.m_data.as_Generic());
if( it != m_enum_repr_cache.end() )
{
@@ -2642,6 +2649,11 @@ namespace {
assign_from_literal([&](){ emit_dst(); m_of << "._0"; }, get_inner_type(e.idx, 0), e.vals[0]);
}
}
+ else if( enm.m_repr != ::HIR::Enum::Repr::Rust || ::std::all_of(enm.m_variants.begin(), enm.m_variants.end(), [](const auto& x){return x.second.is_Unit() || x.second.is_Value();}) )
+ {
+ MIR_ASSERT(*m_mir_res, e.vals.empty(), "Value-only enum with fields");
+ emit_dst(); m_of << ".TAG = " << e.idx;
+ }
else
{
emit_dst(); m_of << ".TAG = " << e.idx;