Ejemplo n.º 1
0
void emitIssetS(HTS& env) {
  auto const ssaPropName = topC(env, BCSPOffset{1});
  if (!ssaPropName->isA(Type::Str)) {
    PUNT(IssetS-PropNameNotString);
  }
  auto const ssaCls = popA(env);

  auto const ret = cond(
    env,
    0,
    [&] (Block* taken) {
      auto propAddr = ldClsPropAddr(env, ssaCls, ssaPropName, false);
      return gen(env, CheckNonNull, taken, propAddr);
    },
    [&] (SSATmp* ptr) { // Next: property or global exists
      return gen(env, IsNTypeMem, Type::Null, gen(env, UnboxPtr, ptr));
    },
    [&] { // Taken: LdClsPropAddr* returned Nullptr because it isn't defined
      return cns(env, false);
    }
  );

  destroyName(env, ssaPropName);
  push(env, ret);
}
Ejemplo n.º 2
0
// Memory Object APIs
cl_mem
clCreateBuffer(cl_context   d_context,
               cl_mem_flags flags,
               size_t       size,
               void *       host_ptr,
               cl_int *     errcode_ret)
{
    cl_int dummy_errcode;
    auto context = pobj(d_context);

    if (!errcode_ret)
        errcode_ret = &dummy_errcode;

    if (!context->isA(Coal::Object::T_Context))
    {
        *errcode_ret = CL_INVALID_CONTEXT;
        return 0;
    }

    *errcode_ret = CL_SUCCESS;

    Coal::Buffer *buf = new Coal::Buffer(context, size, host_ptr, flags,
                                         errcode_ret);

    if (*errcode_ret != CL_SUCCESS || (*errcode_ret = buf->init()) != CL_SUCCESS)
    {
        delete buf;
        return 0;
    }

    return desc(buf);
}
int AbstractArray::isEqual( const Object& obj ) const
{
    PRECONDITION( isA() == obj.isA() );
    AbstractArray& test = (AbstractArray&)obj;
    if( lowerBound() != test.lowerBound() ||
        upperBound() != test.upperBound()
      )
        return 0;

    ContainerIterator& iter1 = initIterator();
    ContainerIterator& iter2 = test.initIterator();
    while( iter1 && iter2 )
        if( iter1.current() != iter2.current() )
            {
            delete &iter1;
            delete &iter2;
            return 0;
            }
        else
            {
            iter1++;
            iter2++;
            }

    delete &iter1;
    delete &iter2;
    return 1;
}
Ejemplo n.º 4
0
cl_int
clGetSupportedImageFormats(cl_context           d_context,
                           cl_mem_flags         flags,
                           cl_mem_object_type   image_type,
                           cl_uint              num_entries,
                           cl_image_format *    image_formats,
                           cl_uint *            num_image_formats)
{
    auto context = pobj(d_context);

    if (!context->isA(Coal::Object::T_Context))
        return CL_INVALID_CONTEXT;

    (void) flags;
    (void) image_type;

    if (!num_entries && image_formats)
        return CL_INVALID_VALUE;

    if (image_formats)
    {
        std::memcpy(image_formats, supported_formats,
                    MIN(num_entries * sizeof(cl_image_format),
                        sizeof(supported_formats)));
    }

    if (num_image_formats)
        *num_image_formats = sizeof(supported_formats) / sizeof(cl_image_format);

    return CL_SUCCESS;
}
Ejemplo n.º 5
0
cl_int
clReleaseKernel(cl_kernel   d_kernel)
{
    auto kernel = pobj(d_kernel);
    if (!kernel->isA(Coal::Object::T_Kernel))
        return CL_INVALID_KERNEL;

    if (kernel->dereference())
    {
        Coal::Program *p =(Coal::Program *)kernel->parent();

        for (size_t i=0; i < p->kernelList.size(); i++) 
        {   
            if (p->kernelList[i]->p_name.compare(kernel->p_name) == 0)
            {
                p->kernelReleasedList.push_back(p->kernelList[i]);
                p->kernelList.erase(p->kernelList.begin() + i);
                // BUG: TAG
                // For some odd reason when we delete this, we're corrupting then inside of some kernel objects
                //delete kernel;
            }   
        }
    }   

    return CL_SUCCESS;
}
Ejemplo n.º 6
0
bool UPolyItem::match(const char * wildname)
{
  const char * p1;
  bool result;
  int n;
  //
  if (true)
  {
    result = wildcmp(wildname, name);
  }
  else
  {
    p1 = strchr(wildname, '*');
    if (p1 != NULL)
    {
      n = p1 - wildname;
      if ((unsigned int)n <= strlen(name))
        result = strncasecmp(name, wildname, n) == 0;
      else
        result = false;
    }
    else
      result = isA(wildname);
  }
  return result;
}
Ejemplo n.º 7
0
void emitEmptyS(IRGS& env) {
  auto const ssaPropName = topC(env, BCSPOffset{1});
  if (!ssaPropName->isA(TStr)) {
    PUNT(EmptyS-PropNameNotString);
  }

  auto const ssaCls = popA(env);
  auto const ret = cond(
    env,
    [&] (Block* taken) {
      auto propAddr = ldClsPropAddr(env, ssaCls, ssaPropName, false);
      return gen(env, CheckNonNull, taken, propAddr);
    },
    [&] (SSATmp* ptr) {
      auto const unbox = gen(env, UnboxPtr, ptr);
      auto const val   = gen(env, LdMem, unbox->type().deref(), unbox);
      return gen(env, XorBool, gen(env, ConvCellToBool, val), cns(env, true));
    },
    [&] { // Taken: LdClsPropAddr* returned Nullptr because it isn't defined
      return cns(env, true);
    });

  destroyName(env, ssaPropName);
  push(env, ret);
}
Ejemplo n.º 8
0
void emitCastArray(HTS& env) {
  auto const src = popC(env);
  push(
    env,
    [&] {
      if (src->isA(Type::Arr))  return src;
      if (src->isA(Type::Null)) return cns(env, staticEmptyArray());
      if (src->isA(Type::Bool)) return gen(env, ConvBoolToArr, src);
      if (src->isA(Type::Dbl))  return gen(env, ConvDblToArr, src);
      if (src->isA(Type::Int))  return gen(env, ConvIntToArr, src);
      if (src->isA(Type::Str))  return gen(env, ConvStrToArr, src);
      if (src->isA(Type::Obj))  return gen(env, ConvObjToArr, src);
      return gen(env, ConvCellToArr, src);
    }()
  );
}
Ejemplo n.º 9
0
// Sampler APIs
cl_sampler
clCreateSampler(cl_context          d_context,
                cl_bool             normalized_coords,
                cl_addressing_mode  addressing_mode,
                cl_filter_mode      filter_mode,
                cl_int *            errcode_ret)
{
    cl_int dummy_errcode;
    auto context = pobj(d_context);

    if (!errcode_ret)
        errcode_ret = &dummy_errcode;

    if (!context->isA(Coal::Object::T_Context))
    {
        *errcode_ret = CL_INVALID_CONTEXT;
        return 0;
    }

    *errcode_ret = CL_SUCCESS;

    Coal::Sampler *sampler = new Coal::Sampler(context,
                                               normalized_coords,
                                               addressing_mode,
                                               filter_mode,
                                               errcode_ret);

    if (*errcode_ret != CL_SUCCESS)
    {
        delete sampler;
        return 0;
    }

    return desc(sampler);
}
Ejemplo n.º 10
0
int Container::isEqual( const Object& testContainer ) const
{
    PRECONDITION( isA() == testContainer.isA() );

    int res = 1;

    ContainerIterator& thisIterator = initIterator();
    ContainerIterator& testContainerIterator =
                            ((Container &)(testContainer)).initIterator();
    while( thisIterator != 0 && testContainerIterator != 0 )
        {
        if( thisIterator++ != testContainerIterator++ )
            {
            res = 0;
            break;
            }
        }

    if( thisIterator != 0 || testContainerIterator != 0 )
        res = 0;

    delete &testContainerIterator;
    delete &thisIterator;
    return res;
}
Ejemplo n.º 11
0
static QueryOperator *
translateInsert(Insert *insert)
{
	List *attr = getAttributeNames(insert->tableName);
	List *dts = getAttributeDataTypes(insert->tableName);
	QueryOperator *insertQuery;

	TableAccessOperator *to;
	to = createTableAccessOp(insert->tableName, NULL, NULL, NIL, deepCopyStringList(attr), dts);
	SET_BOOL_STRING_PROP(to,PROP_TABLE_IS_UPDATED);

	if (isA(insert->query,  List))
	{
		ConstRelOperator *co;
		co = createConstRelOp((List *) insert->query,NIL, deepCopyStringList(attr), dts);
		insertQuery= (QueryOperator *) co;
	}
	else
	    insertQuery =  translateQuery((Node *) insert->query);

	SetOperator *seto;
	seto = createSetOperator(SETOP_UNION, NIL, NIL, deepCopyStringList(attr));

	addChildOperator((QueryOperator *) seto, (QueryOperator *) to);
	addChildOperator((QueryOperator *) seto, insertQuery);

	INFO_LOG("translated insert:\n%s", operatorToOverviewString((Node *) seto));
	DEBUG_LOG("translated insert:\n%s", nodeToString((Node *) seto));

	return (QueryOperator *) seto;
}
Ejemplo n.º 12
0
void emitBindG(IRGS& env) {
  auto const name = topC(env, BCSPOffset{1});
  if (!name->isA(TStr)) PUNT(BindG-NameNotStr);
  auto const box = popV(env);
  auto const ptr = gen(env, LdGblAddrDef, name);
  destroyName(env, name);
  bindMem(env, ptr, box);
}
Ejemplo n.º 13
0
void emitSetG(IRGS& env) {
  auto const name = topC(env, BCSPOffset{1});
  if (!name->isA(TStr)) PUNT(SetG-NameNotStr);
  auto const value   = popC(env, DataTypeCountness);
  auto const unboxed = gen(env, UnboxPtr, gen(env, LdGblAddrDef, name));
  destroyName(env, name);
  bindMem(env, unboxed, value);
}
Ejemplo n.º 14
0
void
shMonster::makePet ()
{
    if (isA (kMonClerkbot)) {
        /* nice try */
        return;
    }

    mTame = 1;
    mDisposition = kHelpful;
    mTactic = kReady;
    mStrategy = kPet;
    //mGlyph.mSym |= A_REVERSE;
    if (isA (kMonCylonCenturion)) { /* The iconic phrase must be there. */
        I->p ("\"By your command.\"");
    }
    Hero.mPets.add (this);
}
Ejemplo n.º 15
0
/**
 * Trace back to the guard that provided the type of val, if
 * any. Constrain it so its type will not be relaxed beyond the given
 * DataTypeCategory. Always returns val, for convenience.
 */
