T_void CompileInclude(T_byte8 *p_include)
{
    T_byte8 name[80] ;

    sscanf(p_include+8, "%s", name) ;
    CompileFile(name) ;
}
示例#2
0
/*
================
idProgram::Restore
================
*/
bool idProgram::Restore( idRestoreGame *savefile ) {
	int i, num, index;
	bool result = true;
	idStr scriptname;

	savefile->ReadInt( num );
	for ( i = 0; i < num; i++ ) {
		savefile->ReadString( scriptname );
		CompileFile( scriptname );
	}

	savefile->ReadInt( index );
	while( index >= 0 ) {
		savefile->ReadByte( variables[index] );
		savefile->ReadInt( index );
	}

	savefile->ReadInt( num );
	for ( i = variableDefaults.Num(); i < num; i++ ) {
		savefile->ReadByte( variables[i] );
	}

	int saved_checksum, checksum;

	savefile->ReadInt( saved_checksum );
	checksum = CalculateChecksum();

	if ( saved_checksum != checksum ) {
		result = false;
	}

	return result;
}
示例#3
0
/*
================
idProgram::Startup
================
*/
void idProgram::Startup( const char *defaultScript ) {
	gameLocal.Printf( "Initializing scripts\n" );

	// make sure all data is freed up
	idThread::Restart();

#ifdef _HH_GLOBAL_COUNTER //HUMANHEAD rww
	globalOutputFile = fileSystem->OpenFileByMode("scriptglobals.txt", FS_WRITE);
	globalOutputUnique = 0;
	globalOutputRunningSize = 0;
#endif //HUMANHEAD END

	// get ready for loading scripts
	BeginCompilation();

	// load the default script
	if ( defaultScript && *defaultScript ) {
		CompileFile( defaultScript );
	}

	FinishCompilation();

#ifdef _HH_GLOBAL_COUNTER //HUMANHEAD rww
	if (globalOutputFile) {
		fileSystem->CloseFile(globalOutputFile);
		globalOutputFile = NULL;
	}
#endif //HUMANHEAD END
}
示例#4
0
bool Builder::Compile(int fileIndex)
{
    QString inputFile;

    // Get the input file path
    inputFile = project->files.at(fileIndex).name;

    switch (project->files.at(fileIndex).type) {
    case ptSource:
        inputFile = config.workspace +  "/" + //QDir::separator() +
                    project->name +  "/source/" + inputFile;
        break;

    case ptExternal:
    case ptExtra:
        inputFile = config.LocateFileUsingSearchPaths(inputFile, "$(LIBRARIES)", false);
        qDebug() << "LibsPath" << inputFile;
        break;
    }
    qDebug() << "inputFile: " << inputFile;
    //msg.buildStage = 0;			/// pre processor
    //CompileFile(inputFile, true, true);
    msg.buildStage = 1;
    return CompileFile(inputFile, true, false);
}
示例#5
0
文件: fe.cpp 项目: nlsynth/nli
void FE::RunFile(const string &file, vm::VM *vm) {
  vm::Method *method = CompileFile(file, dbg_parser_, vm);
  if (!method) {
    return;
  }
  vm->AddThreadFromMethod(NULL, vm->kernel_object_, method);
  vm->Run();
}
示例#6
0
bool Builder::BuildCoreLib(void)
{
    if (QFileInfo(coreLib).exists()) {
        return true;
    }

    map <QString, BoardDef>::const_iterator board = config.boards.find(project->boardName);
    map <QString, BuildDef>::const_iterator bld = config.builds.find(board->second.build_core);

    if (bld == config.builds.end()) {
        msg.Add("Error getting build configuration for board " + project->boardName, mtError);
        return false;
    }

    //buildType = 1;
    progress->SetPhase(BuildWindowTypes::linkingCore);
    int oldPercent = GetPercentage();
    SetPercentage(0);

    QString linkerPath = config.avrPath + "/avr-ar";

    msg.AddOutput("Linking core lib for board :" + project->boardName, false);

    QStringList coreFiles = bld->second.coreLibs.split(";");
    qDebug() << "Core Libs:" << bld->second.coreLibs;
    bool ok = true;

    for (int i=0; i < coreFiles.size(); i++) {
        coreFiles[i] = coreFiles[i].trimmed();
        if (coreFiles[i] == "") {
            continue;
        }
        QString inputFile = config.DecodeMacros(coreFiles.at(i), project);

        if (GetCancel()) {
            msg.Add("Build cancelled by the user!", mtRegular);
            ok = false;
            break;
        }
        ok = ok && CompileFile (inputFile, false, false);//, true);
        if (ok) {
            QString outputFile = MangleFileName(inputFile);
            QStringList arguments;
            arguments << "rcs" << coreLib;
            arguments << outputFile;
            msg.buildStage = 2;
            ok = launcher->RunCommand(linkerPath, arguments);
        }
        SetPercentage(100 * i / coreFiles.size());
    }

    SetPercentage(oldPercent);
    progress->SetPhase(BuildWindowTypes::compiling);
    //buildType = 0;
    return ok;
}
示例#7
0
文件: main.cpp 项目: 6520874/pipiGame
int main(int argc, const char * argv[])
{
    std::string inputFilePath, outputFilePath;
    if (1 == argc) {
        std::cerr << USAGE << std::endl;
        return EC_ERROR;
    }
    else {
        if (1 < argc) {            
            if (std::string(argv[1]) == "-p") { // pipe mode
                fd_set fds;
                FD_ZERO (&fds);
                FD_SET (STDIN_FILENO, &fds);
                int result = select (STDIN_FILENO + 1, &fds, NULL, NULL, NULL); // infinite wait
                if (result) { // STDIN ready to read
                    std::string line;
                    while (std::getline(std::cin, line)) {
                        if (!line.empty()) {
                            CompileFile(line, "");
                        }
                    }
                    return EC_OK;
                }
                else {
                    std::cerr << "Failed to read from pipe" << std::endl;
                    return EC_ERROR;
                }
            }
            else {
                inputFilePath = argv[1];
            }
        }
        if (2 < argc) {
            outputFilePath = argv[2];
        }
        if (CompileFile(inputFilePath, outputFilePath)) {
            return EC_OK;
        }
        return EC_ERROR;
    }
}
示例#8
0
unsigned int CInterpreter::CompileFileList()
{
    char msg[512] = {0};
    MEMORY::SafeDeleteArr(_compile_result);

	unsigned int result = NO_ERROR;
    for(int i = 0; i < m_fileTree.GetNumberOfFiles(); i++)
    {
		result = CompileFile(m_fileTree.GetFile(i));
    }

	return result;
}
示例#9
0
/*
================
idProgram::Startup
================
*/
void idProgram::Startup( const char *defaultScript ) {
	gameLocal.Printf( "Initializing scripts\n" );

	// make sure all data is freed up
	idThread::Restart();

	// get ready for loading scripts
	BeginCompilation();

	// load the default script
	if ( defaultScript && *defaultScript ) {
		CompileFile( defaultScript );
	}

	FinishCompilation();
}
示例#10
0
T_void main(int argc, char *argv[])
{
    puts("\n------- Script Compiler version 0.1 -- LesInk Productions (C) 1996") ;
    if (argc != 3)  {
        printf("USAGE:  SC <script file> <output file>\n") ;
        exit(1) ;
    }
    Initialize() ;
    AddVar("Self", 0x8000) ;
    AddVar("Time", 0x8001) ;
    CompileFile(argv[1]) ;
    if (G_errors == 0)
        SaveFile(argv[2]) ;
    else
        printf("%d errors.\n", G_errors) ;
    puts("Done.") ;
}
示例#11
0
//
// Thread entry point, for non-linking asynchronous mode.
//
// Return 0 for failure, 1 for success.
//
unsigned int CompileShaders(void*)
{
    glslang::TWorkItem* workItem;
    while (Worklist.remove(workItem)) {
        ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options);
        if (compiler == 0)
            return 0;

        CompileFile(workItem->name.c_str(), compiler);

        if (! (Options & EOptionSuppressInfolog))
            workItem->results = ShGetInfoLog(compiler);

        ShDestruct(compiler);
    }

    return 0;
}
int main(int argc, char* argv[])
{
    TFailCode failCode = ESuccess;

    int compileOptions = 0;
    int numCompiles = 0;
    ShHandle vertexCompiler = 0;
    ShHandle fragmentCompiler = 0;
    char* buffer = 0;
    int bufferLen = 0;
    int numAttribs = 0, numUniforms = 0;
    ShShaderSpec spec = SH_GLES2_SPEC;
    ShShaderOutput output = SH_ESSL_OUTPUT;

    ShInitialize();

    ShBuiltInResources resources;
    GenerateResources(&resources);

    argc--;
    argv++;
    for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) {
        if (argv[0][0] == '-') {
            switch (argv[0][1]) {
            case 'i':
                compileOptions |= SH_INTERMEDIATE_TREE;
                break;
            case 'm':
                compileOptions |= SH_MAP_LONG_VARIABLE_NAMES;
                break;
            case 'o':
                compileOptions |= SH_OBJECT_CODE;
                break;
            case 'u':
                compileOptions |= SH_ATTRIBUTES_UNIFORMS;
                break;
            case 'l':
                compileOptions |= SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX;
                break;
            case 'e':
                compileOptions |= SH_EMULATE_BUILT_IN_FUNCTIONS;
                break;
            case 'd':
                compileOptions |= SH_DEPENDENCY_GRAPH;
                break;
            case 't':
                compileOptions |= SH_TIMING_RESTRICTIONS;
                break;
            case 's':
                if (argv[0][2] == '=') {
                    switch (argv[0][3]) {
                    case 'e':
                        spec = SH_GLES2_SPEC;
                        break;
                    case 'w':
                        spec = SH_WEBGL_SPEC;
                        break;
                    case 'c':
                        spec = SH_CSS_SHADERS_SPEC;
                        break;
                    default:
                        failCode = EFailUsage;
                    }
                } else {
                    failCode = EFailUsage;
                }
                break;
            case 'b':
                if (argv[0][2] == '=') {
                    switch (argv[0][3]) {
                    case 'e':
                        output = SH_ESSL_OUTPUT;
                        break;
                    case 'g':
                        output = SH_GLSL_OUTPUT;
                        break;
                    case 'h':
                        output = SH_HLSL_OUTPUT;
                        break;
                    default:
                        failCode = EFailUsage;
                    }
                } else {
                    failCode = EFailUsage;
                }
                break;
            case 'x':
                if (argv[0][2] == '=') {
                    switch (argv[0][3]) {
                    case 'i':
                        resources.OES_EGL_image_external = 1;
                        break;
                    case 'd':
                        resources.OES_standard_derivatives = 1;
                        break;
                    case 'r':
                        resources.ARB_texture_rectangle = 1;
                        break;
                    default:
                        failCode = EFailUsage;
                    }
                } else {
                    failCode = EFailUsage;
                }
                break;
            default:
                failCode = EFailUsage;
            }
        } else {
            ShHandle compiler = 0;
            switch (FindShaderType(argv[0])) {
            case SH_VERTEX_SHADER:
                if (vertexCompiler == 0)
                    vertexCompiler = ShConstructCompiler(
                                         SH_VERTEX_SHADER, spec, output, &resources);
                compiler = vertexCompiler;
                break;
            case SH_FRAGMENT_SHADER:
                if (fragmentCompiler == 0)
                    fragmentCompiler = ShConstructCompiler(
                                           SH_FRAGMENT_SHADER, spec, output, &resources);
                compiler = fragmentCompiler;
                break;
            default:
                break;
            }
            if (compiler) {
                bool compiled = CompileFile(argv[0], compiler, compileOptions);

                LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG");
                ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen);
                buffer = (char*) realloc(buffer, bufferLen * sizeof(char));
                ShGetInfoLog(compiler, buffer);
                puts(buffer);
                LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
                printf("\n\n");

                if (compiled && (compileOptions & SH_OBJECT_CODE)) {
                    LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
                    ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &bufferLen);
                    buffer = (char*) realloc(buffer, bufferLen * sizeof(char));
                    ShGetObjectCode(compiler, buffer);
                    puts(buffer);
                    LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
                    printf("\n\n");
                }
                if (compiled && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) {
                    LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
                    PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0);
                    LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS");
                    printf("\n\n");

                    LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE UNIFORMS");
                    PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0);
                    LogMsg("END", "COMPILER", numCompiles, "ACTIVE UNIFORMS");
                    printf("\n\n");
                }
                if (!compiled)
                    failCode = EFailCompile;
                ++numCompiles;
            } else {
                failCode = EFailCompilerCreate;
            }
        }
    }

    if ((vertexCompiler == 0) && (fragmentCompiler == 0))
        failCode = EFailUsage;
    if (failCode == EFailUsage)
        usage();

    if (vertexCompiler)
        ShDestruct(vertexCompiler);
    if (fragmentCompiler)
        ShDestruct(fragmentCompiler);
    if (buffer)
        free(buffer);
    ShFinalize();

    return failCode;
}
int
main(
    int argc,
    char * argv[]
    )
{
    gctBOOL         dumpLog      = gcvFALSE;
    gctSTRING       fileName[2]  = { gcvNULL, gcvNULL };
    gcSHADER        shaders[2]   = { gcvNULL, gcvNULL };
    gctINT          i;
    gcoOS           os           = gcvNULL;
    gcoHAL          hal          = gcvNULL;
    gceSTATUS       result;
    gctUINT         option       = 1;   /* no optimization */
    char            outFile[128] = { '\0' };
    char            logVSFile[128] = { '\0' };
    char            logFSFile[128] = { '\0' };

    printf("vCompile version 0.8, Copyright (c) 2005-2011, Vivante Corporation\n\n");

#ifdef _WIN32
    _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) /*| _CRTDBG_CHECK_ALWAYS_DF*/ | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
    _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR );
    /* _CrtSetBreakAlloc(79); */
