createMapUpdate updates a map key to a given value, by creating an appropriate runtime call.
(keyType types.Type, m, key, value llvm.Value, pos token.Pos)
| 118 | // createMapUpdate updates a map key to a given value, by creating an |
| 119 | // appropriate runtime call. |
| 120 | func (b *builder) createMapUpdate(keyType types.Type, m, key, value llvm.Value, pos token.Pos) { |
| 121 | valueAlloca, valueSize := b.createTemporaryAlloca(value.Type(), "hashmap.value") |
| 122 | b.CreateStore(value, valueAlloca) |
| 123 | origKeyType := keyType |
| 124 | keyType = keyType.Underlying() |
| 125 | if t, ok := keyType.(*types.Basic); ok && t.Info()&types.IsString != 0 { |
| 126 | // key is a string |
| 127 | params := []llvm.Value{m, key, valueAlloca} |
| 128 | b.createRuntimeCall("hashmapStringSet", params, "") |
| 129 | } else if hashmapIsBinaryKey(keyType) { |
| 130 | // key can be compared with runtime.memequal |
| 131 | keyAlloca, keySize := b.createTemporaryAlloca(key.Type(), "hashmap.key") |
| 132 | b.CreateStore(key, keyAlloca) |
| 133 | b.zeroUndefBytes(b.getLLVMType(keyType), keyAlloca) |
| 134 | params := []llvm.Value{m, keyAlloca, valueAlloca} |
| 135 | b.createRuntimeCall("hashmapBinarySet", params, "") |
| 136 | b.emitLifetimeEnd(keyAlloca, keySize) |
| 137 | } else { |
| 138 | // Key is not trivially comparable, so compare it as an interface instead. |
| 139 | itfKey := key |
| 140 | if _, ok := keyType.(*types.Interface); !ok { |
| 141 | // Not already an interface, so convert it to an interface first. |
| 142 | itfKey = b.createMakeInterface(key, origKeyType, pos) |
| 143 | } |
| 144 | params := []llvm.Value{m, itfKey, valueAlloca} |
| 145 | b.createRuntimeCall("hashmapInterfaceSet", params, "") |
| 146 | } |
| 147 | b.emitLifetimeEnd(valueAlloca, valueSize) |
| 148 | } |
| 149 | |
| 150 | // createMapDelete deletes a key from a map by calling the appropriate runtime |
| 151 | // function. It is the implementation of the Go delete() builtin. |
no test coverage detected