예제 #1
0
bool Globals::parse_argument(char* arg) {
  // range of acceptable characters spelled out for portability reasons
  char name[256];
  #define NAME_RANGE  "[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]"
  if (jvm_sscanf(arg, "-%" NAME_RANGE, name) == 1) {
    return bool_value_put(name, false);
  }
  if (jvm_sscanf(arg, "+%" NAME_RANGE, name) == 1) {
    return bool_value_put(name, true);
  }
  char value[256];
  #define VALUE_RANGE "[-kmKM0123456789]"
  if (jvm_sscanf(arg, "=%" NAME_RANGE "%" VALUE_RANGE, name, value) == 2) {
#if USE_SET_HEAP_LIMIT
    if (jvm_strcmp("HeapMin", name) == 0) {
#ifdef AZZERT
      tty->print_cr("HeapMin flag is not supported in case USE_SET_HEAP_LIMIT = true!");
#endif
      return false;
    }
#endif
    return set_numeric_flag(name, value);
  }
  return false;
}
예제 #2
0
static bool parse_size(char* s, jint& result) {
  jint n = 0;
  int args_read = jvm_sscanf(s, "%d", &n);
  if (args_read != 1) return false;
  if (*s == '-') s++;
  while (*s != '\0' && isdigit(*s)) s++;
  switch (*s) {
    case 'M': case 'm':
      result = n * 1024 * 1024;
      return true;
    case 'K': case 'k':
      result = n * 1024;
      return true;
    case '\0':
      result = n;
      return true;
    default:
      return false;
  }
}
예제 #3
0
bool VSFMergeTest::read_test_case(OsFile_Handle file, 
                                  MergeTestCase * const test_case) {
  enum {
    BUFFER_SIZE = 256
  };

  char read_buffer[BUFFER_SIZE];

  enum { 
    FIRST_STATE = 0,
    LOCATION_COUNT = FIRST_STATE,    
    TYPE,
    SRC_STATUS,
    DST_STATUS,
    SRC_WHERE,
    DST_WHERE,
    SRC_VALUE,
    DST_VALUE,
    LAST_STATE = DST_VALUE,
    STATE_COUNT
  };

  int parse_state = FIRST_STATE;

  static const char * const end_of_suite_marker = "VSF_MERGE_SUITE_END";

  static const char * const keywords[STATE_COUNT] = {
    "Location_count", "Types",
    "Source_status", "Target_status",
    "Source_where", "Target_where",
    "Source_value", "Target_value"
  };

  const int TYPE_COUNT = 2;

  static const char * const type_names[TYPE_COUNT] = {
    "int", "long"
  };

  static const BasicType types[TYPE_COUNT] = {
    T_INT, T_LONG
  };

  static const char * const status_names[] = {
    "flushed", "cached", "changed"
  };

  static const char * const where_names[] = {
    "nowhere", "immediate", "register"
  };

  unsigned int location_count = 0;
  unsigned int index = 0;
  int value = 0;

  VSFMergeTest::initialize();

  while (true) {
    const int bytes_read = 
      CompilerTest::read_line(file, read_buffer, BUFFER_SIZE);
    if (bytes_read == 0) {
      // End-of-file.
      break;
    }

    if (bytes_read == BUFFER_SIZE) {
      tty->print_cr("Line too long");
      break;
    }

    if (read_buffer[0] == '#') {
      continue;
    }

    char buffer[BUFFER_SIZE];
    const char * p = read_buffer;

    // Read the first word to the buffer.
    if (jvm_sscanf(p, "%255s", buffer) != 1) {
      break;
    }

    // Check for the end of suite marker.
    if (parse_state == FIRST_STATE) {
      if (jvm_strcmp(buffer, end_of_suite_marker) == 0) {
        break;
      }
    }

    if (jvm_strcmp(buffer, keywords[parse_state]) != 0) {
      tty->print_cr("Unexpected keyword: %s", buffer);
      break;
    }

    switch (parse_state) {
    case LOCATION_COUNT:
      p = next_word(p);

      if (jvm_sscanf(p, "%d", &location_count) != 1) {
        tty->print_cr("Cannot read location count");
        return false;        
      }
      if (location_count > MAX_TEST_LOCATION_COUNT) {
        tty->print_cr("Too many locations %d > %d", location_count,
                      MAX_TEST_LOCATION_COUNT);
        return false;        
      }
      test_case->location_count = location_count;
      break;
    case TYPE:
      for (index = 0; index < location_count; index++) {
        p = next_word(p);

        if (jvm_sscanf(p, "%255s", buffer) != 1) {
          tty->print_cr("Cannot read type for location %d", index);
          return false;        
        }

        value = CompilerTest::get_keyword_index(type_names, 
                                                ARRAY_SIZE(type_names), 
                                                buffer);
     
        if (value < 0 || value >= TYPE_COUNT) {
          tty->print_cr("Invalid type \"%s\" for location %d", buffer, index);
          return false;        
        }

        BasicType type = types[value];
        // For two-word types the type of the second location must be T_ILLEGAL.
        if (type == T_LONG) {
          if (index > 0 && test_case->types[index - 1] == T_LONG) {
            type = T_ILLEGAL;
          }
        }
        test_case->types[index] = type;
      }
      break;
    case SRC_STATUS: 
    case DST_STATUS: 
    {
      const bool is_source = parse_state == SRC_STATUS;
      const char * const frame_name = is_source ? "source" : "target";
      for (index = 0; index < location_count; index++) {
        p = next_word(p);

        if (jvm_sscanf(p, "%255s", buffer) != 1) {
          tty->print_cr("Cannot read status for %s location %d", 
                        frame_name, index);
          return false;        
        }

        value = CompilerTest::get_keyword_index(status_names, 
                                                ARRAY_SIZE(status_names), 
                                                buffer);
     
        if (value == -1) {
          tty->print_cr("Invalid status \"%s\" for %s location %d", 
                        buffer, frame_name, index);
          return false;        
        }
        if (is_source) {
          test_case->src_status[index] = (RawLocation::Status)value;
        } else {
          test_case->dst_status[index] = (RawLocation::Status)value;
        }
      }
      break;
    }
    case SRC_WHERE: 
    case DST_WHERE: 
    {
      const bool is_source = parse_state == SRC_WHERE;
      const char * const frame_name = is_source ? "source" : "target";
      for (index = 0; index < location_count; index++) {
        p = next_word(p);

        if (jvm_sscanf(p, "%255s", buffer) != 1) {
          tty->print_cr("Cannot read where for %s location %d", 
                        frame_name, index);
          return false;        
        }     

        value = CompilerTest::get_keyword_index(where_names, 
                                                ARRAY_SIZE(where_names), 
                                                buffer);

        if (value == -1) {
          tty->print_cr("Invalid where \"%s\" for %s location %d", 
                        buffer, frame_name, index);
          return false;        
        }
        if (is_source) {
          test_case->src_where[index] = (Value::ValueLocation)value;
        } else {
          test_case->dst_where[index] = (Value::ValueLocation)value;
        }
      }
      break;
    }
    case SRC_VALUE: 
    case DST_VALUE: 
    {
      const bool is_source = parse_state == SRC_VALUE;
      const char * const frame_name = is_source ? "source" : "target";

      for (index = 0; index < location_count; index++) {
        p = next_word(p);

        if (jvm_sscanf(p, "%d", &value) != 1) {
          tty->print_cr("Cannot read value for %s location %d", 
                        frame_name, index);
          return false;        
        }     

        const Value::ValueLocation where = 
          is_source ? test_case->src_where[index] : test_case->dst_where[index];
        int location_value = value;

        if (where == Value::T_REGISTER) {
          if (!is_valid_register(value)) {
            tty->print_cr("Invalid int register %d for %s location %d", 
                          value, frame_name, index);
            return false;        
          }

          location_value = VSFMergeTest::available_int_register(value);
        }

        if (is_source) {
          test_case->src_value[index] = location_value;
        } else {
          test_case->dst_value[index] = location_value;
        }
      }
      break;
    }
    }
    
    if (parse_state == LAST_STATE) {
      return true;
    }

    parse_state++;
  }

  return false;
}