#endif

#if gcdDEBUG
    gcoOS_SetDebugLevel(gcvLEVEL_VERBOSE);
    gcoOS_SetDebugZone(gcvZONE_COMPILER);
#endif

    for (i = 1; i < argc; i++)
    {
        if (gcmIS_SUCCESS(gcoOS_StrCmp(argv[i], "-l")))
        {
            dumpLog = gcvTRUE;
        }
        else if (gcmIS_SUCCESS(gcoOS_StrCmp(argv[i], "-O0")))
        {
            /* Currently, optimization level is either FULL or NONE */
            option = 0;     /* no optimization */
        }
        else if (gcmIS_SUCCESS(gcoOS_StrCmp(argv[i], "-O")))
        {
            option = 1;     /* full optimization */
        }
        else if (gcmIS_SUCCESS(gcoOS_StrCmp(argv[i], "-OT")))
        {
            /* For optimization unit test */
            if (i++ == argc)
            {
                printf("*ERROR* Optimization testing pattern not provided.\n");
                return 1;
            }
            else
            {
                gctINT testPattern;

                gcmVERIFY_OK(gcoOS_StrToInt(argv[i], (gctINT *)&testPattern));
                if (testPattern < 0)
                {
                    printf("*ERROR* Unknown optimization testing pattern.\n");
                    return 1;
                }
                option = testPattern;
            }
        }
        else
        {
            if (fileName[0] == gcvNULL) fileName[0] = argv[i];
            else if (fileName[1] == gcvNULL) fileName[1] = argv[i];
            else
            {
                printf("*ERROR* Too many shaders.\n");
                return 1;
            }
        }
    }

    if (fileName[0] == gcvNULL)
    {
        printf("Usage: %s [-l] [-O0] shaderFileName [shaderFileName]\n", argv[0]);
        printf("  -l   Generate log file.\n"
               "  -O0  Disable optimizations.\n"
               "\n"
               "If only one shader is specified, that shader will be compiled into a .gcSL\n"
               "file.  If two shaders are specified, those shaders will be compiled and\n"
               "linked into a .gcPGM file. With two shaders, the vertex shader file needs\n"
               "to be the first.\n");
        return 0;
    }

    result = gcoOS_Construct(gcvNULL, &os);
    if (result != gcvSTATUS_OK)
    {
        printf("*ERROR* Failed to construct a new gcoOS object\n");
        return 1;
    }

    result = gcoHAL_Construct(gcvNULL, os, &hal);
    if (result != gcvSTATUS_OK)
    {
        printf("*ERROR* Failed to construct a new gcoHAL object\n");
        goto ErrorExit;
    }

    /* Dump compile log only when one shader is present */
    shaders[0] = CompileFile(os, fileName[0], hal, option, dumpLog && (fileName[1] == gcvNULL), fileName[1] == gcvNULL );

    if (shaders[0] == gcvNULL)
    {
        goto ErrorExit;
    }

    if (fileName[1] != gcvNULL)
    {
        gctSIZE_T programBufferSize = 0;
        gctPOINTER programBuffer = gcvNULL;
        gcsHINT_PTR hints = gcvNULL;
        gceSTATUS status;
        gctPOINTER binary = gcvNULL;
        gctSIZE_T binarySize = 0;
        FILE * f;
        gctSTRING p;

        gcoOS_StrCopySafe(outFile, gcmSIZEOF(outFile), fileName[0]);
        p = strrchr(outFile, '.');
        gcoOS_StrCopySafe(p, gcmSIZEOF(outFile) - (p - outFile), ".gcPGM");

        gcoOS_StrCopySafe(logVSFile, gcmSIZEOF(logVSFile), fileName[0]);
        gcoOS_StrCatSafe(logVSFile, gcmSIZEOF(logVSFile), ".log");

        gcoOS_StrCopySafe(logFSFile, gcmSIZEOF(logFSFile), fileName[1]);
        gcoOS_StrCatSafe(logFSFile, gcmSIZEOF(logFSFile), ".log");

        shaders[1] = CompileFile(os, fileName[1], hal, option, gcvFALSE, gcvFALSE);
        if (shaders[1] == gcvNULL)
        {
            goto ErrorExit;
        }

        if ( dumpLog)
        {
            gcoOS_SetDebugShaderFiles(logVSFile, logFSFile);
        }
        status = gcLinkShaders(shaders[0],
                               shaders[1],
                               gcvSHADER_DEAD_CODE
                               | gcvSHADER_RESOURCE_USAGE
                               | gcvSHADER_OPTIMIZER
                               | gcvSHADER_USE_GL_Z
                               | gcvSHADER_USE_GL_POSITION
                               | gcvSHADER_USE_GL_FACE,
                               &programBufferSize,
                               &programBuffer,
                               &hints);
        if ( dumpLog)
        {
            gcoOS_SetDebugShaderFiles(gcvNULL, gcvNULL);
        }

        if (gcmIS_ERROR(status))
        {
            printf("*ERROR* gcLinkShaders returned errror %d\n", status);
        }
        else
        {
            int ret;
            status = gcSaveProgram(shaders[0],
                                   shaders[1],
                                   programBufferSize,
                                   programBuffer,
                                   hints,
                                   &binary,
                                   &binarySize);

            if (gcmIS_ERROR(status))
            {
                printf("*ERROR* gcSaveShaders returned errror %d\n", status);
            }

            f = fopen(outFile, "wb");
            ret = fwrite(binary, binarySize, 1, f);
            if (ret);
            fclose(f);
        }

        if (programBuffer != gcvNULL) gcoOS_Free(os, programBuffer);
        if (hints         != gcvNULL) gcoOS_Free(os, hints);
        if (binary        != gcvNULL) gcoOS_Free(os, binary);
    }

    gcSHADER_Destroy(shaders[0]);
    if (shaders[1] != gcvNULL) gcSHADER_Destroy(shaders[1]);
    gcoHAL_Destroy(hal);
    gcoOS_Destroy(os);
    return 0;

