Exemple #1
0
static LiteralPool* NewLiteralPool (struct SymEntry* Func)
/* Create a new literal pool and return it */
{
    /* Allocate memory */
    LiteralPool* LP = xmalloc (sizeof (*LP));

    /* Initialize the fields */
    LP->Func  = Func;
    InitCollection (&LP->WritableLiterals);
    InitCollection (&LP->ReadOnlyLiterals);

    /* Return the new pool */
    return LP;
}
Exemple #2
0
unsigned GetRegInfo (struct CodeSeg* S, unsigned Index, unsigned Wanted)
/* Determine register usage information for the instructions starting at the
** given index.
*/
{
    CodeEntry*      E;
    Collection      Visited;    /* Visited entries */
    unsigned        R;

    /* Get the code entry for the given index */
    if (Index >= CS_GetEntryCount (S)) {
        /* There is no such code entry */
        return REG_NONE;
    }
    E = CS_GetEntry (S, Index);

    /* Initialize the data structure used to collection information */
    InitCollection (&Visited);

    /* Call the recursive subfunction */
    R = GetRegInfo1 (S, E, Index, &Visited, REG_NONE, REG_NONE, Wanted);

    /* Delete the line collection */
    DoneCollection (&Visited);

    /* Return the registers used */
    return R;
}
Exemple #3
0
CodeEntry* NewCodeEntry (opc_t OPC, am_t AM, const char* Arg,
                         CodeLabel* JumpTo, LineInfo* LI)
/* Create a new code entry, initialize and return it */
{
    /* Get the opcode description */
    const OPCDesc* D = GetOPCDesc (OPC);

    /* Allocate memory */
    CodeEntry* E = xmalloc (sizeof (CodeEntry));

    /* Initialize the fields */
    E->OPC    = D->OPC;
    E->AM     = AM;
    E->Size   = GetInsnSize (E->OPC, E->AM);
    E->Arg    = GetArgCopy (Arg);
    E->Flags  = NumArg (E->Arg, &E->Num)? CEF_NUMARG : 0;   /* Needs E->Arg */
    E->Info   = D->Info;
    E->JumpTo = JumpTo;
    E->LI     = UseLineInfo (LI);
    E->RI     = 0;
    SetUseChgInfo (E, D);
    InitCollection (&E->Labels);

    /* If we have a label given, add this entry to the label */
    if (JumpTo) {
        CollAppend (&JumpTo->JumpFrom, E);
    }

    /* Return the initialized struct */
    return E;
}
Exemple #4
0
/****************************************************************
 *功能:初始化
 *形参:
 *			无
 *返回:
 *			无
 */
