Anonymous - 2012-05-16

I really prefer the VHDL entity instantiation to the old component instantiation because of a defined namespace and less overhead. (See here for an example: http://vhdlguru.blogspot.de/2010/03/entity-instantiation-easy-way-of-port.html)
There seems to be support for these instantiations in VHDL but the name of the library containing the entity is missing. I've patched the code so it will work for me. Perhaps this can be put to the repository if I don't understand something wrong.

From 14615f6d6313593044172a9d265a863effd6a1a7 Mon Sep 17 00:00:00 2001
From: Fabian May <@tu-harburg.de>
Date: Wed, 16 May 2012 14:29:27 +0200
Subject: [PATCH 1/2] Added library name in the EntityInstantiation
---
 .../main/java/de/upb/hni/vmagic/VhdlElement.java   |   12 ++++++-
 .../src/main/java/de/upb/hni/vmagic/VhdlFile.java  |   38 ++++++++++++-------
 .../de/upb/hni/vmagic/libraryunit/LibraryUnit.java |    7 ++--
 .../output/VhdlConcurrentStatementVisitor.java     |    2 +
 4 files changed, 41 insertions(+), 18 deletions(-)
diff --git a/vmagic/src/main/java/de/upb/hni/vmagic/VhdlElement.java b/vmagic/src/main/java/de/upb/hni/vmagic/VhdlElement.java
index 8def9e6..221300e 100644
--- a/vmagic/src/main/java/de/upb/hni/vmagic/VhdlElement.java
+++ b/vmagic/src/main/java/de/upb/hni/vmagic/VhdlElement.java
@@ -29,7 +29,8 @@ import java.util.Map;
  */
 public abstract class VhdlElement {

-    private Map<Class<?>, Object> annotationList;
+    protected static final String DEFAULT_LIBRARY = "work";
+   private Map<Class<?>, Object> annotationList;
     private DeclarativeRegion parent;

     /**
@@ -67,4 +68,13 @@ public abstract class VhdlElement {
     public DeclarativeRegion getParent() {
         return parent;
     }
+    
+    public String getLibraryName() {
+       DeclarativeRegion parent = getParent();
+       if (parent != null && parent instanceof VhdlElement){
+           return ((VhdlElement) parent).getLibraryName();
+       } else {
+           return DEFAULT_LIBRARY;
+       }
+   }
 }
diff --git a/vmagic/src/main/java/de/upb/hni/vmagic/VhdlFile.java b/vmagic/src/main/java/de/upb/hni/vmagic/VhdlFile.java
index c045823..b0eda33 100644
--- a/vmagic/src/main/java/de/upb/hni/vmagic/VhdlFile.java
+++ b/vmagic/src/main/java/de/upb/hni/vmagic/VhdlFile.java
@@ -32,21 +32,31 @@ import java.util.List;
  */
 public class VhdlFile extends VhdlElement implements DeclarativeRegion {

-    private final ResolvableList<LibraryUnit> elements =
-            VhdlCollections.createNamedEntityList(this);
-    private final Scope scope = Scopes.createScope(this, elements);
+   private final ResolvableList<LibraryUnit> elements = VhdlCollections
+           .createNamedEntityList(this);
+   private final Scope scope = Scopes.createScope(this, elements);

-    /**
-     * Returns the list of elements in this VHDL file.
-     * @return the list of elements
-     */
-    public List<LibraryUnit> getElements() {
-        return elements;
-    }
+   /**
+    * Returns the list of elements in this VHDL file.
+    * 
+    * @return the list of elements
+    */
+   public List<LibraryUnit> getElements() {
+       return elements;
+   }

-    public Scope getScope() {
-        return scope;
-    }
+   public Scope getScope() {
+       return scope;
+   }
+
+   @Override
+   public String getLibraryName() {
+       DeclarativeRegion parent = getParent();
+       if (parent != null && parent instanceof LibraryDeclarativeRegion) {
+           return ((LibraryDeclarativeRegion) parent).getIdentifier();
+       } else {
+           return DEFAULT_LIBRARY;
+       }
+   }

-   
 }
diff --git a/vmagic/src/main/java/de/upb/hni/vmagic/libraryunit/LibraryUnit.java b/vmagic/src/main/java/de/upb/hni/vmagic/libraryunit/LibraryUnit.java
index 1910586..801ccc2 100644
--- a/vmagic/src/main/java/de/upb/hni/vmagic/libraryunit/LibraryUnit.java
+++ b/vmagic/src/main/java/de/upb/hni/vmagic/libraryunit/LibraryUnit.java
@@ -28,8 +28,9 @@ import de.upb.hni.vmagic.VhdlElement;
 /**
  * Library unit.
  */
-public abstract class LibraryUnit extends VhdlElement
-        implements DeclarativeRegion {
+public abstract class LibraryUnit extends VhdlElement implements
+       DeclarativeRegion {
+
+   abstract void accept(LibraryUnitVisitor visitor);

-    abstract void accept(LibraryUnitVisitor visitor);
 }
diff --git a/vmagic/src/main/java/de/upb/hni/vmagic/output/VhdlConcurrentStatementVisitor.java b/vmagic/src/main/java/de/upb/hni/vmagic/output/VhdlConcurrentStatementVisitor.java
index a493d70..62537ee 100644
--- a/vmagic/src/main/java/de/upb/hni/vmagic/output/VhdlConcurrentStatementVisitor.java
+++ b/vmagic/src/main/java/de/upb/hni/vmagic/output/VhdlConcurrentStatementVisitor.java
@@ -277,6 +277,8 @@ class VhdlConcurrentStatementVisitor extends ConcurrentStatementVisitor {
     protected void visitEntityInstantiation(EntityInstantiation statement) {
         appendLabel(statement);
         writer.append(Keyword.ENTITY).append(' ');
+        //TODO add library here
+        writer.append(statement.getEntity().getLibraryName()).append('.');
         writer.appendIdentifier(statement.getEntity()).indent();
         appendComponentInstantiationMaps(statement);
         writer.dedent().append(';').newLine();
-- 
1.7.7