Ejemplo n.º 1
0
static const char *test_get_var(void) {
  static const char *post[] = {
    "a=1&&b=2&d&=&c=3%20&e=",
    "q=&st=2012%2F11%2F13+17%3A05&et=&team_id=",
    NULL
  };
  char buf[20];

  ASSERT(get_var(post[0], strlen(post[0]), "a", buf, sizeof(buf)) == 1);
  ASSERT(buf[0] == '1' && buf[1] == '\0');
  ASSERT(get_var(post[0], strlen(post[0]), "b", buf, sizeof(buf)) == 1);
  ASSERT(buf[0] == '2' && buf[1] == '\0');
  ASSERT(get_var(post[0], strlen(post[0]), "c", buf, sizeof(buf)) == 2);
  ASSERT(buf[0] == '3' && buf[1] == ' ' && buf[2] == '\0');
  ASSERT(get_var(post[0], strlen(post[0]), "e", buf, sizeof(buf)) == 0);
  ASSERT(buf[0] == '\0');

  ASSERT(get_var(post[0], strlen(post[0]), "d", buf, sizeof(buf)) == -1);
  ASSERT(get_var(post[0], strlen(post[0]), "c", buf, 2) == -2);

  ASSERT(get_var(post[0], strlen(post[0]), "x", NULL, 10) == -2);
  ASSERT(get_var(post[0], strlen(post[0]), "x", buf, 0) == -2);
  ASSERT(get_var(post[1], strlen(post[1]), "st", buf, 16) == -2);
  ASSERT(get_var(post[1], strlen(post[1]), "st", buf, 17) == 16);
  return NULL;
}
Ejemplo n.º 2
0
void write_flags(FILE *fp,int platform, int optimize)
{
  char tmp[1000];
  char nm[100];
  if (optimize)
    fprintf(fp,"CFLAGS_O=%s",include_path(platform));
  else
    fprintf(fp,"CFLAGS_D=%s",include_path(platform));

  if (optimize) 
    sprintf(nm,"%s_OPTIMIZE",plat_name[platform]);
  else
    sprintf(nm,"%s_DEBUG",plat_name[platform]);

  get_var(nm,tmp);
  fprintf(fp," %s ",tmp);


  if (platform!=DOS && platform!=LINUX)
    fprintf(fp,"-DBIG_ENDIANS ");
  if (platform==SUN)
    fprintf(fp,"-I/lusr/X11R5/include ");
  if (get_var("CFLAGS",z))
    fprintf(fp,"%s ",z);

  sprintf(tmp,"%s_FLAGS",plat_name[platform]);
  if (get_var(tmp,z))
    fprintf(fp,"%s ",z);


  fprintf(fp,"\n");
}
Ejemplo n.º 3
0
main(int argc, char **argv)
{
  int pf,i;
  char tmp[1000];
  first_var=NULL;
  no_include=0;

  for (i=1;i<argc;i++)
  {
    if (!strcmp(argv[i],"-f"))
    {
      i++;
      template_file=argv[i];
    }
    if (!strcmp(argv[i],"-noi"))
      no_include=1;
  }

  process_file(template_file);
  pf=detect_platform();
  printf("Genering Makefile for %s\n",plat_names[pf]);

  if (get_var("O_FILES",tmp))
    ofiles=(char *)strcpy((char *)malloc(strlen(tmp)+1),tmp);
  if (get_var("BASE_NAME",tmp))
    basename=(char *)strcpy((char *)malloc(strlen(tmp)+1),tmp);
  if (get_var("IMLIB_DIR",tmp))
    imlib_dir=(char *)strcpy((char *)malloc(strlen(tmp)+1),tmp);
  if (get_var("IMLIB_OBJS",tmp))
    imlib_objs=(char *)strcpy((char *)malloc(strlen(tmp)+1),tmp);

 
  make_makefile(pf);
  printf("done                                               \n");
}
Ejemplo n.º 4
0
/*
 * Authenticates the user. Takes their password, crypt()'s it using
 * the salt from their password entry and compares the result with
 * their stored password.
 *
 * Returns:
 * 	 0 for successful authentication
 * 	-1 for authentication failed
 * 	-2 for account disabled
 * 	-3 for denied by IP ACL
 */
