示例#1
0
文件: gen.cpp 项目: herumi/opti
	void gen2()
	{
		const int unit = 64;
		resetGlobalIdx();
		Operand pz(IntPtr, unit);
		Operand px(IntPtr, unit);
		Operand py(IntPtr, unit);
		std::string name = "add128";
		Function f(name, Void, pz, px, py);
		beginFunc(f);
		Operand x = load(px);
		Operand y = load(py);
		x = zext(x, 128);
		y = zext(y, 128);
		x = add(x, y);
		Operand L = trunc(x, 64);
		store(L, pz);
		Operand xH = load(getelementptr(px, makeImm(32, 1)));
		Operand yH = load(getelementptr(py, makeImm(32, 1)));
		x = trunc(lshr(x, 64), 64);
		x = add(x, xH);
		x = add(x, yH);
		store(x, getelementptr(pz, makeImm(32, 1)));
		
		ret(Void);
		endFunc();
	}
示例#2
0
void petabricks::CodeGenerator::continuationRequired(const std::string& hookname){
  std::string n = "cont_" + jalib::XToString(_contCounter++);
  newline();
  write("return "+hookname+" new petabricks::MethodCallTask<"+_curClass+", &"+_curClass+"::"+n+">(this));");
  endFunc();
  beginFunc("DynamicTaskPtr", n);
  if(_rf != RuleFlavor::INVALID)
    beginUserCode(_rf);
}
示例#3
0
void petabricks::CodeGenerator::continuationPoint(){
#ifndef DISABLE_CONTINUATIONS
  std::string n = "cont_" + jalib::XToString(_contCounter++);
  beginIf("useContinuation()");
  write("return new petabricks::MethodCallTask<"+_curClass+", &"+_curClass+"::"+n+">( this );");
  elseIf();
  write("return "+n+"();");
  endIf();
  endFunc();
  beginFunc("DynamicTaskPtr", n);
  if(_rf != RuleFlavor::INVALID)
    beginUserCode(_rf);
#endif
}
示例#4
0
文件: gen.cpp 项目: herumi/opti
	void gen1()
	{
		const int bit = 1024;
		resetGlobalIdx();
		Operand pz(IntPtr, bit);
		Operand px(IntPtr, bit);
		Operand py(IntPtr, bit);
		std::string name = "add" + cybozu::itoa(bit);
		Function f(name, Void, pz, px, py);
		beginFunc(f);
		Operand x = load(px);
		Operand y = load(py);
		x = add(x, y);
		store(x, pz);
		ret(Void);
		endFunc();
	}
示例#5
0
void petabricks::CodeGenerator::generateMigrationFunctions(){
  CodeGenerator& in = forkhelper();
  CodeGenerator& out = forkhelper();
  CodeGenerator& size = forkhelper();
  CodeGenerator& migrateRegion = forkhelper();
  CodeGenerator& getDataHosts = forkhelper();

  std::vector<std::string> args;
  args.push_back("char* _buf");
  args.push_back("RemoteHost& _host");

  size.beginFunc("size_t", "serialSize");
  out.beginFunc("void", "serialize", args);

  args[0] = "const char* _buf";
  in.beginFunc("void", "unserialize", args);
  size.write("size_t _sz = 0;");

  std::vector<std::string> args2;
  args2.push_back("RemoteHost& sender");
  migrateRegion.beginFunc("void", "migrateRegions", args2);

  std::vector<std::string> args3;
  args3.push_back("DataHostPidList& list");
  getDataHosts.beginFunc("void", "getDataHosts", args3);

  for(ClassMembers::const_iterator i=_curMembers.begin(); i!=_curMembers.end(); ++i){
    if(jalib::StartsWith(i->type, "distributed::")) {
      out.write(i->name + ".serialize(_buf, _host);");
      out.write("_buf += " + i->name + ".serialSize();");
      in.write(i->name + ".unserialize(_buf, _host);");
      in.write("_buf += " + i->name + ".serialSize();");
      size.write("_sz += " + i->name + ".serialSize();");
      migrateRegion.comment(i->name + ".updateHandlerChain();");
      getDataHosts.write(i->name + ".dataHosts(list);");

    }else if(i->type == "IndexT" || i->type == "int" || i->type == "double") {
      out.write("*reinterpret_cast<"+i->type+"*>(_buf) = "+i->name+";");
      in.write(i->name+" = *reinterpret_cast<const "+i->type+"*>(_buf);");
      size.write("_sz  += sizeof("+i->type+");");
      in  .write("_buf += sizeof("+i->type+");");
      out .write("_buf += sizeof("+i->type+");");
    }else if(jalib::StartsWith(i->type, "std::vector<")) {
      out.write("_serialize_vector(_buf, "+i->name+");");
      in.write("_unserialize_vector(_buf, "+i->name+");");
      size.write("_sz += _serialSize_vector("+i->name+");");
    }else if(i->type == "DynamicTaskPtr") {
      if(i->initializer != "") {
        in.write(i->name+" = "+i->initializer+";");
      }
    }else{
      JASSERT(false)(i->type).Text("cant yet serialize type");
    }
  }

  size.write("return _sz;");
  in.write("_sender = &_host;");

  in.endFunc();
  out.endFunc();
  size.endFunc();
  migrateRegion.endFunc();
  getDataHosts.endFunc();

  hos() << _curClass << "(const char*, RemoteHost&, bool=false);\n";
  os() << _curClass << "::" << _curClass << "(const char* _buf, RemoteHost& _host, bool shouldInit){\n";
  incIndent();
  write("unserialize(_buf, _host);");
  beginIf("shouldInit");
  write(_curConstructorBody);
  endIf();
  decIndent();
  os() << "\n}\n";

  beginFunc(_curClass+"*", "_new_constructor", std::vector<std::string>(1,"const char* _buf, RemoteHost& _host"), true);
  write("return new "+_curClass+"(_buf, _host);");
  endFunc();

  beginFunc("RemoteObjectGenerator", "generator");
  write("return &RemoteTaskReciever<"+_curClass+">::gen;");
  endFunc();
}