Ejemplo n.º 1
0
int terra_toptx(lua_State * L) {
    terra_State * T = terra_getstate(L, 1);
    initializeNVVMState(T);
    lua_getfield(L,1,"llvm_cu");
    TerraCompilationUnit * CU = (TerraCompilationUnit*) terra_tocdatapointer(L,-1);
    llvm::Module * M = CU->M;
    int annotations = 2;
    int dumpmodule = lua_toboolean(L,3);
    int version = lua_tonumber(L,4);
    int major = version / 10;
    int minor = version % 10;

    int N = lua_objlen(L,annotations);
    for(size_t i = 0; i < N; i++) {
        lua_rawgeti(L,annotations,i+1); // {kernel,annotation,value}
        lua_rawgeti(L,-1,1); //kernel name
        lua_rawgeti(L,-2,2); // annotation name
        lua_rawgeti(L,-3,3); // annotation value
        const char * kernelname = luaL_checkstring(L,-3);
        const char * annotationname = luaL_checkstring(L,-2);
        int annotationvalue = luaL_checkint(L,-1);
        llvm::Function * kernel = M->getFunction(kernelname);
        assert(kernel);
        annotateKernel(T,M,kernel,annotationname,annotationvalue);
        lua_pop(L,4); //annotation table and 3 values in it
    }
    
    //sanitize names
    for(llvm::Module::iterator it = M->begin(), end = M->end(); it != end; ++it) {
        const char * prefix = "cudart:";
        int prefixsize = strlen(prefix);
        std::string name = it->getName();
        if(name.size() >= prefixsize && name.substr(0,prefixsize) == prefix) {
            std::string shortname = name.substr(prefixsize);
            it->setName(shortname);
        } if(!it->isDeclaration()) {
            it->setName(sanitizeName(it->getName()));
        }
    }
    for(llvm::Module::global_iterator it = M->global_begin(), end = M->global_end(); it != end; ++it) {
        it->setName(sanitizeName(it->getName()));
    }
	
    std::string ptx;
    moduleToPTX(T,M,major,minor,&ptx);
    if(dumpmodule) {
        fprintf(stderr,"CUDA Module:\n");
        M->dump();
        fprintf(stderr,"Generated PTX:\n%s\n",ptx.c_str());
    }
    lua_pushstring(L,ptx.c_str());
    return 1;
}
Ejemplo n.º 2
0
void AdvancedMetaEngine::updateGameDescriptor(GameDescriptor &desc, const ADGameDescription *realDesc) const {
	if (_singleId != NULL) {
		desc["preferredtarget"] = desc["gameid"];
		desc["gameid"] = _singleId;
	}

	if (!desc.contains("preferredtarget"))
		desc["preferredtarget"] = desc["gameid"];

	if (realDesc->flags & ADGF_AUTOGENTARGET) {
		if (*realDesc->extra)
			desc["preferredtarget"] = sanitizeName(realDesc->extra);
	}

	desc["preferredtarget"] = generatePreferredTarget(desc["preferredtarget"], realDesc);

	if (_flags & kADFlagUseExtraAsHint)
		desc["extra"] = realDesc->extra;

	desc.setGUIOptions(realDesc->guiOptions + _guiOptions);
	desc.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(realDesc->language));

	if (realDesc->flags & ADGF_ADDENGLISH)
		desc.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(Common::EN_ANY));
}
Ejemplo n.º 3
0
/**
 * Return the name of the given value.
 * 
 * @param v  the value
 * @return   the name of the value
 */
std::string JVMWriter::getValueName(const Value *v) {
    if(const GlobalValue *gv = dyn_cast<GlobalValue>(v))
        return sanitizeName(Mangler(MCAsmInfo()).getNameWithPrefix(gv));
    if(v->hasName())
        return '_' + sanitizeName(v->getName());
    if(localVars.count(v)) {
		unsigned int tid;		
		if (temporaryNames.count(v))
			tid = temporaryNames[v];
		else {
			tid = temporaryNames.size();
			temporaryNames[v] = tid;
		}
		return "$" + utostr(tid);
	}
    return "_";
}
Ejemplo n.º 4
0
/**
 * Return the label name of the given block.
 * 
 * @param block  the block
 * @return       the label
 */
std::string JVMWriter::getLabelName(const BasicBlock *block) {
    if(!blockIDs.count(block))
        blockIDs[block] = blockIDs.size() + 1;
    return sanitizeName("label" + utostr(blockIDs[block]));
}
void DataSet::setName(const QString& name, bool sanitize) {
    mName = sanitize ? sanitizeName(name) : name;
}
Ejemplo n.º 6
0
void GGVariable::setName(const QString &name)
{
    // Sanitize name
    m_name = sanitizeName(name);
}