impc:ir:compiler:loop   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/runtime/llvmir.xtm

Implementation

(define impc:ir:compiler:loop
  (lambda (ast types)
    (let* ((os (make-string 0))
           (loop-num (llvm:count++))
           (loop-label (string-append "loop" (number->string loop-num) ":"))
           (closeloop-label (string-append "closeloop" (number->string loop-num) ":"))
           (after-label (string-append "after" (number->string loop-num) ":"))
           (loop (string-append "%loop" (number->string loop-num)))
           (closeloop (string-append "%closeloop" (number->string loop-num)))
           (cmp (string-append "%cmp" (number->string loop-num)))
           (after (string-append "%after" (number->string  loop-num)))
           (iterator (string-append "%" (symbol->string (caar ast)))) ; "Loop" (number->string loop-num)))
           (iterator-type (impc:ir:get-type-str (cdr (assoc-strcmp (caar ast) types))))
           (numstr (impc:ir:compiler (cadar ast) types (cdr (assoc-strcmp (caar ast) types))))
           (num (impc:ir:gname)) ;(ir:eval (cadar ast) os stack sym-table))
           (bodystr (impc:ir:compiler (cdr ast) types)))
      (emit "; setup loop\n" os)
                                        ;(print num 'numstr numstr)
      (emit numstr os)
      (emit  iterator "Ptr = alloca " iterator-type "\n" os)
      (emit (string-append "store " iterator-type (if (impc:ir:fixed-point? (cadr num))
                                                      " 0, "
                                                      " 0.0, ")
                           iterator-type "* " iterator "Ptr\n") os)
      (emit  "br label " loop "\n" os)
      (emit  "\n" loop-label "\n" os)
      (emit bodystr os)
      (emit (string-append "%loop_cnt" (number->string loop-num)
                           " = load " iterator-type ", " iterator-type "* " iterator "Ptr\n") os)
      (emit (string-append "%next" (number->string loop-num)
                           (if (impc:ir:fixed-point? (cadr num))
                               " = add "
                               " = fadd ")
                           iterator-type " %loop_cnt" (number->string loop-num)
                           (if (impc:ir:fixed-point? (cadr num))
                               ", 1\n"
                               ", 1.0\n"))
            os)
      (emit (string-append "store " iterator-type " %next" (number->string loop-num)
                           ", " iterator-type "* " iterator "Ptr\n") os)
      (emit (string-append cmp " = "
                           (if (impc:ir:fixed-point? (cadr num))
                               "icmp ult "
                               "fcmp ult ")
                           (cadr num) " "
                           "%next" (number->string loop-num) ", " (car num) "\n") os)
      (emit  "br i1 " cmp ", label " loop ", label " after "\n" os)
      (emit  "\n" after-label "\n" os)
      (impc:ir:gname "voidmark" (impc:ir:get-type-str *impc:ir:void*))
      (impc:ir:strip-space os))))


Back to Index

Similar Entries

  • AudioBuffer_read_looped    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • AudioBuffer_read_looped    xtlang    /digego/extempore/tree/v0.8.9/libs/core/audiobuffer.xtm
  • _glib_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/slideshow.xtm
  • _glib_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo_multi.xtm
  • _glib_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo.xtm
  • _gst_main_loop_call    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/mediaplayer.xtm
  • beat_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/going-native.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/libs/external/graphics-pipeline-scm.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/game-of-life.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/slideshow.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/kinect_vg.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/drawtext.xtm
  • gl-loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/particles.xtm
  • gl-loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/kinect_fire.xtm
  • gl-loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/kinect_fire.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/spectrogram.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/shader-tutorials/arrows.xtm
  • gl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/shader-tutorials/particles.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/fluids_2d.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nuklear.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/raymarcher.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender3.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender2.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/gl-compatibility.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender1.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender5.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender4.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/xtmrender6.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/shader-tutorials/simple-triangle.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/shader-tutorials/framebuffer.xtm
  • gl_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/shader-tutorials/triangle.xtm
  • glib-main-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/slideshow.xtm
  • glib-main-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo_multi.xtm
  • glib_main_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo.xtm
  • gst-main-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/mediaplayer.xtm
  • gui_render_loop    xtlang    /digego/extempore/tree/v0.8.9/libs/external/gui.xtm
  • impc:ir:compiler:loop    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmir.xtm
  • impc:ir:compiler:while-loop    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmir.xtm
  • impc:ti:doloop    scheme    /digego/extempore/tree/v0.8.9/runtime/llvmti.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/core/audio_101.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/rtmidi.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/polysynth.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/kinect.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/particles.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/opencv_test.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/sampler.xtm
  • loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/sing_a_song.xtm
  • loop2    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/polysynth.xtm
  • loop2    scheme    /digego/extempore/tree/v0.8.9/examples/external/sampler.xtm
  • mainLoop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/horde3d_knight.xtm
  • mainLoop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/bullet.xtm
  • midi-loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/portmidi.xtm
  • midi-loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/portmidi-output.xtm
  • midi_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/portmidi.xtm
  • my-gl-loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/fluid_dynamics.xtm
  • node_reply_loop    xtlang    /digego/extempore/tree/v0.8.9/libs/external/fleet-node.xtm
  • node_reply_loop_stop    xtlang    /digego/extempore/tree/v0.8.9/libs/external/fleet-node.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-request.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-reply.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-respondent.xtm
  • nonblocking_read_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg-surveyor.xtm
  • nvg_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/chipmunk-simple.xtm
  • nvg_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/datavis.xtm
  • nvg_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanovg_helper.xtm
  • nvg_draw_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/external/openvg.xtm
  • opengl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/shadowmap.xtm
  • opengl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/multilight.xtm
  • opengl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/shaderlight.xtm
  • opengl-loop    scheme    /digego/extempore/tree/v0.8.9/examples/contrib/gstvideo_multi.xtm
  • receiver_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg.xtm
  • reply_loop    xtlang    /digego/extempore/tree/v0.8.9/examples/contrib/nanomsg.xtm
  • rmap-loop-runner    macro    /digego/extempore/tree/v0.8.9/libs/core/pattern-language.xtm
  • run_main_event_loop    xtlang    /digego/extempore/tree/v0.8.9/libs/core/scheduler.xtm
  • shadertoy-loop    scheme    /digego/extempore/tree/v0.8.9/examples/external/shader-tutorials/shadertoy.xtm
  • xtm-setup-and-start-gl-loop    scheme    /digego/extempore/tree/v0.8.9/libs/external/graphics-pipeline-scm.xtm