-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfwd.hpp
More file actions
115 lines (92 loc) · 1.84 KB
/
fwd.hpp
File metadata and controls
115 lines (92 loc) · 1.84 KB
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
#pragma once
#include "parser.hpp"
#include <cstdint>
#include <variant>
#include <string_view>
#include <vector>
#include <deque>
#include <unordered_map>
using u32 = std::uint32_t;
struct List;
struct Identifier;
struct Expression;
struct DefExpr;
using Defs = std::unordered_map<std::string_view, DefExpr>;
template<typename ...Ts>
struct Visitor : Ts... {
Visitor(const Ts&... args) : Ts(args)... {}
using Ts::operator()...;
};
enum class PrimitiveType {
eVoid,
eFloat,
eBool,
eRecCall,
};
struct VectorType {
unsigned count;
PrimitiveType primitive;
};
struct MatrixType {
unsigned rows, cols;
PrimitiveType primitive;
};
using Type = std::variant<PrimitiveType, VectorType, MatrixType>;
struct GenExpr {
u32 id;
u32 idtype;
Type type;
};
// Expression for codegen:
// either a standard expression or a GenExpr
struct CExpression {
std::variant<bool, double, std::string_view, List, Identifier, GenExpr> value;
Location loc;
};
CExpression wrap(const Expression& expr);
struct DefExpr {
CExpression expr;
const Defs* scope;
};
[[noreturn]] void throwError(std::string msg, const Location& loc);
// Codegen
struct Codegen {
std::vector<u32> buf; // generated spirv body
u32 id {}; // counter
// reserved ids
u32 idmain;
u32 idmaintype;
u32 idglsl;
u32 entryblock;
u32 idtrue;
u32 idfalse;
u32 block; // id of the current block
struct {
u32 tf32 {};
u32 tvec4 {};
u32 tvoid {};
u32 tbool {};
} types;
struct {
u32 fragCoord;
} inputs;
struct Output {
u32 id;
u32 location;
u32 idtype;
};
struct Constant {
u32 id;
u32 value;
u32 type;
};
std::vector<Output> outputs;
std::vector<Constant> constants;
};
struct Context {
Codegen& codegen;
const Defs& defs;
};
void init(Codegen& ctx);
GenExpr generateExpr(const Context& ctx, const Expression& expr);
std::vector<u32> finish(Codegen& ctx);