all: change special type __volatile to pragma //go:volatile

This is one step towards removing unnecessary special casts in most
cases. It is also part of removing as much magic as possible from the
compiler (the pragma is explicit, the special name is not).
This commit is contained in:
Ayke van Laethem
2018-09-28 13:17:03 +02:00
parent 0e813c4cb7
commit 8d170d3bd2
6 changed files with 52 additions and 30 deletions
+5 -6
View File
@@ -142,11 +142,10 @@ package {pkgName}
import "unsafe"
// Magic type name for the compiler.
type __volatile uint8
// Export this magic type name.
type RegValue = __volatile
// Special type that causes loads/stores to be volatile (necessary for
// memory-mapped registers).
//go:volatile
type RegValue uint8
// Some information about this device.
const (
@@ -169,7 +168,7 @@ const (
out.write('\n\t// {description}\n'.format(**peripheral))
for register in peripheral['registers']:
for variant in register['variants']:
out.write('\t{name} = (*__volatile)(unsafe.Pointer(uintptr(0x{address:x})))\n'.format(**variant))
out.write('\t{name} = (*RegValue)(unsafe.Pointer(uintptr(0x{address:x})))\n'.format(**variant))
out.write(')\n')
for peripheral in device.peripherals:
+8 -9
View File
@@ -216,11 +216,10 @@ package {pkgName}
import "unsafe"
// Magic type name for the compiler.
type __volatile uint32
// Export this magic type name.
type RegValue = __volatile
// Special type that causes loads/stores to be volatile (necessary for
// memory-mapped registers).
//go:volatile
type RegValue uint32
// Some information about this device.
const (
@@ -255,14 +254,14 @@ const (
if address < register['address']:
numSkip = (register['address'] - address) // 4
if numSkip == 1:
out.write('\t_padding{padNumber} __volatile\n'.format(padNumber=padNumber))
out.write('\t_padding{padNumber} RegValue\n'.format(padNumber=padNumber))
else:
out.write('\t_padding{padNumber} [{num}]__volatile\n'.format(padNumber=padNumber, num=numSkip))
out.write('\t_padding{padNumber} [{num}]RegValue\n'.format(padNumber=padNumber, num=numSkip))
padNumber += 1
regType = '__volatile'
regType = 'RegValue'
if register['array'] is not None:
regType = '[{}]__volatile'.format(register['array'])
regType = '[{}]RegValue'.format(register['array'])
out.write('\t{name} {regType}\n'.format(**register, regType=regType))
# next address