github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/transform/testdata/maps.ll (about) 1 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" 2 target triple = "armv7m-none-eabi" 3 4 @answer = constant [6 x i8] c"answer" 5 6 ; func(keySize, valueSize uint8, sizeHint uintptr) *runtime.hashmap 7 declare nonnull ptr @runtime.hashmapMake(i8, i8, i32) 8 9 ; func(map[string]int, string, unsafe.Pointer) 10 declare void @runtime.hashmapStringSet(ptr nocapture, ptr, i32, ptr nocapture readonly) 11 12 ; func(map[string]int, string, unsafe.Pointer) 13 declare i1 @runtime.hashmapStringGet(ptr nocapture, ptr, i32, ptr nocapture) 14 15 define void @testUnused() { 16 ; create the map 17 %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) 18 ; create the value to be stored 19 %hashmap.value = alloca i32 20 store i32 42, ptr %hashmap.value 21 ; store the value 22 call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) 23 ret void 24 } 25 26 ; Note that the following function should ideally be optimized (it could simply 27 ; return 42), but isn't at the moment. 28 define i32 @testReadonly() { 29 ; create the map 30 %map = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) 31 32 ; create the value to be stored 33 %hashmap.value = alloca i32 34 store i32 42, ptr %hashmap.value 35 36 ; store the value 37 call void @runtime.hashmapStringSet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value) 38 39 ; load the value back 40 %hashmap.value2 = alloca i32 41 %commaOk = call i1 @runtime.hashmapStringGet(ptr %map, ptr @answer, i32 6, ptr %hashmap.value2) 42 %loadedValue = load i32, ptr %hashmap.value2 43 44 ret i32 %loadedValue 45 } 46 47 define ptr @testUsed() { 48 %1 = call ptr @runtime.hashmapMake(i8 4, i8 4, i32 0) 49 ret ptr %1 50 }