dol: add support for iterated ports and processes
authorSebastian <basti@sraa.de>
Tue, 17 Dec 2013 22:14:43 +0000 (23:14 +0100)
committerSebastian <basti@sraa.de>
Tue, 17 Dec 2013 22:14:43 +0000 (23:14 +0100)
dol/src/dol/visitor/epiphany/EpiphanyVisitor.java
dol/src/dol/visitor/epiphany/template/Makefile
dol/src/dol/visitor/epiphany/template/process_Wrapper.c

index 5a053ca424e84a289462d5bd141750dd49b7f2ee..75647964c665498c14c085def7ec43f4e0ae7ded 100644 (file)
@@ -97,9 +97,9 @@ public class EpiphanyVisitor extends PNVisitor {
 //                dst.getBasename().equals(_epiphanyHostName)) {
                        /* this is an SHM buffer */
                        System.out.println("\tBuffer: " +
-                               src.getBasename() + ":" + srcP.getBasename() +
+                               src.getName() + ":" + srcP.getName() +
                                " ==> " +
-                               dst.getBasename() + ":" + dstP.getBasename() +
+                               dst.getName() + ":" + dstP.getName() +
                                " (size " + ch.getSize() + ")" +
                                " as SHM:" + _numShmBufs);
 
@@ -194,11 +194,11 @@ public class EpiphanyVisitor extends PNVisitor {
        private void createProcessWrapper(Process p) throws Exception
        {
                System.out.println("\tcreateProcessWrapper(): " +
-                       p.getBasename());
+                       p.getName());
 
                /* copy template file */
                String filename = _packageName + _delimiter + "esrc" +
-                                 _delimiter + p.getBasename() + "_Wrapper.c";
+                                 _delimiter + p.getName() + "_Wrapper.c";
                String template = _ui.getMySystemCLib() + _delimiter +
                                  "process_Wrapper.c";
                       template = template.replaceAll("systemC", "epiphany");
@@ -208,6 +208,34 @@ public class EpiphanyVisitor extends PNVisitor {
                File fTemplate = new File(template);
                copyFile(fTemplate, fFilename);
 
+               /* handle this process' iterators */
+               String instance = "";
+               Vector<Integer> indices = p.getIteratorIndices();
+               switch(indices.size()) {
+               case 0: instance =
+                               "0,0,0,0"; break;
+               case 1: instance =
+                               indices.elementAt(0) +
+                               ",0,0,0"; break;
+               case 2: instance =
+                               indices.elementAt(0) +
+                               indices.elementAt(1) +
+                               ",0,0"; break;
+               case 3: instance =
+                               indices.elementAt(0) +
+                               "," + indices.elementAt(1) +
+                               "," + indices.elementAt(2) +
+                               ",0"; break;
+               case 4: instance =
+                               indices.elementAt(0) +
+                               "," + indices.elementAt(1) +
+                               "," + indices.elementAt(2) +
+                               "," + indices.elementAt(3); break;
+               default:
+                       throw new Exception("Unsupported iterator dimension");
+               }
+
+
                /* handle this process' ports */
                Integer portNum       = 0;
                String  portMapping   = "";
@@ -216,7 +244,7 @@ public class EpiphanyVisitor extends PNVisitor {
                        EpiphanyBuffer buf = getBuffer(p, port);
 
                        /* port mapping */
-                       portMapping += "\t{ \"" + port.getBasename() + "\", size_" + portNum + ", level_" + portNum + ", ";
+                       portMapping += "\t{ \"" + port.getName() + "\", size_" + portNum + ", level_" + portNum + ", ";
                        portMapping += port.isInPort() ? "read_" + portNum + ", " : "NULL, ";
                        portMapping += port.isOutPort() ? "write_" + portNum + ", " : "NULL, ";
                        portMapping += "},\n";
@@ -244,6 +272,7 @@ public class EpiphanyVisitor extends PNVisitor {
                /* replace information */
                Sed sed = new Sed();
                sed.sed(filename, "@@PROCESSNAME@@",   p.getBasename());
+               sed.sed(filename, "@@INSTANCE@@",      instance);
                sed.sed(filename, "@@NUM_PORTS@@",     portNum.toString());
                sed.sed(filename, "@@PORTMAPPING@@",   portMapping);
                sed.sed(filename, "@@PORTFUNCTIONS@@", portFunctions);
@@ -309,6 +338,7 @@ public class EpiphanyVisitor extends PNVisitor {
                String srecFiles = "";
                Integer srecNum = 0;
                for(Process p : pn.getProcessList()) {
+                       /* TODO: fix _epiphanyHostName */
                        if(!_epiphanyHostName.equals(p.getBasename())) {
                                srecFiles += "\t\"bin/" + p.getBasename() + ".srec\",\n";
                                srecNum++;
@@ -354,15 +384,31 @@ public class EpiphanyVisitor extends PNVisitor {
                /* generate srec filenames */
                String srecFiles = "";
                for(Process p : pn.getProcessList()) {
+                       /* TODO: fix _epiphanyHostName */
                        if(!_epiphanyHostName.equals(p.getBasename())) {
                                srecFiles += "\\$(DEST)/" +
-                                       p.getBasename() + ".srec ";
+                                       p.getName() + ".srec ";
                        }
                }
 
+               /* generate .elf rules, because wrapper file names are
+                  non-obvious with iterated processes... */
+               String elfRules = "";
+               for(Process p : pn.getProcessList()) {
+                       elfRules +=
+                               "\\$(EDEST)/" + p.getName() + ".elf: " +
+                               "\\$(EDEST)/" + p.getBasename() + ".o " +
+                               "\\$(EDEST)/" + p.getName() + "_Wrapper.o " +
+                               "\\$(ECOMMON)\n";
+                       elfRules +=
+                               "\t@\\$(ECHO) \"\\\\t(EPIPHANY) LINK\\\\t\\\\t\\$@\"\n" +
+                               "\t@\\$(CC) -o \\$@ \\$^ \\$(LFLAGS)\n\n";
+               }
+
                /* do the replace */
                Sed sed = new Sed();
-               sed.sed(filename, "@@SREC_FILES@@",   srecFiles);
+               sed.sed(filename, "@@SREC_FILES@@", srecFiles);
+               sed.sed(filename, "@@ELF_RULES@@",  elfRules);
                System.out.println("done!");
        }
 }
index 90cc3bf2c6cb7073f20a33bfb9b343343a5d6440..bfafbde11a11e1fc0133144cb8de989aa5120a1a 100644 (file)
@@ -18,7 +18,6 @@ HOBJS = $(HDEST)/main.o
 
 # Epiphany applications and common objects
 EPAPPS = @@SREC_FILES@@
-EWRAPPERS = $(patsubst $(DEST)%,$(EDEST)%,$(EPAPPS:.srec=_Wrapper.o))
 ECOMMON        = $(EDEST)/dol.o $(EDEST)/ports.o $(EDEST)/index.o
 
 # Epiphany build flags
@@ -33,48 +32,50 @@ HOSTCC      = gcc
 HCFLAGS        = -O2 -std=c99 -I$(EPIPHANY_HOME)/tools/host/include -Wall
 HLFLAGS        = -L$(EPIPHANY_HOME)/tools/host/lib -le-hal
 
-# Global rules
+# ===========================================================================
+ECHO   = /bin/echo -e
 .SECONDARY:
 .PHONY: all run host cores clean
 all: run
 
 host: $(HOSTAPP)
 
-cores: $(ECOMMON) $(EWRAPPERS) $(EPAPPS)
+cores: $(ECOMMON) $(EPAPPS)
 
 run: host cores
-       @echo -e "\tRUN"
+       @$(ECHO) "\tRUN"
        @sudo LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) \
              EPIPHANY_HDF=$(EPIPHANY_HDF) \
              $(HOSTAPP)
 
 clean:
-       @echo -e "\tCLEAN"
+       @$(ECHO) "\tCLEAN"
        @rm -v -f $(HOSTAPP) $(EPAPPS) $(EDEST)/* $(HDEST)/*
 
 # Host rules
 $(HOSTAPP): $(HOBJS)
-       @echo -e "\t(HOST)     LINK\t$@"
+       @$(ECHO) "\t(HOST)     LINK\t$@"
        @$(HOSTCC) -o $@ $^ $(HLFLAGS)
 
 $(HDEST)/%.o: $(HSRC)/%.c
-       @echo -e "\t(HOST)     CC\t$@"
+       @$(ECHO) "\t(HOST)     CC\t$@"
        @$(HOSTCC) $(HCFLAGS) -c -o $@ $^
 
 # Epiphany rules
 $(DEST)/%.srec: $(EDEST)/%.elf
-       @echo -e "\t(EPIPHANY) OBJCOPY $@"
+       @$(ECHO) "\t(EPIPHANY) OBJCOPY\t$@"
        @$(OBJCOPY) $(OCFLAGS) --output-target srec --srec-forceS3 $^ $@
 
-$(EDEST)/%.elf: $(EDEST)/%.o $(EDEST)/%_Wrapper.o $(ECOMMON)
-       @echo -e "\t(EPIPHANY) LINK\t$@"
-       @$(CC) -o $@ $^ $(LFLAGS)
+@@ELF_RULES@@
+#$(EDEST)/%.elf: $(EDEST)/%.o $(ECOMMON)
+#      @$(ECHO) "\t(EPIPHANY) LINK\t$@"
+#      @$(CC) -o $@ $^ $(LFLAGS)
 
 $(EDEST)/%.o: $(ESRC)/%.c
-       @echo -e "\t(EPIPHANY) CC\t$@"
+       @$(ECHO) "\t(EPIPHANY) CC\t\t$@"
        @$(CC) $(CFLAGS) -c -o $@ $^
 
 $(EDEST)/%.o: $(ELIB)/%.c
-       @echo -e "\t(EPIPHANY) CC\t$@"
+       @$(ECHO) "\t(EPIPHANY) CC\t\t$@"
        @$(CC) $(CFLAGS) -c -o $@ $^
 
index def5887b9e445a1d98a7abe7130773d058e132f1..12ae88201ad7d9b6459c75b37da96a97528a904c 100644 (file)
@@ -13,7 +13,7 @@ shm_t shm SECTION(".shared_dram");
  * ===================================================================== */
 struct _DOL_wptr @@PROCESSNAME@@_wptr = {
        1,              /* active   */
-       {0,0,0,0}       /* instance */
+       {@@INSTANCE@@}  /* instance */
 };
 
 @@PROCESSNAME@@_State @@PROCESSNAME@@_local;