gen-device-svd: ensure enum bitfields are unique
Этот коммит содержится в:
родитель
d8dbe5748a
коммит
184175378f
1 изменённых файлов: 12 добавлений и 1 удалений
|
@ -470,6 +470,7 @@ func addInterrupt(interrupts map[string]*interrupt, name, interruptName string,
|
||||||
|
|
||||||
func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPrefix string) []Bitfield {
|
func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPrefix string) []Bitfield {
|
||||||
var fields []Bitfield
|
var fields []Bitfield
|
||||||
|
enumSeen := map[string]bool{}
|
||||||
for _, fieldEl := range fieldEls {
|
for _, fieldEl := range fieldEls {
|
||||||
// Some bitfields (like the STM32H7x7) contain invalid bitfield
|
// Some bitfields (like the STM32H7x7) contain invalid bitfield
|
||||||
// names like "CNT[31]". Replace invalid characters with "_" when
|
// names like "CNT[31]". Replace invalid characters with "_" when
|
||||||
|
@ -548,13 +549,23 @@ func parseBitfields(groupName, regName string, fieldEls []*SVDField, bitfieldPre
|
||||||
panic(err)
|
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{
|
fields = append(fields, Bitfield{
|
||||||
name: fmt.Sprintf("%s_%s%s_%s_%s", groupName, bitfieldPrefix, regName, fieldName, enumName),
|
name: enumName,
|
||||||
description: enumDescription,
|
description: enumDescription,
|
||||||
value: uint32(enumValue),
|
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
|
return fields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче