[FIRRTL] Add DontTouch annotation helpers

Add additional helper functions to make dealing with DontTouch
annotations more convenient.
This commit is contained in:
Fabian Schuiki 2021-10-21 18:51:07 +02:00
parent 81c2012d6f
commit 86ae1e83ca
No known key found for this signature in database
GPG Key ID: C42F5825FC5275E6
2 changed files with 54 additions and 0 deletions

View File

@ -159,6 +159,13 @@ public:
/// firrtl.transforms.DontTouchAnnotation
bool hasDontTouch() const;
bool setDontTouch(bool dontTouch);
bool addDontTouch();
bool removeDontTouch();
static bool hasDontTouch(Operation *op);
static bool setDontTouch(Operation *op, bool dontTouch);
static bool addDontTouch(Operation *op);
static bool removeDontTouch(Operation *op);
bool operator==(const AnnotationSet &other) const {
return annotations == other.annotations;

View File

@ -215,6 +215,53 @@ bool AnnotationSet::hasDontTouch() const {
return hasAnnotation(dontTouchAnnoClass);
}
bool AnnotationSet::setDontTouch(bool dontTouch) {
if (dontTouch)
return addDontTouch();
else
return removeDontTouch();
}
bool AnnotationSet::addDontTouch() {
if (hasDontTouch())
return false;
addAnnotations(DictionaryAttr::get(
getContext(), {{Identifier::get("class", getContext()),
StringAttr::get(getContext(), dontTouchAnnoClass)}}));
return true;
}
bool AnnotationSet::removeDontTouch() {
return removeAnnotation(dontTouchAnnoClass);
}
bool AnnotationSet::hasDontTouch(Operation *op) {
return AnnotationSet(op).hasDontTouch();
}
bool AnnotationSet::setDontTouch(Operation *op, bool dontTouch) {
if (dontTouch)
return addDontTouch(op);
else
return removeDontTouch(op);
}
bool AnnotationSet::addDontTouch(Operation *op) {
AnnotationSet annos(op);
auto changed = annos.addDontTouch();
if (changed)
annos.applyToOperation(op);
return changed;
}
bool AnnotationSet::removeDontTouch(Operation *op) {
AnnotationSet annos(op);
auto changed = annos.removeDontTouch();
if (changed)
annos.applyToOperation(op);
return changed;
}
/// Add more annotations to this AttributeSet.
void AnnotationSet::addAnnotations(ArrayRef<Annotation> newAnnotations) {
if (newAnnotations.empty())