Compiler Design

  • Uploaded by: Akshata Katyayana
  • 0
  • 0
  • August 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Compiler Design as PDF for free.

More details

  • Words: 1,015
  • Pages: 5
BubbleSort void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; }

void bubbleSort(int arr[], int n) { int i, j; for (i = 0; i < n-1; i++) for (j = 0; j < n-i-1; j++) if (arr[j] > arr[j+1]) swap(&arr[j], &arr[j+1]); }

int main() { int arr[] = {64, 34, 25, 12, 22, 11, 90}; int n = sizeof(arr)/sizeof(arr[0]); bubbleSort(arr, n); return 0; }

Unoptimised LLVM IR Code define void @swap(i32* %xp, i32* %yp) #0 { %1 = alloca i32*, align 4 %2 = alloca i32*, align 4 %temp = alloca i32, align 4 store i32* %xp, i32** %1, align 4 store i32* %yp, i32** %2, align 4 %3 = load i32*, i32** %1, align 4 %4 = load i32, i32* %3, align 4 store i32 %4, i32* %temp, align 4

%5 = load i32*, i32** %2, align 4 %6 = load i32, i32* %5, align 4 %7 = load i32*, i32** %1, align 4 store i32 %6, i32* %7, align 4 %8 = load i32, i32* %temp, align 4 %9 = load i32*, i32** %2, align 4 store i32 %8, i32* %9, align 4 ret void } ; Function Attrs: nounwind define void @bubbleSort(i32* %arr, i32 %n) #0 { %1 = alloca i32*, align 4 %2 = alloca i32, align 4 %i = alloca i32, align 4 %j = alloca i32, align 4 store i32* %arr, i32** %1, align 4 store i32 %n, i32* %2, align 4 store i32 0, i32* %i, align 4 br label %3 ;

Related Documents

Compiler Design
June 2020 13
Compiler Design
June 2020 9
Compiler Design
August 2019 43
Compiler Design
November 2019 20
Compiler Design
June 2020 16
Compiler Design
November 2019 29

More Documents from "Mehedi Hasan"