int check_auth(void)
{
	int ret = -1;
	int err;
	char *username;
	char *enc_passwd;
	MYSQL_RES *res;
	MYSQL_ROW row;

	err = check_ip_acl();
	if (err == -1)
		return -3;

	username = make_mysql_safe_string(get_var(qvars, "username"));
	res = sql_query("SELECT password, enabled FROM passwd WHERE username "
			"= '%s'", username);
	if (mysql_num_rows(res) < 1)
		goto out;

	row = mysql_fetch_row(res);
	if (atoi(row[1]) == 0) {
		ret = -2;
		goto out;
	}

	enc_passwd = crypt(get_var(qvars, "password"), row[0]);
	if (strcmp(enc_passwd, row[0]) == 0)
		ret = 0;

out:
	mysql_free_result(res);
	free(username);

	return ret;
}
Ejemplo n.º 5
0
static void do_catch_up(struct spk_synth *synth)
{
	u_char ch;
	unsigned long flags;
	unsigned long jiff_max;
	struct var_t *jiffy_delta;
	struct var_t *delay_time;
	int jiffy_delta_val;
	int delay_time_val;

	jiffy_delta = get_var(JIFFY);
	delay_time = get_var(DELAY);
	spk_lock(flags);
	jiffy_delta_val = jiffy_delta->u.n.value;
	spk_unlock(flags);
	jiff_max = jiffies + jiffy_delta_val;
	while (!kthread_should_stop()) {
		spk_lock(flags);
		if (speakup_info.flushing) {
			speakup_info.flushing = 0;
			spk_unlock(flags);
			synth->flush(synth);
			continue;
		}
		if (synth_buffer_empty()) {
			spk_unlock(flags);
			break;
		}
		set_current_state(TASK_INTERRUPTIBLE);
		delay_time_val = delay_time->u.n.value;
		spk_unlock(flags);
		if (synth_full()) {
			schedule_timeout(msecs_to_jiffies(delay_time_val));
			continue;
		}
		set_current_state(TASK_RUNNING);
		spk_lock(flags);
		ch = synth_buffer_getc();
		spk_unlock(flags);
		if (ch == '\n')
			ch = PROCSPEECH;
		spk_out(ch);
		if ((jiffies >= jiff_max) && (ch == SPACE)) {
			spk_out(PROCSPEECH);
			spk_lock(flags);
			delay_time_val = delay_time->u.n.value;
			jiffy_delta_val = jiffy_delta->u.n.value;
			spk_unlock(flags);
			schedule_timeout(msecs_to_jiffies(delay_time_val));
			jiff_max = jiffies + jiffy_delta_val;
		}
	}
	spk_out(PROCSPEECH);
}
static int play(struct action_event *event)
{
	if (obtain_instanceid(event, NULL) < 0) {
		return -1;
	}

	int rc = 0;
	service_lock();
	switch (transport_state_) {
	// even if already playing, we must restart playback when Play
	// action is executed. Kinsky, for example, would not send Stop
	// when changing tracks and playback is already in progress -
	// it will just set new URI, and send Play command
	case TRANSPORT_PLAYING:
	case TRANSPORT_STOPPED:
		// If we were stopped before, we start a new song now. So just
		// set the time to zero now; otherwise we will see the old
		// value of the previous song until it updates some fractions
		// of a second later.
		replace_var(TRANSPORT_VAR_REL_TIME_POS, kZeroTime);

		/* >>> fall through */

	case TRANSPORT_PAUSED_PLAYBACK:
		if (output_play(&inform_play_transition_from_output)) {
			upnp_set_error(event, 704, "Playing failed");
			rc = -1;
		} else {
			change_transport_state(TRANSPORT_PLAYING);
			const char *av_uri = get_var(TRANSPORT_VAR_AV_URI);
			const char *av_meta = get_var(TRANSPORT_VAR_AV_URI_META);
			replace_current_uri_and_meta(av_uri, av_meta);
		}
		break;

	case TRANSPORT_NO_MEDIA_PRESENT:
	case TRANSPORT_TRANSITIONING:
	case TRANSPORT_PAUSED_RECORDING:
	case TRANSPORT_RECORDING:
		/* action not allowed in these states - error 701 */
		upnp_set_error(event, UPNP_TRANSPORT_E_TRANSITION_NA,
			       "Transition not allowed; allowed=%s",
			       get_var(TRANSPORT_VAR_CUR_TRANSPORT_ACTIONS));
		rc = -1;
		break;
	}
	service_unlock();

	return rc;
}
Ejemplo n.º 7
0
void test_reload_insn_is_inserted_at_the_beginning_of_the_interval_if_necessary(void)
{
        struct compilation_unit *cu;
        struct insn *insn_array[2];
        struct var_info *r1, *r2;
        struct basic_block *bb;
	struct insn *insn;

        cu = compilation_unit_alloc(&method);
        r1 = get_var(cu, J_INT);
        r2 = get_var(cu, J_INT);

        insn_array[0] = arithmetic_insn(INSN_ADD, r1, r1, r1);
        insn_array[1] = arithmetic_insn(INSN_ADD, r2, r2, r2);

        bb = get_basic_block(cu, 0, 2);
        bb_add_insn(bb, insn_array[0]);
        bb_add_insn(bb, insn_array[1]);

	r1->interval->spill_reload_reg.interval = r1->interval;
	r2->interval->spill_reload_reg.interval = r2->interval;

	r2->interval->flags |= INTERVAL_FLAG_NEED_RELOAD;
	r2->interval->spill_parent = r1->interval;

	compute_insn_positions(cu);
	analyze_liveness(cu);
	insert_spill_reload_insns(cu);

	/*
	 * A reload instruction is inserted at the beginning.
	 */
	insn = list_first_entry(&bb->insn_list, struct insn, insn_list_node);
	assert_ld_insn(INSN_LD_LOCAL, r2->interval->reg, r1->interval->spill_slot, insn);

	/*
	 * Second instruction stays the same.
	 */
	insn = list_next_entry(&insn->insn_list_node, struct insn, insn_list_node);
	assert_ptr_equals(insn_array[0], insn);

	/*
	 * Last instruction stays the same. 
	 */
	insn = list_next_entry(&insn->insn_list_node, struct insn, insn_list_node);
	assert_ptr_equals(insn_array[1], insn);

	free_compilation_unit(cu);
}
Ejemplo n.º 8
0
bool 
ExpressionVariable::visit_facts(vector<const Fact*>& inputs, CGContext& cg_context) const
{ 
	int deref_level = get_indirect_level();
	const Variable* v = get_var();   
	if (deref_level > 0) { 
		if (!FactPointTo::is_valid_ptr(v, inputs)) {
			return false;
		}
		// Yang: do we need to consider the deref_level?
		bool valid = cg_context.check_read_var(v, inputs) && cg_context.read_pointed(this, inputs) && 
			cg_context.check_deref_volatile(v, deref_level);
		return valid;
	}
	// we filter out bitfield
	if (deref_level < 0) {
		if (v->isBitfield_) 
			return false; 
		// it's actually valid to take address of a null/dead pointer  
		return true;
	}
	else {
		return cg_context.check_read_var(v, inputs);
	} 
}
Ejemplo n.º 9
0
static int
read_file( FILE *file, int *stacksiz)
{
	int  lineno = 1;
	char string[LINE_LENGTH+1];
	
	while( fgets( string, LINE_LENGTH, file) != NULL ) {
		char   *key, *value;
		var_t  *var;
		
		
		
		if( string[strlen(string)-1] != '\n' ) {
			printf( "Line %d: Line too long.\n", lineno);
			return -1;
		}
		
		key = strtok_r( string, ":", &value);
		if( !(var = get_var( key, varlist)) ) {
			printf( "Line %d: Key '%s' not found.\n", lineno, key);
			return -1;
		}
		
		var->stuff.prog = program_init();
		strip_string( value);
		if( parse_expression( value, var->stuff.prog, stacksiz, var->type, symbol_parser) == -1 ) {
			printf( "Line %d: %s\n", lineno, parse_error);
			return -1;
		}
		
		lineno++;
	}
	
	return 0;
};
Ejemplo n.º 10
0
void print_opnd_type(Opnd o) {
  if(is_reg(o)) {
    if(is_hard_reg(o)) {
      std::cout << "(is hard reg)";
    }
    else if(is_virtual_reg(o)) {
      std::cout << "(is virtual reg)[$vr"<<get_reg(o)<<"]";
    }
    else {
      std::cout << "(is undeterminate reg)";
    }
  }
  else if(is_immed(o)) {
    if(is_immed_integer(o)) {
      std::cout << "(is immed integer)";
    }
    else if(is_immed_string(o)) {
      std::cout << "(is immed string)";
    }
    else {
      std::cout << "(is undeterminate immed)";
    }
  }
  else if(is_addr(o)) {
    if(is_addr_sym(o)) {
      FormattedText ft;
      Sym *symbol = get_sym(o);
      symbol->print(ft);
      char* addr_name;
      
      addr_name =  (char*)(symbol->get_name()).c_str();
  
      std::cout << "(is addr sym)["<<addr_name<<"]";
    }
    else if(is_addr_exp(o)) {
      std::cout << "(is addr exp)";
    }
    else {
      std::cout << "(is undeterminate addr)";
    }
  }
  else if(is_var(o)) {
    FormattedText ft;
    VarSym *vsym = get_var(o);
    vsym->print(ft);
    char* var_name;
    
    var_name =  (char*)(vsym->get_name()).c_str();

    std::cout << "(is var)["<<var_name<<"]";
  }
  else if(is_null(o)) {
    std::cout << "(is null)";
  }
  else {
    std::cout << "(I don't know) !!!)";
  }

  return;
}
Ejemplo n.º 11
0
/*
 * Returns 1 if bootenv.rc was modified, 0 otherwise.
 */