ErrorExit:
    if (shaders[0] != gcvNULL) gcSHADER_Destroy(shaders[0]);
    if (shaders[1] != gcvNULL) gcSHADER_Destroy(shaders[1]);
    if (gcvNULL != hal) gcoHAL_Destroy(hal);
    if (gcvNULL != os) gcoOS_Destroy(os);

    return 1;
}
int main(int argc, char *argv[])
{
    TFailCode failCode = ESuccess;

    int compileOptions = 0;
    int numCompiles = 0;
    ShHandle vertexCompiler = 0;
    ShHandle fragmentCompiler = 0;
    ShShaderSpec spec = SH_GLES2_SPEC;
    ShShaderOutput output = SH_ESSL_OUTPUT;

    ShInitialize();

    ShBuiltInResources resources;
    GenerateResources(&resources);

    argc--;
    argv++;
    for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++)
    {
        if (argv[0][0] == '-')
        {
            switch (argv[0][1])
            {
              case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break;
              case 'o': compileOptions |= SH_OBJECT_CODE; break;
              case 'u': compileOptions |= SH_VARIABLES; break;
              case 'l': compileOptions |= SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX; break;
              case 'e': compileOptions |= SH_EMULATE_BUILT_IN_FUNCTIONS; break;
              case 'd': compileOptions |= SH_DEPENDENCY_GRAPH; break;
              case 't': compileOptions |= SH_TIMING_RESTRICTIONS; break;
              case 'p': resources.WEBGL_debug_shader_precision = 1; break;
              case 's':
                if (argv[0][2] == '=')
                {
                    switch (argv[0][3])
                    {
                      case 'e':
                        if (argv[0][4] == '3')
                        {
                            spec = SH_GLES3_SPEC;
                        }
                        else
                        {
                            spec = SH_GLES2_SPEC;
                        }
                        break;
                      case 'w':
                        if (argv[0][4] == '2')
                        {
                            spec = SH_WEBGL2_SPEC;
                        }
                        else
                        {
                            spec = SH_WEBGL_SPEC;
                        }
                        break;
                      case 'c': spec = SH_CSS_SHADERS_SPEC; break;
                      default: failCode = EFailUsage;
                    }
                }
                else
                {
                    failCode = EFailUsage;
                }
                break;
              case 'b':
                if (argv[0][2] == '=')
                {
                    switch (argv[0][3])
                    {
                      case 'e': output = SH_ESSL_OUTPUT; break;
                      case 'g': output = SH_GLSL_OUTPUT; break;
                      case 'h':
                        if (argv[0][4] == '1' && argv[0][5] == '1')
                        {
                            output = SH_HLSL11_OUTPUT;
                        }
                        else
                        {
                            output = SH_HLSL9_OUTPUT;
                        }
                        break;
                      default: failCode = EFailUsage;
                    }
                }
                else
                {
                    failCode = EFailUsage;
                }
                break;
              case 'x':
                if (argv[0][2] == '=')
                {
                    switch (argv[0][3])
                    {
                      case 'i': resources.OES_EGL_image_external = 1; break;
                      case 'd': resources.OES_standard_derivatives = 1; break;
                      case 'r': resources.ARB_texture_rectangle = 1; break;
                      case 'l': resources.EXT_shader_texture_lod = 1; break;
                      case 'f': resources.EXT_shader_framebuffer_fetch = 1; break;
                      case 'n': resources.NV_shader_framebuffer_fetch = 1; break;
                      case 'a': resources.ARM_shader_framebuffer_fetch = 1; break;
                      default: failCode = EFailUsage;
                    }
                }
                else
                {
                    failCode = EFailUsage;
                }
                break;
              default: failCode = EFailUsage;
            }
        }
        else
        {
            ShHandle compiler = 0;
            switch (FindShaderType(argv[0]))
            {
              case GL_VERTEX_SHADER:
                if (vertexCompiler == 0)
                {
                    vertexCompiler = ShConstructCompiler(
                        GL_VERTEX_SHADER, spec, output, &resources);
                }
                compiler = vertexCompiler;
                break;
              case GL_FRAGMENT_SHADER:
                if (fragmentCompiler == 0)
                {
                    fragmentCompiler = ShConstructCompiler(
                        GL_FRAGMENT_SHADER, spec, output, &resources);
                }
                compiler = fragmentCompiler;
                break;
              default: break;
            }
            if (compiler)
            {
                bool compiled = CompileFile(argv[0], compiler, compileOptions);

                LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG");
                std::string log = ShGetInfoLog(compiler);
                puts(log.c_str());
                LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
                printf("\n\n");

                if (compiled && (compileOptions & SH_OBJECT_CODE))
                {
                    LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
                    std::string code = ShGetObjectCode(compiler);
                    puts(code.c_str());
                    LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
                    printf("\n\n");
                }
                if (compiled && (compileOptions & SH_VARIABLES))
                {
                    LogMsg("BEGIN", "COMPILER", numCompiles, "VARIABLES");
                    PrintActiveVariables(compiler);
                    LogMsg("END", "COMPILER", numCompiles, "VARIABLES");
                    printf("\n\n");
                }
                if (!compiled)
                  failCode = EFailCompile;
                ++numCompiles;
            }
            else
            {
                failCode = EFailCompilerCreate;
            }
        }
    }

    if ((vertexCompiler == 0) && (fragmentCompiler == 0))
        failCode = EFailUsage;
    if (failCode == EFailUsage)
        usage();

    if (vertexCompiler)
        ShDestruct(vertexCompiler);
    if (fragmentCompiler)
        ShDestruct(fragmentCompiler);
    ShFinalize();

    return failCode;
}
示例#15
0
文件: bob.c 项目: dbetz/bob
/* main - the main routine */
int main(int argc,char **argv)
{
	int interactiveP = TRUE;
    BobUnwindTarget target;
    BobInterpreter *c;
    
    /* make the workspace */
    if ((c = BobMakeInterpreter(interpreterSpace,sizeof(interpreterSpace),STACK_SIZE)) == NULL)
        exit(1);

    /* setup standard i/o */
    c->standardInput = (BobStream *)&consoleStream;
    c->standardOutput = (BobStream *)&consoleStream;
    c->standardError = (BobStream *)&consoleStream;
    
    /* setup the error handler */
    c->errorHandler = ErrorHandler;
    
    /* setup the error handler target */
    BobPushUnwindTarget(c,&target);

    /* abort if any errors occur during initialization */
    if (BobUnwindCatch(c))
        exit(1);

    /* initialize the workspace */
    if (!BobInitInterpreter(c))
        exit(1);

    /* use stdio for file i/o */
    BobUseStandardIO(c);
     
    /* add the library functions to the symbol table */
    BobEnterLibrarySymbols(c);

    /* use the math routines */
#ifdef BOB_INCLUDE_FLOAT_SUPPORT
    BobUseMath(c);
#endif

    /* use the eval package */
    BobUseEval(c,compilerSpace,sizeof(compilerSpace));

    /* catch errors and restart read/eval/print loop */
    if (BobUnwindCatch(c) == 0) {
        char *inputName,*outputName = NULL;
        int verboseP = FALSE;
        int i;

        /* process arguments */
        for (i = 1; i < argc; ++i) {
            if (argv[i][0] == '-') {
                switch (argv[i][1]) {
			    case '?':
                    Usage();
                    break;
                case 'c':   /* compile source file */
                    if (argv[i][2])
                        inputName = &argv[i][2];
                    else if (++i < argc)
                        inputName = argv[i];
                    else
                        Usage();
                    CompileFile(c,inputName,outputName);
                    interactiveP = FALSE;
                    outputName = NULL;
                    break;
                case 'i':   /* enter interactive mode after loading */
                    interactiveP = TRUE;
                    break;
                case 'o':   /* specify output filename when compiling */
                    if (argv[i][2])
                        outputName = &argv[i][2];
                    else if (++i < argc)
                        outputName = argv[i];
                    else
                        Usage();
                    interactiveP = FALSE;
                    break;
                case 'v':   /* display values of expressions loaded */
                    verboseP = TRUE;
                    break;
                default:
                    Usage();
                    break;
                }
            }
            else {
                LoadFile(c,argv[i],verboseP);
                interactiveP = FALSE;
                verboseP = FALSE;
            }
        }
    }
    
    /* read/eval/print loop */
    if (interactiveP)
        ReadEvalPrint(c);
    
    /* pop the unwind target */
    BobPopUnwindTarget(c);

    /* return successfully */
    return 0;
}