Exemplo n.º 1
0
SymTableNode_T newtemp(){
    SymTableNode_T sym;
    char* name;

    sym = (SymTableNode_T) malloc (sizeof(struct symbol));

    name = newtempname();
    sym = SymTable_getNodeFromScope(name, cur_scope);

    if (sym == NULL){
        sym = SymTableNode_put(name, yylineno, cur_scope, VARIABLE, TRUE_T);
        sym->space = currscopespace();
        sym->offset = currscopeoffset();
        inccurrscopeoffset();
    }
    return sym;
}
Exemplo n.º 2
0
// Creates a new hidden var
SymbolTableEntry * newtemp(){
	// MONO NEES KRIFES METAVLITES
	// OXI EPANAXRISIMOPOIHSH

	SymbolTableEntry* entry;
	entry = (SymbolTableEntry *)malloc(sizeof(SymbolTableEntry));

	Variable *var;
	var = (Variable *)malloc(sizeof(Variable));
	
	var->name = strdup(newtempname());
	var->scope = get_current_scope();
	var->line = yylineno;

	entry->value.varVal = var;
	entry->isActive = SYM_TRUE;
	entry->scope = get_current_scope();
        entry->space = currscopespace();
	inccurrscopeoffset();
        entry->offset = currscopeoffset();
	//entry->type = ;

	return entry;
}
Exemplo n.º 3
0
// Creates a new hidden var
SymbolTableEntry * newtemp(){
	// MONO NEES KRIFES METAVLITES
	// OXI EPANAXRISIMOPOIHSH

	char* new_name = strdup(newtempname());
	if(lookup_sym(new_name, get_current_scope()) != NULL)
		{
		return lookup_sym(new_name, get_current_scope());
		}
	else
		{

		SymbolTableEntry* entry;
		entry = (SymbolTableEntry *)malloc(sizeof(SymbolTableEntry));

		Variable *var;
		var = (Variable *)malloc(sizeof(Variable));
	
		var->name = strdup(new_name);
		var->scope = get_current_scope();
		var->line = yylineno;

		entry->value.varVal = var;
		entry->isActive = SYM_TRUE;
		entry->scope = get_current_scope();
		entry->space = currscopespace();
		inccurrscopeoffset();
		entry->offset = currscopeoffset();
		if(get_current_scope() == 0)
			{
			entry->type = GLOBAL;
			printf("LOOKUP: %d\n", Lookup(new_name,VAR,GLOBAL));
			if(Lookup(new_name,VAR,GLOBAL) == 0)
				{
				insert(entry);
				insert_in_heads(entry);
				}
			else
				{
				printf("GLOBAL ERROR\n");
				}
			}
		else
			{
			entry->type = SYM_LOCAL;
			if(Lookup(new_name,VAR,SYM_LOCAL) == 1)
				{
				insert(entry);
				insert_in_heads(entry);
				}
			else if(Lookup(new_name,VAR,SYM_LOCAL) == 2)
				{
				insert(entry);
				update_heads(entry,0,0);
				}
			else if(Lookup(new_name,VAR,SYM_LOCAL) == 5)
				{
				printf("pedaraki\n");
				}
			else if(Lookup(new_name,VAR,SYM_LOCAL) == 0)
				{
				printf("LOCAL ERROR\n");
				}
			}
// kode gia insert tou entry sto symbol table

		return entry;
		}
}
Exemplo n.º 4
0
void generate_CALL( quad* quad ){
	quad->taddress = nextInstructionLabel();
	///print///printf("QUAD FUNC NUM: %d",quad->line );
	instruction *t = malloc( sizeof( instruction ) );
	t->result = malloc(sizeof(vmarg));
	t->opcode = call_v;
	make_operand( quad->result, t->result );
	reset_operand(t->arg1);
	reset_operand(t->arg2);
	t->srcLine = quad->line;
	
	t->result->val = FindFunctionUser((quad->result->sym)->name,deepestFunctionScope);
	if (t->result->val == -1){
		if(isLibFunction((quad->result->sym)->name)){
			int check = FindLibFunction((quad->result->sym)->name);
			if (check == -1){
				instruction *t1 =(instruction *) InitInstruction();
				expr * e = malloc(sizeof(expr));
				e->type = libraryfunc_e;
				e->sym =createS( (quad->result->sym)->name, 0, 0, (quad->result->sym)->name, 0, 0, "lib_func", 1,currscopespace(),currscopeoffset());
				make_operand(e,t1->arg1);
			}
			t->result->val = FindLibFunction((quad->result->sym)->name);
			t->result->type = libfunc_a;
			emitVmarg( t );
		}
	}
	else {
		emitVmarg( t );
	}
	
	
	

	return;
}