Exemple #1
0
void check_stmt(tree t) {
	for( ; t != NULL; t = t->next ) {
		switch (t->kind) {
			case If:
			case Elseif:
				if( check_expr(t->first) != Boolean ) {
					print_error("Invalid IF statement.", t);
				}
				check_stmt(t->second);
				check_stmt(t->third);
				continue;
			case Else:
				check_stmt(t->first);
				continue;
			case Exit:
				if(check_expr(t->first) != Boolean) {
					print_error("exit when must produce a boolean.", t);
				}
				continue;
			case Assign:
				if(t->first->kind == Obracket | check_expr(t->first) != check_expr(t->second)) {
					print_error("Invalid assignment statement.", t);
				}
				continue;
			case For:
				new_scope();
				declare_var(id_name(t->first->value), Integer);
				if(check_expr(t->second->first) != Integer | check_expr(t->second->second) != Integer)//TODO or add a range check
					print_error("Invalid range.", t->second);
				
				check_stmt(t->third);
				end_scope();
				continue;
			case Declaration:;
				if(t->second->kind == Array) {
					for(tree cur = t->first; cur != NULL; cur = cur->next)
						declare_array(id_name(cur->value), t->second->second->kind);
				} else {
					for(tree cur = t->first; cur != NULL; cur = cur->next)
						declare_var(id_name(cur->value), t->second->kind);
				}
				continue;
			case Declare:
				new_scope();
				check_stmt(t->first);
				check_stmt(t->second);
				end_scope();
				continue;
			default:
				print_error("Token of this type not checked by check_stmt.", t);
				continue;
		}
	}
}
Exemple #2
0
declare_parameters()
{
	struct t_param *current=param_head;
	int t_argnum=1;

	while(current){
		printf("%s %s;\n",spec_get_param_type(procname,t_argnum-1),current->name);
		declare_var(current->name,NS_VAR,lookup(itoa(t_argnum++),procnum));
		current=current->next;
	}
}
/**
 @par Detailed Description:
 */
char* Trick::MemoryManager::mm_strdup( const char* s) {
    char *allocation;
    int extent;

    /** @par Design: */
    /** @li Allocate sufficient space for the duplicate character string. */
    extent = (int)strlen(s)+1;

    /** @li Allocate the duplicate character string */
    allocation = (char*)declare_var(TRICK_CHARACTER, "", 0, "", 1, &extent);

    /** @li Copy the contents of the original character string to the duplicate. */
    /** @li Return the address of the new allocation.*/
    return( strcpy(allocation, s));
}
Exemple #4
0
int Parser::make_func() {
	uint32_t espBgn, params = 0;
	std::string funcName = tok.next().val;

	funcs.now++; funcs.inside = true;
	if(tok.skip("(")) { // get params
		do { declare_var(); tok.skip(); params++; } while(tok.skip(","));
		tok.skip(")");
	}
	funcs.append(funcName, ntv.count, params);
	undef_funcs.rep_undef(funcName, ntv.count);

	ntv.genas("push ebp");
	ntv.genas("mov ebp esp");
	espBgn = ntv.count + 2; ntv.genas("sub esp 0"); // align

	uint32_t pos_save[128], i;

	for(i = 0; i < params; i++) {
		ntv.gencode(0x8b); ntv.gencode(0x45);
		ntv.gencode(0x08 + (params - i - 1) * ADDR_SIZE);
		ntv.gencode(0x89); ntv.gencode(0x44); ntv.gencode(0x24);
		pos_save[i] = ntv.count; ntv.gencode(0x00);
	}

	eval(0, BLOCK_FUNC);

	for(int i = 0; i < return_list.count; i++) {
		ntv.gencode_int32_insert(ntv.count - return_list.addr_list[i] - 4, return_list.addr_list[i]);
	} return_list.count = 0;

	ntv.genas("add esp %u", ADDR_SIZE * (var.focus().size() + 6)); // add esp nn
	ntv.gencode(0xc9);// leave
	ntv.gencode(0xc3);// ret
	ntv.gencode_int32_insert(ADDR_SIZE * (var.focus().size() + 6), espBgn);


	for(i = 1; i <= params; i++) {
		ntv.code[pos_save[i - 1]] =
			256 - ADDR_SIZE * i + (((var.focus().size() + 6) * ADDR_SIZE) - 4);
	}
#ifdef DEBUG
	printf("%s() has %u funcs or vars\n", funcName.c_str(), var.focus().size());
#endif
	return 0;
}