boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

017-int-roundtrip.scm (1207B)


      1 ;; tests/cc-cg/17-int-roundtrip.scm — width-correct 32-bit load/store
      2 ;; on adjacent unsigned-int lvals.
      3 ;;
      4 ;; Models:
      5 ;;   unsigned int a = 0xAABBCCDD, b = 0x11223344;
      6 ;;   return a == 0xAABBCCDD;
      7 ;;
      8 ;; Two 4-byte slots are allocated back-to-back at offsets 8 and 12.
      9 ;; The buggy 8-byte path would store 8 bytes from sp+8 and 8 bytes
     10 ;; from sp+12, contaminating each slot. Width-aware emission (4-byte
     11 ;; decomposition: byte-gather load, %shri-cascade store) round-trips
     12 ;; cleanly → comparison true → exit 1.
     13 
     14 (let ((cg (cg-init)))
     15   (cg-fn-begin cg "main" '() %t-i32)
     16   (let* ((off-a (cg-alloc-slot cg 4 4))
     17          (off-b (cg-alloc-slot cg 4 4))
     18          (sym-a (%sym "a" 'var 'auto %t-u32 off-a))
     19          (sym-b (%sym "b" 'var 'auto %t-u32 off-b)))
     20     ;; a = 0xAABBCCDD
     21     (cg-push-sym cg sym-a)
     22     (cg-push-imm cg %t-u32 2864434397)
     23     (cg-assign cg) (cg-pop cg)
     24     ;; b = 0x11223344
     25     (cg-push-sym cg sym-b)
     26     (cg-push-imm cg %t-u32 287454020)
     27     (cg-assign cg) (cg-pop cg)
     28     ;; return a == 0xAABBCCDD
     29     (cg-push-sym cg sym-a)
     30     (cg-load cg)
     31     (cg-push-imm cg %t-u32 2864434397)
     32     (cg-binop cg 'eq)
     33     (cg-return cg))
     34   (cg-fn-end cg)
     35   (write-bv-fd 1 (cg-finish cg)))