R/value.R

Defines functions getValueName getNumUses isSwiftError hasValueHandle isUsedByMetadata isUsedInBasicBlock getValueName getAllUsers getAllUses replaceAllUsesWith getLinkage

Documented in getAllUsers getAllUses getLinkage getNumUses getValueName hasValueHandle isSwiftError isUsedByMetadata isUsedInBasicBlock replaceAllUsesWith

setAs("GlobalValue", "Module",
       function(from)
         .Call("R_GlobalValue_getParent", from))



setMethod("getType", "Value",
           function(obj, ...) {
               ans = .Call("R_Value_getType", obj)
               upgradeTypeClass(ans)
           })

#XXX Hopefully this won't come back to bite me.
# Adding it here so that
#   createGlobalVariable("counter1", m, val = 0L)
# doesn't raise an error.
setMethod("getType", "integer", function(obj, ...) Int32Type)



setMethod("[[", "Value",
          function(x, i, ..., value = TRUE) {
              ty = getType(x)
              if(!is(ty, "ArrayType") && !is(ty, "StructType") && !is(ty, "PointerType"))
                  stop("can't get element from ", class(ty))

              if(i < 0)
                  stop("Can't use negative indexing")

              ans = .Call("R_getOperand", x, as.integer(i)-1L)
              if(value) {
                  ty2 = getType(ans)
                  if(!is(ty2, "CompositeType"))
                     ans = getValue(ans)
              }
              ans
          })


getLinkage =
function(obj)
{
   ans = .Call("R_GlobalValue_getLinkage", obj)
   # now match to known constants
   i = match(ans, LinkageTypes)
   LinkageTypes[i]
}



replaceAllUsesWith =
function(val, other)
  .Call("R_Value_replaceAllUsesWith", as(val, "Value"), as(other, "Value"))    

getAllUses = 
function(obj)
    .Call("R_Value_getAllUses", as(obj, "Value"))


getAllUsers = 
function(obj, uses = getAllUses(obj))
{
   rev(lapply(uses, getUser))
}



setMethod("getValue", "Use", function(x, ...) .Call("R_Use_get", x))




getValueName =
function(val)
{
  .Call("R_Value_getValueName", val)
}

isUsedInBasicBlock =
function(val)    
{
  .Call("R_Value_isUsedInBasicBlock", as(val, "Value"))
}

isUsedByMetadata =
function(val)    
{
  .Call("R_Value_isUsedByMetadata", as(val, "Value"))
}

hasValueHandle =
function(val)    
{
  .Call("R_Value_hasValueHandle", as(val, "Value"))
}

isSwiftError =
function(val)    
{
  .Call("R_Value_isSwiftError", as(val, "Value"))
}

getNumUses =
function(val)    
{
  .Call("R_Value_getNumUses", as(val, "Value"))
}


getValueName =
function(val)    
{
  .Call("R_Value_getValueName", as(val, "Value"))
}
duncantl/Rllvm documentation built on April 23, 2024, 6:14 p.m.