static int
set_var(char *name, char *val, eplist_t *list)
{
	benv_ent_t *p;

	if (strcmp(name, "bootcmd") == 0)
		return (0);

	if (verbose) {
		(void) printf("old:");
		print_var(name, list);
	}

	if ((p = get_var(name, list)) != NULL) {
		free(p->val);
		p->val = strdup(val);
	} else
		add_bent(list, NULL, "setprop", name, val);

	if (verbose) {
		(void) printf("new:");
		print_var(name, list);
	}
	return (1);
}
Ejemplo n.º 12
0
int main() {
  struct _type_t var1, var2, var3, *var4;
  _i32 i = 10, j = 20;

  ast.env.n_vars = 0;
  new_var(&ast, &var1, "variable1", 1, &i);
  new_var(&ast, &var2, "variable2", 1, &j);
  new_var(&ast, &var3, "str", STR, "hello world");

  PRINT_INTEGER(var1);
  PRINT_INTEGER(var2);
  PRINT_STR(var3);

  if (get_var(&ast, &var4, "variable1")) {
    PRINT_VAR((*var4));
  } else {
    printf("failed to get variable\n");
  }

  assign(&ast, "variable1", 15);

  PRINT_VAR(var1);

  assign(&ast, "variable1", 20);

  PRINT_VAR(var1);
  
  return 0;
}
Ejemplo n.º 13
0
/**
 * Parses a free instruction
 *
 * @param cmd String representing an allocation command in the program
 * @returns Status of read and execute
 */
