File: cast-fp.ll

package info (click to toggle)
llvm 2.2-12
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 38,648 kB
  • ctags: 28,258
  • sloc: cpp: 215,479; sh: 12,132; ansic: 10,002; yacc: 5,525; perl: 2,352; ml: 1,580; makefile: 956; pascal: 718; lex: 602; exp: 320; ada: 193; lisp: 160; csh: 116; objc: 59; python: 59; tcl: 20
file content (49 lines) | stat: -rw-r--r-- 1,526 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
; RUN: llvm-upgrade < %s | llvm-as | llc

%a_fstr = internal constant [8 x sbyte] c"a = %f\0A\00"
%a_lstr = internal constant [10 x sbyte] c"a = %lld\0A\00"
%a_dstr = internal constant [8 x sbyte] c"a = %d\0A\00"

%b_dstr = internal constant [8 x sbyte] c"b = %d\0A\00"
%b_fstr = internal constant [8 x sbyte] c"b = %f\0A\00"

declare int %printf(sbyte*, ...)
%A = global double 2.0
%B = global int 2

int %main() {  
  ;; A
  %a = load double* %A
  %a_fs = getelementptr [8 x sbyte]* %a_fstr, long 0, long 0
  call int (sbyte*, ...)* %printf(sbyte* %a_fs, double %a)

  ;; cast double to long
  %a_d2l = cast double %a to long
  %a_ls = getelementptr [10 x sbyte]* %a_lstr, long 0, long 0
  call int (sbyte*, ...)* %printf(sbyte* %a_ls, long %a_d2l)

  ;; cast double to int
  %a_d2i = cast double %a to int
  %a_ds = getelementptr [8 x sbyte]* %a_dstr, long 0, long 0
  call int (sbyte*, ...)* %printf(sbyte* %a_ds, int %a_d2i)

  ;; cast double to sbyte
  %a_d2sb = cast double %a to sbyte
  call int (sbyte*, ...)* %printf(sbyte* %a_ds, sbyte %a_d2sb)

  ;; cast int to sbyte
  %a_d2i2sb = cast int %a_d2i to sbyte
  call int (sbyte*, ...)* %printf(sbyte* %a_ds, sbyte %a_d2i2sb)

  ;; B
  %b = load int* %B
  %b_ds = getelementptr [8 x sbyte]* %b_dstr, long 0, long 0
  call int (sbyte*, ...)* %printf(sbyte* %b_ds, int %b)

  ;; cast int to double
  %b_i2d = cast int %b to double
  %b_fs = getelementptr [8 x sbyte]* %b_fstr, long 0, long 0
  call int (sbyte*, ...)* %printf(sbyte* %b_fs, double %b_i2d)

  ret int 0
}