# Week 3 - Slicing Arrays and Passing them to User Defined Functions

Hi, sorry to keep you waiting for previous week’s progress of my GSoC project. As the title says, I worked on two things, slicing arrays and passing them to user defined functions in Fortran. Let’s get started.

Array Slicing

When I raised an MR for this, I thought that it would be better to do a bunch of extra changes along with adding an ASR pass for array slicing. So, I went on with adding support for printing arrays, i.e., supporting statements like, print *, array. I did that with the help of an ASR pass (as usual, changing ASR is easier than handcoding minute details in LLVM IR). Now, considering the array slicing feature, it is ready, however, there are two issues remaning to be resolved. The first one is finding the stopping point of the resulting sliced array. Specifically, I save the resulting output of sliced array in a new array and store it in a symbol table. Its easy to guess that this array would contain lesser elements than the original array. Hence, we need to find a way to allocate an array on the stack without using, llvm::ArrayType (it requires array size at compile time, which is not possible since slicing indices can be variables resulting in variable sized outputs). So, to resolve this, one idea is to pass number of elements to AllocaInst in llvm. I am not sure if it will work but if it works then it would be a great refief. Other idea is to add some optional parameters to dimension_t to identify the stopping points. This way we can keep the size same as that of the original array but fill the descriptor at LLVM IR with these stopping points.

MR - !943.

Passing Arrays To User Defined Functions/Subroutines

The difference between intrinsic functions like size and lbound and user defined functions for arrays is that, in the former only the descriptor of the array is needed (content of the array doesn’t matter). However, for user defined functions, content should be passed too. In LLVM, ArrayType changes with the change in size of underlying array. So, to avoid overloading the same function for different, ArrayTypes, we just extract the pointer to its first element and pass it to the user function along with other descriptor information. And it works well without much difficulty (at least for the test cases we explored).

MR - !947.

That’s all for now. Coming up with more progress by the end of this week.

### Email

singh.23@iitj.ac.in