Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/compactc.ss
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ The following flags, if present, affect the compiler's behavior as follows:

--trace-passes causes the compiler to print tracing information that is
generally useful only to compiler developers.

--analyzed-ir causes the compiler to also write compiler/analyzed-ir.sexp
into the target directory: the analyzed program in the compiler's own
intermediate-language vocabulary, with each ledger operation and emit
expanded to its Impact VM instructions. An SDK in any language can
execute circuits from it. The format follows the intermediate language,
so it can change between compiler versions.
"))

(usage "<flag> ... <source-pathname> <target-directory-pathname>")
Expand All @@ -100,6 +107,7 @@ The following flags, if present, affect the compiler's behavior as follows:
[(--compact-path) (string search-list)]
[(--trace-search)]
[(--trace-passes)]
[(--analyzed-ir)]
[(--feature-zkir-v3)])
(string source-pathname)
(string target-directory-pathname))
Expand All @@ -109,6 +117,7 @@ The following flags, if present, affect the compiler's behavior as follows:
[skip-zk ?--skip-zk]
[no-communications-commitment ?--no-communications-commitment]
[feature-zkir-v3 ?--feature-zkir-v3]
[write-analyzed-ir ?--analyzed-ir]
[compact-path (if ?--compact-path (split-search-path search-list) (compact-path))]
[trace-search ?--trace-search])
(when source-root (register-source-root! source-root))
Expand Down
3 changes: 3 additions & 0 deletions compiler/config-params.ss
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,7 @@

; feature flags
(export-parameter feature-zkir-v3 #f)

; extra output
(export-parameter write-analyzed-ir #f)
)
111 changes: 111 additions & 0 deletions compiler/langs.ss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Lnodisclose unparse-Lnodisclose Lnodisclose-pretty-formats
Lnoserialize unparse-Lnoserialize Lnoserialize-pretty-formats
Lloweredemit unparse-Lloweredemit Lloweredemit-pretty-formats Lloweredemit-Export-Type-Definition?
Lanalyzed unparse-Lanalyzed Lanalyzed-pretty-formats
Ltypescript unparse-Ltypescript Ltypescript-pretty-formats Ltypescript-ADT-Op? Ltypescript-ADT-Runtime-Op?
Lposttypescript unparse-Lposttypescript Lposttypescript-pretty-formats
Lnoenums unparse-Lnoenums Lnoenums-pretty-formats
Expand Down Expand Up @@ -500,6 +501,18 @@
(lambda (x p wr)
(fprintf p "~a~s.~s" (id-prefix) (id-sym x) (id-uniq x)))))

(define (artifact-sexp? x)
(or (null? x)
(boolean? x)
(number? x)
(symbol? x)
(string? x)
(bytevector? x)
(id? x)
(and (pair? x)
(artifact-sexp? (car x))
(artifact-sexp? (cdr x)))))

(define-language/pretty Lexpanded (extends Lpreexpand)
(terminals
(+ (len (len)))
Expand Down Expand Up @@ -917,6 +930,104 @@
(+ (emit src event-version event-tag len expr vm-code) =>
(emit event-version event-tag expr))))