static status_t parse_free(char* cmd)
{
	assert(cmd != NULL);

	char var_name;
	int matched;
	var_t* var;

	// Read the command string
	errno = 0;
	matched = sscanf(cmd, "free(%c)", &var_name);

	// Check if sscanf was valid
	if (matched != 1 || errno != 0 || (var = get_var(var_name)) == NULL)
		return parse_error(cmd);

	// Ensure that the variable is in use
	if (!var->in_use) {
		print_fault(cmd, "Double free", ERROR);
		return DOUBLEFREE;
	}

	// Free variable
	buddy_free(var->mem);
	var->mem = NULL;
	var->in_use = false;

	return SUCCESS;
}
Ejemplo n.º 14
0
void	color_number_down_100(void)
{
	t_var	*var;

	var = get_var();
	var->color_number -= 100;
}
Ejemplo n.º 15
0
void get_instructions(struct mg_connection *conn,
		 const struct mg_request_info *ri)
{
    char *inst_list;
    char base_address_hex[16];
    char count[16];
    UInt32 base_address;

    get_var(ri, "base_address", base_address_hex, 16);
    sscanf(base_address_hex, "%x", &base_address);
    get_var(ri, "count", count, 16);

    inst_list = get_instructions_at_address(base_address, atoi(count));
    mg_write(conn, inst_list, strlen(inst_list));
    free(inst_list);
}
static int pause_stream(struct action_event *event)
{
	if (obtain_instanceid(event, NULL) < 0) {
		return -1;
	}

	int rc = 0;
	service_lock();
	switch (transport_state_) {
        case TRANSPORT_PAUSED_PLAYBACK:
		// Nothing to change.
		break;

	case TRANSPORT_PLAYING:
		if (output_pause()) {
			upnp_set_error(event, 704, "Pause failed");
			rc = -1;
		} else {
			change_transport_state(TRANSPORT_PAUSED_PLAYBACK);
		}
		break;

        default:
		/* action not allowed in these states - error 701 */
		upnp_set_error(event, UPNP_TRANSPORT_E_TRANSITION_NA,
			       "Transition not allowed; allowed=%s",
			       get_var(TRANSPORT_VAR_CUR_TRANSPORT_ACTIONS));
		rc = -1;
        }
	service_unlock();

	return rc;
}
Ejemplo n.º 17
0
int main()
{
    int type;
    double op2;
    char s[MAXOP];

    while ((type = getop(s)) != EOF) {
        switch (type) {
            case NUMBER:
                push(atof(s));
                break;
            case LIBFUNC:
                push(dofunc(s));
                break;
            case GETVAR:
                // 1 a= a +
                push(get_var(s[0]));
                break;
            case SETVAR:
                // 1 a=
                op2 = pop();
                save_var(op2, s[0]);
                push(op2);
                break;
            case '+':
                push(pop() + pop());
                break;
            case '*':
                push(pop() * pop());
                break;
            case '-':
                op2 = pop();
                push(pop() - op2);
                break;
            case '/':
                op2 = pop();
                if (op2 != 0.0)
                    push(pop() / op2);
                else
                    printf("error: zero divisor\n");
                break;
            case '%':
                op2 = pop();
                if (op2 != 0.0)
                    push(fmod(pop(), op2));
                else
                    printf("error: zero divisor\n");
                break;
            case '\n':
                recent_result = pop();
                printf("\t = %.8g\n", recent_result);
                break;
            default:
                printf("error: unknown command %s\n", s);
                break;
        }
    }

    return 0;
}
static int stop(struct action_event *event)
{
	if (obtain_instanceid(event, NULL) < 0) {
		return -1;
	}

	service_lock();
	switch (transport_state_) {
	case TRANSPORT_STOPPED:
		// nothing to change.
		break;
	case TRANSPORT_PLAYING:
	case TRANSPORT_TRANSITIONING:
	case TRANSPORT_PAUSED_RECORDING:
	case TRANSPORT_RECORDING:
	case TRANSPORT_PAUSED_PLAYBACK:
		output_stop();
		change_transport_state(TRANSPORT_STOPPED);
		break;

	case TRANSPORT_NO_MEDIA_PRESENT:
		/* action not allowed in these states - error 701 */
		upnp_set_error(event, UPNP_TRANSPORT_E_TRANSITION_NA,
			       "Transition not allowed; allowed=%s",
			       get_var(TRANSPORT_VAR_CUR_TRANSPORT_ACTIONS));

		break;
	}
	service_unlock();

	return 0;
}
Ejemplo n.º 19
0
/*
 * Attempt to load, in the order specified by BootOrder EFI variable, the
 * available load-options, finding and returning the first one that can
 * be loaded successfully.
 */
