A tool to generate C-to-C transformations.
The C c$::abstract-syntax has many cases as well as large,
mutually recursive cliques. Transformations will therefore have
significant sections of boilerplate in which functions do nothing but
call the appropriate sub-transformation on each child of the AST node. In
addition, most all such transformations will have the same termination
argument.
(deftrans name :extra-args extra-args ;; Default: nil :with-output-off with-output-off ;; Default: (:other-than summary error) ... other-keywords ... )
The name of the transformation, to be used as a prefix in the generated functions.
A list of arguments to be passed to the transformation functions, in addition to the AST term. This list is expected to be in the format of std::extended-formals.
Controls the output. The value should be suitable for use in the
For each case of the AST, you may specify
You may call other generated functions within
The following example will generate a transformation
(deftrans my-simpadd0 :expr (lambda (expr) (expr-case expr :ident (expr-fix expr) :const (expr-fix expr) :string (expr-fix expr) :paren (expr-paren (my-simpadd0-expr expr.inner)) :gensel (make-expr-gensel :control (my-simpadd0-expr expr.control) :assocs (my-simpadd0-genassoc-list expr.assocs)) :arrsub (make-expr-arrsub :arg1 (my-simpadd0-expr expr.arg1) :arg2 (my-simpadd0-expr expr.arg2)) :funcall (make-expr-funcall :fun (my-simpadd0-expr expr.fun) :args (my-simpadd0-expr-list expr.args)) :member (make-expr-member :arg (my-simpadd0-expr expr.arg) :name expr.name) :memberp (make-expr-memberp :arg (my-simpadd0-expr expr.arg) :name expr.name) :complit (make-expr-complit :type (my-simpadd0-tyname expr.type) :elems (my-simpadd0-desiniter-list expr.elems) :final-comma expr.final-comma) :unary (make-expr-unary :op expr.op :arg (my-simpadd0-expr expr.arg)) :sizeof (expr-sizeof (my-simpadd0-tyname expr.type)) :sizeof-ambig (prog2$ (raise "Misusage error: ~x0." (expr-fix expr)) (expr-fix expr)) :alignof (make-expr-alignof :type (my-simpadd0-tyname expr.type) :uscores expr.uscores) :cast (make-expr-cast :type (my-simpadd0-tyname expr.type) :arg (my-simpadd0-expr expr.arg)) :binary (b* ((arg1 (my-simpadd0-expr expr.arg1)) (arg2 (my-simpadd0-expr expr.arg2))) ;; zero-folding occurs here (if (c$::expr-zerop arg2) arg1 (make-expr-binary :op expr.op :arg1 arg1 :arg2 arg2))) :cond (make-expr-cond :test (my-simpadd0-expr expr.test) :then (my-simpadd0-expr-option expr.then) :else (my-simpadd0-expr expr.else)) :comma (make-expr-comma :first (my-simpadd0-expr expr.first) :next (my-simpadd0-expr expr.next)) :cast/call-ambig (prog2$ (raise "Misusage error: ~x0." (expr-fix expr)) (expr-fix expr)) :cast/mul-ambig (prog2$ (raise "Misusage error: ~x0." (expr-fix expr)) (expr-fix expr)) :cast/add-ambig (prog2$ (raise "Misusage error: ~x0." (expr-fix expr)) (expr-fix expr)) :cast/sub-ambig (prog2$ (raise "Misusage error: ~x0." (expr-fix expr)) (expr-fix expr)) :cast/and-ambig (prog2$ (raise "Misusage error: ~x0." (expr-fix expr)) (expr-fix expr)) :stmt (expr-stmt (my-simpadd0-block-item-list expr.items)) :tycompat (make-expr-tycompat :type1 (my-simpadd0-tyname expr.type1) :type2 (my-simpadd0-tyname expr.type2)) :offsetof (make-expr-offsetof :type (my-simpadd0-tyname expr.type) :member (my-simpadd0-member-designor expr.member)) :va-arg (make-expr-va-arg :list (my-simpadd0-expr expr.list) :type (my-simpadd0-tyname expr.type)) :extension (expr-extension (my-simpadd0-tyname expr.expr)))))