Corrected overlapping register detection in TDF validation script
This commit is contained in:
@@ -488,19 +488,6 @@ class ValidationService
|
||||
$failures[] = 'Duplicate register key ("' . $register->key . '") detected';
|
||||
}
|
||||
|
||||
if ($register->alternative !== true) {
|
||||
foreach ($registerGroup->registers as $registerOther) {
|
||||
if ($register->key === $registerOther->key || $registerOther->alternative === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($register->intersectsWith($registerOther)) {
|
||||
$failures[] = 'Register "' . $register->key . '" overlaps with register "'
|
||||
. $registerOther->key . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$processedChildKeys[] = $register->key;
|
||||
}
|
||||
|
||||
@@ -1118,6 +1105,22 @@ class ValidationService
|
||||
. implode(',', $segmentKeys) . ')';
|
||||
continue;
|
||||
}
|
||||
|
||||
$registerAddressRange = $register->addressRange($addressSpace->unitSize);
|
||||
if ($register->alternative !== true) {
|
||||
foreach ($registerGroup->registers as $registerOther) {
|
||||
if ($register->key === $registerOther->key || $registerOther->alternative === true) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$registerOtherAddressRange = $registerOther->addressRange($addressSpace->unitSize);
|
||||
if ($registerAddressRange->intersectsWith($registerOtherAddressRange)) {
|
||||
$failures[] = 'Register "' . $register->key . '" overlaps with register "'
|
||||
. $registerOther->key . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -412,6 +412,7 @@ class TargetDescriptionFile
|
||||
$register->initialValue,
|
||||
$register->description,
|
||||
$register->access,
|
||||
$register->alternative,
|
||||
array_map(
|
||||
fn (BitField $bitField): TargetRegisterBitField => $this->targetRegisterBitFieldFromBitField($bitField),
|
||||
$register->bitFields
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
namespace Targets;
|
||||
|
||||
use Targets\TargetDescriptionFiles\AddressRange;
|
||||
use Targets\TargetDescriptionFiles\TargetDescriptionFile;
|
||||
|
||||
require_once __DIR__ . "/TargetRegisterBitField.php";
|
||||
require_once __DIR__ . "/TargetDescriptionFiles/AddressRange.php";
|
||||
|
||||
/**
|
||||
* Do not confuse this with `TargetDescriptionFiles\Register` - that class represents a <register> element in a TDF,
|
||||
@@ -25,6 +27,7 @@ class TargetRegister
|
||||
public ?int $initialValue = null;
|
||||
public ?string $description = null;
|
||||
public ?string $access = null;
|
||||
public ?bool $alternative = null;
|
||||
|
||||
/** @var TargetRegisterBitField[] */
|
||||
public array $bitFields;
|
||||
@@ -38,6 +41,7 @@ class TargetRegister
|
||||
?int $initialValue,
|
||||
?string $description,
|
||||
?string $access,
|
||||
?bool $alternative,
|
||||
array $bitFields
|
||||
) {
|
||||
$this->key = $key;
|
||||
@@ -48,6 +52,17 @@ class TargetRegister
|
||||
$this->initialValue = $initialValue;
|
||||
$this->description = $description;
|
||||
$this->access = $access;
|
||||
$this->alternative = $alternative;
|
||||
$this->bitFields = $bitFields;
|
||||
}
|
||||
|
||||
public function addressRange(?int $addressSpaceUnitSize): ?AddressRange
|
||||
{
|
||||
return $this->address !== null
|
||||
? new AddressRange(
|
||||
$this->address,
|
||||
$this->address + ($this->size / ($addressSpaceUnitSize ?? 1)) - 1
|
||||
)
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user