aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-01-19 17:02:45 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-20 10:03:50 +0000
commit85d8754632d597fe3d94404406082bcbb2f5ff94 (patch)
treea118c7d4e6c294fb2b775da8fb75efad6227b0f0 /gcc/rust/backend
parent6e09093f1f759a78387d214b6d0fe8ba17b752b6 (diff)
downloadgcc-85d8754632d597fe3d94404406082bcbb2f5ff94.zip
gcc-85d8754632d597fe3d94404406082bcbb2f5ff94.tar.gz
gcc-85d8754632d597fe3d94404406082bcbb2f5ff94.tar.bz2
Implement NegationExpression
This is an example of a unary expression in gimple. The rules for enforcing the types are observed in the type resolver here too. Unary negate cannot be applied to bools but only integers and floats. Unary not cannot be applied to floating points but can be applied to integers and bools.
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index ff02d6b..da3c9cd 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -378,6 +378,25 @@ public:
expr.get_locus ());
}
+ void visit (HIR::NegationExpr &expr)
+ {
+ Operator op (OPERATOR_INVALID);
+ switch (expr.get_negation_type ())
+ {
+ case HIR::NegationExpr::NegationType::NEGATE:
+ op = OPERATOR_MINUS;
+ break;
+
+ case HIR::NegationExpr::NegationType::NOT:
+ op = OPERATOR_NOT;
+ break;
+ }
+
+ Bexpression *negated_expr = CompileExpr::Compile (expr.get_expr (), ctx);
+ translated = ctx->get_backend ()->unary_expression (op, negated_expr,
+ expr.get_locus ());
+ }
+
void visit (HIR::IfExpr &expr)
{
auto stmt = CompileConditionalBlocks::compile (&expr, ctx);