11cb0ef41Sopenharmony_ci#!/usr/bin/env python
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci#
41cb0ef41Sopenharmony_ci# Copyright 2012 the V8 project authors. All rights reserved.
51cb0ef41Sopenharmony_ci# Redistribution and use in source and binary forms, with or without
61cb0ef41Sopenharmony_ci# modification, are permitted provided that the following conditions are
71cb0ef41Sopenharmony_ci# met:
81cb0ef41Sopenharmony_ci#
91cb0ef41Sopenharmony_ci#     * Redistributions of source code must retain the above copyright
101cb0ef41Sopenharmony_ci#       notice, this list of conditions and the following disclaimer.
111cb0ef41Sopenharmony_ci#     * Redistributions in binary form must reproduce the above
121cb0ef41Sopenharmony_ci#       copyright notice, this list of conditions and the following
131cb0ef41Sopenharmony_ci#       disclaimer in the documentation and/or other materials provided
141cb0ef41Sopenharmony_ci#       with the distribution.
151cb0ef41Sopenharmony_ci#     * Neither the name of Google Inc. nor the names of its
161cb0ef41Sopenharmony_ci#       contributors may be used to endorse or promote products derived
171cb0ef41Sopenharmony_ci#       from this software without specific prior written permission.
181cb0ef41Sopenharmony_ci#
191cb0ef41Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
201cb0ef41Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
211cb0ef41Sopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
221cb0ef41Sopenharmony_ci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
231cb0ef41Sopenharmony_ci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
241cb0ef41Sopenharmony_ci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
251cb0ef41Sopenharmony_ci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
261cb0ef41Sopenharmony_ci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
271cb0ef41Sopenharmony_ci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
281cb0ef41Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
291cb0ef41Sopenharmony_ci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
301cb0ef41Sopenharmony_ci#
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci#
331cb0ef41Sopenharmony_ci# Emits a C++ file to be compiled and linked into libv8 to support postmortem
341cb0ef41Sopenharmony_ci# debugging tools.  Most importantly, this tool emits constants describing V8
351cb0ef41Sopenharmony_ci# internals:
361cb0ef41Sopenharmony_ci#
371cb0ef41Sopenharmony_ci#    v8dbg_type_CLASS__TYPE = VALUE             Describes class type values
381cb0ef41Sopenharmony_ci#    v8dbg_class_CLASS__FIELD__TYPE = OFFSET    Describes class fields
391cb0ef41Sopenharmony_ci#    v8dbg_parent_CLASS__PARENT                 Describes class hierarchy
401cb0ef41Sopenharmony_ci#    v8dbg_frametype_NAME = VALUE               Describes stack frame values
411cb0ef41Sopenharmony_ci#    v8dbg_off_fp_NAME = OFFSET                 Frame pointer offsets
421cb0ef41Sopenharmony_ci#    v8dbg_prop_NAME = OFFSET                   Object property offsets
431cb0ef41Sopenharmony_ci#    v8dbg_NAME = VALUE                         Miscellaneous values
441cb0ef41Sopenharmony_ci#
451cb0ef41Sopenharmony_ci# These constants are declared as global integers so that they'll be present in
461cb0ef41Sopenharmony_ci# the generated libv8 binary.
471cb0ef41Sopenharmony_ci#
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci# for py2/py3 compatibility
501cb0ef41Sopenharmony_cifrom __future__ import print_function
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_ciimport io
531cb0ef41Sopenharmony_ciimport re
541cb0ef41Sopenharmony_ciimport sys
551cb0ef41Sopenharmony_ci
561cb0ef41Sopenharmony_ci#
571cb0ef41Sopenharmony_ci# Miscellaneous constants such as tags and masks used for object identification,
581cb0ef41Sopenharmony_ci# enumeration values used as indexes in internal tables, etc..
591cb0ef41Sopenharmony_ci#
601cb0ef41Sopenharmony_ciconsts_misc = [
611cb0ef41Sopenharmony_ci    { 'name': 'FirstNonstringType',     'value': 'FIRST_NONSTRING_TYPE' },
621cb0ef41Sopenharmony_ci    { 'name': 'APIObjectType',    'value': 'JS_API_OBJECT_TYPE' },
631cb0ef41Sopenharmony_ci    { 'name': 'SpecialAPIObjectType',   'value': 'JS_SPECIAL_API_OBJECT_TYPE' },
641cb0ef41Sopenharmony_ci
651cb0ef41Sopenharmony_ci    { 'name': 'FirstContextType',     'value': 'FIRST_CONTEXT_TYPE' },
661cb0ef41Sopenharmony_ci    { 'name': 'LastContextType',     'value': 'LAST_CONTEXT_TYPE' },
671cb0ef41Sopenharmony_ci
681cb0ef41Sopenharmony_ci    { 'name': 'IsNotStringMask',  'value': 'kIsNotStringMask' },
691cb0ef41Sopenharmony_ci    { 'name': 'StringTag',        'value': 'kStringTag' },
701cb0ef41Sopenharmony_ci
711cb0ef41Sopenharmony_ci    { 'name': 'StringEncodingMask',     'value': 'kStringEncodingMask' },
721cb0ef41Sopenharmony_ci    { 'name': 'TwoByteStringTag',       'value': 'kTwoByteStringTag' },
731cb0ef41Sopenharmony_ci    { 'name': 'OneByteStringTag',       'value': 'kOneByteStringTag' },
741cb0ef41Sopenharmony_ci
751cb0ef41Sopenharmony_ci    { 'name': 'StringRepresentationMask',
761cb0ef41Sopenharmony_ci  'value': 'kStringRepresentationMask' },
771cb0ef41Sopenharmony_ci    { 'name': 'SeqStringTag',     'value': 'kSeqStringTag' },
781cb0ef41Sopenharmony_ci    { 'name': 'ConsStringTag',    'value': 'kConsStringTag' },
791cb0ef41Sopenharmony_ci    { 'name': 'ExternalStringTag',      'value': 'kExternalStringTag' },
801cb0ef41Sopenharmony_ci    { 'name': 'SlicedStringTag',  'value': 'kSlicedStringTag' },
811cb0ef41Sopenharmony_ci    { 'name': 'ThinStringTag',    'value': 'kThinStringTag' },
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci    { 'name': 'HeapObjectTag',    'value': 'kHeapObjectTag' },
841cb0ef41Sopenharmony_ci    { 'name': 'HeapObjectTagMask',      'value': 'kHeapObjectTagMask' },
851cb0ef41Sopenharmony_ci    { 'name': 'SmiTag',     'value': 'kSmiTag' },
861cb0ef41Sopenharmony_ci    { 'name': 'SmiTagMask',       'value': 'kSmiTagMask' },
871cb0ef41Sopenharmony_ci    { 'name': 'SmiValueShift',    'value': 'kSmiTagSize' },
881cb0ef41Sopenharmony_ci    { 'name': 'SmiShiftSize',     'value': 'kSmiShiftSize' },
891cb0ef41Sopenharmony_ci    { 'name': 'SystemPointerSize',      'value': 'kSystemPointerSize' },
901cb0ef41Sopenharmony_ci    { 'name': 'SystemPointerSizeLog2',  'value': 'kSystemPointerSizeLog2' },
911cb0ef41Sopenharmony_ci    { 'name': 'TaggedSize',       'value': 'kTaggedSize' },
921cb0ef41Sopenharmony_ci    { 'name': 'TaggedSizeLog2',   'value': 'kTaggedSizeLog2' },
931cb0ef41Sopenharmony_ci
941cb0ef41Sopenharmony_ci    { 'name': 'CodeKindFieldMask',      'value': 'Code::KindField::kMask' },
951cb0ef41Sopenharmony_ci    { 'name': 'CodeKindFieldShift',     'value': 'Code::KindField::kShift' },
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci    { 'name': 'CodeKindBytecodeHandler',
981cb0ef41Sopenharmony_ci      'value': 'static_cast<int>(CodeKind::BYTECODE_HANDLER)' },
991cb0ef41Sopenharmony_ci    { 'name': 'CodeKindInterpretedFunction',
1001cb0ef41Sopenharmony_ci      'value': 'static_cast<int>(CodeKind::INTERPRETED_FUNCTION)' },
1011cb0ef41Sopenharmony_ci    { 'name': 'CodeKindBaseline',
1021cb0ef41Sopenharmony_ci      'value': 'static_cast<int>(CodeKind::BASELINE)' },
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci    { 'name': 'OddballFalse',     'value': 'Oddball::kFalse' },
1051cb0ef41Sopenharmony_ci    { 'name': 'OddballTrue',      'value': 'Oddball::kTrue' },
1061cb0ef41Sopenharmony_ci    { 'name': 'OddballTheHole',   'value': 'Oddball::kTheHole' },
1071cb0ef41Sopenharmony_ci    { 'name': 'OddballNull',      'value': 'Oddball::kNull' },
1081cb0ef41Sopenharmony_ci    { 'name': 'OddballArgumentsMarker', 'value': 'Oddball::kArgumentsMarker' },
1091cb0ef41Sopenharmony_ci    { 'name': 'OddballUndefined',       'value': 'Oddball::kUndefined' },
1101cb0ef41Sopenharmony_ci    { 'name': 'OddballUninitialized',   'value': 'Oddball::kUninitialized' },
1111cb0ef41Sopenharmony_ci    { 'name': 'OddballOther',     'value': 'Oddball::kOther' },
1121cb0ef41Sopenharmony_ci    { 'name': 'OddballException',       'value': 'Oddball::kException' },
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ci    { 'name': 'ContextRegister',  'value': 'kContextRegister.code()' },
1151cb0ef41Sopenharmony_ci    { 'name': 'ReturnRegister0',  'value': 'kReturnRegister0.code()' },
1161cb0ef41Sopenharmony_ci    { 'name': 'JSFunctionRegister',     'value': 'kJSFunctionRegister.code()' },
1171cb0ef41Sopenharmony_ci    { 'name': 'InterpreterBytecodeOffsetRegister',
1181cb0ef41Sopenharmony_ci      'value': 'kInterpreterBytecodeOffsetRegister.code()' },
1191cb0ef41Sopenharmony_ci    { 'name': 'InterpreterBytecodeArrayRegister',
1201cb0ef41Sopenharmony_ci      'value': 'kInterpreterBytecodeArrayRegister.code()' },
1211cb0ef41Sopenharmony_ci    { 'name': 'RuntimeCallFunctionRegister',
1221cb0ef41Sopenharmony_ci      'value': 'kRuntimeCallFunctionRegister.code()' },
1231cb0ef41Sopenharmony_ci
1241cb0ef41Sopenharmony_ci    { 'name': 'prop_kind_Data',
1251cb0ef41Sopenharmony_ci  'value': 'static_cast<int>(PropertyKind::kData)' },
1261cb0ef41Sopenharmony_ci    { 'name': 'prop_kind_Accessor',
1271cb0ef41Sopenharmony_ci  'value': 'static_cast<int>(PropertyKind::kAccessor)' },
1281cb0ef41Sopenharmony_ci    { 'name': 'prop_kind_mask',
1291cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::KindField::kMask' },
1301cb0ef41Sopenharmony_ci    { 'name': 'prop_location_Descriptor',
1311cb0ef41Sopenharmony_ci  'value': 'static_cast<int>(PropertyLocation::kDescriptor)' },
1321cb0ef41Sopenharmony_ci    { 'name': 'prop_location_Field',
1331cb0ef41Sopenharmony_ci  'value': 'static_cast<int>(PropertyLocation::kField)' },
1341cb0ef41Sopenharmony_ci    { 'name': 'prop_location_mask',
1351cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::LocationField::kMask' },
1361cb0ef41Sopenharmony_ci    { 'name': 'prop_location_shift',
1371cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::LocationField::kShift' },
1381cb0ef41Sopenharmony_ci    { 'name': 'prop_attributes_NONE', 'value': 'NONE' },
1391cb0ef41Sopenharmony_ci    { 'name': 'prop_attributes_READ_ONLY', 'value': 'READ_ONLY' },
1401cb0ef41Sopenharmony_ci    { 'name': 'prop_attributes_DONT_ENUM', 'value': 'DONT_ENUM' },
1411cb0ef41Sopenharmony_ci    { 'name': 'prop_attributes_DONT_DELETE', 'value': 'DONT_DELETE' },
1421cb0ef41Sopenharmony_ci    { 'name': 'prop_attributes_mask',
1431cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::AttributesField::kMask' },
1441cb0ef41Sopenharmony_ci    { 'name': 'prop_attributes_shift',
1451cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::AttributesField::kShift' },
1461cb0ef41Sopenharmony_ci    { 'name': 'prop_index_mask',
1471cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::FieldIndexField::kMask' },
1481cb0ef41Sopenharmony_ci    { 'name': 'prop_index_shift',
1491cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::FieldIndexField::kShift' },
1501cb0ef41Sopenharmony_ci    { 'name': 'prop_representation_mask',
1511cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::RepresentationField::kMask' },
1521cb0ef41Sopenharmony_ci    { 'name': 'prop_representation_shift',
1531cb0ef41Sopenharmony_ci  'value': 'PropertyDetails::RepresentationField::kShift' },
1541cb0ef41Sopenharmony_ci    { 'name': 'prop_representation_smi',
1551cb0ef41Sopenharmony_ci  'value': 'Representation::Kind::kSmi' },
1561cb0ef41Sopenharmony_ci    { 'name': 'prop_representation_double',
1571cb0ef41Sopenharmony_ci  'value': 'Representation::Kind::kDouble' },
1581cb0ef41Sopenharmony_ci    { 'name': 'prop_representation_heapobject',
1591cb0ef41Sopenharmony_ci  'value': 'Representation::Kind::kHeapObject' },
1601cb0ef41Sopenharmony_ci    { 'name': 'prop_representation_tagged',
1611cb0ef41Sopenharmony_ci  'value': 'Representation::Kind::kTagged' },
1621cb0ef41Sopenharmony_ci
1631cb0ef41Sopenharmony_ci    { 'name': 'prop_desc_key',
1641cb0ef41Sopenharmony_ci  'value': 'DescriptorArray::kEntryKeyIndex' },
1651cb0ef41Sopenharmony_ci    { 'name': 'prop_desc_details',
1661cb0ef41Sopenharmony_ci  'value': 'DescriptorArray::kEntryDetailsIndex' },
1671cb0ef41Sopenharmony_ci    { 'name': 'prop_desc_value',
1681cb0ef41Sopenharmony_ci  'value': 'DescriptorArray::kEntryValueIndex' },
1691cb0ef41Sopenharmony_ci    { 'name': 'prop_desc_size',
1701cb0ef41Sopenharmony_ci  'value': 'DescriptorArray::kEntrySize' },
1711cb0ef41Sopenharmony_ci
1721cb0ef41Sopenharmony_ci    { 'name': 'elements_fast_holey_elements',
1731cb0ef41Sopenharmony_ci  'value': 'HOLEY_ELEMENTS' },
1741cb0ef41Sopenharmony_ci    { 'name': 'elements_fast_elements',
1751cb0ef41Sopenharmony_ci  'value': 'PACKED_ELEMENTS' },
1761cb0ef41Sopenharmony_ci    { 'name': 'elements_dictionary_elements',
1771cb0ef41Sopenharmony_ci  'value': 'DICTIONARY_ELEMENTS' },
1781cb0ef41Sopenharmony_ci
1791cb0ef41Sopenharmony_ci    { 'name': 'bit_field2_elements_kind_mask',
1801cb0ef41Sopenharmony_ci  'value': 'Map::Bits2::ElementsKindBits::kMask' },
1811cb0ef41Sopenharmony_ci    { 'name': 'bit_field2_elements_kind_shift',
1821cb0ef41Sopenharmony_ci  'value': 'Map::Bits2::ElementsKindBits::kShift' },
1831cb0ef41Sopenharmony_ci    { 'name': 'bit_field3_is_dictionary_map_shift',
1841cb0ef41Sopenharmony_ci  'value': 'Map::Bits3::IsDictionaryMapBit::kShift' },
1851cb0ef41Sopenharmony_ci    { 'name': 'bit_field3_number_of_own_descriptors_mask',
1861cb0ef41Sopenharmony_ci  'value': 'Map::Bits3::NumberOfOwnDescriptorsBits::kMask' },
1871cb0ef41Sopenharmony_ci    { 'name': 'bit_field3_number_of_own_descriptors_shift',
1881cb0ef41Sopenharmony_ci  'value': 'Map::Bits3::NumberOfOwnDescriptorsBits::kShift' },
1891cb0ef41Sopenharmony_ci    { 'name': 'class_Map__instance_descriptors_offset',
1901cb0ef41Sopenharmony_ci  'value': 'Map::kInstanceDescriptorsOffset' },
1911cb0ef41Sopenharmony_ci
1921cb0ef41Sopenharmony_ci    { 'name': 'off_fp_context_or_frame_type',
1931cb0ef41Sopenharmony_ci  'value': 'CommonFrameConstants::kContextOrFrameTypeOffset'},
1941cb0ef41Sopenharmony_ci    { 'name': 'off_fp_context',
1951cb0ef41Sopenharmony_ci  'value': 'StandardFrameConstants::kContextOffset' },
1961cb0ef41Sopenharmony_ci    { 'name': 'off_fp_constant_pool',
1971cb0ef41Sopenharmony_ci  'value': 'StandardFrameConstants::kConstantPoolOffset' },
1981cb0ef41Sopenharmony_ci    { 'name': 'off_fp_function',
1991cb0ef41Sopenharmony_ci  'value': 'StandardFrameConstants::kFunctionOffset' },
2001cb0ef41Sopenharmony_ci    { 'name': 'off_fp_args',
2011cb0ef41Sopenharmony_ci  'value': 'StandardFrameConstants::kFixedFrameSizeAboveFp' },
2021cb0ef41Sopenharmony_ci    { 'name': 'off_fp_bytecode_array',
2031cb0ef41Sopenharmony_ci  'value': 'UnoptimizedFrameConstants::kBytecodeArrayFromFp' },
2041cb0ef41Sopenharmony_ci    { 'name': 'off_fp_bytecode_offset',
2051cb0ef41Sopenharmony_ci  'value': 'UnoptimizedFrameConstants::kBytecodeOffsetOrFeedbackVectorFromFp' },
2061cb0ef41Sopenharmony_ci
2071cb0ef41Sopenharmony_ci    { 'name': 'scopeinfo_idx_nparams',
2081cb0ef41Sopenharmony_ci  'value': 'ScopeInfo::kParameterCount' },
2091cb0ef41Sopenharmony_ci    { 'name': 'scopeinfo_idx_ncontextlocals',
2101cb0ef41Sopenharmony_ci  'value': 'ScopeInfo::kContextLocalCount' },
2111cb0ef41Sopenharmony_ci    { 'name': 'scopeinfo_idx_first_vars',
2121cb0ef41Sopenharmony_ci  'value': 'ScopeInfo::kVariablePartIndex' },
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci    { 'name': 'jsarray_buffer_was_detached_mask',
2151cb0ef41Sopenharmony_ci  'value': 'JSArrayBuffer::WasDetachedBit::kMask' },
2161cb0ef41Sopenharmony_ci    { 'name': 'jsarray_buffer_was_detached_shift',
2171cb0ef41Sopenharmony_ci  'value': 'JSArrayBuffer::WasDetachedBit::kShift' },
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci    { 'name': 'context_idx_scope_info',
2201cb0ef41Sopenharmony_ci  'value': 'Context::SCOPE_INFO_INDEX' },
2211cb0ef41Sopenharmony_ci    { 'name': 'context_idx_prev',
2221cb0ef41Sopenharmony_ci  'value': 'Context::PREVIOUS_INDEX' },
2231cb0ef41Sopenharmony_ci    { 'name': 'context_min_slots',
2241cb0ef41Sopenharmony_ci  'value': 'Context::MIN_CONTEXT_SLOTS' },
2251cb0ef41Sopenharmony_ci    { 'name': 'native_context_embedder_data_offset',
2261cb0ef41Sopenharmony_ci  'value': 'Internals::kNativeContextEmbedderDataOffset' },
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_ci
2291cb0ef41Sopenharmony_ci    { 'name': 'namedictionaryshape_prefix_size',
2301cb0ef41Sopenharmony_ci  'value': 'NameDictionaryShape::kPrefixSize' },
2311cb0ef41Sopenharmony_ci    { 'name': 'namedictionaryshape_entry_size',
2321cb0ef41Sopenharmony_ci  'value': 'NameDictionaryShape::kEntrySize' },
2331cb0ef41Sopenharmony_ci    { 'name': 'globaldictionaryshape_entry_size',
2341cb0ef41Sopenharmony_ci  'value': 'GlobalDictionaryShape::kEntrySize' },
2351cb0ef41Sopenharmony_ci
2361cb0ef41Sopenharmony_ci    { 'name': 'namedictionary_prefix_start_index',
2371cb0ef41Sopenharmony_ci  'value': 'NameDictionary::kPrefixStartIndex' },
2381cb0ef41Sopenharmony_ci
2391cb0ef41Sopenharmony_ci    { 'name': 'numberdictionaryshape_prefix_size',
2401cb0ef41Sopenharmony_ci  'value': 'NumberDictionaryShape::kPrefixSize' },
2411cb0ef41Sopenharmony_ci    { 'name': 'numberdictionaryshape_entry_size',
2421cb0ef41Sopenharmony_ci  'value': 'NumberDictionaryShape::kEntrySize' },
2431cb0ef41Sopenharmony_ci
2441cb0ef41Sopenharmony_ci    { 'name': 'simplenumberdictionaryshape_prefix_size',
2451cb0ef41Sopenharmony_ci  'value': 'SimpleNumberDictionaryShape::kPrefixSize' },
2461cb0ef41Sopenharmony_ci    { 'name': 'simplenumberdictionaryshape_entry_size',
2471cb0ef41Sopenharmony_ci  'value': 'SimpleNumberDictionaryShape::kEntrySize' },
2481cb0ef41Sopenharmony_ci
2491cb0ef41Sopenharmony_ci    { 'name': 'type_JSError__JS_ERROR_TYPE', 'value': 'JS_ERROR_TYPE' },
2501cb0ef41Sopenharmony_ci];
2511cb0ef41Sopenharmony_ci
2521cb0ef41Sopenharmony_ci#
2531cb0ef41Sopenharmony_ci# The following useful fields are missing accessors, so we define fake ones.
2541cb0ef41Sopenharmony_ci# Please note that extra accessors should _only_ be added to expose offsets that
2551cb0ef41Sopenharmony_ci# can be used to access actual V8 objects' properties. They should not be added
2561cb0ef41Sopenharmony_ci# for exposing other values. For instance, enumeration values or class'
2571cb0ef41Sopenharmony_ci# constants should be exposed by adding an entry in the "consts_misc" table, not
2581cb0ef41Sopenharmony_ci# in this "extras_accessors" table.
2591cb0ef41Sopenharmony_ci#
2601cb0ef41Sopenharmony_ciextras_accessors = [
2611cb0ef41Sopenharmony_ci    'JSFunction, context, Context, kContextOffset',
2621cb0ef41Sopenharmony_ci    'JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset',
2631cb0ef41Sopenharmony_ci    'HeapObject, map, Map, kMapOffset',
2641cb0ef41Sopenharmony_ci    'JSObject, elements, Object, kElementsOffset',
2651cb0ef41Sopenharmony_ci    'JSObject, internal_fields, uintptr_t, kHeaderSize',
2661cb0ef41Sopenharmony_ci    'FixedArray, data, uintptr_t, kHeaderSize',
2671cb0ef41Sopenharmony_ci    'BytecodeArray, data, uintptr_t, kHeaderSize',
2681cb0ef41Sopenharmony_ci    'JSArrayBuffer, backing_store, uintptr_t, kBackingStoreOffset',
2691cb0ef41Sopenharmony_ci    'JSArrayBuffer, byte_length, size_t, kByteLengthOffset',
2701cb0ef41Sopenharmony_ci    'JSArrayBufferView, byte_length, size_t, kByteLengthOffset',
2711cb0ef41Sopenharmony_ci    'JSArrayBufferView, byte_offset, size_t, kByteOffsetOffset',
2721cb0ef41Sopenharmony_ci    'JSDate, value, Object, kValueOffset',
2731cb0ef41Sopenharmony_ci    'JSRegExp, source, Object, kSourceOffset',
2741cb0ef41Sopenharmony_ci    'JSTypedArray, external_pointer, uintptr_t, kExternalPointerOffset',
2751cb0ef41Sopenharmony_ci    'JSTypedArray, length, Object, kLengthOffset',
2761cb0ef41Sopenharmony_ci    'Map, instance_size_in_words, char, kInstanceSizeInWordsOffset',
2771cb0ef41Sopenharmony_ci    'Map, inobject_properties_start_or_constructor_function_index, char, kInobjectPropertiesStartOrConstructorFunctionIndexOffset',
2781cb0ef41Sopenharmony_ci    'Map, instance_type, uint16_t, kInstanceTypeOffset',
2791cb0ef41Sopenharmony_ci    'Map, bit_field, char, kBitFieldOffset',
2801cb0ef41Sopenharmony_ci    'Map, bit_field2, char, kBitField2Offset',
2811cb0ef41Sopenharmony_ci    'Map, bit_field3, int, kBitField3Offset',
2821cb0ef41Sopenharmony_ci    'Map, prototype, Object, kPrototypeOffset',
2831cb0ef41Sopenharmony_ci    'Oddball, kind_offset, int, kKindOffset',
2841cb0ef41Sopenharmony_ci    'HeapNumber, value, double, kValueOffset',
2851cb0ef41Sopenharmony_ci    'ExternalString, resource, Object, kResourceOffset',
2861cb0ef41Sopenharmony_ci    'SeqOneByteString, chars, char, kHeaderSize',
2871cb0ef41Sopenharmony_ci    'SeqTwoByteString, chars, char, kHeaderSize',
2881cb0ef41Sopenharmony_ci    'UncompiledData, inferred_name, String, kInferredNameOffset',
2891cb0ef41Sopenharmony_ci    'UncompiledData, start_position, int32_t, kStartPositionOffset',
2901cb0ef41Sopenharmony_ci    'UncompiledData, end_position, int32_t, kEndPositionOffset',
2911cb0ef41Sopenharmony_ci    'Script, source, Object, kSourceOffset',
2921cb0ef41Sopenharmony_ci    'Script, name, Object, kNameOffset',
2931cb0ef41Sopenharmony_ci    'Script, line_ends, Object, kLineEndsOffset',
2941cb0ef41Sopenharmony_ci    'SharedFunctionInfo, raw_function_token_offset, int16_t, kFunctionTokenOffsetOffset',
2951cb0ef41Sopenharmony_ci    'SharedFunctionInfo, internal_formal_parameter_count, uint16_t, kFormalParameterCountOffset',
2961cb0ef41Sopenharmony_ci    'SharedFunctionInfo, flags, int, kFlagsOffset',
2971cb0ef41Sopenharmony_ci    'SharedFunctionInfo, length, uint16_t, kLengthOffset',
2981cb0ef41Sopenharmony_ci    'SlicedString, parent, String, kParentOffset',
2991cb0ef41Sopenharmony_ci    'Code, flags, uint32_t, kFlagsOffset',
3001cb0ef41Sopenharmony_ci    'Code, instruction_start, uintptr_t, kHeaderSize',
3011cb0ef41Sopenharmony_ci    'Code, instruction_size, int, kInstructionSizeOffset',
3021cb0ef41Sopenharmony_ci    'String, length, int32_t, kLengthOffset',
3031cb0ef41Sopenharmony_ci    'DescriptorArray, header_size, uintptr_t, kHeaderSize',
3041cb0ef41Sopenharmony_ci    'ConsString, first, String, kFirstOffset',
3051cb0ef41Sopenharmony_ci    'ConsString, second, String, kSecondOffset',
3061cb0ef41Sopenharmony_ci    'SlicedString, offset, SMI, kOffsetOffset',
3071cb0ef41Sopenharmony_ci    'ThinString, actual, String, kActualOffset',
3081cb0ef41Sopenharmony_ci    'Symbol, name, Object, kDescriptionOffset',
3091cb0ef41Sopenharmony_ci    'FixedArrayBase, length, SMI, kLengthOffset',
3101cb0ef41Sopenharmony_ci];
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci#
3131cb0ef41Sopenharmony_ci# The following is a whitelist of classes we expect to find when scanning the
3141cb0ef41Sopenharmony_ci# source code. This list is not exhaustive, but it's still useful to identify
3151cb0ef41Sopenharmony_ci# when this script gets out of sync with the source. See load_objects().
3161cb0ef41Sopenharmony_ci#
3171cb0ef41Sopenharmony_ciexpected_classes = [
3181cb0ef41Sopenharmony_ci    'ConsString', 'FixedArray', 'HeapNumber', 'JSArray', 'JSFunction',
3191cb0ef41Sopenharmony_ci    'JSObject', 'JSRegExp', 'JSPrimitiveWrapper', 'Map', 'Oddball', 'Script',
3201cb0ef41Sopenharmony_ci    'SeqOneByteString', 'SharedFunctionInfo', 'ScopeInfo', 'JSPromise',
3211cb0ef41Sopenharmony_ci    'DescriptorArray'
3221cb0ef41Sopenharmony_ci];
3231cb0ef41Sopenharmony_ci
3241cb0ef41Sopenharmony_ci
3251cb0ef41Sopenharmony_ci#
3261cb0ef41Sopenharmony_ci# The following structures store high-level representations of the structures
3271cb0ef41Sopenharmony_ci# for which we're going to emit descriptive constants.
3281cb0ef41Sopenharmony_ci#
3291cb0ef41Sopenharmony_citypes = {};       # set of all type names
3301cb0ef41Sopenharmony_citypeclasses = {};       # maps type names to corresponding class names
3311cb0ef41Sopenharmony_ciklasses = {};     # known classes, including parents
3321cb0ef41Sopenharmony_cifields = [];      # field declarations
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_ciheader = '''
3351cb0ef41Sopenharmony_ci/*
3361cb0ef41Sopenharmony_ci * This file is generated by %s.  Do not edit directly.
3371cb0ef41Sopenharmony_ci */
3381cb0ef41Sopenharmony_ci
3391cb0ef41Sopenharmony_ci#include "src/init/v8.h"
3401cb0ef41Sopenharmony_ci#include "src/codegen/register.h"
3411cb0ef41Sopenharmony_ci#include "src/execution/frames.h"
3421cb0ef41Sopenharmony_ci#include "src/execution/frames-inl.h" /* for architecture-specific frame constants */
3431cb0ef41Sopenharmony_ci#include "src/objects/contexts.h"
3441cb0ef41Sopenharmony_ci#include "src/objects/objects.h"
3451cb0ef41Sopenharmony_ci#include "src/objects/data-handler.h"
3461cb0ef41Sopenharmony_ci#include "src/objects/js-promise.h"
3471cb0ef41Sopenharmony_ci#include "src/objects/js-regexp-string-iterator.h"
3481cb0ef41Sopenharmony_ci
3491cb0ef41Sopenharmony_cinamespace v8 {
3501cb0ef41Sopenharmony_cinamespace internal {
3511cb0ef41Sopenharmony_ci
3521cb0ef41Sopenharmony_ciextern "C" {
3531cb0ef41Sopenharmony_ci
3541cb0ef41Sopenharmony_ci/* stack frame constants */
3551cb0ef41Sopenharmony_ci#define FRAME_CONST(value, klass)       \
3561cb0ef41Sopenharmony_ci    V8_EXPORT int v8dbg_frametype_##klass = StackFrame::value;
3571cb0ef41Sopenharmony_ci
3581cb0ef41Sopenharmony_ciSTACK_FRAME_TYPE_LIST(FRAME_CONST)
3591cb0ef41Sopenharmony_ci
3601cb0ef41Sopenharmony_ci#undef FRAME_CONST
3611cb0ef41Sopenharmony_ci
3621cb0ef41Sopenharmony_ci''' % sys.argv[0]
3631cb0ef41Sopenharmony_ci
3641cb0ef41Sopenharmony_cifooter = '''
3651cb0ef41Sopenharmony_ci}
3661cb0ef41Sopenharmony_ci
3671cb0ef41Sopenharmony_ci}
3681cb0ef41Sopenharmony_ci}
3691cb0ef41Sopenharmony_ci'''
3701cb0ef41Sopenharmony_ci
3711cb0ef41Sopenharmony_ci#
3721cb0ef41Sopenharmony_ci# Get the base class
3731cb0ef41Sopenharmony_ci#
3741cb0ef41Sopenharmony_cidef get_base_class(klass):
3751cb0ef41Sopenharmony_ci  if (klass == 'Object'):
3761cb0ef41Sopenharmony_ci    return klass;
3771cb0ef41Sopenharmony_ci
3781cb0ef41Sopenharmony_ci  if (not (klass in klasses)):
3791cb0ef41Sopenharmony_ci    return None;
3801cb0ef41Sopenharmony_ci
3811cb0ef41Sopenharmony_ci  k = klasses[klass];
3821cb0ef41Sopenharmony_ci
3831cb0ef41Sopenharmony_ci  return get_base_class(k['parent']);
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_ci#
3861cb0ef41Sopenharmony_ci# Loads class hierarchy and type information from "objects.h" etc.
3871cb0ef41Sopenharmony_ci#
3881cb0ef41Sopenharmony_cidef load_objects():
3891cb0ef41Sopenharmony_ci  #
3901cb0ef41Sopenharmony_ci  # Construct a dictionary for the classes we're sure should be present.
3911cb0ef41Sopenharmony_ci  #
3921cb0ef41Sopenharmony_ci  checktypes = {};
3931cb0ef41Sopenharmony_ci  for klass in expected_classes:
3941cb0ef41Sopenharmony_ci    checktypes[klass] = True;
3951cb0ef41Sopenharmony_ci
3961cb0ef41Sopenharmony_ci
3971cb0ef41Sopenharmony_ci  for filename in sys.argv[2:]:
3981cb0ef41Sopenharmony_ci    if not filename.endswith("-inl.h"):
3991cb0ef41Sopenharmony_ci      load_objects_from_file(filename, checktypes)
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ci  if (len(checktypes) > 0):
4021cb0ef41Sopenharmony_ci    for klass in checktypes:
4031cb0ef41Sopenharmony_ci      print('error: expected class \"%s\" not found' % klass);
4041cb0ef41Sopenharmony_ci
4051cb0ef41Sopenharmony_ci    sys.exit(1);
4061cb0ef41Sopenharmony_ci
4071cb0ef41Sopenharmony_ci
4081cb0ef41Sopenharmony_cidef load_objects_from_file(objfilename, checktypes):
4091cb0ef41Sopenharmony_ci  objfile = io.open(objfilename, 'r', encoding='utf-8');
4101cb0ef41Sopenharmony_ci  in_insttype = False;
4111cb0ef41Sopenharmony_ci  in_torque_insttype = False
4121cb0ef41Sopenharmony_ci  in_torque_fulldef = False
4131cb0ef41Sopenharmony_ci
4141cb0ef41Sopenharmony_ci  typestr = '';
4151cb0ef41Sopenharmony_ci  torque_typestr = ''
4161cb0ef41Sopenharmony_ci  torque_fulldefstr = ''
4171cb0ef41Sopenharmony_ci  uncommented_file = ''
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ci  #
4201cb0ef41Sopenharmony_ci  # Iterate the header file line-by-line to collect type and class
4211cb0ef41Sopenharmony_ci  # information. For types, we accumulate a string representing the entire
4221cb0ef41Sopenharmony_ci  # InstanceType enum definition and parse it later because it's easier to
4231cb0ef41Sopenharmony_ci  # do so without the embedded newlines.
4241cb0ef41Sopenharmony_ci  #
4251cb0ef41Sopenharmony_ci  for line in objfile:
4261cb0ef41Sopenharmony_ci    if (line.startswith('enum InstanceType : uint16_t {')):
4271cb0ef41Sopenharmony_ci      in_insttype = True;
4281cb0ef41Sopenharmony_ci      continue;
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ci    if (line.startswith('#define TORQUE_ASSIGNED_INSTANCE_TYPE_LIST')):
4311cb0ef41Sopenharmony_ci      in_torque_insttype = True
4321cb0ef41Sopenharmony_ci      continue
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_ci    if (line.startswith('#define TORQUE_INSTANCE_CHECKERS_SINGLE_FULLY_DEFINED')):
4351cb0ef41Sopenharmony_ci      in_torque_fulldef = True
4361cb0ef41Sopenharmony_ci      continue
4371cb0ef41Sopenharmony_ci
4381cb0ef41Sopenharmony_ci    if (in_insttype and line.startswith('};')):
4391cb0ef41Sopenharmony_ci      in_insttype = False;
4401cb0ef41Sopenharmony_ci      continue;
4411cb0ef41Sopenharmony_ci
4421cb0ef41Sopenharmony_ci    if (in_torque_insttype and (not line or line.isspace())):
4431cb0ef41Sopenharmony_ci      in_torque_insttype = False
4441cb0ef41Sopenharmony_ci      continue
4451cb0ef41Sopenharmony_ci
4461cb0ef41Sopenharmony_ci    if (in_torque_fulldef and (not line or line.isspace())):
4471cb0ef41Sopenharmony_ci      in_torque_fulldef = False
4481cb0ef41Sopenharmony_ci      continue
4491cb0ef41Sopenharmony_ci
4501cb0ef41Sopenharmony_ci    pre = line.strip()
4511cb0ef41Sopenharmony_ci    line = re.sub('// .*', '', line.strip());
4521cb0ef41Sopenharmony_ci
4531cb0ef41Sopenharmony_ci    if (in_insttype):
4541cb0ef41Sopenharmony_ci      typestr += line;
4551cb0ef41Sopenharmony_ci      continue;
4561cb0ef41Sopenharmony_ci
4571cb0ef41Sopenharmony_ci    if (in_torque_insttype):
4581cb0ef41Sopenharmony_ci      torque_typestr += line
4591cb0ef41Sopenharmony_ci      continue
4601cb0ef41Sopenharmony_ci
4611cb0ef41Sopenharmony_ci    if (in_torque_fulldef):
4621cb0ef41Sopenharmony_ci      torque_fulldefstr += line
4631cb0ef41Sopenharmony_ci      continue
4641cb0ef41Sopenharmony_ci
4651cb0ef41Sopenharmony_ci    uncommented_file += '\n' + line
4661cb0ef41Sopenharmony_ci
4671cb0ef41Sopenharmony_ci  for match in re.finditer(r'\nclass(?:\s+V8_EXPORT(?:_PRIVATE)?)?'
4681cb0ef41Sopenharmony_ci         r'\s+(\w[^:;]*)'
4691cb0ef41Sopenharmony_ci         r'(?:: public (\w[^{]*))?\s*{\s*',
4701cb0ef41Sopenharmony_ci         uncommented_file):
4711cb0ef41Sopenharmony_ci    klass = match.group(1).strip();
4721cb0ef41Sopenharmony_ci    pklass = match.group(2);
4731cb0ef41Sopenharmony_ci    if (pklass):
4741cb0ef41Sopenharmony_ci      # Check for generated Torque class.
4751cb0ef41Sopenharmony_ci      gen_match = re.match(
4761cb0ef41Sopenharmony_ci          r'TorqueGenerated\w+\s*<\s*\w+,\s*(\w+)\s*>',
4771cb0ef41Sopenharmony_ci          pklass)
4781cb0ef41Sopenharmony_ci      if (gen_match):
4791cb0ef41Sopenharmony_ci        pklass = gen_match.group(1)
4801cb0ef41Sopenharmony_ci      # Strip potential template arguments from parent
4811cb0ef41Sopenharmony_ci      # class.
4821cb0ef41Sopenharmony_ci      match = re.match(r'(\w+)(<.*>)?', pklass.strip());
4831cb0ef41Sopenharmony_ci      pklass = match.group(1).strip();
4841cb0ef41Sopenharmony_ci    klasses[klass] = { 'parent': pklass };
4851cb0ef41Sopenharmony_ci
4861cb0ef41Sopenharmony_ci  #
4871cb0ef41Sopenharmony_ci  # Process the instance type declaration.
4881cb0ef41Sopenharmony_ci  #
4891cb0ef41Sopenharmony_ci  entries = typestr.split(',');
4901cb0ef41Sopenharmony_ci  for entry in entries:
4911cb0ef41Sopenharmony_ci    types[re.sub('\s*=.*', '', entry).lstrip()] = True;
4921cb0ef41Sopenharmony_ci  entries = torque_typestr.split('\\')
4931cb0ef41Sopenharmony_ci  for entry in entries:
4941cb0ef41Sopenharmony_ci    name = re.sub(r' *V\(|\).*', '', entry)
4951cb0ef41Sopenharmony_ci    types[name] = True
4961cb0ef41Sopenharmony_ci  entries = torque_fulldefstr.split('\\')
4971cb0ef41Sopenharmony_ci  for entry in entries:
4981cb0ef41Sopenharmony_ci    entry = entry.strip()
4991cb0ef41Sopenharmony_ci    if not entry:
5001cb0ef41Sopenharmony_ci      continue
5011cb0ef41Sopenharmony_ci    start = entry.find('(');
5021cb0ef41Sopenharmony_ci    end = entry.find(')', start);
5031cb0ef41Sopenharmony_ci    rest = entry[start + 1: end];
5041cb0ef41Sopenharmony_ci    args = re.split('\s*,\s*', rest);
5051cb0ef41Sopenharmony_ci    typename = args[0]
5061cb0ef41Sopenharmony_ci    typeconst = args[1]
5071cb0ef41Sopenharmony_ci    types[typeconst] = True
5081cb0ef41Sopenharmony_ci    typeclasses[typeconst] = typename
5091cb0ef41Sopenharmony_ci  #
5101cb0ef41Sopenharmony_ci  # Infer class names for each type based on a systematic transformation.
5111cb0ef41Sopenharmony_ci  # For example, "JS_FUNCTION_TYPE" becomes "JSFunction".  We find the
5121cb0ef41Sopenharmony_ci  # class for each type rather than the other way around because there are
5131cb0ef41Sopenharmony_ci  # fewer cases where one type maps to more than one class than the other
5141cb0ef41Sopenharmony_ci  # way around.
5151cb0ef41Sopenharmony_ci  #
5161cb0ef41Sopenharmony_ci  for type in types:
5171cb0ef41Sopenharmony_ci    usetype = type
5181cb0ef41Sopenharmony_ci
5191cb0ef41Sopenharmony_ci    #
5201cb0ef41Sopenharmony_ci    # Remove the "_TYPE" suffix and then convert to camel case,
5211cb0ef41Sopenharmony_ci    # except that a "JS" prefix remains uppercase (as in
5221cb0ef41Sopenharmony_ci    # "JS_FUNCTION_TYPE" => "JSFunction").
5231cb0ef41Sopenharmony_ci    #
5241cb0ef41Sopenharmony_ci    if (not usetype.endswith('_TYPE')):
5251cb0ef41Sopenharmony_ci      continue;
5261cb0ef41Sopenharmony_ci
5271cb0ef41Sopenharmony_ci    usetype = usetype[0:len(usetype) - len('_TYPE')];
5281cb0ef41Sopenharmony_ci    parts = usetype.split('_');
5291cb0ef41Sopenharmony_ci    cctype = '';
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_ci    if (parts[0] == 'JS'):
5321cb0ef41Sopenharmony_ci      cctype = 'JS';
5331cb0ef41Sopenharmony_ci      start = 1;
5341cb0ef41Sopenharmony_ci    else:
5351cb0ef41Sopenharmony_ci      cctype = '';
5361cb0ef41Sopenharmony_ci      start = 0;
5371cb0ef41Sopenharmony_ci
5381cb0ef41Sopenharmony_ci    for ii in range(start, len(parts)):
5391cb0ef41Sopenharmony_ci      part = parts[ii];
5401cb0ef41Sopenharmony_ci      cctype += part[0].upper() + part[1:].lower();
5411cb0ef41Sopenharmony_ci
5421cb0ef41Sopenharmony_ci    #
5431cb0ef41Sopenharmony_ci    # Mapping string types is more complicated.  Both types and
5441cb0ef41Sopenharmony_ci    # class names for Strings specify a representation (e.g., Seq,
5451cb0ef41Sopenharmony_ci    # Cons, External, or Sliced) and an encoding (TwoByte/OneByte),
5461cb0ef41Sopenharmony_ci    # In the simplest case, both of these are explicit in both
5471cb0ef41Sopenharmony_ci    # names, as in:
5481cb0ef41Sopenharmony_ci    #
5491cb0ef41Sopenharmony_ci    #       EXTERNAL_ONE_BYTE_STRING_TYPE => ExternalOneByteString
5501cb0ef41Sopenharmony_ci    #
5511cb0ef41Sopenharmony_ci    # However, either the representation or encoding can be omitted
5521cb0ef41Sopenharmony_ci    # from the type name, in which case "Seq" and "TwoByte" are
5531cb0ef41Sopenharmony_ci    # assumed, as in:
5541cb0ef41Sopenharmony_ci    #
5551cb0ef41Sopenharmony_ci    #       STRING_TYPE => SeqTwoByteString
5561cb0ef41Sopenharmony_ci    #
5571cb0ef41Sopenharmony_ci    # Additionally, sometimes the type name has more information
5581cb0ef41Sopenharmony_ci    # than the class, as in:
5591cb0ef41Sopenharmony_ci    #
5601cb0ef41Sopenharmony_ci    #       CONS_ONE_BYTE_STRING_TYPE => ConsString
5611cb0ef41Sopenharmony_ci    #
5621cb0ef41Sopenharmony_ci    # To figure this out dynamically, we first check for a
5631cb0ef41Sopenharmony_ci    # representation and encoding and add them if they're not
5641cb0ef41Sopenharmony_ci    # present.  If that doesn't yield a valid class name, then we
5651cb0ef41Sopenharmony_ci    # strip out the representation.
5661cb0ef41Sopenharmony_ci    #
5671cb0ef41Sopenharmony_ci    if (cctype.endswith('String')):
5681cb0ef41Sopenharmony_ci      if (cctype.find('Cons') == -1 and
5691cb0ef41Sopenharmony_ci          cctype.find('External') == -1 and
5701cb0ef41Sopenharmony_ci          cctype.find('Sliced') == -1):
5711cb0ef41Sopenharmony_ci        if (cctype.find('OneByte') != -1):
5721cb0ef41Sopenharmony_ci          cctype = re.sub('OneByteString$',
5731cb0ef41Sopenharmony_ci              'SeqOneByteString', cctype);
5741cb0ef41Sopenharmony_ci        else:
5751cb0ef41Sopenharmony_ci          cctype = re.sub('String$',
5761cb0ef41Sopenharmony_ci              'SeqString', cctype);
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ci      if (cctype.find('OneByte') == -1):
5791cb0ef41Sopenharmony_ci        cctype = re.sub('String$', 'TwoByteString',
5801cb0ef41Sopenharmony_ci            cctype);
5811cb0ef41Sopenharmony_ci
5821cb0ef41Sopenharmony_ci      if (not (cctype in klasses)):
5831cb0ef41Sopenharmony_ci        cctype = re.sub('OneByte', '', cctype);
5841cb0ef41Sopenharmony_ci        cctype = re.sub('TwoByte', '', cctype);
5851cb0ef41Sopenharmony_ci
5861cb0ef41Sopenharmony_ci    #
5871cb0ef41Sopenharmony_ci    # Despite all that, some types have no corresponding class.
5881cb0ef41Sopenharmony_ci    #
5891cb0ef41Sopenharmony_ci    if (cctype in klasses):
5901cb0ef41Sopenharmony_ci      typeclasses[type] = cctype;
5911cb0ef41Sopenharmony_ci      if (cctype in checktypes):
5921cb0ef41Sopenharmony_ci        del checktypes[cctype];
5931cb0ef41Sopenharmony_ci
5941cb0ef41Sopenharmony_ci#
5951cb0ef41Sopenharmony_ci# For a given macro call, pick apart the arguments and return an object
5961cb0ef41Sopenharmony_ci# describing the corresponding output constant.  See load_fields().
5971cb0ef41Sopenharmony_ci#
5981cb0ef41Sopenharmony_cidef parse_field(call):
5991cb0ef41Sopenharmony_ci  # Replace newlines with spaces.
6001cb0ef41Sopenharmony_ci  for ii in range(0, len(call)):
6011cb0ef41Sopenharmony_ci    if (call[ii] == '\n'):
6021cb0ef41Sopenharmony_ci      call[ii] == ' ';
6031cb0ef41Sopenharmony_ci
6041cb0ef41Sopenharmony_ci  idx = call.find('(');
6051cb0ef41Sopenharmony_ci  kind = call[0:idx];
6061cb0ef41Sopenharmony_ci  rest = call[idx + 1: len(call) - 1];
6071cb0ef41Sopenharmony_ci  args = re.split('\s*,\s*', rest);
6081cb0ef41Sopenharmony_ci
6091cb0ef41Sopenharmony_ci  consts = [];
6101cb0ef41Sopenharmony_ci
6111cb0ef41Sopenharmony_ci  klass = args[0];
6121cb0ef41Sopenharmony_ci  field = args[1];
6131cb0ef41Sopenharmony_ci  dtype = None
6141cb0ef41Sopenharmony_ci  offset = None
6151cb0ef41Sopenharmony_ci  if kind.startswith('WEAK_ACCESSORS'):
6161cb0ef41Sopenharmony_ci    dtype = 'weak'
6171cb0ef41Sopenharmony_ci    offset = args[2];
6181cb0ef41Sopenharmony_ci  elif not (kind.startswith('SMI_ACCESSORS') or kind.startswith('ACCESSORS_TO_SMI')):
6191cb0ef41Sopenharmony_ci    dtype = args[2].replace('<', '_').replace('>', '_')
6201cb0ef41Sopenharmony_ci    offset = args[3];
6211cb0ef41Sopenharmony_ci  else:
6221cb0ef41Sopenharmony_ci    offset = args[2];
6231cb0ef41Sopenharmony_ci    dtype = 'SMI'
6241cb0ef41Sopenharmony_ci
6251cb0ef41Sopenharmony_ci
6261cb0ef41Sopenharmony_ci  assert(offset is not None and dtype is not None);
6271cb0ef41Sopenharmony_ci  return ({
6281cb0ef41Sopenharmony_ci      'name': 'class_%s__%s__%s' % (klass, field, dtype),
6291cb0ef41Sopenharmony_ci      'value': '%s::%s' % (klass, offset)
6301cb0ef41Sopenharmony_ci  });
6311cb0ef41Sopenharmony_ci
6321cb0ef41Sopenharmony_ci#
6331cb0ef41Sopenharmony_ci# Load field offset information from objects-inl.h etc.
6341cb0ef41Sopenharmony_ci#
6351cb0ef41Sopenharmony_cidef load_fields():
6361cb0ef41Sopenharmony_ci  for filename in sys.argv[2:]:
6371cb0ef41Sopenharmony_ci    if filename.endswith("-inl.h"):
6381cb0ef41Sopenharmony_ci      load_fields_from_file(filename)
6391cb0ef41Sopenharmony_ci
6401cb0ef41Sopenharmony_ci  for body in extras_accessors:
6411cb0ef41Sopenharmony_ci    fields.append(parse_field('ACCESSORS(%s)' % body));
6421cb0ef41Sopenharmony_ci
6431cb0ef41Sopenharmony_ci
6441cb0ef41Sopenharmony_cidef load_fields_from_file(filename):
6451cb0ef41Sopenharmony_ci  inlfile = io.open(filename, 'r', encoding='utf-8');
6461cb0ef41Sopenharmony_ci
6471cb0ef41Sopenharmony_ci  #
6481cb0ef41Sopenharmony_ci  # Each class's fields and the corresponding offsets are described in the
6491cb0ef41Sopenharmony_ci  # source by calls to macros like "ACCESSORS" (and friends).  All we do
6501cb0ef41Sopenharmony_ci  # here is extract these macro invocations, taking into account that they
6511cb0ef41Sopenharmony_ci  # may span multiple lines and may contain nested parentheses.  We also
6521cb0ef41Sopenharmony_ci  # call parse_field() to pick apart the invocation.
6531cb0ef41Sopenharmony_ci  #
6541cb0ef41Sopenharmony_ci  prefixes = [ 'ACCESSORS', 'ACCESSORS2', 'ACCESSORS_GCSAFE',
6551cb0ef41Sopenharmony_ci         'SMI_ACCESSORS', 'ACCESSORS_TO_SMI',
6561cb0ef41Sopenharmony_ci         'RELEASE_ACQUIRE_ACCESSORS', 'WEAK_ACCESSORS' ];
6571cb0ef41Sopenharmony_ci  prefixes += ([ prefix + "_CHECKED" for prefix in prefixes ] +
6581cb0ef41Sopenharmony_ci         [ prefix + "_CHECKED2" for prefix in prefixes ])
6591cb0ef41Sopenharmony_ci  current = '';
6601cb0ef41Sopenharmony_ci  opens = 0;
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ci  for line in inlfile:
6631cb0ef41Sopenharmony_ci    if (opens > 0):
6641cb0ef41Sopenharmony_ci      # Continuation line
6651cb0ef41Sopenharmony_ci      for ii in range(0, len(line)):
6661cb0ef41Sopenharmony_ci        if (line[ii] == '('):
6671cb0ef41Sopenharmony_ci          opens += 1;
6681cb0ef41Sopenharmony_ci        elif (line[ii] == ')'):
6691cb0ef41Sopenharmony_ci          opens -= 1;
6701cb0ef41Sopenharmony_ci
6711cb0ef41Sopenharmony_ci        if (opens == 0):
6721cb0ef41Sopenharmony_ci          break;
6731cb0ef41Sopenharmony_ci
6741cb0ef41Sopenharmony_ci      current += line[0:ii + 1];
6751cb0ef41Sopenharmony_ci      continue;
6761cb0ef41Sopenharmony_ci
6771cb0ef41Sopenharmony_ci    for prefix in prefixes:
6781cb0ef41Sopenharmony_ci      if (not line.startswith(prefix + '(')):
6791cb0ef41Sopenharmony_ci        continue;
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_ci      if (len(current) > 0):
6821cb0ef41Sopenharmony_ci        fields.append(parse_field(current));
6831cb0ef41Sopenharmony_ci        current = '';
6841cb0ef41Sopenharmony_ci
6851cb0ef41Sopenharmony_ci      for ii in range(len(prefix), len(line)):
6861cb0ef41Sopenharmony_ci        if (line[ii] == '('):
6871cb0ef41Sopenharmony_ci          opens += 1;
6881cb0ef41Sopenharmony_ci        elif (line[ii] == ')'):
6891cb0ef41Sopenharmony_ci          opens -= 1;
6901cb0ef41Sopenharmony_ci
6911cb0ef41Sopenharmony_ci        if (opens == 0):
6921cb0ef41Sopenharmony_ci          break;
6931cb0ef41Sopenharmony_ci
6941cb0ef41Sopenharmony_ci      current += line[0:ii + 1];
6951cb0ef41Sopenharmony_ci
6961cb0ef41Sopenharmony_ci  if (len(current) > 0):
6971cb0ef41Sopenharmony_ci    fields.append(parse_field(current));
6981cb0ef41Sopenharmony_ci    current = '';
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ci#
7011cb0ef41Sopenharmony_ci# Emit a block of constants.
7021cb0ef41Sopenharmony_ci#
7031cb0ef41Sopenharmony_cidef emit_set(out, consts):
7041cb0ef41Sopenharmony_ci  lines = set()  # To remove duplicates.
7051cb0ef41Sopenharmony_ci
7061cb0ef41Sopenharmony_ci  # Fix up overzealous parses.  This could be done inside the
7071cb0ef41Sopenharmony_ci  # parsers but as there are several, it's easiest to do it here.
7081cb0ef41Sopenharmony_ci  ws = re.compile('\s+')
7091cb0ef41Sopenharmony_ci  for const in consts:
7101cb0ef41Sopenharmony_ci    name = ws.sub('', const['name'])
7111cb0ef41Sopenharmony_ci    value = ws.sub('', str(const['value']))  # Can be a number.
7121cb0ef41Sopenharmony_ci    lines.add('V8_EXPORT int v8dbg_%s = %s;\n' % (name, value))
7131cb0ef41Sopenharmony_ci
7141cb0ef41Sopenharmony_ci  for line in lines:
7151cb0ef41Sopenharmony_ci    out.write(line);
7161cb0ef41Sopenharmony_ci  out.write('\n');
7171cb0ef41Sopenharmony_ci
7181cb0ef41Sopenharmony_ci#
7191cb0ef41Sopenharmony_ci# Emit the whole output file.
7201cb0ef41Sopenharmony_ci#
7211cb0ef41Sopenharmony_cidef emit_config():
7221cb0ef41Sopenharmony_ci  out = open(sys.argv[1], 'w');
7231cb0ef41Sopenharmony_ci
7241cb0ef41Sopenharmony_ci  out.write(header);
7251cb0ef41Sopenharmony_ci
7261cb0ef41Sopenharmony_ci  out.write('/* miscellaneous constants */\n');
7271cb0ef41Sopenharmony_ci  emit_set(out, consts_misc);
7281cb0ef41Sopenharmony_ci
7291cb0ef41Sopenharmony_ci  out.write('/* class type information */\n');
7301cb0ef41Sopenharmony_ci  consts = [];
7311cb0ef41Sopenharmony_ci  for typename in sorted(typeclasses):
7321cb0ef41Sopenharmony_ci    klass = typeclasses[typename];
7331cb0ef41Sopenharmony_ci    consts.append({
7341cb0ef41Sopenharmony_ci        'name': 'type_%s__%s' % (klass, typename),
7351cb0ef41Sopenharmony_ci        'value': typename
7361cb0ef41Sopenharmony_ci    });
7371cb0ef41Sopenharmony_ci
7381cb0ef41Sopenharmony_ci  emit_set(out, consts);
7391cb0ef41Sopenharmony_ci
7401cb0ef41Sopenharmony_ci  out.write('/* class hierarchy information */\n');
7411cb0ef41Sopenharmony_ci  consts = [];
7421cb0ef41Sopenharmony_ci  for klassname in sorted(klasses):
7431cb0ef41Sopenharmony_ci    pklass = klasses[klassname]['parent'];
7441cb0ef41Sopenharmony_ci    bklass = get_base_class(klassname);
7451cb0ef41Sopenharmony_ci    if (bklass != 'Object'):
7461cb0ef41Sopenharmony_ci      continue;
7471cb0ef41Sopenharmony_ci    if (pklass == None):
7481cb0ef41Sopenharmony_ci      continue;
7491cb0ef41Sopenharmony_ci
7501cb0ef41Sopenharmony_ci    consts.append({
7511cb0ef41Sopenharmony_ci        'name': 'parent_%s__%s' % (klassname, pklass),
7521cb0ef41Sopenharmony_ci        'value': 0
7531cb0ef41Sopenharmony_ci    });
7541cb0ef41Sopenharmony_ci
7551cb0ef41Sopenharmony_ci  emit_set(out, consts);
7561cb0ef41Sopenharmony_ci
7571cb0ef41Sopenharmony_ci  out.write('/* field information */\n');
7581cb0ef41Sopenharmony_ci  emit_set(out, fields);
7591cb0ef41Sopenharmony_ci
7601cb0ef41Sopenharmony_ci  out.write(footer);
7611cb0ef41Sopenharmony_ci
7621cb0ef41Sopenharmony_ciif (len(sys.argv) < 4):
7631cb0ef41Sopenharmony_ci  print('usage: %s output.cc objects.h objects-inl.h' % sys.argv[0]);
7641cb0ef41Sopenharmony_ci  sys.exit(2);
7651cb0ef41Sopenharmony_ci
7661cb0ef41Sopenharmony_ciload_objects();
7671cb0ef41Sopenharmony_ciload_fields();
7681cb0ef41Sopenharmony_ciemit_config();
769