Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Array bracket syntax (myArray[0]) #17

Open
ChocolateLoverRaj opened this issue Dec 24, 2022 · 0 comments
Open

Array bracket syntax (myArray[0]) #17

ChocolateLoverRaj opened this issue Dec 24, 2022 · 0 comments
Labels
plugin Not part of core llvm parser. Additional optional feature.

Comments

@ChocolateLoverRaj
Copy link
Owner

Before:

@msg = private unnamed_addr constant [13 x i8] c"Element: %i\0A\00"

declare i32 @printf(ptr, ...)

@array = private unnamed_addr constant [3 x i32] [i32 111, i32 222, i32 333]

define void @getElementInLocalMemory () {
  EntryBlock:
    %array = load [3 x i32], ptr @array
    %element = extractvalue [3 x i32] %array, 2
    call i32 @printf(ptr @msg, i32 %element)
    ret void
}

define void @getElementWithPtr () {
  EntryBlock:
    %elementPtr = getelementptr [3 x i32], ptr @array, i64 0, i64 2
    %element = load i32, ptr %elementPtr
    call i32 @printf(ptr @msg, i32 %element)
    ret void
}

define i1 @main () {
  EntryBlock:
    call void @getElementInLocalMemory()
    call void @getElementWithPtr()
    ret i1 0
}

After:

@msg = private unnamed_addr constant [13 x i8] c"Element: %i\0A\00"

declare i32 @printf(ptr, ...)

@array = private unnamed_addr constant [3 x i32] [i32 111, i32 222, i32 333]

define void @getElementInLocalMemory () {
  EntryBlock:
    %array = load [3 x i32], ptr @array
    %element = %array[2]
    call i32 @printf(ptr @msg, i32 %element)
    ret void
}

define void @getElementWithPtr () {
  EntryBlock:
    %elementPtr = @array[2]
    %element = load i32, ptr %elementPtr
    call i32 @printf(ptr @msg, i32 %element)
    ret void
}

define i1 @main () {
  EntryBlock:
    call void @getElementInLocalMemory()
    call void @getElementWithPtr()
    ret i1 0
}

Note:

@ChocolateLoverRaj ChocolateLoverRaj added the plugin Not part of core llvm parser. Additional optional feature. label Dec 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin Not part of core llvm parser. Additional optional feature.
Projects
None yet
Development

No branches or pull requests

1 participant