void *efi_bootmgr_load(struct efi_device_path **device_path,
		       struct efi_device_path **file_path)
{
	uint16_t *bootorder;
	unsigned long size;
	void *image = NULL;
	int i, num;

	__efi_entry_check();

	bs = systab.boottime;
	rs = systab.runtime;

	bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size);
	if (!bootorder)
		goto error;

	num = size / sizeof(uint16_t);
	for (i = 0; i < num; i++) {
		debug("%s: trying to load Boot%04X\n", __func__, bootorder[i]);
		image = try_load_entry(bootorder[i], device_path, file_path);
		if (image)
			break;
	}

	free(bootorder);

error:
	__efi_exit_check();

	return image;
}
static void change_transport_state(enum transport_state new_state) {
	transport_state_ = new_state;
	assert(new_state >= TRANSPORT_STOPPED
	       && new_state < TRANSPORT_NO_MEDIA_PRESENT);
	if (!replace_var(TRANSPORT_VAR_TRANSPORT_STATE,
			 transport_states[new_state])) {
		return;  // no change.
	}
	const char *available_actions = NULL;
	switch (new_state) {
	case TRANSPORT_STOPPED:
		if (strlen(get_var(TRANSPORT_VAR_AV_URI)) == 0) {
			available_actions = "PLAY";
		} else {
			available_actions = "PLAY,SEEK";
		}
		break;
	case TRANSPORT_PLAYING:
		available_actions = "PAUSE,STOP,SEEK";
		break;
	case TRANSPORT_PAUSED_PLAYBACK:
		available_actions = "PLAY,STOP,SEEK";
		break;
	case TRANSPORT_TRANSITIONING:
	case TRANSPORT_PAUSED_RECORDING:
	case TRANSPORT_RECORDING:
	case TRANSPORT_NO_MEDIA_PRESENT:
		// We should not switch to this state.
		break;
	}
	if (available_actions) {
		replace_var(TRANSPORT_VAR_CUR_TRANSPORT_ACTIONS,
			    available_actions);
	}
}
Ejemplo n.º 21
0
void expand_line(char *line, char *buffer)
{
  char tmp[100],*cp2;
  for (;*line;)
  {   
    if (*line=='$')
    {
      line++;
      if (*line=='$')
        *(buffer++)=*(line++);
      else if (*line!='(')
      {
	printf("Expecting ( after $\n");
	exit(0);
      } else      
      {
	line++;
	for (cp2=tmp;*line!=')' && *line;line++,cp2++) *cp2=*line; line++;
	*cp2=0;
	get_var(tmp,buffer);
	while (*buffer) buffer++;
      }
    } else *(buffer++)=*(line++);      
  }
  *buffer=0;
}
Ejemplo n.º 22
0
static const char *get_string(interp_t *interp, const char *name)
{
    var_t *var;

    var = get_var(interp, name);
    if (var == NULL)
        return NULL;

    if (var->type == VAR_NUMBER)
    {
        if (var->v_number.strvalue == NULL)
        {
            // convert to a string
            char *str = to_string(var->v_number.value);
            if (str == NULL)
                return NULL;
            var->v_number.strvalue = str;
        }
        return var->v_number.strvalue;
    }
    if (var->type == VAR_STRING)
        return var->v_string.value;
    if (var->type == VAR_NULL)
        return "";
    return NULL;
}
Ejemplo n.º 23
0
void	color_number_up_100(void)
{
	t_var	*var;

	var = get_var();
	var->color_number += 100;
}
Ejemplo n.º 24
0
void test_variable_range_spans_two_basic_blocks(void)
{
	struct basic_block *bb1, *bb2;
	struct compilation_unit *cu;
	struct var_info *r1, *r2;
	struct insn *insn[4];

	cu = compilation_unit_alloc(&method);
	r1 = get_var(cu);
	r2 = get_var(cu);

	bb1 = get_basic_block(cu, 0, 2);
	bb2 = get_basic_block(cu, 2, 4);
	bb_add_successor(bb1, bb2);

	insn[2] = imm_insn(INSN_SETL, 0x02, r2);
	bb_add_insn(bb2, insn[2]);

	insn[3] = arithmetic_insn(INSN_ADD, r1, r2, r2);
	bb_add_insn(bb2, insn[3]);

	insn[0] = imm_insn(INSN_SETL, 0x01, r1);
	bb_add_insn(bb1, insn[0]);

	insn[1] = branch_insn(INSN_JMP, bb2);
	bb_add_insn(bb1, insn[1]);

	compute_insn_positions(cu);
	analyze_liveness(cu);

	assert_defines(bb1, r1);
	assert_defines(bb2, r2);
	assert_uses(bb2, r1);

	assert_live_range(r1->interval, 0, 4);
	assert_live_range(r2->interval, 2, 4);

	assert_ptr_equals(insn[0], r1->interval->insn_array[0]);
	assert_ptr_equals(insn[1], r1->interval->insn_array[1]);
	assert_ptr_equals(insn[2], r1->interval->insn_array[2]);
	assert_ptr_equals(insn[3], r1->interval->insn_array[3]);

	assert_ptr_equals(insn[2], r2->interval->insn_array[0]);
	assert_ptr_equals(insn[3], r2->interval->insn_array[1]);

	free_compilation_unit(cu);
}
Ejemplo n.º 25
0
void init_reg_var(TRASH *t){
	int n=sizeof(_REG)/4;
	for (int i=0;i<n;i++){
		if (t->reg[i].st){
			t->reg[i].var=get_var(t);
		}
	}
}
Ejemplo n.º 26
0
void test_spill_insn_is_inserted_at_the_end_of_the_interval_if_necessary(void)
{
        struct compilation_unit *cu;
        struct insn *insn_array[2];
        struct var_info *r1, *r2;
        struct basic_block *bb;
	struct insn *insn;

        cu = compilation_unit_alloc(&method);
        r1 = get_var(cu);
        r2 = get_var(cu);

        insn_array[0] = arithmetic_insn(INSN_ADD, r1, r1, r1);
        insn_array[1] = arithmetic_insn(INSN_ADD, r2, r2, r2);

        bb = get_basic_block(cu, 0, 2);
        bb_add_insn(bb, insn_array[0]);
        bb_add_insn(bb, insn_array[1]);

	r1->interval->need_spill = true;

	compute_insn_positions(cu);
	analyze_liveness(cu);
	insert_spill_reload_insns(cu);

	/*
	 * First instruction stays the same. 
	 */
	insn = list_first_entry(&bb->insn_list, struct insn, insn_list_node);
	assert_ptr_equals(insn_array[0], insn);

	/*
	 * Last instruction stays the same. 
	 */
	insn = list_next_entry(&insn->insn_list_node, struct insn, insn_list_node);
	assert_ptr_equals(insn_array[1], insn);

	/*
	 * A spill instruction is inserted after the interval end.
	 */ 
	insn = list_next_entry(&insn->insn_list_node, struct insn, insn_list_node);
	assert_st_insn(INSN_ST_LOCAL, r1->interval->spill_slot, r1->interval->reg, insn);

	free_compilation_unit(cu);
}
Ejemplo n.º 27
0
value type_var(value f)
	{
	if (f->N == 0)
		{
		drop(get_var(f));
		return 0;
		}
	return type_void(f);
	}
