示例#1
0
int code_stmt(ASTNode stmt,int BASEREG){
	switch(stmt->type){
		case Block:
			code_block(stmt,BASEREG);
			break;
		case IfClause:
			code_ifclause(stmt,BASEREG);
			break;
		case AssignExp:
			code_assign(stmt,BASEREG);
			break;
		case NilStmt:
			stmt->codes.head=stmt->codes.tail=NULL;
			break;
		case WhileClause:
			code_whileclause(stmt,BASEREG);
			break;
		case FunctionCall:
			code_call(stmt,BASEREG);
			break;
		default:
			fprintf(stderr,"unsupported stmt\n");
	}
	return 0;
}
示例#2
0
void dll_init(void)
{
	code_call(ctx->mem_mcs);
}
示例#3
0
void code_tac(FILE *file, RegDesc *registers, Tac *current)
{
  switch (current->op)
    {
    case TAC_BEGINPROGRAM:
      code_main(file);
      code_begin_function(file, current->result);
      break;

    case TAC_BEGINFUNCTION:
      code_begin_function(file, current->result);
      break;

    case TAC_ENDFUNCTION:
      code_end_function(file, registers);
      break;

    case TAC_RETURN:
      code_return(file, registers, current->result);
      break;

    case TAC_ENDPROGRAM:
      code_end_function(file, registers);
      break;

    case TAC_GOTO:
      code_jump(file, registers, JUMP, current->location->result, NULL);
      break;

    case TAC_IFZ:
      code_jump(file, registers, JUMP_NE, current->location->result, current->condition);
      break;

    case TAC_IFNZ:
      code_jump(file, registers, JUMP_E, current->location->result, current->condition);
      break;

    case TAC_ADD:
      code_binary(file, registers, ADD, current->result, current->operand1, current->operand2);
      break;

    case TAC_SUBTRACT:
      code_binary(file, registers, SUBTRACT, current->result, current->operand1, current->operand2);
      break;

    case TAC_MULTIPLY:
      code_binary(file, registers, MULTIPLY, current->result, current->operand1, current->operand2);
      break;

    case TAC_DIVIDE:
      code_binary(file, registers, DIVIDE, current->result, current->operand1, current->operand2);
      break;

    case TAC_NOT:
      //FIX 5-19-2011 - INVERT is not what we want - thats a bit wise invert
      //Since we are using booleans, just xor them
      //code_unary(file, registers, INVERT, current->result, current->operand1);
      code_binary(file, registers, LOGIC_XOR, current->result, current->operand1, symbol_one);
      break;

    case TAC_NEGATIVE:
      code_unary(file, registers, NEGATE, current->result, current->operand1);
      break;

    case TAC_AND:
      code_binary(file, registers, LOGIC_AND, current->result, current->operand1, current->operand2);
      break;

    case TAC_OR:
      code_binary(file, registers, LOGIC_OR, current->result, current->operand1, current->operand2);
      break;

    case TAC_MOD:
      code_binary(file, registers, ATT_MOD, current->result, current->operand1, current->operand2);
      break;

    case TAC_COPY:
      code_copy(file, registers, current->result, current->operand1);
      break;

    case TAC_ARG:
      code_arg(file, registers, current->result);
      break;

    case TAC_CALL://On a TAC call, the function is the operand, and the return is the result
      code_call(file, registers, current->operand1, current->result);
      break;

    case TAC_LABEL:
      debug("Code_Label - Symbol: %s", symbol_to_string(current->result));
      code_flush_all(file, registers);
      fprintf(file, "%s:\n", current->result->name);
      break;

    case TAC_GT:
      code_compare(file, registers, IS_GREATER, current->result, current->operand1, current->operand2);
      break;

    case TAC_LT:
      code_compare(file, registers, IS_LESS, current->result, current->operand1, current->operand2);
      break;

    case TAC_GTE:
      code_compare(file, registers, IS_GREATER_EQUAL, current->result, current->operand1, current->operand2);
      break;

    case TAC_LTE:
      code_compare(file, registers, IS_LESS_EQUAL, current->result, current->operand1, current->operand2);
      break;

    case TAC_EQUAL:
      code_compare(file, registers, IS_EQUAL, current->result, current->operand1, current->operand2);
      break;

    case TAC_NOTEQUAL:
      code_compare(file, registers, IS_NOT_EQUAL, current->result, current->operand1, current->operand2);
      break;

    case TAC_VARIABLE:
      //do nothing
      break;

    case TAC_NOP:
      //Do nothing
      break;

    default:
      die("Unrecognized TAC: %d", current->op);
      break;

    }
}
示例#4
0
int labelFunc(lua_State* l) {
	unsigned short* const label = (unsigned short*)lua_tointeger(l, lua_upvalueindex(1));
	code_call(label);
	return stat;
}