Skip to content

Commit 881cdd9

Browse files
committed
print address
1 parent 46de01b commit 881cdd9

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

backend/src/ffi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
#include <iostream>
17+
1618
extern "C" {
19+
void print_address(void* ptr) {
20+
std::cout << ptr << std::endl;
21+
}
22+
1723
int sizeof_int() {
1824
return sizeof(int);
1925
}

backend/src/ffi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616
extern "C" {
17+
void print_address(void* ptr); // doesn't belong here?
18+
1719
int sizeof_int();
1820

1921
void set_array_int(int* arr, int idx, int value);

src/Compiler/Xla/Prim/Util.idr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public export
2121
libxla : String -> String
2222
libxla fname = "C:" ++ fname ++ ",libc_xla_extension"
2323

24+
export
25+
%foreign (libxla "print_address")
26+
prim__printAddress : GCAnyPtr -> PrimIO ()
27+
2428
export
2529
%foreign (libxla "sizeof_int")
2630
sizeofInt : Int

src/Compiler/Xla/Util.idr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ boolToCInt : Bool -> Int
3333
boolToCInt True = 1
3434
boolToCInt False = 0
3535

36+
export
37+
printAddress : GCAnyPtr -> IO ()
38+
printAddress = primIO . prim__printAddress
39+
3640
public export
3741
data IntArray : Type where
3842
MkIntArray : GCPtr Int -> IntArray

0 commit comments

Comments
 (0)