SSATmp* TraceBuilder::constrainValue(SSATmp* const val, DataTypeCategory cat) {
  if (!val) {
    FTRACE(1, "constrainValue(nullptr, {}), bailing\n", cat);
    return nullptr;
  }

  FTRACE(1, "constrainValue({}, {})\n", *val->inst(), cat);

  // If cat is DataTypeGeneric, there's nothing to do.
  if (cat == DataTypeGeneric) return val;

  auto inst = val->inst();

  if (inst->op() == LdLoc || inst->op() == LdLocAddr) {
    // We've hit a LdLoc(Addr). If the source of the value is non-null and not
    // a FramePtr, it's a real value that was killed by a Call. The value won't
    // be live but it's ok to use it to track down the guard.

    auto source = inst->extra<LdLocData>()->valSrc;
    if (!source) {
      // val was newly created in this trace. Nothing to constrain.
      FTRACE(2, "  - valSrc is null, bailing\n");
      return val;
    }

    // If valSrc is a FramePtr, it represents the frame the value was
    // originally loaded from. Look for the guard for this local.
    if (source->isA(Type::FramePtr)) {
      constrainLocal(inst->extra<LocalId>()->locId, source, cat,
                     "constrainValue");
      return val;
    }

    // Otherwise, keep chasing down the source of val.
    constrainValue(source, cat);
  } else if (inst->op() == LdStack) {
    constrainStack(inst->src(0), inst->extra<StackOffset>()->offset, cat);
  } else if (inst->op() == CheckType) {
    // Constrain this CheckType and keep going on its source value, in case
    // there are more guards to constrain.
    constrainGuard(inst, cat);
    constrainValue(inst->src(0), cat);
  } else if (inst->op() == StRef || inst->op() == StRefNT) {
    // TODO(t2598894): This can be tightened up. As a conservative
    // approximation, pass the constraint through to the source of the value.
    constrainValue(inst->src(1), cat);
  } else if (inst->isPassthrough()) {
    constrainValue(inst->getPassthroughValue(), cat);
  } else {
    // Any instructions not special cased above produce a new value, so
    // there's no guard for us to constrain.
    FTRACE(2, "  - value is new in this trace, bailing\n");
  }

  return val;
}
Ejemplo n.º 16
0
void emitVGetG(IRGS& env) {
  auto const name = topC(env);
  if (!name->isA(TStr)) PUNT(VGetG-NonStrName);
  auto const ptr = gen(env, LdGblAddrDef, name);
  destroyName(env, name);
  pushIncRef(
    env,
    gen(env, LdMem, TBoxedInitCell, gen(env, BoxPtr, ptr))
  );
}
Ejemplo n.º 17
0
// Command Queue APIs
cl_command_queue
clCreateCommandQueue(cl_context                     d_context,
                     cl_device_id                   d_device,
                     cl_command_queue_properties    properties,
                     cl_int *                       errcode_ret)
{
    cl_int default_errcode_ret;
    auto device = pobj(d_device);
    auto context = pobj(d_context);

    // No errcode_ret ?
    if (!errcode_ret)
        errcode_ret = &default_errcode_ret;

    if (!device->isA(Coal::Object::T_Device))
    {
        *errcode_ret = CL_INVALID_DEVICE;
        return 0;
    }

    if (!context->isA(Coal::Object::T_Context))
    {
        *errcode_ret = CL_INVALID_CONTEXT;
        return 0;
    }

    *errcode_ret = CL_SUCCESS;
    Coal::CommandQueue *queue = new Coal::CommandQueue(
                                        context,
                                        device,
                                        properties,
                                        errcode_ret);

    if (*errcode_ret != CL_SUCCESS)
    {
        // Initialization failed, destroy context
        delete queue;
        return 0;
    }

    return desc(queue);
}
Ejemplo n.º 18
0
cl_int
clRetainKernel(cl_kernel    d_kernel)
{
    auto kernel = pobj(d_kernel);
    if (!kernel->isA(Coal::Object::T_Kernel))
        return CL_INVALID_KERNEL;

    kernel->reference();

    return CL_SUCCESS;
}
Ejemplo n.º 19
0
void emitCGetG(IRGS& env) {
  auto const exit = makeExitSlow(env);
  auto const name = topC(env);
  if (!name->isA(TStr)) PUNT(CGetG-NonStrName);
  auto const ptr = gen(env, LdGblAddr, exit, name);
  destroyName(env, name);
  pushIncRef(
    env,
    gen(env, LdMem, TCell, gen(env, UnboxPtr, ptr))
  );
}
Ejemplo n.º 20
0
cl_int
clRetainDevice(cl_device_id d_device)
{
    auto device = pobj(d_device);

    if (!device->isA(Coal::Object::T_Device))
        return CL_INVALID_DEVICE;

    device->reference();

    return CL_SUCCESS;
}
Ejemplo n.º 21
0
cl_int
clRetainSampler(cl_sampler d_sampler)
{
    auto sampler = pobj(d_sampler);

    if (!sampler->isA(Coal::Object::T_Sampler))
        return CL_INVALID_SAMPLER;

    sampler->reference();

    return CL_SUCCESS;
}
Ejemplo n.º 22
0
cl_int
clSetKernelArg(cl_kernel    d_kernel,
               cl_uint      arg_indx,
               size_t       arg_size,
               const void * arg_value)
{
    auto kernel = pobj(d_kernel);
    if (!kernel->isA(Coal::Object::T_Kernel))
        return CL_INVALID_KERNEL;

    return kernel->setArg(arg_indx, arg_size, arg_value);
}
Ejemplo n.º 23
0
/* function definitions */
Node *
provRewriteQBModel (Node *qbModel)
{
    if (isA(qbModel, List))
        return (Node *) provRewriteQueryList((List *) qbModel);
    else if (IS_OP(qbModel))
        return (Node *) provRewriteQuery((QueryOperator *) qbModel);

    FATAL_LOG("cannot rewrite node <%s>", nodeToString(qbModel));

    return NULL;
}
Ejemplo n.º 24
0
static void *Iterable_constructor (void *_self, va_list *app)
{
    Class_constructor_m ctor = method (super (Iterable ()), "__constructor__");
    struct Iterable *self = ctor (_self, app);

    if (isA (self, Iterable ()))
    {
        throw (AbstractError, "Iterable: cannot instantiate abstract class");
    }

    return self;
}
Ejemplo n.º 25
0
cl_int
clRetainMemObject(cl_mem d_memobj)
{
    auto memobj = pobj(d_memobj);

    if (!memobj->isA(Coal::Object::T_MemObject))
        return CL_INVALID_MEM_OBJECT;

    memobj->reference();

    return CL_SUCCESS;
}
Ejemplo n.º 26
0
cl_int
clRetainCommandQueue(cl_command_queue d_command_queue)
{
    auto command_queue = pobj(d_command_queue);

    if (!command_queue->isA(Coal::Object::T_CommandQueue))
        return CL_INVALID_COMMAND_QUEUE;

    command_queue->reference();

    return CL_SUCCESS;
}
Ejemplo n.º 27
0
/*----------------------------------------------------------------------*/
static void showInstance(int ins)
{
    char str[80];

    if (ins > header->instanceMax) {
        sprintf(str, "Instance code %d is out of range", ins);
        output(str);
        return;
    }

    output("The");
    say(ins);
    sprintf(str, "[%d]", ins);
    output(str);
    if (instances[ins].parent) {
        sprintf(str, "Isa %s[%d]", idOfClass(instances[ins].parent), instances[ins].parent);
        output(str);
    }

    if (!isA(ins, header->locationClassId) || (isA(ins, header->locationClassId) && admin[ins].location != 0)) {
        sprintf(str, "$iLocation: ");
        output(str);
        showInstanceLocation(ins, " ");
    }

    output("$iAttributes:");
    showAttributes(admin[ins].attributes);

    if (instances[ins].container)
        showContents(ins);

    if (isA(ins, header->actorClassId)) {
        if (admin[ins].script == 0)
            output("$iIs idle");
        else {
            sprintf(str, "$iExecuting script: %d, Step: %d", admin[ins].script, admin[ins].step);
            output(str);
        }
    }
}
Ejemplo n.º 28
0
void * reduce_phase2(const void * _exp)
{
	if(isA(_exp, Integer()))
		return domainCast(_exp, Real());
	else if(isA(_exp, Real()) || isA(_exp, Var()))
		return copy(_exp);
	else if(isA(_exp, Sum()) || isA(_exp, Product()))
	{
		void * s = copy(_exp);
		size_t i;
		for(i = 0; i < size(s); ++i)
		{
			delete(argv(s, i));
			setArgv(s, i, reduce_phase2(argv(_exp, i)));
		}
		return s;
	}
	else if(isA(_exp, Pow()))
	{
		void * p = copy(_exp);
		delete(base(p));
		delete(power(p));
		setBase(p, reduce_phase2(base(_exp)));
		setPower(p, reduce_phase2(power(_exp)));
		return p;
	}
	else if(isOf(_exp, Apply_1()))
	{
		void * f = copy(_exp);
		delete(arg(f));
		setArg(f, reduce_phase2(arg(_exp)));
		return f;
	}
	assert(0);
}
Ejemplo n.º 29
0
cl_int
clReleaseMemObject(cl_mem d_memobj)
{
    auto memobj = pobj(d_memobj);

    if (!memobj->isA(Coal::Object::T_MemObject))
        return CL_INVALID_MEM_OBJECT;

    if (memobj->dereference())
        delete memobj;

    return CL_SUCCESS;
}
Ejemplo n.º 30
0
cl_int
clSetCommandQueueProperty(cl_command_queue              d_command_queue,
                          cl_command_queue_properties   properties,
                          cl_bool                       enable,
                          cl_command_queue_properties * old_properties)
{
    auto command_queue = pobj(d_command_queue);

    if (!command_queue->isA(Coal::Object::T_CommandQueue))
        return CL_INVALID_COMMAND_QUEUE;

    return command_queue->setProperty(properties, enable, old_properties);
}