mirror of https://github.com/llvm/circt.git
[FIRRTL] Add DontTouch annotation helpers
Add additional helper functions to make dealing with DontTouch annotations more convenient.
This commit is contained in:
parent
81c2012d6f
commit
86ae1e83ca
|
@ -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;
|
||||
|
|
|
@ -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())
|
||||
|
|
Loading…
Reference in New Issue