impc:ir:make-const-string   scheme

Defined in:


(define impc:ir:make-const-string
  (lambda (ast)
    (let* ((os (make-string 0))
           (lgthstr1 (regex:replace-all ast "\\\\[0-9][0-9]" "x"))
           (lgthstr2 (if (and *impc:aot:current-output-port* (not *impc:compiler:aot:dll*))
                         (regex:replace-all lgthstr1 "[\n]" "x") ;(if (string=? (sys:platform) "Windows") "xx" "x"))
           (lgth (number->string (+ (string-length lgthstr2) 1))) ;; unix & windows above just used to determine string length
           (strtyp (string-append "[" lgth " x i8]*"))
           (strname (string-append "@gs" (if (string? *impc:compiler:global-module-name*) *impc:compiler:global-module-name* "")
                                   (if #f ;;(< (string-length ast) 1024)
                                       (cname-encode ast)
                                       (number->string *impc:ir:gstrcnt*))))
           (strsym '()))
      (if (not (llvm:get-llvm-alias ast))
          (let ((compile-str (string-append strname
                                            (if (sys:mcjit-enabled)
                                                (string-append " = hidden constant [" lgth " x i8] c\"")
                                                (string-append " = private unnamed_addr constant [" lgth " x i8] c\""))
                                            ast "\\00\"")))
            (llvm:compile-ir compile-str)
            (set! strsym strname)
            (llvm:add-llvm-alias ast strsym)
            (if #t ;; (>= (string-length ast) 1024)
                (set! *impc:ir:gstrcnt* (+ *impc:ir:gstrcnt* 1))))
          (set! strsym (llvm:get-llvm-alias ast)))
      (emit (string-append (impc:ir:gname "var" "i8*") " = bitcast " strtyp " " strsym " to i8*\n") os)
      (impc:ir:strip-space os))))

Back to Index