void InitEM(void)
{	
	InitCollection();
	InitControl();
	InitDebug();
	InitSimulatTimer();
}
Exemple #5
0
static MacroExp* InitMacroExp (MacroExp* E, Macro* M)
/* Initialize a MacroExp structure */
{
    InitCollection (&E->ActualArgs);
    SB_Init (&E->Replacement);
    E->M = M;
    return E;
}
Exemple #6
0
void main() {
   BinQueue H = InitCollection(3);
   H = Insert(12, H);
   //H = Insert(24, H);
   //H = Insert(21, H);
   //H = Insert(65, H);
   // TODO 执行到这一句的时候Segment Fault
   PrintQueue(H);
    
}
Exemple #7
0
static LineInfo* NewLineInfo (const LineInfoKey* Key)
/* Create and return a new line info. Usage will be zero. */
{
    /* Allocate memory */
    LineInfo* LI = xmalloc (sizeof (LineInfo));

    /* Initialize the fields */
    InitHashNode (&LI->Node);
    LI->Id        = ~0U;
    LI->Key       = *Key;
    LI->RefCount  = 0;
    InitCollection (&LI->Spans);
    InitCollection (&LI->OpenSpans);

    /* Add it to the hash table, so we will find it if necessary */
    HT_Insert (&LineInfoTab, LI);

    /* Return the new struct */
    return LI;
}
Exemple #8
0
// 书上并没有提供该函数的例程,也许可以有更好的写法
BinQueue Insert(ElementType X, BinQueue H1) {
    
    BinQueue H2 = InitCollection(1); 
    BinTree T = InitBinNode(X);
    
    H2->TheTrees[MaxTrees - 1] = T;
    // 二项队列的插入,可以理解为创建一个只包含一个
    // 新节点的集合,然后将已存在的二项队列与之合并
    return Merge(H1, H2);
    
}
Exemple #9
0
CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
/* Create a new code segment, initialize and return it */
{
    unsigned I;
    const Type* RetType;

    /* Allocate memory */
    CodeSeg* S = xmalloc (sizeof (CodeSeg));

    /* Initialize the fields */
    S->SegName  = xstrdup (SegName);
    S->Func	= Func;
    InitCollection (&S->Entries);
    InitCollection (&S->Labels);
    for (I = 0; I < sizeof(S->LabelHash) / sizeof(S->LabelHash[0]); ++I) {
	S->LabelHash[I] = 0;
    }

    /* If we have a function given, get the return type of the function.
     * Assume ANY return type besides void will use the A and X registers.
     */
    if (S->Func && !IsTypeVoid ((RetType = GetFuncReturn (Func->Type)))) {
	if (SizeOf (RetType) == SizeOf (type_long)) {
	    S->ExitRegs = REG_EAX;
	} else {
	    S->ExitRegs = REG_AX;
	}
    } else {
	S->ExitRegs = REG_NONE;
    }

    /* Copy the global optimization settings */
    S->Optimize       = (unsigned char) IS_Get (&Optimize);
    S->CodeSizeFactor = (unsigned) IS_Get (&CodeSizeFactor);

    /* Return the new struct */
    return S;
}
Exemple #10
0
ElementType DeleteMin(BinQueue H) {
    
    int i, j;
    int MinTree;
    BinQueue DeletedQueue;
    Position DeletedTree, OldRoot;
    ElementType MinItem;
    
    if(H->CurrentSize == 0) {
        printf("Empty binomial queue");
        return -Infinity;
    }
    
    MinItem = Infinity;
    // 寻找集合中根节点最小的二项树
    for(i = 0; i < MaxTrees; i++) {
        if(H->TheTrees[i] &&
                H->TheTrees[i]->Element < MinItem) {
            MinItem = H->TheTrees[i]->Element;
            MinTree = i;
        }
    }
    
    // 取出待删除的二项树
    DeletedTree = H->TheTrees[MinTree];
    OldRoot = DeletedTree;
    DeletedTree = DeletedTree->LeftChild;
    free(OldRoot);
    // TODO 这里CurrentSize的大小还没弄懂
    DeletedQueue = InitCollection((1 << MinTree) - 1);
    // 删除根节点以后,要将根节点LeftChild的中NextSibling全部拆开 
    for(j = MinTree - 1; j >= 0; j--) {
        DeletedQueue->TheTrees[j] = DeletedTree;
        DeletedTree = DeletedTree->NextSibling;
        DeletedQueue->TheTrees[j]->NextSibling = NULL;
    }
    // 将原来二项队列中包含最小根元素的二项树删除
    // 因为已经将其拆散后保存在新的空二项队列中了
    H->TheTrees[MinTree] = NULL;
    H->CurrentSize -= DeletedQueue->CurrentSize + 1;
    
    // 这里合并的是两个二项队列
    Merge(H, DeletedQueue);
    
    return MinItem;
    
}
Exemple #11
0
TRI_collection_t* TRI_CreateCollection (TRI_vocbase_t* vocbase,
                                        TRI_collection_t* collection,
                                        char const* path,
                                        const TRI_col_info_t* const parameter) {
  char* filename;

  // sanity check
  if (sizeof(TRI_df_header_marker_t) + sizeof(TRI_df_footer_marker_t) > parameter->_maximalSize) {
    TRI_set_errno(TRI_ERROR_ARANGO_DATAFILE_FULL);

    LOG_ERROR("cannot create datafile '%s' in '%s', maximal size '%u' is too small",
              parameter->_name,
              path,
              (unsigned int) parameter->_maximalSize);

    return NULL;
  }

  if (! TRI_IsDirectory(path)) {
    TRI_set_errno(TRI_ERROR_ARANGO_WRONG_VOCBASE_PATH);

    LOG_ERROR("cannot create collection '%s', path is not a directory", path);

    return NULL;
  }


  filename = TRI_GetDirectoryCollection(path, parameter);
  if (filename == NULL) {
    LOG_ERROR("cannot create collection '%s'", TRI_last_error());
    return NULL;
  }

  // directory must not exist
  if (TRI_ExistsFile(filename)) {
    TRI_set_errno(TRI_ERROR_ARANGO_COLLECTION_DIRECTORY_ALREADY_EXISTS);

    LOG_ERROR("cannot create collection '%s' in '%s', directory already exists",
              parameter->_name, filename);

    TRI_FreeString(TRI_CORE_MEM_ZONE, filename);

    return NULL;
  }

  // create directory
  if (! TRI_CreateDirectory(filename)) {
    LOG_ERROR("cannot create collection '%s' in '%s' as '%s': %s",
              parameter->_name,
              path,
              filename,
              TRI_last_error());

    TRI_FreeString(TRI_CORE_MEM_ZONE, filename);

    return NULL;
  }

  // create collection structure
  if (collection == NULL) {
    collection = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_collection_t), false);
    if (collection == NULL) {
      TRI_FreeString(TRI_CORE_MEM_ZONE, filename);

      LOG_ERROR("cannot create collection '%s', out of memory", path);

      return NULL;
    }
  }

  // we are passing filename to this struct, so we must not free it if you use the struct later
  InitCollection(vocbase, collection, filename, parameter);
  /* PANAIA: 1) the parameter file if it exists must be removed
             2) if collection
  */

  return collection;
}
Exemple #12
0
Collection* NewCollection (void)
/* Create and return a new collection with the given initial size */
{
    /* Allocate memory, intialize the collection and return it */
    return InitCollection (xmalloc (sizeof (Collection)));
}