Пример #1
0
static int cpustr_to_cpulist_scatter(bstring bcpustr, int* cpulist, int length)
{
    topology_init();
    CpuTopology_t cpuid_topology = get_cpuTopology();
    affinity_init();
    AffinityDomains_t affinity = get_affinityDomains();
    char* cpustring = bstr2cstr(bcpustr, '\0');
    if (bstrchrp(bcpustr, ':', 0) != BSTR_ERR)
    {
        int insert = 0;
        int suitidx = 0;
        int* suitable = (int*)malloc(affinity->numberOfAffinityDomains*sizeof(int));
        if (!suitable)
        {
            bcstrfree(cpustring);
            return -ENOMEM;
        }
        for (int i=0; i<affinity->numberOfAffinityDomains; i++)
        {
            if (bstrchrp(affinity->domains[i].tag, cpustring[0], 0) != BSTR_ERR)
            {
                suitable[suitidx] = i;
                suitidx++;
            }
        }
        int* sortedList = (int*) malloc(affinity->domains[suitable[0]].numberOfProcessors * sizeof(int));
        if (!sortedList)
        {
            free(suitable);
            bcstrfree(cpustring);
            return -ENOMEM;
        }
        for (int off=0;off<affinity->domains[suitable[0]].numberOfProcessors;off++)
        {
            for(int i=0;i < suitidx; i++)
            {
                cpulist_sort(affinity->domains[suitable[i]].processorList, sortedList, affinity->domains[suitable[i]].numberOfProcessors);
                cpulist[insert] = sortedList[off];
                insert++;
                if (insert == length)
                    goto scatter_done;
            }
        }
scatter_done:
        bcstrfree(cpustring);
        free(sortedList);
        free(suitable);
        return insert;
    }
    bcstrfree(cpustring);
    return 0;
}
int main(int argc, char** argv)
{
    FILE* outputFile;
    GLSLShader result;
    GLLang language = LANG_DEFAULT;
	int returnValue = 0;//EXIT_SUCCESS
    Timer_t timer;
    int compiledOK = 0;
    double crossCompileTime = 0;
    double glslCompileTime = 0;

    printf("args: bytecode-file [output-file] [language override - es100 es300 120 130 etc.]\n");

    if(argc < 2 || !fileExists(argv[1]))
    {
        printf("Bad args. Supply a valid shader path, optionaly followed by the output path\n");
        return 1;//EXIT_FAILURE
    }

    if(argc > 3)
    {
        language = LanguageFromString(argv[3]);
    }

    InitTimer(&timer);

    ResetTimer(&timer);
    compiledOK = TranslateHLSLFromFile(argv[1], 0, language, NULL, &result);
    crossCompileTime = ReadTimer(&timer);

    if(compiledOK)
    {
        printf("cc time: %.2f us\n", crossCompileTime);

        if(argc > 2)
        {
            //Dump to file
            outputFile = fopen(argv[2], "w");
            fprintf(outputFile, result.sourceCode);
            fclose(outputFile);
        }

#if defined(VALIDATE_OUTPUT)
        compiledOK = TryCompileShader(result.shaderType, (argc > 2) ? argv[2] : "", result.sourceCode, &glslCompileTime);
        
        if(!compiledOK)
		{
			returnValue = 1;//EXIT_FAILURE
		}
        else
        {
            printf("glsl time: %.2f us\n", glslCompileTime);
        }
#endif

        bcstrfree(result.sourceCode);
    }

	return returnValue;
}
void removeSignalWatch(
		Signals* signals,
		char* busname,
		char* objectpath,
		char* interface,
		char* signalname)
{
	DBusError dbusError;
	dbus_error_init(&dbusError);
	bstring rule = createRule(busname, objectpath, interface, signalname);

	char* cstr_rule = bstr2cstr(rule,'\0');
	printf("Rule         : %s\n",cstr_rule);

	pthread_mutex_lock(&signals->dbus_mutex);
	dbus_bus_remove_match(signals->con,cstr_rule,&dbusError);
	pthread_mutex_unlock(&signals->dbus_mutex);
	if (dbus_error_is_set(&dbusError)) {
		fprintf(stderr, "%s %d: Error occurred: %s\n",__FILE__,__LINE__, dbusError.message);
		dbus_error_free(&dbusError);
	}

	bcstrfree(cstr_rule);
	bdestroy(rule);
}
Пример #4
0
/* Consume el fin de línea.
 * Indica si encontro basura antes del fin de línea*/
