Advertisement
Guest User

Untitled

a guest
Jan 7th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
LLVM 3.69 KB | None | 0 0
  1.  
  2. @dnl = internal constant [4 x i8] c"%d\0A\00"
  3. @fnl = internal constant [6 x i8] c"%.1f\0A\00"
  4. @d   = internal constant [3 x i8] c"%d\00"
  5. @lf  = internal constant [4 x i8] c"%lf\00"
  6.  
  7. declare i32 @printf(i8*, ...)
  8. declare i32 @scanf(i8*, ...)
  9. declare i32 @puts(i8*)
  10. declare noalias i8* @malloc(i32)
  11. declare void @free(i8*)
  12. declare i32 @strlen(i8*)
  13. declare i8* @strcpy(i8*, i8*)
  14. declare i32 @strcmp(i8*, i8*)
  15.  
  16. %struct.S = type { i8*, i32 }
  17.  
  18. define void @printInt(i32 %x) {
  19.        %t0 = getelementptr [4 x i8], [4 x i8]* @dnl, i32 0, i32 0
  20.        call i32 (i8*, ...) @printf(i8* %t0, i32 %x)
  21.        ret void
  22. }
  23.  
  24. define i32 @readInt() {
  25. entry:  %res = alloca i32
  26.         %t1 = getelementptr [3 x i8], [3 x i8]* @d, i32 0, i32 0
  27.     call i32 (i8*, ...) @scanf(i8* %t1, i32* %res)
  28.     %t2 = load i32, i32* %res
  29.     ret i32 %t2
  30. }
  31.  
  32.  
  33. ; string functions
  34.  
  35.  
  36. define dso_local noalias %struct.S* @__builtin__add_string(%struct.S* nocapture readonly, %struct.S* nocapture readonly) local_unnamed_addr {
  37.   %3 = getelementptr inbounds %struct.S, %struct.S* %0, i32 0, i32 0
  38.   %4 = load i8*, i8** %3
  39.   %5 = tail call i32 @strlen(i8* %4)
  40.   %6 = getelementptr inbounds %struct.S, %struct.S* %1, i32 0, i32 0
  41.   %7 = load i8*, i8** %6
  42.   %8 = tail call i32 @strlen(i8* %7)
  43.   %9 = add i32 %5, 1
  44.   %10 = add i32 %9, %8
  45.   %11 = tail call noalias i8* @malloc(i32 %10)
  46.   %12 = tail call noalias i8* @malloc(i32 8)
  47.   %13 = bitcast i8* %12 to %struct.S*
  48.   %14 = tail call i8* @strcpy(i8* %11, i8* %4)
  49.   %15 = getelementptr inbounds i8, i8* %11, i32 %5
  50.   %16 = load i8*, i8** %6
  51.   %17 = tail call i8* @strcpy(i8* %15, i8* %16)
  52.   %18 = getelementptr inbounds i8, i8* %12, i32 4
  53.   %19 = bitcast i8* %18 to i32*
  54.   store i32 1, i32* %19
  55.   %20 = bitcast i8* %12 to i8**
  56.   store i8* %11, i8** %20
  57.   ret %struct.S* %13
  58. }
  59.  
  60. define dso_local i32 @__builtin__eq_string(%struct.S* nocapture readonly, %struct.S* nocapture readonly) local_unnamed_addr {
  61.   %3 = getelementptr inbounds %struct.S, %struct.S* %0, i32 0, i32 0
  62.   %4 = load i8*, i8** %3
  63.   %5 = getelementptr inbounds %struct.S, %struct.S* %1, i32 0, i32 0
  64.   %6 = load i8*, i8** %5
  65.   %7 = tail call i32 @strcmp(i8* %4, i8* %6)
  66.   %8 = icmp eq i32 %7, 0
  67.   %9 = zext i1 %8 to i32
  68.   ret i32 %9
  69. }
  70.  
  71. define dso_local i32 @__builtin__ne_string(%struct.S* nocapture readonly, %struct.S* nocapture readonly) local_unnamed_addr {
  72.   %3 = getelementptr inbounds %struct.S, %struct.S* %0, i32 0, i32 0
  73.   %4 = load i8*, i8** %3
  74.   %5 = getelementptr inbounds %struct.S, %struct.S* %1, i32 0, i32 0
  75.   %6 = load i8*, i8** %5
  76.   %7 = tail call i32 @strcmp(i8* %4, i8* %6)
  77.   %8 = icmp ne i32 %7, 0
  78.   %9 = zext i1 %8 to i32
  79.   ret i32 %9
  80. }
  81.  
  82. define dso_local void @__builtin__destroy_string(%struct.S* nocapture) local_unnamed_addr {
  83.   %2 = getelementptr inbounds %struct.S, %struct.S* %0, i32 0, i32 1
  84.   %3 = load i32, i32* %2
  85.   %4 = add i32 %3, -1
  86.   store i32 %4, i32* %2
  87.   %5 = icmp eq i32 %4, 0
  88.   br i1 %5, label %6, label %10
  89.  
  90. ; <label>:6:                                      ; preds = %1
  91.   %7 = getelementptr inbounds %struct.S, %struct.S* %0, i32 0, i32 0
  92.   %8 = load i8*, i8** %7
  93.   tail call void @free(i8* %8)
  94.   %9 = bitcast %struct.S* %0 to i8*
  95.   tail call void @free(i8* %9)
  96.   br label %10
  97.  
  98. ; <label>:10:                                     ; preds = %6, %1
  99.   ret void
  100. }
  101.  
  102. define dso_local void @printString(%struct.S* nocapture readonly) local_unnamed_addr {
  103.   %2 = getelementptr inbounds %struct.S, %struct.S* %0, i32 0, i32 0
  104.   %3 = load i8*, i8** %2
  105.   %4 = tail call i32 @puts(i8* %3)
  106.   ret void
  107. }
  108.  
  109.  
  110. define i32 @main() {
  111. entry:
  112.     call void @foo()
  113.     ret i32 0
  114. }
  115.  
  116. define void @foo() {
  117. entry:
  118.     call void @printString(%struct.S* "foo")
  119.     ret void
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement