Welcome to mirror list, hosted at ThFree Co, Russian Federation.

main.cpp « buildHeaders « tools - github.com/KhronosGroup/SPIRV-Headers.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9a5971408cfd6e3839cadd536fcbd7d17526b584 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) 2014-2019 The Khronos Group Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and/or associated documentation files (the "Materials"),
// to deal in the Materials without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Materials, and to permit persons to whom the
// Materials are furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Materials.
//
// MODIFICATIONS TO THIS FILE MAY MEAN IT NO LONGER ACCURATELY REFLECTS KHRONOS
// STANDARDS. THE UNMODIFIED, NORMATIVE VERSIONS OF KHRONOS SPECIFICATIONS AND
// HEADER INFORMATION ARE LOCATED AT https://www.khronos.org/registry/
//
// THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM,OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS
// IN THE MATERIALS.

//#include <fstream>
#include <string>
#include <algorithm>

#include "jsonToSpirv.h"
#include "header.h"

// Command-line options
enum TOptions {
    EOptionNone                       = 0x000,
    EOptionPrintHeader                = 0x008,
};

std::string jsonPath;
int Options;
spv::TLanguage Language;

void Usage()
{
    printf("Usage: spirv option [file]\n"
           "\n"
           "  -h <language> print header for given language to stdout, from one of:\n"
           "     C      - C99 header\n"
           "     C++    - C++03 or greater header (also accepts C++03)\n"
           "     C++11  - C++11 or greater header\n"
           "     JSON   - JSON format data\n"
           "     Lua    - Lua module\n"
           "     Python - Python module (also accepts Py)\n"
           "     C#     - C# module (also accepts CSharp)\n"
           "     D      - D module\n"
           "     Beef   - Beef module\n"
           "  -H print header in all supported languages to files in current directory\n"
           );
}

std::string tolower_s(std::string s)
{
    std::transform(s.begin(), s.end(), s.begin(), ::tolower);
    return s;
}

bool ProcessArguments(int argc, char* argv[])
{
    argc--;
    argv++;
    for (; argc >= 1; argc--, argv++) {
        if (argv[0][0] == '-') {
            switch (argv[0][1]) {
            case 'H':
                Options |= EOptionPrintHeader;
                Language = spv::ELangAll;
                break;
            case 'h': {
                if (argc < 2)
                    return false;

                Options |= EOptionPrintHeader;
                const std::string language(tolower_s(argv[1]));

                if (language == "c") {
                    Language = spv::ELangC;
                } else if (language == "c++" || language == "c++03") {
                    Language = spv::ELangCPP;
                } else if (language == "c++11") {
                    Language = spv::ELangCPP11;
                } else if (language == "json") {
                    Language = spv::ELangJSON;
                } else if (language == "lua") {
                    Language = spv::ELangLua;
                } else if (language == "python" || language == "py") {
                    Language = spv::ELangPython;
                } else if (language == "c#" || language == "csharp") {
                    Language = spv::ELangCSharp;
                } else if (language == "d") {
                    Language = spv::ELangD;
                } else if (language == "beef") {
                    Language = spv::ELangBeef;
                } else
                    return false;

                return true;
            }
            default:
                return false;
            }
        } else {
            jsonPath = std::string(argv[0]);
        }
    }

    return true;
}

int main(int argc, char* argv[])
{
    if (argc < 2 || ! ProcessArguments(argc, argv)) {
        Usage();
        return 1;
    }

    spv::jsonToSpirv(jsonPath, (Options & EOptionPrintHeader) != 0);
    if (Options & EOptionPrintHeader)
        spv::PrintHeader(Language, std::cout);

    return 0;
}