(define-language/pretty Lanalyzed (extends Lloweredemit)
(terminals
(- (boolean (pure-dcl nominal))
(string (mesg opaque-type file discloses sugar)))
(+ (boolean (pure-dcl nominal exported-flag pure-flag proof-flag))
(string (mesg opaque-type file discloses sugar compiler-version-value language-version-value runtime-version-value native-function))
(artifact-sexp (artifact-sexp artifact-sexp*))))
(Program (p)
(- (program src (contract-type* ...) ((export-name* name*) ...) pelt* ...))
(+ (analyzed-ir compiler-version-value language-version-value runtime-version-value (artifact-sexp* ...) (type* ...) pelt* ...) =>
(analyzed-ir
(compiler-version compiler-version-value)
(language-version language-version-value)
(runtime-version runtime-version-value)
(exports artifact-sexp* ...)
(contract-types type* ...)
pelt* ...)))
(Circuit-Definition (cdefn)
(- (circuit src function-name (arg* ...) type expr))
(+ (circuit src function-name exported-flag pure-flag proof-flag (arg* ...) type expr) =>
(circuit function-name
(exported exported-flag)
(pure pure-flag)
(proof proof-flag)
(arg* ...)
type
expr)))
(Native-Declaration (ndecl)
(- (native src function-name native-entry (arg* ...) type))
(+ (native src function-name native-function artifact-sexp (type* ...) (arg* ...) type) =>
(native function-name
(entry native-function artifact-sexp)
(type-arguments type* ...)
(arg* ...)
type)))
(Public-Ledger-Binding (public-binding)
(- (src ledger-field-name (path-index* ...) type))
(+ (src ledger-field-name (path-index* ...) exported-flag type) =>
(ledger-field-name
(path-index* ...)
(exported exported-flag)
type)))
(Public-Ledger-Array (pl-array)
(- (public-ledger-array pl-array-elt ...))
(+ (public-ledger-array pl-array-elt ...) =>
(public-ledger-array pl-array-elt ...)))
(Tuple-Argument (tuple-arg)
(- (single src expr))
(+ (single src expr) => (single expr)))
(Map-Argument (map-arg)
(- (expr type type^))
(+ (expr type type^) => (expr type type^)))
(Function (fun)
(- (fref src function-name))
(+ (fref src function-name) => (fref function-name)))
(Expression (expr index)
(- (quote src datum)
(var-ref src var-name)
(tuple-slice src type expr kindex len)
(vector-ref src type expr index)
(vector-slice src type expr index len)
(bytes-ref src type expr index)
(bytes-slice src type expr index len)
(< src bits expr1 expr2)
(<= src bits expr1 expr2)
(> src bits expr1 expr2)
(>= src bits expr1 expr2)
(== src type expr1 expr2)
(!= src type expr1 expr2)
(map src len fun map-arg map-arg* ...)
(fold src len fun (expr0 type0) map-arg map-arg* ...)
(emit src event-version event-tag len expr vm-code)
(public-ledger src ledger-field-name (maybe sugar) (path-elt ...) src^ adt-op expr* ...)
(return src expr))
(+ (quote src datum) => (quote datum)
(var-ref src var-name) => (var-ref var-name)
(tuple-slice src type expr kindex len) => (tuple-slice type expr kindex len)
(vector-ref src type expr index) => (vector-ref type expr index)
(vector-slice src type expr index len) => (vector-slice type expr index len)
(bytes-ref src type expr index) => (bytes-ref type expr index)
(bytes-slice src type expr index len) => (bytes-slice type expr index len)
(< src bits expr1 expr2) => (< bits expr1 expr2)
(<= src bits expr1 expr2) => (<= bits expr1 expr2)
(> src bits expr1 expr2) => (> bits expr1 expr2)
(>= src bits expr1 expr2) => (>= bits expr1 expr2)
(== src type expr1 expr2) => (== type expr1 expr2)
(!= src type expr1 expr2) => (!= type expr1 expr2)
(map src len fun map-arg map-arg* ...) => (map len fun map-arg map-arg* ...)
(fold src len fun (expr0 type0) map-arg map-arg* ...) =>
(fold len fun (expr0 type0) map-arg map-arg* ...)
(emit src event-version event-tag len expr (artifact-sexp* ...)) =>
(emit event-version event-tag len expr (instructions artifact-sexp* ...))
(public-ledger src ledger-field-name op-class (path-elt* ...) ledger-op type (artifact-sexp* ...) expr* ...) =>
(public-ledger ledger-field-name op-class (path-elt* ...) ledger-op type
(instructions artifact-sexp* ...)
expr* ...)
(return src expr) => (return expr))))

(define-language/pretty Ltypescript (extends Lloweredemit)
(terminals
(- (id (name var-name function-name ledger-field-name)))
Expand Down
5 changes: 5 additions & 0 deletions compiler/passes.ss
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
(frontend-passes)
(analysis-passes)
(save-contract-info-passes)
(save-analyzed-ir-passes)
(typescript-passes)
(circuit-passes)
(zkir-passes)
Expand Down Expand Up @@ -145,6 +146,10 @@
(with-target-ports
'((contract-info.json . "compiler/contract-info.json"))
(run-passes save-contract-info-passes analyzed-ir proof-circuit-name*))
(when (write-analyzed-ir)
(with-target-ports
'((analyzed-ir.sexp . "compiler/analyzed-ir.sexp"))
(run-passes save-analyzed-ir-passes analyzed-ir proof-circuit-name*)))
(with-target-ports
(map (lambda (sym) (cons sym (format "zkir/~a.zkir" sym)))
proof-circuit-name*)
Expand Down
36 changes: 36 additions & 0 deletions compiler/save-analyzed-ir-passes.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
;;; This file is part of Compact.
;;; Copyright (C) 2025 Midnight Foundation
;;; SPDX-License-Identifier: Apache-2.0
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.

#!chezscheme

(library (save-analyzed-ir-passes)
(export save-analyzed-ir-passes)
(import (except (chezscheme) errorf)
(utils)
(nanopass)
(langs)
(vm)
(compiler-version)
(language-version)
(runtime-version)
(pass-helpers))

(include "save-analyzed-ir-passes/extract-analyzed-ir.ss")

(include "save-analyzed-ir-passes/save-analyzed-ir.ss")

(define-passes save-analyzed-ir-passes
(save-analyzed-ir Lloweredemit))
)
Loading
Loading