示例#1
0
bool Neg2MovOppositeOptimization::optimize(AsmCode& code, int index){
	if (prepare(code[index], code[index + 1]) 
		&& *cmd1 == cmdMOV && *cmd1->firstArg() == EAX
		&& *cmd2 == cmdNEG && *cmd2->argument() == EAX
		&& dynamic_cast<AsmImmediateArg*>(cmd1->secondArg())){
			int val = dynamic_cast<AsmImmediateArg*>(cmd1->secondArg())->value;
			AsmCmd2* optCmd = new AsmCmd2(cmdMOV, makeArg(EAX), makeArg(-val));
			code.deleteRange(index, index + 1);
			code.insert(optCmd, index);
			return true;
	}
	return false;
}
示例#2
0
bool CompactAdditionOptimization::optimize(AsmCode& code, int index){
	if(	prepare(code[index], code[index + 1], code[index + 2])
		&& *cmd1 == cmdMOV && *cmd2 == cmdMOV && *cmd1->firstArg() == EBX 
		&& *cmd1->secondArg() == cmd2->firstArg() && *cmd3 == cmdADD 
		&& *cmd3->firstArg() == cmd2->firstArg() && *cmd3->secondArg() == cmd1->firstArg()){
			AsmCmd2* optCmd = new AsmCmd2(cmdMOV, makeArg(EBX), cmd2->secondArg());
			code.deleteRange(index, index + 1);
			code.insert(optCmd, index);
			return true;
	} 
	return false;
}
示例#3
0
bool MultIntByInt2MovOptimization::optimize(AsmCode& code, int index){
	if(	prepare(code[index], code[index + 1], code[index + 2])
		&& *cmd1 == cmdMOV && *cmd2 == cmdMOV
		&& *cmd1->firstArg() == EAX && *cmd2->firstArg() == EBX
		&& cmd1->secondArg()->isImmediate() && cmd2->secondArg()->isImmediate()
		&& *cmd3 == cmdIMUL){
			int val1 = dynamic_cast<AsmImmediateArg*>(cmd1->secondArg())->value,
				val2 = dynamic_cast<AsmImmediateArg*>(cmd2->secondArg())->value;
			AsmCmd2* optCmd = new AsmCmd2(cmdMOV, cmd3->firstArg(), makeArg(val1 * val2));
			code.deleteRange(index, index + 2);
			code.insert(optCmd, index);
			return true;
	}
	return false;
}
示例#4
0
/*
 * Iterate through the passed name=value pairs
 * and construct extArg structs for each of them.
 *
 * Add them to the array of extArg structs inside
 * the req struct 
 */
