| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "ast.h" | 30 #include "ast.h" |
| 31 #include "scopes.h" | 31 #include "scopes.h" |
| 32 #include "variables.h" | 32 #include "variables.h" |
| 33 | 33 |
| 34 namespace v8 { | 34 namespace v8 { |
| 35 namespace internal { | 35 namespace internal { |
| 36 | 36 |
| 37 // ---------------------------------------------------------------------------- | 37 // ---------------------------------------------------------------------------- |
| 38 // Implementation UseCount. | |
| 39 | |
| 40 UseCount::UseCount() | |
| 41 : nreads_(0), | |
| 42 nwrites_(0) { | |
| 43 } | |
| 44 | |
| 45 | |
| 46 void UseCount::RecordRead(int weight) { | |
| 47 ASSERT(weight > 0); | |
| 48 nreads_ += weight; | |
| 49 // We must have a positive nreads_ here. Handle | |
| 50 // any kind of overflow by setting nreads_ to | |
| 51 // some large-ish value. | |
| 52 if (nreads_ <= 0) nreads_ = 1000000; | |
| 53 ASSERT(is_read() & is_used()); | |
| 54 } | |
| 55 | |
| 56 | |
| 57 void UseCount::RecordWrite(int weight) { | |
| 58 ASSERT(weight > 0); | |
| 59 nwrites_ += weight; | |
| 60 // We must have a positive nwrites_ here. Handle | |
| 61 // any kind of overflow by setting nwrites_ to | |
| 62 // some large-ish value. | |
| 63 if (nwrites_ <= 0) nwrites_ = 1000000; | |
| 64 ASSERT(is_written() && is_used()); | |
| 65 } | |
| 66 | |
| 67 | |
| 68 void UseCount::RecordAccess(int weight) { | |
| 69 RecordRead(weight); | |
| 70 RecordWrite(weight); | |
| 71 } | |
| 72 | |
| 73 | |
| 74 void UseCount::RecordUses(UseCount* uses) { | |
| 75 if (uses->nreads() > 0) RecordRead(uses->nreads()); | |
| 76 if (uses->nwrites() > 0) RecordWrite(uses->nwrites()); | |
| 77 } | |
| 78 | |
| 79 | |
| 80 #ifdef DEBUG | |
| 81 void UseCount::Print() { | |
| 82 // PrintF("r = %d, w = %d", nreads_, nwrites_); | |
| 83 PrintF("%du = %dr + %dw", nuses(), nreads(), nwrites()); | |
| 84 } | |
| 85 #endif | |
| 86 | |
| 87 | |
| 88 // ---------------------------------------------------------------------------- | |
| 89 // Implementation StaticType. | 38 // Implementation StaticType. |
| 90 | 39 |
| 91 | 40 |
| 92 const char* StaticType::Type2String(StaticType* type) { | 41 const char* StaticType::Type2String(StaticType* type) { |
| 93 switch (type->kind_) { | 42 switch (type->kind_) { |
| 94 case UNKNOWN: | 43 case UNKNOWN: |
| 95 return "UNKNOWN"; | 44 return "UNKNOWN"; |
| 96 case LIKELY_SMI: | 45 case LIKELY_SMI: |
| 97 return "LIKELY_SMI"; | 46 return "LIKELY_SMI"; |
| 98 default: | 47 default: |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 Mode mode, | 90 Mode mode, |
| 142 bool is_valid_LHS, | 91 bool is_valid_LHS, |
| 143 Kind kind) | 92 Kind kind) |
| 144 : scope_(scope), | 93 : scope_(scope), |
| 145 name_(name), | 94 name_(name), |
| 146 mode_(mode), | 95 mode_(mode), |
| 147 is_valid_LHS_(is_valid_LHS), | 96 is_valid_LHS_(is_valid_LHS), |
| 148 kind_(kind), | 97 kind_(kind), |
| 149 local_if_not_shadowed_(NULL), | 98 local_if_not_shadowed_(NULL), |
| 150 is_accessed_from_inner_scope_(false), | 99 is_accessed_from_inner_scope_(false), |
| 100 is_used_(false), |
| 151 rewrite_(NULL) { | 101 rewrite_(NULL) { |
| 152 // names must be canonicalized for fast equality checks | 102 // names must be canonicalized for fast equality checks |
| 153 ASSERT(name->IsSymbol()); | 103 ASSERT(name->IsSymbol()); |
| 154 } | 104 } |
| 155 | 105 |
| 156 | 106 |
| 157 bool Variable::is_global() const { | 107 bool Variable::is_global() const { |
| 158 // Temporaries are never global, they must always be allocated in the | 108 // Temporaries are never global, they must always be allocated in the |
| 159 // activation frame. | 109 // activation frame. |
| 160 return mode_ != TEMPORARY && scope_ != NULL && scope_->is_global_scope(); | 110 return mode_ != TEMPORARY && scope_ != NULL && scope_->is_global_scope(); |
| 161 } | 111 } |
| 162 | 112 |
| 163 } } // namespace v8::internal | 113 } } // namespace v8::internal |
| OLD | NEW |