## 层次违例(Hierarchy violation) ### 一、简介 SpinalHDL将会检查当前层次设计的信号不会访问到该组件的外部区域。 下述信号可以被一个组件内所访问: + 在当前组件中定义的所有无方向(directionless)信号 + 当前组件的所有输入/输出和IO信号 + 子(child)组件的所有输入/输出和IO信号 同时, 下列信号可以被分配赋值到组件内部: + 在当前组件中定义的所有无方向(directionless)信号 + 当前组件的所有输出和IO信号 + 子组件的所有输入/输出信号 如果发生了一个`HIERARCHY VIOLATION`错误, 意味着上述的某一规则被违反。 ### 二、例子 下列代码: ```Scala class TopLevel extends Component { val io = new Bundle { val a = in UInt(8 bits) } val tmp = U"x42" io.a := tmp } ``` 会产生如下报错: ``` HIERARCHY VIOLATION : (toplevel/io_a : in UInt[8 bits]) is driven by (toplevel/tmp : UInt[8 bits]), but isn't accessible in the toplevel component. *** Source file location of the `io.a := tmp` via the stack trace *** ``` 修复如下: ```Scala class TopLevel extends Component { val io = new Bundle { val a = out UInt(8 bits) // in转为out } val tmp = U"x42" io.a := tmp } ```