typing-asm.h 5.04 KB
Newer Older
1 2 3 4 5 6 7 8
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_TYPING_ASM_H_
#define V8_TYPING_ASM_H_

#include "src/allocation.h"
9
#include "src/ast/ast.h"
10 11 12 13 14 15 16 17
#include "src/effects.h"
#include "src/type-info.h"
#include "src/types.h"
#include "src/zone.h"

namespace v8 {
namespace internal {

18
class TypeCache;
19 20 21 22 23 24

class AsmTyper : public AstVisitor {
 public:
  explicit AsmTyper(Isolate* isolate, Zone* zone, Script* script,
                    FunctionLiteral* root);
  bool Validate();
25
  void set_allow_simd(bool simd) { allow_simd_ = simd; }
26 27
  const char* error_message() { return error_message_; }

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  enum StandardMember {
    kNone = 0,
    kStdlib,
    kInfinity,
    kNaN,
    kMathAcos,
    kMathAsin,
    kMathAtan,
    kMathCos,
    kMathSin,
    kMathTan,
    kMathExp,
    kMathLog,
    kMathCeil,
    kMathFloor,
    kMathSqrt,
    kMathAbs,
    kMathMin,
    kMathMax,
    kMathAtan2,
    kMathPow,
    kMathImul,
    kMathFround,
    kMathE,
    kMathLN10,
    kMathLN2,
    kMathLOG2E,
    kMathLOG10E,
    kMathPI,
    kMathSQRT1_2,
    kMathSQRT2,
  };

  StandardMember VariableAsStandardMember(Variable* variable);

63 64 65
  DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();

 private:
66
  Zone* zone_;
67
  Isolate* isolate_;
68 69 70
  Script* script_;
  FunctionLiteral* root_;
  bool valid_;
71 72 73 74 75 76
  bool allow_simd_;

  struct VariableInfo : public ZoneObject {
    Type* type;
    bool is_check_function;
    bool is_constructor_function;
77
    StandardMember standard_member;
78 79 80 81

    VariableInfo()
        : type(NULL),
          is_check_function(false),
82 83
          is_constructor_function(false),
          standard_member(kNone) {}
84
    explicit VariableInfo(Type* t)
85 86 87 88
        : type(t),
          is_check_function(false),
          is_constructor_function(false),
          standard_member(kNone) {}
89
  };
90 91 92 93

  // Information for bi-directional typing with a cap on nesting depth.
  Type* expected_type_;
  Type* computed_type_;
94
  VariableInfo* property_info_;
95
  int32_t intish_;  // How many ops we've gone without a x|0.
96 97 98 99

  Type* return_type_;  // Return type of last function.
  size_t array_size_;  // Array size of last ArrayLiteral.

100
  typedef ZoneMap<std::string, VariableInfo*> ObjectTypeMap;
101 102 103
  ObjectTypeMap stdlib_types_;
  ObjectTypeMap stdlib_heap_types_;
  ObjectTypeMap stdlib_math_types_;
104 105 106 107 108
#define V(NAME, Name, name, lane_count, lane_type) \
  ObjectTypeMap stdlib_simd_##name##_types_;       \
  VariableInfo* stdlib_simd_##name##_constructor_type_;
  SIMD128_TYPES(V)
#undef V
109 110 111 112 113 114 115

  // Map from Variable* to global/local variable Type*.
  ZoneHashMap global_variable_type_;
  ZoneHashMap local_variable_type_;

  bool in_function_;  // In module function?
  bool building_function_tables_;
116
  bool visiting_exports_;
117

118
  TypeCache const& cache_;
119 120 121 122 123 124 125 126

  static const int kErrorMessageLimit = 100;
  char error_message_[kErrorMessageLimit];

  static const int kMaxUncombinedAdditiveSteps = 1 << 20;
  static const int kMaxUncombinedMultiplicativeSteps = 1;

  void InitializeStdlib();
127
  void InitializeStdlibSIMD();
128 129 130 131

  void VisitDeclarations(ZoneList<Declaration*>* d) override;
  void VisitStatements(ZoneList<Statement*>* s) override;

132
  void VisitExpressionAnnotation(Expression* e, Variable* var, bool is_return);
133 134 135
  void VisitFunctionAnnotation(FunctionLiteral* f);
  void VisitAsmModule(FunctionLiteral* f);

136
  void VisitHeapAccess(Property* expr, bool assigning, Type* assignment_type);
137

138 139 140
  void CheckPolymorphicStdlibArguments(enum StandardMember standard_member,
                                       ZoneList<Expression*>* args);

141 142 143 144 145 146 147 148
  Expression* GetReceiverOfPropertyAccess(Expression* expr, const char* name);
  bool IsMathObject(Expression* expr);
  bool IsSIMDObject(Expression* expr);
  bool IsSIMDTypeObject(Expression* expr, const char* name);
  bool IsStdlibObject(Expression* expr);

  void VisitSIMDProperty(Property* expr);

149
  int ElementShiftSize(Type* type);
150
  Type* StorageType(Type* type);
151 152 153

  void SetType(Variable* variable, Type* type);
  Type* GetType(Variable* variable);
154 155
  VariableInfo* GetVariableInfo(Variable* variable);
  VariableInfo* MakeVariableInfo(Variable* variable);
156
  void SetVariableInfo(Variable* variable, const VariableInfo* info);
157

158 159
  VariableInfo* LibType(ObjectTypeMap* map, Handle<String> name);
  void VisitLibraryAccess(ObjectTypeMap* map, Property* expr);
160 161 162 163 164 165 166

  void SetResult(Expression* expr, Type* type);
  void IntersectResult(Expression* expr, Type* type);

  void VisitWithExpectation(Expression* expr, Type* expected_type,
                            const char* msg);

167 168
  void VisitLiteral(Literal* expr, bool is_return);

169 170 171
  void VisitIntegerBitwiseOperator(BinaryOperation* expr, Type* left_expected,
                                   Type* right_expected, Type* result_type,
                                   bool conversion);
bradnelson's avatar
bradnelson committed
172

173 174
  Zone* zone() const { return zone_; }

175
#define DECLARE_VISIT(type) void Visit##type(type* node) override;
176 177 178 179 180
  AST_NODE_LIST(DECLARE_VISIT)
#undef DECLARE_VISIT

  DISALLOW_COPY_AND_ASSIGN(AsmTyper);
};
181 182
}  // namespace internal
}  // namespace v8
183 184

#endif  // V8_TYPING_ASM_H_