+/*
+ * Square_wrapper.cpp
+ *
+ * Created on: Feb 27, 2009
+ * Author: lschor
+ */
+
+
+#include "@PROCESSNAME@Wrapper.h"
+#include "../lib/spu/dolSupport.h"
+
+#include "@PROCESSNAME@.c"
+
+@PROCESSNAME@Wrapper::@PROCESSNAME@Wrapper(uint64_t argp) {
+ // reserve DMA tag ID
+ uint32_t tag_id;
+ if((tag_id=mfc_tag_reserve())==MFC_TAG_INVALID){
+ printf("SPE: ERROR - can't reserve a tag ID\n"); return;
+ }
+
+ // Get the context information for the whole system
+ mfc_get((void*) &ctx_proc, argp, sizeof(ctx_proc), tag_id, 0, 0);
+ mfc_write_tag_mask(1<<tag_id);
+ mfc_read_tag_status_all();
+
+ this->name = (char *)_malloc_align((uint32_t)ctx_proc.processNameLen, 4);
+ if(!this->name) {
+ fprintf(stderr,"[SPUProcessWrapper] Memory allocation failure\n");
+ exit(-1);
+ }
+ mfc_get((void *)this->name, ctx_proc.processName, ctx_proc.processNameLen, tag_id, 0, 0);
+ waittag(tag_id);
+
+
+ //initialize the index array
+ for (int i = 0; i < 4; i++) {
+ this->_iteratorIndex[i] = getIndex(this->name, "_", i);
+ }
+
+ try { _state = (LocalState) new @PROCESSNAME_UPPER@_State; }
+ catch(std::bad_alloc &e) {
+ fprintf(stderr, "[SPUProcessWrapper] Memory allocation failure\n");
+ exit(-1);
+ }
+ _process.local = _state;
+ _process.init = @PROCESSNAME@_init;
+ _process.fire = @PROCESSNAME@_fire;
+ _process.wptr = (void*)&_wrapper_data;
+
+ _wrapper_data.wrapper = this;
+
+ // Init the process
+ _process.init(&_process);
+
+ // release tag ID before exiting
+ mfc_tag_release(tag_id);
+}
+
+@PROCESSNAME@Wrapper::~@PROCESSNAME@Wrapper() {
+ // Free the state
+ if (_state)
+ delete (@PROCESSNAME_UPPER@_State*) _state;
+
+ // Free the name of the wrapper
+ _free_align(this->name);
+}