Exemple #1
0
static  void    AssignPushLocals( void ) {
/***********************************
    Scan through HeadBlock to see if there are any leading instructions of
    the form MOV REG => temp, where temp is on the stack. We can eliminate
    the instruction (call DoNothing to mark it as unnecessary to generate)
    and then the guy that generates the prolog can come along later and
    generate PUSH REG, and adjust the SUB SP,n instruction appropriately.
    this replaces a move with a less expensive push, and if all locals
    turn out to be push locals, eliminates the SUP SP,n instruction as well
*/

    instruction *move;
    name        *src;
    name        *dst;
    type_length curr_offset;

    move = HeadBlock->ins.hd.next;
    curr_offset = 0;
    for(;;) {
        if( CurrProc->prolog_state & GENERATED_PROLOG ) break;
        if( DoesSomething( move ) ) {
            if( move->head.opcode != OP_MOV ) break;
            if( UnChangeable( move ) ) break;
            src = move->operands[ 0 ];
            dst = move->result;
            if( src->n.class != N_REGISTER ) break;
            if( _IsFloating( src->n.name_class ) ) break; /*90-Dec-17*/
            if( dst->n.class != N_TEMP ) break;
        #if _TARGET & _TARG_80386
            if( dst->n.size != 4 ) break;
        #else
            if( dst->n.size != 2 && dst->n.size != 4 ) break;
        #endif
            curr_offset -= PushSize( dst->n.size );/* assume it will be pushed*/
            if( DeAlias( dst ) != dst ) break;
            if( dst->v.usage & HAS_MEMORY ) {
                if( dst->t.location != curr_offset ) break;
            } else {
                CurrProc->targ.push_local_size += PushSize( dst->n.size );
                dst->t.location = - CurrProc->targ.push_local_size;
                dst->v.usage |= HAS_MEMORY;
                PropLocal( dst );
            }
            move->head.state = OPERANDS_NEED_WORK;
            DoNothing( move );
        }
        move = move->head.next;
    }
}
filelines *
GetFile(memory_arena *Arena,
        const char *FileName)
{
  filelines *FileLines = PushStruct(Arena, filelines);

  struct stat sb;
  if(stat (FileName, &sb) != 0)
  {
    ERROR("Unable to STAT file: %s.", FileName);
  }
  else
  {
    int32 len = sb.st_size;


    FILE *DAY = fopen(FileName, "r");
    if(DAY)
    {
      FileLines->File = (char *)PushSize(Arena, len);
      fread(FileLines->File, sizeof(char), (len), DAY);
      FileLines->Lines[0] = FileLines->File;

      int32 numlines = 1;
      for(int i = 0; i < len; ++i)
      {
        char Character = *(FileLines->File + i);
        if( Character == EOF)
        {
          len = i;
          break;
        }
        if( Character == '\n')
        {
          *(FileLines->File + i) = '\0';
          FileLines->Lines[numlines] = FileLines->File + i + 1;
          numlines++;
        }
      }

      FileLines->File[len] = '\0';
      FileLines->NumLines = --numlines;
      FileLines->FileSize = len;

      fclose(DAY);
    }
    else
    {
      ERROR("Unable to open file: %s.\n", FileName);
      FileLines->File = 0;
      FileLines->NumLines = 0;
      FileLines->FileSize = -1;

    }
  }


  return(FileLines);
}
Exemple #3
0
assets_s* AllocateAssets(memoryBlock_s* memoryBlock)
{
	assets_s* assets = PushStruct(memoryBlock, assets_s);
    assets->assetUseQueue = InitLinkedList(memoryBlock, Kilobytes(2));
    assets->dyMemoryBlock = InitDynamicMemoryBlock(memoryBlock, Megabytes(64), Kilobytes(10));
    assets->tagCount = 1;
    assets->assetCount = 1;

    platformFileGroup_s* fileGroup = Platform.getAllFilesOfTypeBegin("wa");
    assets->fileCount = fileGroup->fileCount;
    assets->files = PushArray(memoryBlock, assets->fileCount, assetFile_s);
    for(uint32_t index = 0; index < assets->fileCount; index++)
    {
        assetFile_s* file = assets->files + index;
        file->tagBase = assets->tagCount;
        file->handle = Platform.openNextFile(fileGroup);
        file->header = {};

        Platform.readDataFromFile(file->handle, 0, sizeof(file->header), &file->header);

        uint32_t assetTypeArraySize = file->header.assetTypesCount*sizeof(waAssetType_s);
        file->assetTypeArray = (waAssetType_s*) PushSize(memoryBlock, assetTypeArraySize);
        Platform.readDataFromFile(file->handle, file->header.assetTypes, assetTypeArraySize, 
            file->assetTypeArray);
        if(PlatformNoFileErrors(file->handle))
        {
            if(file->header.magicValue != MAGIC_VALUE)
            {
                Platform.fileError(file->handle, "wa file has an invalid magic value");
            }
            if(file->header.version > WALLACE_ASSET_VERSION)
            {
                Platform.fileError(file->handle, "wa file has a version which exceeds game version");
            } 

            if(PlatformNoFileErrors(file->handle))
            {
                // NOTE: The first asset and tag slot in every
                // .wa is a null (reserved) so we don't count it as
                // something we will need space for!
                assets->tagCount += (file->header.tagCount - 1);
                assets->assetCount += (file->header.assetCount - 1);
            }
        }
        else
        {
            InvalidCodePath;
        }
    }
    Platform.getAllFilesOfTypeEnd(fileGroup);
    assets->assets = PushArray(memoryBlock, assets->assetCount, assetFileData_s);
    assets->slots = PushArray(memoryBlock, assets->assetCount, assetData_s);
    assets->tags = PushArray(memoryBlock, assets->tagCount, waTag_s);

    assets->tags[0] = {};

    for(uint32_t fileIndex = 0; fileIndex < assets->fileCount; fileIndex++)
    {
        assetFile_s* file = assets->files + fileIndex;
        if(PlatformNoFileErrors(file->handle))
        {
            uint32_t tagArraySize = sizeof(waTag_s) * (file->header.tagCount - 1);
            Platform.readDataFromFile(file->handle, file->header.tags + sizeof(waTag_s), tagArraySize, 
                assets->tags + file->tagBase);
        }
    }

    // NOTE: Reserve one null asset at the beginning
    uint32_t assetCount = 0;
    assets->assets[assetCount] = {};
    assetCount++;
    for(uint32_t destTypeId = 0; destTypeId < assetType_last; destTypeId++)
    {
        waAssetType_s* destType = assets->assetTypes + destTypeId;
        destType->firstAssetIndex = assetCount;
        for(uint32_t fileIndex = 0; fileIndex < assets->fileCount; fileIndex++)
        {
            assetFile_s* file = assets->files + fileIndex;
            if(PlatformNoFileErrors(file->handle))
            {
                for(uint32_t sourceIndex = 0; sourceIndex < file->header.assetTypesCount; sourceIndex++)
                {
                    waAssetType_s* sourceType = file->assetTypeArray + sourceIndex;
                    if(sourceType->typeId == destTypeId)
                    {
                        uint32_t assetCountForType = sourceType->onePastLastAssetIndex - 
                            sourceType->firstAssetIndex;
                        temporaryMemory_s tempMem = BeginTemporaryMemory(memoryBlock);
                        waAssetFileData_s* waAssetArray = PushArray(memoryBlock, assetCountForType, waAssetFileData_s);
                        Platform.readDataFromFile(file->handle, file->header.assets +
                                                  sourceType->firstAssetIndex * sizeof(waAssetFileData_s),
                                                  assetCountForType * sizeof(waAssetFileData_s), waAssetArray);
                        for(uint32_t assetIndex = 0; assetIndex < assetCountForType; assetIndex++)
                        {
                            waAssetFileData_s* waAsset = waAssetArray + assetIndex;

                            // Assert(assetCount < assets->assetCount);
                            assetFileData_s* asset = assets->assets + assetCount++;
                            
                            asset->fileIndex = fileIndex;
                            asset->wa = *waAsset;
                            if(asset->wa.firstTagIndex == 0)
                            {
                                asset->wa.firstTagIndex = 0;
                                asset->wa.onePastLastTagIndex = 0;
                            }
                            else
                            {
                                asset->wa.firstTagIndex += (file->tagBase - 1);
                                asset->wa.onePastLastTagIndex += (file->tagBase - 1);
                            }
                        }

                        EndTemporaryMemory(tempMem);
                    }
                }
            }
        }
        destType->onePastLastAssetIndex = assetCount;
    }

    // Assert(assetCount == assets->assetCount);
	return assets;
}