diff options
author | Philip Herron <herron.philip@googlemail.com> | 2020-05-28 19:09:43 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2020-11-28 21:13:15 +0000 |
commit | 121ebe3f8338aeef47846cef83e4108c5e3aa0e6 (patch) | |
tree | 95fcac598e12c16f13dc489f531a7c4cb62a2c44 /gcc/rust/backend/rust-compile.cc | |
parent | ab24b0549e3c0b358875d86c7528f301ddcc0e49 (diff) | |
download | gcc-121ebe3f8338aeef47846cef83e4108c5e3aa0e6.zip gcc-121ebe3f8338aeef47846cef83e4108c5e3aa0e6.tar.gz gcc-121ebe3f8338aeef47846cef83e4108c5e3aa0e6.tar.bz2 |
Compile LazyBooleans and ComparisonExpr to gimple
Diffstat (limited to 'gcc/rust/backend/rust-compile.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 90 |
1 files changed, 84 insertions, 6 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 480fa9f..13d6b80 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -357,10 +357,92 @@ Compilation::visit (AST::ArithmeticOrLogicalExpr &expr) void Compilation::visit (AST::ComparisonExpr &expr) -{} +{ + Bexpression *lhs = NULL; + VISIT_POP (expr.get_lhs ()->get_locus_slow (), expr.get_lhs (), lhs, exprs); + if (lhs == NULL) + { + rust_error_at (expr.get_lhs ()->get_locus_slow (), "failed to compile"); + return; + } + + Bexpression *rhs = NULL; + VISIT_POP (expr.right_expr->get_locus_slow (), expr.right_expr, rhs, exprs); + if (rhs == NULL) + { + rust_error_at (expr.right_expr->get_locus_slow (), "failed to compile"); + return; + } + + Operator op; + switch (expr.expr_type) + { + case AST::ComparisonExpr::EQUAL: + op = OPERATOR_EQEQ; + break; + case AST::ComparisonExpr::NOT_EQUAL: + op = OPERATOR_NOTEQ; + break; + case AST::ComparisonExpr::GREATER_THAN: + op = OPERATOR_GT; + break; + case AST::ComparisonExpr::LESS_THAN: + op = OPERATOR_LT; + break; + case AST::ComparisonExpr::GREATER_OR_EQUAL: + op = OPERATOR_GE; + break; + case AST::ComparisonExpr::LESS_OR_EQUAL: + op = OPERATOR_LE; + break; + default: + rust_fatal_error (expr.get_locus_slow (), "failed to compile operator"); + return; + } + + auto compExpr + = backend->binary_expression (op, lhs, rhs, expr.get_locus_slow ()); + exprs.push_back (compExpr); +} + void Compilation::visit (AST::LazyBooleanExpr &expr) -{} +{ + Bexpression *lhs = NULL; + VISIT_POP (expr.get_lhs ()->get_locus_slow (), expr.get_lhs (), lhs, exprs); + if (lhs == NULL) + { + rust_error_at (expr.get_lhs ()->get_locus_slow (), "failed to compile"); + return; + } + + Bexpression *rhs = NULL; + VISIT_POP (expr.right_expr->get_locus_slow (), expr.right_expr, rhs, exprs); + if (rhs == NULL) + { + rust_error_at (expr.right_expr->get_locus_slow (), "failed to compile"); + return; + } + + Operator op; + switch (expr.expr_type) + { + case AST::LazyBooleanExpr::LOGICAL_OR: + op = OPERATOR_OROR; + break; + case AST::LazyBooleanExpr::LOGICAL_AND: + op = OPERATOR_ANDAND; + break; + default: + rust_fatal_error (expr.get_locus_slow (), "failed to compile operator"); + return; + } + + auto compExpr + = backend->binary_expression (op, lhs, rhs, expr.get_locus_slow ()); + exprs.push_back (compExpr); +} + void Compilation::visit (AST::TypeCastExpr &expr) {} @@ -463,14 +545,12 @@ void Compilation::visit (AST::CallExpr &expr) { Bexpression *fn = NULL; - translatedType = NULL; VISIT_POP (expr.function->get_locus_slow (), expr.function, fn, exprs); if (fn == NULL) { rust_error_at (expr.function->get_locus_slow (), "failed to resolve"); return; } - Btype *returnType = translatedType; // can be NULL std::vector<Bexpression *> args; for (auto ¶m : expr.params) @@ -535,8 +615,6 @@ Compilation::visit (AST::RangeToInclExpr &expr) void Compilation::visit (AST::ReturnExpr &expr) { - printf ("ReturnExpr: %s\n", expr.as_string ().c_str ()); - Bexpression *ret = NULL; VISIT_POP (expr.return_expr->get_locus_slow (), expr.return_expr, ret, exprs); if (ret == NULL) |