1// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_COMPILER_BACKEND_EVALUATOR_H_
6#define RUNTIME_VM_COMPILER_BACKEND_EVALUATOR_H_
7
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
10#endif // defined(DART_PRECOMPILED_RUNTIME)
11
12#include "vm/allocation.h"
13#include "vm/compiler/backend/flow_graph.h"
14#include "vm/compiler/backend/il.h"
15#include "vm/compiler/backend/locations.h"
16
17namespace dart {
18
19// Namespace for static helper methods that evaluate constant expressions.
20class Evaluator : public AllStatic {
21 public:
22 // Truncates the given int64 value based on the representation.
23 static int64_t TruncateTo(int64_t v, Representation r);
24
25 // Evaluates a binary integer operation and returns a pointer to a
26 // canonicalized RawInteger.
27 static IntegerPtr BinaryIntegerEvaluate(const Object& left,
28 const Object& right,
29 Token::Kind token_kind,
30 bool is_truncating,
31 Representation representation,
32 Thread* thread);
33
34 // Evaluates a unary integer operation and returns a pointer to a
35 // canonicalized RawInteger.
36 static IntegerPtr UnaryIntegerEvaluate(const Object& value,
37 Token::Kind token_kind,
38 Representation representation,
39 Thread* thread);
40
41 // Evaluates a binary double operation and returns the result.
42 static double EvaluateDoubleOp(const double left,
43 const double right,
44 Token::Kind token_kind);
45
46 // Returns whether the value is an int64, and returns the int64 value
47 // through the result parameter.
48 static bool ToIntegerConstant(Value* value, int64_t* result);
49};
50
51} // namespace dart
52
53#endif // RUNTIME_VM_COMPILER_BACKEND_EVALUATOR_H_
54