Exemplo n.º 1
0
int PluginXMLParser::parseDOM(const QDomDocument& doc) {
QDomElement topElem = doc.documentElement();

  if (topElem.tagName().lower() == QString::fromLatin1("module")) {
    QDomNode n = topElem.firstChild();

    while (!n.isNull()) {
      QDomElement e = n.toElement();
      QString tn = e.tagName().lower();
      int rc = 0;

      if (tn == QS_interface) {
        rc = parseInterface(e);
      } else if (tn == QS_intro) {
        rc = parseIntro(e);
      } else if (tn == QS_paralist) {
        rc = parseParalist(e);
      } else {
        // Unknown tag
      }

      if (rc < 0) {  // error occurred
        return rc;
      }

      n = n.nextSibling();
    }

  } else {
    return -3;  // XML parse error - no "module" at the top
  }

return 0;
}
Exemplo n.º 2
0
 Desc parseDesc( JSON::Entity const &object )
 {
   Desc result;
   
   JSON::ObjectDecoder objectDecoder( object );
   JSON::Entity keyString, valueEntity;
   while ( objectDecoder.getNext( keyString, valueEntity ) )
   {
     try
     {
       if ( keyString.stringIs( "libs", 4 ) )
       {
         parseHostStringsVector( valueEntity, result.libs );
       }
       else if ( keyString.stringIs( "code", 4 ) )
       {
         parseHostStringsVector( valueEntity, result.code );
       }
       else if ( keyString.stringIs( "jsConstants", 11 ) )
       {
         parseHostStringsVector( valueEntity, result.jsConstants );
       }
       else if ( keyString.stringIs( "interface", 9 ) )
       {
         valueEntity.requireObject();
         parseInterface( valueEntity, result.interface );
       }
     }
     catch ( Exception e )
     {
       objectDecoder.rethrow( e );
     }
   }
   
   return result;
 }
//-----------------------------------------------------------------------------
// Function: GlobalMemoryMapHeaderWriter::writeMemoryMapHeader()
//-----------------------------------------------------------------------------
void GlobalMemoryMapHeaderWriter::writeMemoryMapHeader(QSharedPointer<Component> globalComponent,
    QList<GlobalHeaderSaveModel::SaveFileOptions*> saveOptions)
{
    saveOptions_ = saveOptions;
    QList<GlobalHeaderSaveModel::SaveFileOptions*> options = saveOptions_;

    bool changed = false;

	operatedInterfaces_.clear();
    
    GlobalHeaderSaveModel model(utility_->getLibraryInterface(), parentObject_);
    model.setDesign(globalComponent, componentDesign_);

    if (options.isEmpty())
    {
        // create the dialog to display the headers to be generated
        FileSaveDialog dialog(utility_->getParentWidget());
        dialog.setModel(&model);

        int result = dialog.exec();

        // if user clicked cancel
        if (result == QDialog::Rejected)
        {
            informGenerationAbort();
            return;
        }

        options = model.getHeaderOptions();
    }

    informStartOfGeneration();

	foreach (GlobalHeaderSaveModel::SaveFileOptions* headerOpt, options)
    {
		QFile file(headerOpt->fileInfo_.absoluteFilePath());

        checkDirectoryStructure(headerOpt->fileInfo_.dir());

		if (!file.open(QFile::Truncate | QFile::WriteOnly))
        {
            openFileErrorMessage(headerOpt->fileInfo_.absoluteFilePath());
			break;
		}

		QTextStream stream(&file);

        QString description (" * Header file generated by Kactus2 for instance \"" + headerOpt->instance_ +
            "\" interface \"" + headerOpt->interface_ + "\".\n"+
            " * This file contains addresses of the memories and registers defined in the memory maps " +
            "of connected components.\n" +
            " * Source component: " + headerOpt->comp_.toString() + ".\n" +
        	"*/\n");

        QString headerGuard ("__" + headerOpt->instance_.toUpper() + "_" + headerOpt->interface_.toUpper() + "_H");

        writeTopOfHeaderFile(stream, headerOpt->fileInfo_.fileName(), headerGuard, description);

		Interface cpuMasterInterface(headerOpt->instance_, headerOpt->interface_);
		operatedInterfaces_.append(cpuMasterInterface);

		// start the address parsing from the cpu's interface
		parseInterface(0, stream, cpuMasterInterface);

		stream << "#endif /* " << headerGuard << " */" << endl << endl;

        file.close();

        informWritingFinished(headerOpt->fileInfo_.fileName());

		addHeaderFile(globalComponent, headerOpt->fileInfo_, headerOpt->instance_, QStringList(),
            headerOpt->instanceId_);

		// a header file was added
		changed = true;

		// the list must be cleared when moving to completely new master interface so each header generation
        // starts from scratch.
		operatedInterfaces_.clear();
	}