[swift-dev] swift module format

Coder coder at seasonsoftware.com
Tue Aug 22 13:57:44 CDT 2017


I’m working on extracting information from .swiftmodule files. Currently I can read all blocks and records but I’m having trouble identifying all DECLs in the DECLS_AND_TYPES_BLOCK. Below is a bcanalyzer dump of a swifmodule file created from this one line of code:

class Example {} 

A couple questions:

• The DECL_OFFSETS record contains 6 indexes but I only count 5 DECLs (class, destructor, constructor, 2 param). Where is the 6th?
• According to documentation, the DECL_OFFSETS point to records in the DECLS_AND_TYPES_BLOCK blob but offset indexes show below (the “op” attributes) are larger than the blob length. Where do the indexes start from?

Sorry if this is the wrong place to ask and thanks for any help,

--------- bcanalyzer dump ---------

<MODULE_BLOCK NumWords=514 BlockCodeSize=2>
  <CONTROL_BLOCK NumWords=35 BlockCodeSize=3>
    <MODULE_NAME abbrevid=4/> blob data = 'tool'
    <METADATA abbrevid=5 op0=0 op1=310 op2=3/> blob data = '3.1/Apple Swift version 3.1 (swiftlang-802.0.53 clang-802.0.42)'
    <TARGET abbrevid=6/> blob data = 'x86_64-apple-macosx10.9'
    <OPTIONS_BLOCK NumWords=2 BlockCodeSize=3>
      <IS_SIB abbrevid=4 op0=0/>
  <INPUT_BLOCK NumWords=17 BlockCodeSize=4>
    <IMPORTED_MODULE abbrevid=4 op0=0 op1=0/> blob data = 'Swift'
    <IMPORTED_MODULE abbrevid=4 op0=0 op1=0/> blob data = 'SwiftOnoneSupport'
  <SIL_BLOCK NumWords=72 BlockCodeSize=6>
  <SIL_INDEX_BLOCK NumWords=3 BlockCodeSize=4>
  <DECLS_AND_TYPES_BLOCK NumWords=309 BlockCodeSize=8>
    <CLASS_DECL abbrevid=49 op0=3 op1=0 op2=0 op3=0 op4=0 op5=0 op6=0 op7=2 op8=1/> record string = ''
    <MEMBERS abbrevid=90 op0=2 op1=3/>
    <NORMAL_PROTOCOL_CONFORMANCE_ID abbrevid=85 op0=1/>
    <NOMINAL_TYPE abbrevid=7 op0=1 op1=0/>
    <ObjC_DECL_ATTR abbrevid=95 op0=1 op1=0 op2=0/> record string = ''
    <DESTRUCTOR_DECL abbrevid=54 op0=1 op1=1 op2=1 op3=0 op4=2/>
    <PARAMETERLIST abbrevid=55 op0=1/>
    <PARAMETERLIST_ELT abbrevid=56 op0=4 op1=0 op2=0/>
    <CONSTRUCTOR_DECL abbrevid=38 op0=1 op1=0 op2=1 op3=0 op4=0 op5=0 op6=0 op7=0 op8=3 op9=0 op10=2/> record string = ''
    <PARAMETERLIST abbrevid=55 op0=1/>
    <PARAMETERLIST_ELT abbrevid=56 op0=5 op1=0 op2=0/>
    <PARAMETERLIST abbrevid=55 op0=0/>
    <FUNCTION_TYPE abbrevid=11 op0=1 op1=4 op2=0 op3=0 op4=0 op5=0/>
    <LOCAL_DISCRIMINATOR abbrevid=88 op0=0/>
    <PARAM_DECL abbrevid=40 op0=0 op1=4 op2=2 op3=1 op4=1/>
    <FUNCTION_TYPE abbrevid=11 op0=5 op1=6 op2=0 op3=0 op4=0 op5=0/>
    <LOCAL_DISCRIMINATOR abbrevid=88 op0=0/>
    <PARAM_DECL abbrevid=40 op0=0 op1=4 op2=3 op3=1 op4=1/>
    <FUNCTION_TYPE abbrevid=11 op0=7 op1=7 op2=0 op3=0 op4=0 op5=0/>
    <METATYPE_TYPE abbrevid=12 op0=1 op1=0/>
    <FUNCTION_TYPE abbrevid=11 op0=7 op1=1 op2=0 op3=0 op4=0 op5=0/>
    <TUPLE_TYPE abbrevid=9/>
    <DECL_CONTEXT abbrevid=70 op0=1 op1=1/>
    <DECL_CONTEXT abbrevid=70 op0=2 op1=1/>
    <DECL_CONTEXT abbrevid=70 op0=3 op1=1/>
    <NORMAL_PROTOCOL_CONFORMANCE abbrevid=82 op0=6 op1=1 op2=0 op3=0 op4=0/> record string = ''
    <XREF abbrevid=91 op0=5 op1=1/>
    <XREF_TYPE_PATH_PIECE abbrevid=75 op0=6 op1=0/>
  <IDENTIFIER_DATA_BLOCK NumWords=10 BlockCodeSize=3>
    <IDENTIFIER_DATA abbrevid=4/> blob data = unprintable, 30 bytes.
  <INDEX_BLOCK NumWords=53 BlockCodeSize=4>
    <DECL_OFFSETS abbrevid=4 op0=73085 op1=73418 op2=73598 op3=73894 op4=74114 op5=74671/>
    <TYPE_OFFSETS abbrevid=4 op0=73348 op1=73817 op2=74037 op3=74257 op4=74334 op5=74375 op6=74452/>
    <IDENTIFIER_OFFSETS abbrevid=4 op0=1 op1=9 op2=14 op3=20/>
    <DECL_CONTEXT_OFFSETS abbrevid=4 op0=74460 op1=74500 op2=74540/>
    <LOCAL_DECL_CONTEXT_OFFSETS abbrevid=4/> record string = ''
    <GENERIC_ENVIRONMENT_OFFSETS abbrevid=4/> record string = ''
    <NORMAL_CONFORMANCE_OFFSETS abbrevid=4 op0=74580/> record string = 'T'
    <SIL_LAYOUT_OFFSETS abbrevid=4/> record string = ''
    <TOP_LEVEL_DECLS abbrevid=5 op0=28/> blob data = unprintable, 40 bytes.
    <OBJC_METHODS abbrevid=6 op0=32/> blob data = unprintable, 44 bytes.

More information about the swift-dev mailing list