Ejemplo n.º 1
0
void* hw_malloc_debug(hwu32 size, const char* file, int line)
{
    /* TODO */
    (void)file;
    (void)line;

	return hw_malloc(size);
}
Ejemplo n.º 2
0
match_line_list *create_match_line_list()
{
    match_line_list *list = (match_line_list *)hw_malloc(sizeof(match_line_list));
    list->first = NULL;
    list->last  = NULL;
    list->current_for_search = NULL;
    list->max_line_no = 1;
    return list;
}
Ejemplo n.º 3
0
void allocate_work(context_t* context)
{
    if(context->node_count > 0) {
        context->nodes = (hwgm_node_t*)hw_malloc(context->node_total_size);
    }

    if(context->mesh_count > 0) {
        context->meshes = (hwgm_mesh_t*)hw_malloc(context->mesh_total_size);
    }

    if(context->material_count > 0) {
        context->maerials = (hwgm_material_t*)hw_malloc(context->material_total_size);
    }

    if(context->texture_count > 0) {
        context->textures = (hwgm_texture_t*)hw_malloc(context->texture_total_size);
    }

    if(context->vertices_count > 0) {
        context->vertices = (hwgm_vertices_t*)hw_mallc(context->vertices_total_size);
    }
}
static void
attach_m68hc11eepr_regs (struct hw *me,
                         struct m68hc11eepr *controller)
{
  unsigned_word attach_address;
  int attach_space;
  unsigned attach_size;
  reg_property_spec reg;

  if (hw_find_property (me, "reg") == NULL)
    hw_abort (me, "Missing \"reg\" property");

  if (!hw_find_reg_array_property (me, "reg", 0, &reg))
    hw_abort (me, "\"reg\" property must contain one addr/size entry");

  hw_unit_address_to_attach_address (hw_parent (me),
				     &reg.address,
				     &attach_space,
				     &attach_address,
				     me);
  hw_unit_size_to_attach_size (hw_parent (me),
			       &reg.size,
			       &attach_size, me);

  /* Attach the two IO registers that control the EEPROM.
     The EEPROM is only attached at reset time because it may
     be enabled/disabled by the EEON bit in the CONFIG register.  */
  hw_attach_address (hw_parent (me), M6811_IO_LEVEL,
                     io_map, M6811_PPROG, 1, me);
  hw_attach_address (hw_parent (me), M6811_IO_LEVEL,
                     io_map, M6811_CONFIG, 1, me);

  if (hw_find_property (me, "file") == NULL)
    controller->file_name = "m6811.eeprom";
  else
    controller->file_name = hw_find_string_property (me, "file");
  
  controller->attach_space = attach_space;
  controller->base_address = attach_address;
  controller->eeprom = (char*) hw_malloc (me, attach_size + 1);
  controller->eeprom_min_cycles = 10000;
  controller->size = attach_size + 1;
  controller->mapped = 0;
  
  m6811eepr_memory_rw (controller, O_RDONLY);
}
Ejemplo n.º 5
0
/**
 * Collect after lines from `last_line_end`.
 */
const char *after_context(const char *next_line_head,
                          const char *last_line_end,
                          ssize_t rest_len,
                          int line_no,
                          match_line_list *match_lines,
                          char eol,
                          int *count)
{
    const char *current = last_line_end;
    int lim = MAX(op.context, op.after_context);
    *count = 0;

    for (int i = 0; i < lim; i++) {
        // Break this loop if the current line reaches to the next line.
        if (next_line_head == current || rest_len <= 0) {
            break;
        }

        const char *after_line = memchr(current, eol, rest_len);
        if (after_line == NULL) {
            after_line = current + rest_len;
        }

        int line_len = after_line - current;

        match_line_node *node = (match_line_node *)hw_malloc(sizeof(match_line_node));
        node->line_no = line_no + i + 1;
        node->context = CONTEXT_AFTER;
        node->line = (char *)hw_calloc(line_len + 1, SIZE_OF_CHAR);

        if (!op.no_omit && line_len > op.omit_threshold) {
            strncat(node->line, current, op.omit_threshold - DOT_LENGTH);
            APPEND_DOT(op.color, node->line);
        } else {
            strncat(node->line, current, line_len);
        }

        enqueue_match_line(match_lines, node);
        (*count)++;

        rest_len -= after_line - current + 1;
        current = ++after_line;
    }

    return current;
}
Ejemplo n.º 6
0
void before_context(const char *buf,
                    const char *line_head,
                    const char *last_match_line_end_pos,
                    int line_no,
                    match_line_list *match_lines,
                    char eol)
{
    int lim = MAX(op.context, op.before_context);
    const char *lines[lim + 1];
    lines[0] = line_head;

    int before_count = 0;
    for (int i = 0; i < lim; i++) {
        if (lines[i] == buf || last_match_line_end_pos == lines[i]) {
            break;
        }

        const char *p = reverse_char(buf, eol, lines[i] - buf - 1);
        p = p == NULL ? buf : p + 1;

        lines[i + 1] = p;
        before_count++;
    }

    for (int i = before_count; i > 0; i--) {
        int line_len = lines[i - 1] - lines[i] - 1;

        match_line_node *node = (match_line_node *)hw_malloc(sizeof(match_line_node));
        node->line_no = line_no - i;
        node->context = CONTEXT_BEFORE;
        node->line = (char *)hw_calloc(line_len + 1, SIZE_OF_CHAR);

        if (!op.no_omit && line_len > op.omit_threshold) {
            strncat(node->line, lines[i], op.omit_threshold - DOT_LENGTH);
            APPEND_DOT(op.color, node->line);
        } else {
            strncat(node->line, lines[i], line_len);
        }
        enqueue_match_line(match_lines, node);
    }
}
Ejemplo n.º 7
0
int main()
{
	int my_addr;
	
    init_platform();

	print("What's up World!\n");
	
	/* to set up the empty allocation tree */
    init_ddr(); 
    init_ddr();

	my_addr = hw_malloc(1000); //malloc
	
	print("Allocated memory address is ");
    putnum(result);
	
	hw_mfree(my_addr);//mfree   

	return 0;
}
static void
attach_nvram_regs (struct hw *me, struct nvram *controller)
{
  unsigned_word attach_address;
  int attach_space;
  unsigned attach_size;
  reg_property_spec reg;
  int result, oerrno;

  /* Get ram bank description (base and size).  */
  if (hw_find_property (me, "reg") == NULL)
    hw_abort (me, "Missing \"reg\" property");

  if (!hw_find_reg_array_property (me, "reg", 0, &reg))
    hw_abort (me, "\"reg\" property must contain one addr/size entry");

  hw_unit_address_to_attach_address (hw_parent (me),
				     &reg.address,
				     &attach_space,
				     &attach_address,
				     me);
  hw_unit_size_to_attach_size (hw_parent (me),
			       &reg.size,
			       &attach_size, me);

  hw_attach_address (hw_parent (me), 0,
		     attach_space, attach_address, attach_size,
		     me);

  controller->mode         = NVRAM_SAVE_ALL;
  controller->base_address = attach_address;
  controller->size         = attach_size;
  controller->fd           = -1;
  
  /* Get the file where the ram content must be loaded/saved.  */
  if(hw_find_property (me, "file") == NULL)
    hw_abort (me, "Missing \"file\" property");
  
  controller->file_name = hw_find_string_property (me, "file");

  /* Get the mode which defines how to save the memory.  */
  if(hw_find_property (me, "mode") != NULL)
    {
      const char *value = hw_find_string_property (me, "mode");

      if (strcmp (value, "map") == 0)
        controller->mode = NVRAM_MAP_FILE;
      else if (strcmp (value, "save-modified") == 0)
        controller->mode = NVRAM_SAVE_MODIFIED;
      else if (strcmp (value, "save-all") == 0)
        controller->mode = NVRAM_SAVE_ALL;
      else
	hw_abort (me, "illegal value for mode parameter `%s': "
                  "use map, save-modified or save-all", value);
    }

  /* Initialize the ram by loading/mapping the file in memory.
     If the file does not exist, create and give it some content.  */
  switch (controller->mode)
    {
    case NVRAM_MAP_FILE:
      hw_abort (me, "'map' mode is not yet implemented, use 'save-modified'");
      break;

    case NVRAM_SAVE_MODIFIED:
    case NVRAM_SAVE_ALL:
      controller->data = (char*) hw_malloc (me, attach_size);
      if (controller->data == 0)
        hw_abort (me, "Not enough memory, try to use the mode 'map'");

      memset (controller->data, 0, attach_size);
      controller->fd = open (controller->file_name, O_RDWR);
      if (controller->fd < 0)
        {
          controller->fd = open (controller->file_name,
                                 O_RDWR | O_CREAT, 0644);
          if (controller->fd < 0)
            hw_abort (me, "Cannot open or create file '%s'",
                      controller->file_name);
          result = write (controller->fd, controller->data, attach_size);
          if (result != attach_size)
            {
              oerrno = errno;
              hw_free (me, controller->data);
              close (controller->fd);
              errno = oerrno;
              hw_abort (me, "Failed to save the ram content");
            }
        }
      else
        {
          result = read (controller->fd, controller->data, attach_size);
          if (result != attach_size)
            {
              oerrno = errno;
              hw_free (me, controller->data);
              close (controller->fd);
              errno = oerrno;
              hw_abort (me, "Failed to load the ram content");
            }
        }
      if (controller->mode == NVRAM_SAVE_ALL)
        {
          close (controller->fd);
          controller->fd = -1;
        }
      break;

    default:
      break;
    }
}
Ejemplo n.º 9
0
/**
 * Search PATTERN from the line and format.
 */
int format_line(const char *line,
                size_t line_len,
                const char *pattern,
                int pattern_len,
                enum file_type t,
                int line_no,
                match *first_match,
                match_line_list *match_lines,
                int thread_no)
{
    // Create new match object default size. Maybe, in the most case, default size is very enough
    // because the PATTERN is appeared in one line only less than 10 count.
    int n = 10;
    match *matches = (match *)hw_malloc(sizeof(match) * n);

    int match_count = 1;
    int offset = first_match->end;
    matches[0] = *first_match;

    // Search the all of PATTERN in the line.
    while (search_by(line + offset, line_len - offset, pattern, pattern_len, t, &matches[match_count], thread_no)) {
        matches[match_count].start += offset;
        matches[match_count].end   += offset;
        offset = matches[match_count].end;

        match_count++;

        // Two times memory will be reallocated if match size is not enough.
        if (n <= match_count) {
            n *= 2;
            matches = (match *)hw_realloc(matches, sizeof(match) * n);
        }
    }

    // Allocate memory for colorized result string.
    int buffer_len = line_len + (op.color_match_len + OMIT_ESCAPE_LEN) * match_count;
    match_line_node *node = (match_line_node *)hw_malloc(sizeof(match_line_node));
    node->line_no = line_no;
    node->context = CONTEXT_NONE;
    node->line = (char *)hw_calloc(buffer_len, SIZE_OF_CHAR);

    const char *start = line;
    int old_end = 0;
    for (int i = 0; i < match_count; i++) {
        /* format_match_string(node->line, start, &matches[i], old_end, i); */
        match m = matches[i];

        // Append prefix string.
        int prefix_len = m.start - old_end;
        format_line_middle(node->line, start, prefix_len, i == 0 ? AT_FIRST : AT_MIDDLE);

        // Append matching word with color.
        strncat_with_color(node->line, start + prefix_len, m.end - m.start, op.color_match);

        start += m.end - old_end;
        old_end = m.end;
    }

    // Append suffix string.
    format_line_middle(node->line, start, line_len - matches[match_count - 1].end, AT_LAST);

    enqueue_match_line(match_lines, node);
    tc_free(matches);

    return match_count;
}
Ejemplo n.º 10
0
static void
cris_finish (struct hw *me)
{
  struct cris_hw *crishw;
  const struct hw_property *vec_for_int;
  const struct hw_property *multiple_int;

  crishw = HW_ZALLOC (me, struct cris_hw);
  set_hw_data (me, crishw);
  set_hw_ports (me, cris_ports);
  set_hw_port_event (me, cris_port_event);

  vec_for_int = hw_find_property (me, "vec-for-int");
  if (vec_for_int != NULL)
    {
      unsigned32 vecsize;
      unsigned32 i;

      if (hw_property_type (vec_for_int) != array_property)
	hw_abort (me, "property \"vec-for-int\" has the wrong type");

      vecsize = hw_property_sizeof_array (vec_for_int) / sizeof (signed_cell);

      if ((vecsize % 2) != 0)
	hw_abort (me, "translation vector does not consist of even pairs");

      crishw->int_to_vec
	= hw_malloc (me, (vecsize/2 + 1) * sizeof (crishw->int_to_vec[0]));

      for (i = 0; i < vecsize/2; i++)
	{
	  signed_cell portval_sc;
	  signed_cell vec_sc;

	  if (!hw_find_integer_array_property (me, "vec-for-int", i*2,
					       &portval_sc)
	      || !hw_find_integer_array_property (me, "vec-for-int", i*2 + 1,
						  &vec_sc)
	      || portval_sc < 0
	      || vec_sc < 0)
	    hw_abort (me, "no valid vector translation pair %u", i);

	  crishw->int_to_vec[i].portval = (unsigned32) portval_sc;
	  crishw->int_to_vec[i].vec = (unsigned32) vec_sc;
	}

      crishw->int_to_vec[i].portval = 0;
      crishw->int_to_vec[i].vec = 0;
    }

  multiple_int = hw_find_property (me, "multiple-int");
  if (multiple_int != NULL)
    {
      if (hw_property_type (multiple_int) == integer_property)
	{
	  crishw->multiple_int_vector
	    = hw_find_integer_property (me, "multiple-int");
	  crishw->multi_int_action = cris_multint_vector;
	}
      else
	{
	  const char *action = hw_find_string_property (me, "multiple-int");

	  if (action == NULL)
	    hw_abort (me, "property \"multiple-int\" has the wrong type");

	  if (strcmp (action, "abort") == 0)
	    crishw->multi_int_action = cris_multint_abort;
	  else if (strcmp (action, "ignore_previous") == 0)
	    crishw->multi_int_action = cris_multint_ignore_previous;
	  else
	    hw_abort (me, "property \"multiple-int\" must be one of <vector number>\n"
		      "\"abort\" and \"ignore_previous\", not \"%s\"", action);
	}
    }
  else
    crishw->multi_int_action = cris_multint_abort;
}
Ejemplo n.º 11
0
/*  Malloc & free Wrapper */
int *SysMalloc(int size){
	int *nowPtr;
	//nowPtr = (int*)malloc(size);
	nowPtr = hw_malloc(size);
	return nowPtr;
}
Ejemplo n.º 12
0
void init_option(int argc, char **argv)
{
    static int flag;

    static struct option longopts[] = {
        { "all-files",            no_argument,       NULL,  'a' },
        { "follow-link",          no_argument,       NULL,  'f' },
        { "help",                 no_argument,       NULL,  'h' },
        { "ignore-case",          no_argument,       NULL,  'i' },
        { "file-with-matches",    no_argument,       NULL,  'l' },
        { "line-number",          no_argument,       NULL,  'n' },
        { "word-regexp",          no_argument,       NULL,  'w' },
        { "ext",                  required_argument, NULL,  'x' },
        { "after-context",        required_argument, NULL,  'A' },
        { "before-context",       required_argument, NULL,  'B' },
        { "context",              required_argument, NULL,  'C' },
        { "no-line-number",       no_argument,       NULL,  'N' },
        { "debug",                no_argument,       &flag,  1  },
        { "worker",               required_argument, &flag,  2  },
        { "no-omit",              no_argument,       &flag,  3  },
        { "version",              no_argument,       &flag,  4  },
        { "color",                no_argument,       &flag,  5  },
        { "no-color",             no_argument,       &flag,  6  },
        { "group",                no_argument,       &flag,  7  },
        { "no-group",             no_argument,       &flag,  8  },
        { "no-buffering",         no_argument,       &flag,  9  },
        { "color-path",           required_argument, &flag, 10  },
        { "color-match",          required_argument, &flag, 11  },
        { "color-line-number",    required_argument, &flag, 12  },
        { "color-before-context", required_argument, &flag, 13  },
        { "color-after-context",  required_argument, &flag, 14  },
        { 0, 0, 0, 0 }
    };

#ifndef _WIN32
    struct winsize w;
    ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
#endif

#ifndef _WIN32
    op.worker               = MAX(DEFAULT_WORKER, sysconf(_SC_NPROCESSORS_ONLN) - 1);
#else
    op.worker               = DEFAULT_WORKER;
#endif
    op.root_paths[0]        = ".";
    op.paths_count          = 1;
    op.ext_count            = 0;
    op.has_dot_path         = true;
#ifndef _WIN32
    op.omit_threshold       = MAX(MIN_LINE_LENGTH, w.ws_col / 2);
#else
    op.omit_threshold       = MIN_LINE_LENGTH;
#endif
    op.after_context        = 0;
    op.before_context       = 0;
    op.context              = 0;
    op.file_with_matches    = false;
    op.word_regex           = false;
    op.use_regex            = false;
    op.all_files            = false;
    op.no_omit              = false;
    op.ignore_case          = false;
    op.follow_link          = false;
    op.stdout_redirect      = IS_STDOUT_REDIRECT;
    op.stdin_redirect       = IS_STDIN_REDIRECT;
    op.show_line_number     = !op.stdin_redirect;
#ifndef _WIN32
    op.color                = !op.stdout_redirect;
#else
    op.color                = 0;
#endif
    op.group                = !op.stdout_redirect && !op.stdin_redirect;
    op.buffering            = !op.stdin_redirect;

    sprintf(op.color_path,           COLOR_ESCAPE_SEQUENCE, PATH_COLOR);
    sprintf(op.color_match,          COLOR_ESCAPE_SEQUENCE, MATCH_COLOR);
    sprintf(op.color_line_number,    COLOR_ESCAPE_SEQUENCE, LINE_NUMBER_COLOR);
    sprintf(op.color_before_context, COLOR_ESCAPE_SEQUENCE, BEFORE_CONTEXT_COLOR);
    sprintf(op.color_after_context,  COLOR_ESCAPE_SEQUENCE, AFTER_CONTEXT_COLOR);
    op.color_match_len = strlen(op.color_match);

    int ch;
    bool show_version = false;
    while ((ch = getopt_long(argc, argv, "aefhilnvwx:A:B:C:N", longopts, NULL)) != -1) {
        switch (ch) {
            case 0:
                switch (flag) {
                    case 1: /* --debug */
                        set_log_level(LOG_LEVEL_DEBUG);
                        break;
                    case 2: /* --worker */
                        op.worker = atoi(optarg);
                        break;
                    case 3: /* --no-omit */
                        op.no_omit = true;
                        break;
                    case 4: /* --version */
                        show_version = true;
                        break;
                    case 5: /* --color */
                        op.color = true;
                        break;
                    case 6: /* --no-color */
                        op.color = false;
                        break;
                    case 7: /* --group */
                        op.group = true;
                        break;
                    case 8: /* --no-group */
                        op.group = false;
                        break;
                    case 9: /* --no-buffering */
                        op.buffering = false;
                        break;
                    case 10: /* --color-path */
                        sprintf(op.color_path, COLOR_ESCAPE_SEQUENCE, optarg);
                        break;
                    case 11: /* --color-match */
                        sprintf(op.color_match, COLOR_ESCAPE_SEQUENCE, optarg);
                        op.color_match_len = strlen(op.color_match);
                        break;
                    case 12: /* --color-line-number */
                        sprintf(op.color_line_number, COLOR_ESCAPE_SEQUENCE, optarg);
                        break;
                    case 13: /* --color-before-context */
                        sprintf(op.color_before_context, COLOR_ESCAPE_SEQUENCE, optarg);
                        break;
                    case 14: /* --color-after-context */
                        sprintf(op.color_after_context, COLOR_ESCAPE_SEQUENCE, optarg);
                        break;
                }
                break;

            case 'a': /* All files searching */
                op.all_files = true;
                break;

            case 'e': /* Use regular expression */
                op.use_regex = true;
                break;

            case 'f': /* Following symbolic link */
                op.follow_link = true;
                break;

            case 'h': /* Show help */
                usage();
                exit(0);
                break;

            case 'i': /* Ignore case */
                op.ignore_case = true;
                op.use_regex   = true;
                break;

            case 'l': /* Show only filenames */
                op.file_with_matches = true;
                break;

            case 'n': /* Show line number */
                op.show_line_number = true;
                break;

            case 'w': /* Match only whole word */
                op.word_regex = true;
                break;

            case 'x': /* Extension */
                if (op.ext_count == 0) {
                    op.ext = (char **)hw_malloc(sizeof(char *));
                } else {
                    op.ext = (char **)hw_realloc(op.ext, sizeof(char *) * (op.ext_count + 1));
                }
                op.ext[op.ext_count++] = optarg;
                break;

            case 'A': /* After context */
                op.after_context = atoi(optarg);
                break;

            case 'B': /* Before context */
                op.before_context = atoi(optarg);
                break;

            case 'C': /* Context */
                op.context = atoi(optarg);
                break;

            case 'N': /* Not show line number */
                op.show_line_number = false;
                break;

            case '?':
            default:
                usage();
                exit(1);
        }
    }

    if (show_version) {
        printf("highway version %s\n", PACKAGE_VERSION);
        exit(0);
    }

    if (argc == optind) {
        usage();
        exit(1);
    }

    op.pattern = argv[optind++];

    int paths_count = argc - optind;
    if (paths_count > MAX_PATHS_COUNT) {
        log_w("Too many PATHs(%d) was passed. You can specify %d paths at most.", paths_count, MAX_PATHS_COUNT);
        log_w("You might want to enclose PATHs by quotation If you use glob format.");
        paths_count = MAX_PATHS_COUNT;
    }
    if (paths_count > 0) {
        op.has_dot_path = false;
        for (int i = 0; i < paths_count; i++) {
            char *path = argv[optind + i];
            int len = strlen(path);
            if (IS_PATHSEP(path[len - 1])) {
                path[len - 1] = '\0';
            }
            op.root_paths[i] = path;

            if (strcmp(path, ".") == 0) {
                op.has_dot_path = true;
            }
        }
        op.paths_count = paths_count;
    }
}