diff --git a/elab_scope.cc b/elab_scope.cc index 640a6514c..149a87bba 100644 --- a/elab_scope.cc +++ b/elab_scope.cc @@ -741,7 +741,11 @@ void PGModule::elaborate_scope_mod_(Design*des, Module*mod, NetScope*sc) const /* Stash the instance array of scopes into the parent scope. Later elaboration passes will use this vector to - further elaborate the array. */ + further elaborate the array. + + Note that the array is ordered from LSB to MSB. We will use + that fact in the main elaborate to connect things in the + correct order. */ sc->instance_arrays[get_name()] = instances; } diff --git a/elaborate.cc b/elaborate.cc index 8992c1685..49c72f683 100644 --- a/elaborate.cc +++ b/elaborate.cc @@ -1037,7 +1037,9 @@ void PGModule::elaborate_mod_(Design*des, Module*rmod, NetScope*scope) const unsigned prts_vector_width = 0; for (unsigned inst = 0 ; inst < instance.count() ; inst += 1) { - NetScope*inst_scope = instance[inst]; + // Scan the instances from MSB to LSB. The port + // will be assembled in that order as well. + NetScope*inst_scope = instance[instance.count()-inst-1]; // Scan the module sub-ports for this instance... for (unsigned ldx = 0 ; ldx < mport.count() ; ldx += 1) {