• 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
        • Bv
        • Imp-language
        • Event-macros
        • Java
          • Atj
            • Atj-implementation
              • Atj-types
              • Atj-java-primitive-array-model
              • Atj-java-abstract-syntax
              • Atj-input-processing
              • Atj-java-pretty-printer
              • Atj-code-generation
                • Atj-gen-test-method
                • Atj-shallow-code-generation
                • Atj-common-code-generation
                • Atj-shallow-quoted-constant-generation
                • Atj-pre-translation
                • Atj-gen-everything
                • Atj-name-translation
                • Atj-gen-test-cunit
                • Atj-gen-test-class
                • Atj-gen-main-file
                • Atj-post-translation
                • Atj-deep-code-generation
                • Atj-gen-test-methods
                • Atj-gen-test-file
                • Atj-gen-env-file
                • Atj-gen-output-subdir
              • Atj-java-primitives
              • Atj-java-primitive-arrays
              • Atj-type-macros
              • Atj-java-syntax-operations
              • Atj-fn
              • Atj-library-extensions
              • Atj-java-input-types
              • Atj-test-structures
              • Aij-notions
              • Atj-macro-definition
            • Atj-tutorial
          • Aij
          • Language
        • 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
  • Atj-implementation

Atj-code-generation

Code generation performed by ATJ.

We generate Java abstract syntax, which we then pretty-print to files.

We translate ACL2 values, terms, and lambda expressions to Java expressions ``preceded by'' Java blocks. By this we mean that the relevant code generation functions generally return a Java block and a Java expression, such that the block must be executed before the expression. That is, the Java block provides the necessary code to ``prepare'' the evaluation of the Java expression. The Java block may include Java expressions and blocks that are recursively generated.

To illustrate this concept, consider the generation of a Java expression to build the Java representation of an ACL2 cons pair. In some circumstances, since the pair may be a large binary tree, we prefer not to generate a large Java expression. Instead, we generate a Java block that sets a local variable to be the car, a Java block that sets another local variable to be the cdr, and then a Java expression that builds the pair from those two variables. The two blocks are concatenated, resulting in a block and an expression for the cons pair in question. But the expressions assigned to the two local variables may in turn need to be built that way, recursively. This recursion ends when an atom value is reached. A similar strategy is used to build Java representations of ACL2 terms and lambda expressions, which have a recursive structure analogously to cons pairs.

As special cases, some of these code generation functions may return just Java expressions and no blocks, since they would always return empty blocks.

These code generation functions keep track of the next local variables to use via numeric indices that are threaded through the functions. The indices are appended to the base names for the local variables in order to guarantee the uniqueness of the local variables.

The atj-gen-deep-... functions are used for the deep embedding approach. The atj-gen-shallow-... functions are used for the shallow embedding approach. The other functions are generally used for both approaches.

The code generation process consists of a pre-translation from ACL2 to ACL2, followed by a translation from ACL2 to Java, followed by a post-translation from Java to Java. The pre-translation turns the ACL2 code into a form that is closer to the target Java code, thus making the translation simpler. The correctness of the pre-translation can be formally proved within ACL2, without involving (the semantics of) Java; however, some of the proofs may need to be based on an an evaluation semantics of ACL2, rather than just a logical semantics. The post-translation makes some improvements directly on the Java code, making it more efficient and idiomatic.

Subtopics

Atj-gen-test-method
Generate a Java method to run one of the specified tests.
Atj-shallow-code-generation
Code generation that is specific to the shallow embedding approach.
Atj-common-code-generation
Code generation that is common to the deep and shallow embedding approaches.
Atj-shallow-quoted-constant-generation
Representation of quoted constants in the shallow embedding.
Atj-pre-translation
Pre-translation performed by ATJ, as part of code generation.
Atj-gen-everything
Generate the main Java file, the environment-building Java file, and optionally the test Java file.
Atj-name-translation
Translation of ACL2 names to Java names performed by ATJ.
Atj-gen-test-cunit
Generate the test Java compilation unit.
Atj-gen-test-class
Generate the test Java class declaration.
Atj-gen-main-file
Generate the main Java file.
Atj-post-translation
Post-translation performed by ATJ, as part of code generation.
Atj-deep-code-generation
Code generation that is specific to the deep embedding approach.
Atj-gen-test-methods
Generate all the Java methods to run the specified tests.
Atj-gen-test-file
Generate the test Java file.
Atj-gen-env-file
Generate the file whose code builds the ACL2 environment.
Atj-gen-output-subdir
Generate the output subdirectory where the Java files go, if needed.