int parse_next_line (Lexer *input){
	bool result = PARSER_OK; /*si es EOF (o el sig char es '\n'), sera true*/
	bstring taken = NULL; /*caracteres leidos*/
	
	/*Pre:*/
	assert(input != NULL);

	/*consumo toda la basura anterior al primer '\n' (o EOF)*/
	taken = next_bstring (input, END_LINE);
	/*si leyo algo, entonces taken no es nulo*/
	if (taken != NULL){
		result = PARSER_ERR;
		bdestroy (taken);

	return result;
}



/*INTERNAS*/


/*Parsea un argumento de los ingresados.
 * Si no hubo error, asigna el argumento parseado en 'arg' y retorna PARSER_OK
 * Si hubo error, no asigna nada a 'arg' y retorna PARSER_ERR
 * El llamador se encarga de liberarlo.
*/
static int parse_argument (Lexer *input, u32 arg){
	int result = PARSER_ERR; /*retorno (error al menos que todo salga bien)*/
	bstring barg = NULL; /*argumento leido en tipo bstring*/
	char * sarg = NULL; /*argumento leido convertido a string*/
	
	assert(input != NULL);
	
	if (!lexer_is_off (input)){
		/*leo hasta el siguiente caracter distinto de 'DIGIT'*/
		barg = next_bstring (input, ALPHA BLANK);
		if (barg != NULL){
			/* lo convierto a string*/
			sarg = bstr2cstr (barg, '\0');
			if (sarg != NULL){
				/* lo convierto a u32*/
				arg = (u32) atoi(sarg);
				result = PARSER_OK;
				/*destruyo sarg*/
				bcstrfree (sarg);
			}
			/*destruyo barg*/
			bdestroy (barg);
		}
		
	}
	
	return result,
}
Пример #5
0
void log_console_message(lua_State *L, char *level) {
  Engine *engine = luaL_get_engine(L);
  
  // Manipulate bstr with var args
  
  bstring totalstr = bfromcstr("");
  concat_log_message(L, totalstr);
  
  char *bcstr = bstr2cstr(totalstr, ' ');
  engine->console->_(log)(engine->console, bcstr, level);
  bcstrfree(bcstr);
  
  bdestroy(totalstr);
}
Пример #6
0
void dbg_lua_handle_hook(struct dbg_state* state, void* ud, freed_bstring type, uint16_t pos)
{
    struct lua_debugst* ds;
    unsigned int i;
    char* cstr;

    // Convert the name to lowercase.
    btolower(type.ref);
    cstr = bstr2cstr(type.ref, '0');

    printd(LEVEL_EVERYTHING, "firing hook %s.\n", cstr);

    // Loop through all of the modules.
    for (i = 0; i < list_size(&modules); i++)
    {
        ds = list_get_at(&modules, i);

        // Set stack top (I don't know why the top of the
        // stack is negative!)
        lua_settop(ds->state, 0);

        // Search handler table for entries.
        lua_getglobal(ds->state, HANDLER_TABLE_HOOKS_NAME);
        lua_getfield(ds->state, -1, cstr);
        if (!lua_istable(ds->state, -1))
        {
            // No such entry.
            printd(LEVEL_EVERYTHING, "no matching hook for %s.\n", cstr);
            lua_pop(ds->state, 2);
            continue;
        }

        // Call the handler function.
        printd(LEVEL_EVERYTHING, "calling hook %s.\n", cstr);
        lua_getfield(ds->state, -1, HANDLER_FIELD_FUNCTION_NAME);
        dbg_lua_push_state(ds, state, ud);
        lua_pushnumber(ds->state, pos);
        if (lua_pcall(ds->state, 2, 0, 0) != 0)
        {
            printd(LEVEL_ERROR, "error: unable to call debugger hook handler for '%s'.\n", type.ref->data);
            printd(LEVEL_ERROR, "%s\n", lua_tostring(ds->state, -1));
            lua_pop(ds->state, 2);
            continue;
        }
    }

    // Clean up.
    bcstrfree(cstr);
    bautodestroy(type);
}
Пример #7
0
///
/// Returns the directory name component of the specified path.
///
/// Returns the directory component of the specified path in a
/// cross-platform manner.
///
/// @param path The path to retrieve the directory name of.
/// @return The directory name component.
///
bstring osutil_dirname(bstring path)
{
    bstring bpath;
    char* cpath;
    char* opath;

    cpath = bstr2cstr(path, '0');
    // needs to return in case of dirname implementation not changing parameter
    // in particular this doesn't work on OS X check $ man 3 dirname
    opath = dirname(cpath);
    bpath = bfromcstr(opath);
    bcstrfree(cpath);

    return bpath;
}
Пример #8
0
int test8 (void) {
struct tagbstring t = bsStatic ("Hello world");
bstring b;
char * c;
int ret = 0;

	printf ("TEST: NetStr functions.\n");
	c = bStr2NetStr (&t);
	ret += 0 != strcmp (c, "11:Hello world,");
	b = bNetStr2Bstr (c);
	ret += 0 >= biseq (b, &t);
	bdestroy (b);
	bcstrfree (c);

	printf ("\t# failures: %d\n", ret);

	return ret;
}
Пример #9
0
END_TEST

START_TEST(core_008)
{
	struct tagbstring t = bsStatic("Hello world");
	int ret = 0;
	bstring b;
	char *c;
	c = bStr2NetStr(&t);
	ck_assert(c != NULL);
	ret = strcmp(c, "11:Hello world,");
	ck_assert_int_eq(ret, 0);
	b = bNetStr2Bstr(c);
	ck_assert(b != NULL);
	ret = biseq(b, &t);
	ck_assert_int_eq(ret, 1);
	ret = bdestroy(b);
	ck_assert_int_eq(ret, BSTR_OK);
	ret = bcstrfree(c);
	ck_assert_int_eq(ret, BSTR_OK);
}
Пример #10
0
int TextResource_getString(TextResource tr, const char* key, unsigned int maxSize, char* buffer) {

	bstring str = tr_evalKey(tr, key);
	normalize_space(str);
	char* cstr = bstr2cstr(str,'0');

	//copy no more than maxSize bytes
	int copysize = strlen(cstr) + 1;
	int rv = copysize;
	if (copysize > maxSize) {
		copysize = maxSize-1;
		buffer[maxSize-1] = '\0'; //null terminate the buffer
		rv = -maxSize; //negative signals we got truncated
	}

	strncpy(buffer,cstr,copysize);
	bcstrfree(cstr);
	bdestroy(str);

	return rv;
}
Пример #11
0
HLSLCC_API void HLSLCC_APIENTRY FreeGLSLShader(GLSLShader* s)
{
    bcstrfree(s->sourceCode);
    s->sourceCode = NULL;
    FreeShaderInfo(&s->reflection);
}
Пример #12
0
static bstring tr_eval(TextResource tr, trnode_t* node) {
	//internally we work with bstrings



	trnode_t* tmpNode;

	switch(node->type) {
	case TRNODE_TEXT:
		return bstrcpy(node->textData);
	case TRNODE_REPR:
		; int match=0;
		if (node->condKey) {
			assert(node->condValue);
			//conditional
			char* condkey = bstr2cstr(node->condKey,'\0');
			bstring val = ght_get(tr->parameters,strlen(condkey),condkey);
			bcstrfree(condkey);

			if (val && !bstrcmp(node->condValue, val)) {
				//matches
				match = 1;
			}
		} else {
			//unconditional, so go too
			match=1;
		}

		if (match) {
			return tr_evalKey(tr,node->reprKey->data);
		} else
			return bfromcstr("");
	case TRNODE_STRING:
		//these guys have a blob of nodes that needs to be catted together smartly
		tmpNode = node->children_list;
		bstring tmpStr = bfromcstralloc(32,"");
		while(tmpNode) {
			bstring childStr = tr_eval(tr,tmpNode);
			bconchar(tmpStr,' ');
			bconcat(tmpStr,childStr);
			bdestroy(childStr);
			tmpNode = tmpNode->next;
		}
		return tmpStr;
	case TRNODE_SWITCH:
		//look through the children for matching choice
		; char* switchVar = bstr2cstr(node->switchVar,'\0');
		bstring val = ght_get(tr->parameters,strlen(switchVar),switchVar);
		bcstrfree(switchVar);

		tmpNode = node->children_list;
		while(tmpNode) {
			assert(tmpNode->type == TRNODE_STRING);
			assert(tmpNode->caseValue);

			if (!bstrcmp(tmpNode->caseValue,val)) {
				//we match, return this
				return tr_eval(tr,tmpNode);
			}
			//try next
			tmpNode = tmpNode->next;
		}
		return bfromcstr("");
	default:
		assert(0);
	}

	assert(0);
	return NULL;
}
Пример #13
0
void dbg_lua_handle_command(struct dbg_state* state, void* ud, freed_bstring name, list_t* parameters)
{
    struct lua_debugst* ds;
    struct customarg_entry* carg;
    char* cstr;
    unsigned int i, k;
    int paramtbl;

    // Convert the name to lowercase.
    btolower(name.ref);
    cstr = bstr2cstr(name.ref, '0');

    // Loop through all of the modules.
    for (k = 0; k < list_size(&modules); k++)
    {
        ds = list_get_at(&modules, k);

        // Set stack top (I don't know why the top of the
        // stack is negative!)
        lua_settop(ds->state, 0);

        // Search handler table for entries.
        lua_getglobal(ds->state, HANDLER_TABLE_COMMANDS_NAME);
        lua_getfield(ds->state, -1, cstr);
        if (!lua_istable(ds->state, -1))
        {
            // No such entry.
            lua_pop(ds->state, 2);
            continue;
        }

        // Call the handler function.
        lua_getfield(ds->state, -1, HANDLER_FIELD_FUNCTION_NAME);
        dbg_lua_push_state(ds, state, ud);
        lua_newtable(ds->state);
        paramtbl = lua_gettop(ds->state);
        for (i = 0; i < list_size(parameters); i++)
        {
            carg = list_get_at(parameters, i);

            lua_newtable(ds->state);
            if (carg->type == DBG_CUSTOMARG_TYPE_PATH)
                lua_pushstring(ds->state, "PATH");
            else if (carg->type == DBG_CUSTOMARG_TYPE_PARAM)
                lua_pushstring(ds->state, "PARAM");
            else if (carg->type == DBG_CUSTOMARG_TYPE_STRING)
                lua_pushstring(ds->state, "STRING");
            else
                lua_pushstring(ds->state, "NUMBER");
            lua_setfield(ds->state, -2, "type");
            if (carg->type == DBG_CUSTOMARG_TYPE_PATH)
                lua_pushstring(ds->state, carg->path->data);
            else if (carg->type == DBG_CUSTOMARG_TYPE_PARAM)
                lua_pushstring(ds->state, carg->param->data);
            else if (carg->type == DBG_CUSTOMARG_TYPE_STRING)
                lua_pushstring(ds->state, carg->string->data);
            else
                lua_pushnumber(ds->state, carg->number);
            lua_setfield(ds->state, -2, "value");
            lua_rawseti(ds->state, paramtbl, i + 1);
        }
        if (lua_pcall(ds->state, 2, 0, 0) != 0)
        {
            printd(LEVEL_ERROR, "error: unable to call debugger command handler for '%s'.\n", name.ref->data);
            printd(LEVEL_ERROR, "%s\n", lua_tostring(ds->state, -1));
            bautodestroy(name);
            bcstrfree(cstr);
            lua_pop(ds->state, 2);
            list_iterator_stop(&modules);
            list_destroy(parameters);
            return;
        }

        bautodestroy(name);
        bcstrfree(cstr);
        lua_pop(ds->state, 2);
        list_iterator_stop(&modules);
        list_destroy(parameters);

        // The command may have started the virtual machine, check the
        // status of the VM and execute if needed.
        if (state->get_vm()->halted == false)
            vm_execute(state->get_vm(), NULL);

        return;
    }

    // There is no command to handle this.
    printd(LEVEL_ERROR, "no such command found.\n");

    // Clean up.
    list_destroy(parameters);
    bautodestroy(name);
    bcstrfree(cstr);
}
Пример #14
0
void pp_lua_handle(struct pp_state* state, void* scanner, bstring name, list_t* parameters)
{
	struct lua_preproc* pp;
	struct customarg_entry* carg;
	char* cstr;
	bstring dot;
	unsigned int i;
	int paramtbl;

	// Convert the name to lowercase.
	btolower(name);
	cstr = bstr2cstr(name, '0');

	// Loop through all of the modules.
	list_iterator_start(&modules);
	while (list_iterator_hasnext(&modules))
	{
		pp = list_iterator_next(&modules);

		// Set stack top (I don't know why the top of the
		// stack is negative!)
		lua_settop(pp->state, 0);

		// Search handler table for entries.
		lua_getglobal(pp->state, HANDLER_TABLE_NAME);
		lua_getfield(pp->state, -1, cstr);
		if (!lua_istable(pp->state, -1))
		{
			// No such entry.
			lua_pop(pp->state, 2);
			continue;
		}

		// Call the handler function.
		lua_getfield(pp->state, -1, HANDLER_FIELD_FUNCTION_NAME);
		pp_lua_push_state(pp, state, scanner);
		lua_newtable(pp->state);
		paramtbl = lua_gettop(pp->state);
		for (i = 0; i < list_size(parameters); i++)
		{
			carg = list_get_at(parameters, i);

			lua_newtable(pp->state);
			if (carg->expr != NULL)
				lua_pushstring(pp->state, "EXPRESSION");
			else if (carg->string != NULL)
				lua_pushstring(pp->state, "STRING");
			else if (carg->word != NULL)
				lua_pushstring(pp->state, "WORD");
			else
				lua_pushstring(pp->state, "NUMBER");
			lua_setfield(pp->state, -2, "type");
			if (carg->expr != NULL)
				luaX_pushexpression(pp->state, carg->expr);
			else if (carg->string != NULL)
				lua_pushstring(pp->state, carg->string->data);
			else if (carg->word != NULL)
				lua_pushstring(pp->state, carg->word->data);
			else
				lua_pushnumber(pp->state, carg->number);
			lua_setfield(pp->state, -2, "value");
			lua_rawseti(pp->state, paramtbl, i + 1);
		}
		if (lua_pcall(pp->state, 2, 0, 0) != 0)
		{
			printd(LEVEL_ERROR, "error: unable to call preprocessor handler for '%s'.\n", name->data);
			printd(LEVEL_ERROR, "%s\n", lua_tostring(pp->state, -1));
			bdestroy(name);
			bcstrfree(cstr);
			lua_pop(pp->state, 2);
			list_iterator_stop(&modules);
			list_destroy(parameters);
			return;
		}

		bdestroy(name);
		bcstrfree(cstr);
		lua_pop(pp->state, 2);
		list_iterator_stop(&modules);
		list_destroy(parameters);
		return;
	}
	list_iterator_stop(&modules);

	// There is no custom preprocessor module that handles this directive, however
	// it could be a directive that is recognised by the underlying assembler / compiler,
	// so pass it through as output.
	dot = bfromcstr(".");
	bconcat(dot, name);
	btoupper(dot);
	bconchar(dot, ' ');
	list_iterator_start(parameters);
	while (list_iterator_hasnext(parameters))
	{
		carg = list_iterator_next(parameters);

		// Output the parameter based on the type.
		if (carg->word != NULL)
			bconcat(dot, carg->word);
		else if (carg->string != NULL)
		{
			bconchar(dot, '"');
			bescape(carg->string);
			bconcat(dot, carg->string);
			bconchar(dot, '"');
		}
		else
			bformata(dot, "%i", carg->number);
	}
	list_iterator_stop(parameters);
	handle_pp_lua_print_line(dot->data, scanner);

	// Clean up.
	list_destroy(parameters);
	bdestroy(name);
	bcstrfree(cstr);
}