github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/volatile.go (about) 1 package compiler 2 3 import "go/types" 4 5 // This file implements volatile loads/stores in runtime/volatile.LoadT and 6 // runtime/volatile.StoreT as compiler builtins. 7 8 // createVolatileLoad is the implementation of the intrinsic function 9 // runtime/volatile.LoadT(). 10 func (b *builder) createVolatileLoad() { 11 b.createFunctionStart(true) 12 addr := b.getValue(b.fn.Params[0], getPos(b.fn)) 13 b.createNilCheck(b.fn.Params[0], addr, "deref") 14 valType := b.getLLVMType(b.fn.Params[0].Type().(*types.Pointer).Elem()) 15 val := b.CreateLoad(valType, addr, "") 16 val.SetVolatile(true) 17 b.CreateRet(val) 18 } 19 20 // createVolatileStore is the implementation of the intrinsic function 21 // runtime/volatile.StoreT(). 22 func (b *builder) createVolatileStore() { 23 b.createFunctionStart(true) 24 addr := b.getValue(b.fn.Params[0], getPos(b.fn)) 25 val := b.getValue(b.fn.Params[1], getPos(b.fn)) 26 b.createNilCheck(b.fn.Params[0], addr, "deref") 27 store := b.CreateStore(val, addr) 28 store.SetVolatile(true) 29 b.CreateRetVoid() 30 }