Ejemplo n.º 1
0
Archivo: Heap.c Proyecto: YuKill/ftc
void registerHeap(SymbolTable *TyTable, LLVMContextRef Con) {
    char *Name, Buf[] = "struct.Heap", BufRA[] = "struct.RA";
    Name = (char*) malloc(strlen(Buf) * sizeof(char));
    strcpy(Name, Buf);

    RAType = symTableFindGlobal(TyTable, BufRA);

    HeapType = LLVMStructCreateNamed(Con, Name);
    symTableInsertGlobal(TyTable, Name, HeapType);

    LLVMTypeRef AttrTy[]  = {
        LLVMPointerType(RAType, 0),
        LLVMPointerType(HeapType, 0)
    };
    LLVMStructSetBody(HeapType, AttrTy, 2, 0);

    // Initializing Head of Heap.
    HeapHead = LLVMAddGlobal(Module, LLVMPointerType(HeapType, 0), "global.HeapHead");
    LLVMTypeRef HeapHeadConType = LLVMGetElementType(LLVMTypeOf(HeapHead));
    LLVMSetInitializer(HeapHead, LLVMConstPointerNull(HeapHeadConType));

    // Defining functions.
    createPushHeapFunction();
    createPopHeapFunction();
}
Ejemplo n.º 2
0
static LLVMValueRef
translateNilExpr(SymbolTable *TyTable, SymbolTable *ValTable, ASTNode *Node) {
  if (!Node->Value) exit(1);
  Type   *RecordType = createType(IdTy, ((Type*)Node->Value)->Val);
  LLVMTypeRef Record = getLLVMTypeFromType(TyTable, RecordType);
  return LLVMConstPointerNull(LLVMPointerType(Record, 0));
}
Ejemplo n.º 3
0
LLVMValueRef ett_default_value(EagleComplexType *type)
{
    switch(type->type)
    {
        case ETInt1:
        case ETInt8:
        case ETUInt8:
        case ETInt16:
        case ETUInt16:
        case ETInt32:
        case ETUInt32:
        case ETInt64:
        case ETUInt64:
        case ETEnum:
            return LLVMConstInt(ett_llvm_type(type), 0, 0);
        case ETFloat:
        case ETDouble:
            return LLVMConstReal(ett_llvm_type(type), 0.0);
        case ETPointer:
            return LLVMConstPointerNull(ett_llvm_type(type));
        case ETStruct:
        {
            Arraylist *types;

            ty_struct_get_members(type, NULL, &types);
            LLVMValueRef vals[types->count];
            for(int i = 0; i < types->count; i++)
                vals[i] = ett_default_value(types->items[i]);

            return LLVMConstNamedStruct(ett_llvm_type(type), vals, types->count);
        }
        case ETArray:
        {
            EagleArrayType *at = (EagleArrayType *)type;
            LLVMValueRef val = ett_default_value(at->of);
            LLVMValueRef vals[at->ct];
            for(int i = 0; i < at->ct; i++)
                vals[i] = val;

            return LLVMConstArray(ett_llvm_type(at->of), vals, at->ct);
        }
        default:
            return NULL;
    }
}