summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/trans/codegen_c.cpp97
-rw-r--r--src/trans/mangling.cpp27
-rw-r--r--src/trans/monomorphise.cpp2
3 files changed, 120 insertions, 6 deletions
diff --git a/src/trans/codegen_c.cpp b/src/trans/codegen_c.cpp
index c2998302..a0215a32 100644
--- a/src/trans/codegen_c.cpp
+++ b/src/trans/codegen_c.cpp
@@ -84,12 +84,54 @@ namespace {
}
else {
const auto& e = stmt.as_Assign();
+ DEBUG("- " << e.dst << " = " << e.src);
m_of << "\t"; emit_lvalue(e.dst); m_of << " = ";
TU_MATCHA( (e.src), (ve),
(Use,
emit_lvalue(ve);
),
(Constant,
+ TU_MATCHA( (ve), (c),
+ (Int,
+ m_of << c;
+ ),
+ (Uint,
+ m_of << ::std::hex << "0x" << c << ::std::dec;
+ ),
+ (Float,
+ m_of << c;
+ ),
+ (Bool,
+ m_of << (c ? "true" : "false");
+ ),
+ // TODO: These need to be arrays, not strings! (strings are NUL terminated)
+ (Bytes,
+ m_of << "\"" << ::std::oct;
+ for(const auto& v : c) {
+ if( ' ' <= v && v < 0x7F && v != '"' && v != '\\' )
+ m_of << v;
+ else
+ m_of << "\\" << (unsigned int)v;
+ }
+ m_of << "\"" << ::std::dec;
+ ),
+ (StaticString,
+ m_of << "\"" << ::std::oct;
+ for(const auto& v : c) {
+ if( ' ' <= v && v < 0x7F && v != '"' && v != '\\' )
+ m_of << v;
+ else
+ m_of << "\\" << (unsigned int)v;
+ }
+ m_of << "\"" << ::std::dec;
+ ),
+ (Const,
+ // TODO: This should have been eliminated?
+ ),
+ (ItemAddr,
+ m_of << "&" << Trans_Mangle(c);
+ )
+ )
),
(SizedArray,
m_of << "{";
@@ -210,8 +252,22 @@ namespace {
m_of << "\t}\n";
),
(CallValue,
+ m_of << "\t"; emit_lvalue(e.ret_val); m_of << " = ("; emit_lvalue(e.fcn_val); m_of << ")(";
+ for(unsigned int j = 0; j < e.args.size(); j ++) {
+ if(j != 0) m_of << ",";
+ m_of << " "; emit_lvalue(e.args[j]);
+ }
+ m_of << " )\n";
+ m_of << "\tgoto bb" << e.ret_block << ";\n";
),
(CallPath,
+ m_of << "\t"; emit_lvalue(e.ret_val); m_of << " = " << Trans_Mangle(e.fcn_path) << "(";
+ for(unsigned int j = 0; j < e.args.size(); j ++) {
+ if(j != 0) m_of << ",";
+ m_of << " "; emit_lvalue(e.args[j]);
+ }
+ m_of << " )\n";
+ m_of << "\tgoto bb" << e.ret_block << ";\n";
)
)
}
@@ -232,6 +288,43 @@ namespace {
m_of << ")";
}
void emit_lvalue(const ::MIR::LValue& val) {
+ TU_MATCHA( (val), (e),
+ (Variable,
+ m_of << "var" << e;
+ ),
+ (Temporary,
+ m_of << "tmp" << e.idx;
+ ),
+ (Argument,
+ m_of << "arg" << e.idx;
+ ),
+ (Return,
+ m_of << "rv";
+ ),
+ (Static,
+ m_of << Trans_Mangle(e);
+ ),
+ (Field,
+ // TODO: Also used for indexing
+ emit_lvalue(*e.val);
+ m_of << "._" << e.field_index;
+ ),
+ (Deref,
+ m_of << "*";
+ emit_lvalue(*e.val);
+ ),
+ (Index,
+ m_of << "(";
+ emit_lvalue(*e.val);
+ m_of << ")[";
+ emit_lvalue(*e.idx);
+ m_of << "]";
+ ),
+ (Downcast,
+ emit_lvalue(*e.val);
+ m_of << ".var_" << e.variant_index;
+ )
+ )
}
void emit_ctype(const ::HIR::TypeRef& ty) {
TU_MATCHA( (ty.m_data), (te),
@@ -270,10 +363,10 @@ namespace {
m_of << "struct s_" << Trans_Mangle(te.path);
),
(Union,
- m_of << "struct e_" << Trans_Mangle(te.path);
+ m_of << "union u_" << Trans_Mangle(te.path);
),
(Enum,
- m_of << "union u_" << Trans_Mangle(te.path);
+ m_of << "struct e_" << Trans_Mangle(te.path);
),
(Unbound,
BUG(Span(), "Unbound path in trans - " << ty);
diff --git a/src/trans/mangling.cpp b/src/trans/mangling.cpp
index fc85f532..c5c568d9 100644
--- a/src/trans/mangling.cpp
+++ b/src/trans/mangling.cpp
@@ -4,6 +4,15 @@
*
* trans/mangling.hpp
* - Name mangling support
+ *
+ *
+ * $D = ! type
+ * $A = Array
+ * $S = *-ptr
+ * $R = &-ptr
+ * $P = + symbol
+ * $E = = symbol
+ * $pL/$pR = Left/right paren
*/
#include "mangling.hpp"
#include <hir/type.hpp>
@@ -27,10 +36,10 @@
BUG(Span(), "UfcsUnknown - " << path);
),
(UfcsKnown,
- return FMT_CB(ss, );
+ return FMT_CB(ss, ss << "/*ufcsknown*/";);
),
(UfcsInherent,
- return FMT_CB(ss, );
+ return FMT_CB(ss, ss << "/*ufcsinherent*/"; );
)
)
throw "";
@@ -54,7 +63,17 @@
BUG(Span(), "Generic in trans - " << ty);
),
(TraitObject,
- BUG(Span(), "Raw trait object - " << ty);
+ return FMT_CB(ss,
+ ss << "$pL";
+ ss << Trans_Mangle(te.m_trait.m_path);
+ for(const auto& bound : te.m_trait.m_type_bounds) {
+ ss << "_" << bound.first << "$E" << Trans_Mangle(bound.second);
+ }
+ for(const auto& marker : te.m_markers) {
+ ss << "$P" << Trans_Mangle(marker);
+ }
+ ss << "$pR";
+ );
),
(ErasedType,
BUG(Span(), "ErasedType in trans - " << ty);
@@ -86,7 +105,7 @@
),
(Pointer,
return FMT_CB(ss,
- ss << "$P";
+ ss << "$S";
switch(te.type)
{
case ::HIR::BorrowType::Shared: ss << "s"; break;
diff --git a/src/trans/monomorphise.cpp b/src/trans/monomorphise.cpp
index e27369f8..b47ad15d 100644
--- a/src/trans/monomorphise.cpp
+++ b/src/trans/monomorphise.cpp
@@ -67,11 +67,13 @@ namespace {
output.named_variables.reserve( tpl->named_variables.size() );
for(const auto& var : tpl->named_variables)
{
+ DEBUG("- var" << output.named_variables.size());
output.named_variables.push_back( params.monomorph(crate, var) );
}
output.temporaries.reserve( tpl->temporaries.size() );
for(const auto& ty : tpl->temporaries)
{
+ DEBUG("- var" << output.temporaries.size());
output.temporaries.push_back( params.monomorph(crate, ty) );
}