• Top
    • Documentation
    • Books
    • Boolean-reasoning
    • Projects
    • Debugging
    • Std
    • Proof-automation
    • Macro-libraries
    • ACL2
    • Interfacing-tools
    • Hardware-verification
    • Software-verification
      • Kestrel-books
        • Crypto-hdwallet
        • Apt
        • Error-checking
        • Fty-extensions
        • Isar
        • Kestrel-utilities
        • Set
        • Soft
        • C
          • Syntax-for-tools
            • Disambiguator
              • Dimb-exprs/decls/stmts
              • Dimb-make/adjust-expr-binary
              • Dimb-transunit
                • Dimb-params-to-names
                • Dimb-cast/call-to-call
                • Dimb-make/adjust-expr-cast
                • Dimb-fundef
                • Dimb-make/adjust-expr-unary
                • Dimb-expr
                • Dimb-dirdeclor
                • Dimb-amb-declor/absdeclor
                • Dimb-cast/call-to-cast
                • Dimb-cast/addsub-to-cast
                • Dimb-cast/addsub-to-addsub
                • Dimb-transunit-ensemble
                • Dimb-add-ident
                • Dimb-kind
                • Dimb-declor
                • Dimb-amb-expr/tyname
                • Dimb-cast/mul-to-cast
                • Dimb-cast/and-to-cast
                • Dimb-cast/mul-to-mul
                • Dimb-cast/and-to-and
                • Dimb-kind-option
                • Dimb-type-spec
                • Dimb-extdecl-list
                • Dimb-extdecl
                • Dimb-lookup-ident
                • Dimb-param-declor
                • Dimb-decl-spec
                • Dimb-add-idents-objfun
                • Dimb-param-declon
                • Dimb-add-ident-objfun
                • Dimb-table
                • Dimb-amb-decl/stmt
                • Dimb-pop-scope
                • Dimb-push-scope
                • Dimb-initdeclor
                • Dimb-declor-option
                • Dimb-enumspec
                • Dimb-decl
                • Dimb-stmt
                • Dimb-scope
                • Dimb-structdeclor
                • Dimb-initdeclor-list
                • Dimb-decl-spec-list
                • Dimb-absdeclor
                • Dimb-init-table
                • Dimb-dirabsdeclor
                • Dimb-align-spec
                • Dimb-strunispec
                • Irr-dimb-table
                • Irr-dimb-kind
                • Dimb-spec/qual-list
                • Dimb-spec/qual
                • Dimb-param-declon-list
                • Dimb-label
                • Dimb-enumer-list
                • Dimb-enumer
                • Dimb-dirabsdeclor-option
                • Dimb-block-item
                • Dimb-structdeclor-list
                • Dimb-structdecl-list
                • Dimb-statassert
                • Dimb-desiniter-list
                • Dimb-desiniter
                • Dimb-decl-list
                • Dimb-const-expr-option
                • Dimb-absdeclor-option
                • Dimb-structdecl
                • Dimb-member-designor
                • Dimb-initer-option
                • Dimb-initer
                • Dimb-genassoc-list
                • Dimb-genassoc
                • Dimb-expr-option
                • Dimb-expr-list
                • Dimb-designor-list
                • Dimb-designor
                • Dimb-const-expr
                • Dimb-block-item-list
                • Dimb-tyname
              • Abstract-syntax
              • Parser
              • Validator
              • Printer
              • Formalized-subset
              • Mapping-to-language-definition
              • Input-files
              • Defpred
              • Output-files
              • Abstract-syntax-operations
              • Validation-information
              • Implementation-environments
              • Concrete-syntax
              • Unambiguity
              • Ascii-identifiers
              • Preprocessing
              • Abstraction-mapping
            • Atc
            • Language
            • Representation
            • Transformation-tools
            • Insertion-sort
            • Pack
          • Bv
          • Imp-language
          • Event-macros
          • Java
          • Bitcoin
          • Ethereum
          • Yul
          • Zcash
          • ACL2-programming-language
          • Prime-fields
          • Json
          • Syntheto
          • File-io-light
          • Cryptography
          • Number-theory
          • Lists-light
          • Axe
          • Builtins
          • Solidity
          • Helpers
          • Htclient
          • Typed-lists-light
          • Arithmetic-light
        • X86isa
        • Axe
        • Execloader
      • Math
      • Testing-utilities
    • Disambiguator

    Dimb-transunit

    Disambiguate a translation unit.

    Signature
    (dimb-transunit tunit gcc) → (mv erp new-tunit)
    Arguments
    tunit — Guard (transunitp tunit).
    gcc — Guard (booleanp gcc).
    Returns
    new-tunit — Type (transunitp new-tunit).

    We initialize the disambiguation table, we disambiguate all the external declarations in order, and we discard the final disambiguation table.

    If the GCC flag is nil (i.e. no GCC extensions), the initial disambiguation table is empty. If the flag is t, for now the only difference is that we initialize the disambiguation table with some GCC built-ins. For now we only add some built-ins that we have observed in some preprocessed files. We should revisit this, adding all the GCC built-ins, with clear and accurate references.

    We also add entries for certain built-in variables corresponding to the x86 registers, i.e. __eax etc. We could not find those documented in the GCC manual, but we found them in practical code. Experiments suggest that these variables are somewhat restricted in usage. The normal pattern seems to be something like

    unsigned long __eax = __eax;

    after which one can use __eax as a regular variable. However, without the declaration above, __eax cannot be used as a regular variable. This is odd, because the validity of the declaration above presupposes that __eax is already in scope. It is not clear why such a declaration is needed in the first place. To add to the strangeness, one can change the above initializer to __eax + 1 (and presumably other similar expressions) and the compiler acceptes it.

    However, none of this matters for the disambiguator, which does not need to validate the code, and is only required to return correct results only if the code is indeed valid (even though validity is checked after disambiguation). We add these special variables to the initial disambiguation table, so that declarations such as the one above do not cause an error during disambiguation. The declaration itself is handled by the disambiguator by overriding any preceding entry with the same name (see dimb-add-ident), so after a declaration like the one above __eax is still in the table, with the right kind, and can be used as an expression in scope. However, note that these variables only make sense on an x86 platform: we should refine our GCC flag with a richer description of the C implementation.

    Definitions and Theorems

    Function: dimb-transunit

    (defun dimb-transunit (tunit gcc)
     (declare (xargs :guard (and (transunitp tunit)
                                 (booleanp gcc))))
     (let ((__function__ 'dimb-transunit))
       (declare (ignorable __function__))
       (b*
        (((reterr) (irr-transunit))
         (edecls (transunit->decls tunit))
         (table (dimb-init-table))
         (table
              (if gcc (dimb-add-idents-objfun
                           (list (ident "__atomic_signal_fence")
                                 (ident "__builtin_add_overflow")
                                 (ident "__builtin_bswap16")
                                 (ident "__builtin_bswap32")
                                 (ident "__builtin_bswap64")
                                 (ident "__builtin_choose_expr")
                                 (ident "__builtin_clz")
                                 (ident "__builtin_clzl")
                                 (ident "__builtin_clzll")
                                 (ident "__builtin_constant_p")
                                 (ident "__builtin_ctzl")
                                 (ident "__builtin_dynamic_object_size")
                                 (ident "__builtin_expect")
                                 (ident "__builtin_memchr")
                                 (ident "__builtin_memcmp")
                                 (ident "__builtin_memcpy")
                                 (ident "__builtin_memset")
                                 (ident "__builtin_mul_overflow")
                                 (ident "__builtin_object_size")
                                 (ident "__builtin_return_address")
                                 (ident "__builtin_strcpy")
                                 (ident "__builtin_strlen")
                                 (ident "__builtin_strncat")
                                 (ident "__builtin_strncpy")
                                 (ident "__builtin_sub_overflow")
                                 (ident "__builtin_unreachable")
                                 (ident "__builtin_va_end")
                                 (ident "__builtin_va_start")
                                 (ident "__eax")
                                 (ident "__ebx")
                                 (ident "__ecx")
                                 (ident "__edx")
                                 (ident "__esi")
                                 (ident "__edi")
                                 (ident "__ebp")
                                 (ident "__esp")
                                 (ident "__sync_add_and_fetch")
                                 (ident "__sync_and_and_fetch")
                                 (ident "__sync_bool_compare_and_swap")
                                 (ident "__sync_fetch_and_add")
                                 (ident "__sync_fetch_and_and")
                                 (ident "__sync_fetch_and_nand")
                                 (ident "__sync_fetch_and_or")
                                 (ident "__sync_fetch_and_sub")
                                 (ident "__sync_fetch_and_xor")
                                 (ident "__sync_lock_release")
                                 (ident "__sync_lock_test_and_set")
                                 (ident "__sync_nand_and_fetch")
                                 (ident "__sync_or_and_fetch")
                                 (ident "__sync_sub_and_fetch")
                                 (ident "__sync_synchronize")
                                 (ident "__sync_val_compare_and_swap")
                                 (ident "__sync_xor_and_fetch"))
                           table)
                table)
    )
         ((erp new-edecls &)
          (dimb-extdecl-list edecls table)))
        (retok (make-transunit :decls new-edecls
                               :info nil)))))

    Theorem: transunitp-of-dimb-transunit.new-tunit

    (defthm transunitp-of-dimb-transunit.new-tunit
      (b* (((mv acl2::?erp ?new-tunit)
            (dimb-transunit tunit gcc)))
        (transunitp new-tunit))
      :rule-classes :rewrite)

    Theorem: transunit-unambp-of-dimb-transunit

    (defthm transunit-unambp-of-dimb-transunit
      (b* (((mv acl2::?erp ?new-tunit)
            (dimb-transunit tunit gcc)))
        (implies (not erp)
                 (transunit-unambp new-tunit))))

    Theorem: dimb-transunit-of-transunit-fix-tunit

    (defthm dimb-transunit-of-transunit-fix-tunit
      (equal (dimb-transunit (transunit-fix tunit)
                             gcc)
             (dimb-transunit tunit gcc)))

    Theorem: dimb-transunit-transunit-equiv-congruence-on-tunit

    (defthm dimb-transunit-transunit-equiv-congruence-on-tunit
      (implies (transunit-equiv tunit tunit-equiv)
               (equal (dimb-transunit tunit gcc)
                      (dimb-transunit tunit-equiv gcc)))
      :rule-classes :congruence)

    Theorem: dimb-transunit-of-bool-fix-gcc

    (defthm dimb-transunit-of-bool-fix-gcc
      (equal (dimb-transunit tunit (bool-fix gcc))
             (dimb-transunit tunit gcc)))

    Theorem: dimb-transunit-iff-congruence-on-gcc

    (defthm dimb-transunit-iff-congruence-on-gcc
      (implies (iff gcc gcc-equiv)
               (equal (dimb-transunit tunit gcc)
                      (dimb-transunit tunit gcc-equiv)))
      :rule-classes :congruence)