github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-reg-class.c (about)

     1  /*
     2   * jit-reg-class.c - Register class routines for the JIT.
     3   *
     4   * Copyright (C) 2006  Southern Storm Software, Pty Ltd.
     5   *
     6   * This file is part of the libjit library.
     7   *
     8   * The libjit library is free software: you can redistribute it and/or
     9   * modify it under the terms of the GNU Lesser General Public License
    10   * as published by the Free Software Foundation, either version 2.1 of
    11   * the License, or (at your option) any later version.
    12   *
    13   * The libjit library is distributed in the hope that it will be useful,
    14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    16   * Lesser General Public License for more details.
    17   *
    18   * You should have received a copy of the GNU Lesser General Public
    19   * License along with the libjit library.  If not, see
    20   * <http://www.gnu.org/licenses/>.
    21   */
    22  
    23  #include "jit-internal.h"
    24  #include "jit-reg-class.h"
    25  #include <stdarg.h>
    26  
    27  _jit_regclass_t *
    28  _jit_regclass_create(const char *name, int flags, int num_regs, ...)
    29  {
    30  	_jit_regclass_t *regclass;
    31  	va_list args;
    32  	int reg;
    33  
    34  	regclass = jit_malloc(sizeof(_jit_regclass_t) + sizeof(int) * (num_regs - 1));
    35  	if(!regclass)
    36  	{
    37  		return 0;
    38  	}
    39  	regclass->name = name;
    40  	regclass->flags = flags;
    41  	regclass->num_regs = num_regs;
    42  
    43  	va_start(args, num_regs);
    44  	for(reg = 0; reg < num_regs; reg++)
    45  	{
    46  		regclass->regs[reg] = va_arg(args, int);
    47  	}
    48  	va_end(args);
    49  
    50  	return regclass;
    51  }
    52  
    53  _jit_regclass_t *
    54  _jit_regclass_combine(const char *name, int flags,
    55  		      _jit_regclass_t *class1,
    56  		      _jit_regclass_t *class2)
    57  {
    58  	_jit_regclass_t *regclass;
    59  	int num_regs;
    60  
    61  	num_regs = class1->num_regs + class2->num_regs;
    62  
    63  	regclass = jit_malloc(sizeof(_jit_regclass_t) + sizeof(int) * (num_regs - 1));
    64  	if(!regclass)
    65  	{
    66  		return 0;
    67  	}
    68  	regclass->name = name;
    69  	regclass->flags = flags;
    70  	regclass->num_regs = num_regs;
    71  
    72  	jit_memcpy(regclass->regs, class1->regs, sizeof(int) * class1->num_regs);
    73  	jit_memcpy(regclass->regs + class1->num_regs, class2->regs, sizeof(int) * class2->num_regs);
    74  
    75  	return regclass;
    76  }
    77  
    78  void
    79  _jit_regclass_free(_jit_regclass_t *regclass)
    80  {
    81  	jit_free(regclass);
    82  }