Ejemplo n.º 28
0
/**
 *  tests set()
 */
static char * test_set() {
    Logo good, b_num_args, b_var, b_syntax1, b_syntax2, b_polish1, b_polish2, b_polish3;
    int ret;
    float a, num;
    printf("Testing %s\n", __FUNCTION__);
    
    /* good input */
    good = setup(1, "SET A := 3 2 9 8 + - * ;");
    /* bad number of args */
    b_num_args = setup(1, "SET A :=");
    /* bad var input */
    b_var = setup(1, "SET AB := 8 ;");
    /* bad syntax (bad equal sign) */
    b_syntax1 = setup(1, "SET A = 8 ;");
    /* bad syntax (bad instruction) */
    b_syntax2 = setup(1, "DO A := 10 ;");
    /* bad polish (will be tested more thoroughly later) */
    b_polish1 = setup(1, "SET A := 9 8 & ;");
    /* unbalanced polish. parser allows this but the interpreter should flag it
       as an error */
    b_polish2 = setup(1, "SET A := 9 8 8 7 + - ;");
    /* a polish only has a ; */
    b_polish3 = setup(1, "SET A := ;");
    
    /* test them all */
    ret = set(good);
    mu_assert("error, ret != 0", ret == 0);    
    /* this should have set A, calculate the above polish expression */
    num = 3 * (2 - (9 + 8));
    /* get the value in A */
    get_var("A", good->vars, &a);
    mu_assert("error, A != polish expression", a == num);
    ret = set(b_num_args);
    mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR);
    ret = set(b_var);
    mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR);
    ret = set(b_syntax1);
    mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR);
    ret = set(b_syntax2);
    mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR);
    ret = set(b_polish1);
    mu_assert("error, ret != PARSE_ERR", ret == PARSE_ERR);
    ret = set(b_polish2);
    mu_assert("error, ret != POL_ERR", ret == POL_ERR);    
    ret = set(b_polish3);
    mu_assert("error, ret != POL_ERR", ret == POL_ERR);
    
    tear_down(good);
    tear_down(b_num_args);
    tear_down(b_var);
    tear_down(b_syntax1);
    tear_down(b_syntax2);
    tear_down(b_polish1);
    tear_down(b_polish2);
    tear_down(b_polish3);
    return 0;
}
Ejemplo n.º 29
0
NcVar* NcFile::get_var( NcToken name ) const
{
    int varid;
    if(NcError::set_err(
			nc_inq_varid(the_id, name, &varid)
			) != NC_NOERR)
	return 0;
    return get_var(varid);
}
void timerPlay(char *uri)
{

	service_lock();
	output_stop();
	change_transport_state(TRANSPORT_STOPPED);
	output_set_uri(uri, NULL);
	replace_var(TRANSPORT_VAR_REL_TIME_POS, kZeroTime);
	if (output_play(&inform_play_transition_from_output)) {
		
	} else {
		change_transport_state(TRANSPORT_PLAYING);
		const char *av_uri = get_var(TRANSPORT_VAR_AV_URI);
		const char *av_meta = get_var(TRANSPORT_VAR_AV_URI_META);
		replace_current_uri_and_meta(av_uri, av_meta);
	}
	
	service_unlock();
}