aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorardnew <[email protected]>2020-09-22 14:55:37 -0500
committerRon Evans <[email protected]>2020-10-10 12:52:11 +0200
commit184175378f56e8ad03b6048fb40f5138e9710adb (patch)
tree9e1c09dc3d1e60df73570183d74d98240b4e4f06 /tools
parentd8dbe5748a82231f878f42080eb38727cbe7b629 (diff)
downloadtinygo-184175378f56e8ad03b6048fb40f5138e9710adb.tar.gz
tinygo-184175378f56e8ad03b6048fb40f5138e9710adb.zip
gen-device-svd: ensure enum bitfields are unique
Diffstat (limited to 'tools')
-rwxr-xr-xtools/gen-device-svd/gen-device-svd.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/gen-device-svd/gen-device-svd.go b/tools/gen-device-svd/gen-device-svd.go
index d6e1ca686..4c8867ab2 100755
--- a/tools/gen-device-svd/gen-device-svd.go
+++ b/tools/gen-device-svd/gen-device-svd.go
@@ -470,6 +470,7 @@ func addInterrupt(interrupts map[string]*interrupt, name, interruptName string,
func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPrefix string) []Bitfield {
var fields []Bitfield
+ enumSeen := map[string]bool{}
for _, fieldEl := range fieldEls {
// Some bitfields (like the STM32H7x7) contain invalid bitfield
// names like "CNT[31]". Replace invalid characters with "_" when
@@ -548,13 +549,23 @@ func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPre
panic(err)
}
}
+ enumName = fmt.Sprintf("%s_%s%s_%s_%s", groupName, bitfieldPrefix, regName, fieldName, enumName)
+ _, seen := enumSeen[enumName]
+ enumSeen[enumName] = seen
fields = append(fields, Bitfield{
- name: fmt.Sprintf("%s_%s%s_%s_%s", groupName, bitfieldPrefix, regName, fieldName, enumName),
+ name: enumName,
description: enumDescription,
value: uint32(enumValue),
})
}
}
+ // check if any of the field names appeared more than once. if so, append
+ // its value onto its name to ensure each name is unique.
+ for i, field := range fields {
+ if dup, seen := enumSeen[field.name]; dup && seen {
+ fields[i].name = fmt.Sprintf("%s_%d", field.name, field.value)
+ }
+ }
return fields
}