int parseArguments(struct extRequest *req) {

  char **array, **arrayStep;
  if (cgiFormEntries(&array) != cgiFormSuccess) {
    return 0;
  }

  int num_args = countArguments();
  int arg_num = 0;

  req->numargs = num_args;
  /* make req->args big enough to hold all the extArg structs */
  req->args = (struct extArg **)malloc(sizeof(struct extArg)*num_args);

  arrayStep = array;
  int val_size = 0;
  char *val;
  while (*arrayStep) {

    /* If the name is not a URL, method, or callback, we need to add it */
    if(strcmp(*arrayStep, URL_PARAM_NAME) != 0 &&
       strcmp(*arrayStep, CALLBACK_PARAM_NAME) != 0) {

      /* Get the length of the passed string so our buffer is big enough. */
      cgiFormStringSpaceNeeded(*arrayStep, &val_size);
      val = (char*)malloc(sizeof(char)*val_size);
      cgiFormString(*arrayStep, val, val_size);
      req->args[arg_num++] = makeArg(*arrayStep, val);

      /* The val has been passed to makeArg, so free it */
      free(val);

    }
    arrayStep++;
  }
  cgiStringArrayFree(array);

  return 1;
}
示例#5
0
void outputFile(ClassModelItem clazz, FunctionList functions,
                QList<QPair<QString,QString> > extraFunctions)
{
    // setup
    QString className = clazz->name();
    QString shortName = className.mid(className.lastIndexOf(QRegExp("[A-Z][a-z]*"))).toLower();
    QString tstClassName = "tst_" + className;
    QString indent = "    ";
    QTextStream out(stdout);

    // Includes
    out << endl;
    out << "#include <QtTest/QtTest>" << endl;
    QString classFileName = clazz->fileName().mid(clazz->fileName().indexOf('/'));
    if (classFileName[0] == '/')
        classFileName = classFileName.mid(1);
    out << "#include <" << classFileName << ">" << endl;

    // Generate class definition
    out << endl;
    out << QString("class %1 : public QObject").arg(tstClassName) << endl;
    out << "{" << endl;
    {
        out << indent << "Q_OBJECT" << endl;

        out << endl;
        out << "public slots:" << endl;
        for(int i = 0; i < extraFunctions.count(); ++i) {
            out << indent << QString("void %1();").arg(extraFunctions.at(i).first) << endl;

        }

        out << endl;
        out << "private slots:" << endl;
        out << indent << QString("void %1_data();").arg(className.toLower()) << endl;
        out << indent << QString("void %1();").arg(className.toLower()) << endl;
        out << endl;
        QStringList done;
        foreach (FunctionModelItem fun, functions) {
            if (done.contains(fun->name()))
                continue;
            out << indent << QString("void %1_data();").arg(fun->name()) << endl;
            out << indent << QString("void %1();").arg(fun->name()) << endl;
            done.append(fun->name());
        }
    }
    out << "};" << endl;


    // Generate subclass
    out << endl;
    out << "// Subclass that exposes the protected functions." << endl;
    out << "class Sub" + className + " : public " << className << endl;
    out << "{" << endl;
    {
        out << "public:" << endl;
        foreach (FunctionModelItem fun, functions) {
            // implement protected or virtual functions
            if (fun->accessPolicy() != CodeModel::Protected && !fun->isAbstract())
                continue;

            if (fun->isAbstract())
                out << indent << QString("// %1::%2 is a pure virtual function.").arg(className).arg(fun->name()) << endl;
            out << indent << makeFunction(fun, fun->isAbstract() ? "" : "call_") << endl;

            out << indent << indent << "{ ";
            {
                ArgumentList arguments = fun->arguments();
                if (!fun->isAbstract()) {
                    QStringList args;
                    for (int j = 0; j < arguments.count(); ++j) {
                        QString arg = arguments[j]->name();
                        if (arg.isEmpty())
                            arg = QString("arg%1").arg(j);
                        args += arg;
                    }
                    out << QString("return Sub%1::%2(%3);").arg(className).arg(fun->name()).arg(args.join(", "));
                }
            }
            out << " }" << endl;
            out << endl;
        }
    }
    out << "};" << endl;


    // Generate extra functions
    for(int i = 0; i < extraFunctions.count(); ++i) {
        out << endl;
        out << QString("// %1").arg(extraFunctions.at(i).second) << endl;
        out << QString("void %1::%2()\n{\n}").arg(tstClassName).arg(extraFunctions.at(i).first) << endl;
    }

    QStringList declared;

    // Make the test that calls every function
    out << endl;
    out << QString("void %1::%2_data()\n{\n}\n").arg(tstClassName).arg(className.toLower()) << endl;
    out << QString("void %1::%2()").arg(tstClassName).arg(className.toLower()) << endl;
    out << "{" << endl;
    {
        out << indent << QString("Sub%1 %2;").arg(className).arg(shortName) << endl;
        out << "#if 0" << endl;
        foreach (FunctionModelItem fun, functions) {
            QStringList args;
            for (int i = 0; i < fun->arguments().count(); ++i) {
                QString type= fun->arguments()[i]->type().toString();
                args += makeArg(type);
            }
            QString returnType = makeArg(fun->type().toString());
            out << indent;
            if (returnType != "void")
                out << "QCOMPARE(";
            out << shortName << ".";
            if (fun->accessPolicy() == CodeModel::Protected)
                out << "call_";
            out << fun->name() << "(";
            QString functionArgs = args.join(", ");
            if (functionArgs.endsWith("*"))
                out << "(" << functionArgs << ")0";
            else if (functionArgs == "int")
                out << "0";
            else if (functionArgs == "QString const&")
                out << "QString()";
            else
                out << functionArgs;
            out << ")";
            if (returnType != "void") {
                out << ", ";
                if (returnType == "int")
                    out << "0";
                else if (returnType == "int")
                    out << "0";
                else
                    out << returnType;
                out << ")";
            }
            out << ";" << endl;
        }
        out << "#endif" << endl;
        out << indent << "QSKIP(\"Test is not implemented.\", SkipAll);" << endl;
    }