shaderir: Remove Ident

This commit is contained in:
Hajime Hoshi 2020-05-17 03:00:57 +09:00
parent dbbe4ee09c
commit 094d845edd
3 changed files with 29 additions and 30 deletions

View File

@ -166,7 +166,7 @@ func (p *Program) glslFunc(f *Func) []string {
} }
var lines []string var lines []string
lines = append(lines, fmt.Sprintf("%s %s(%s) {", p.glslType(&f.Return), f.Name, argsstr)) lines = append(lines, fmt.Sprintf("%s F%d(%s) {", p.glslType(&f.Return), f.Index, argsstr))
lines = append(lines, p.glslBlock(&f.Block, 0, idx)...) lines = append(lines, p.glslBlock(&f.Block, 0, idx)...)
lines = append(lines, "}") lines = append(lines, "}")
@ -230,12 +230,12 @@ func (p *Program) glslBlock(b *Block, level int, localVarIndex int) []string {
case BuiltinFuncExpr: case BuiltinFuncExpr:
return string(e.BuiltinFunc) return string(e.BuiltinFunc)
case SwizzlingExpr: case SwizzlingExpr:
if !isValidSwizzling(e.Ident) { if !isValidSwizzling(e.Swizzling) {
return fmt.Sprintf("?(unexpected swizzling: %s)", e.Ident) return fmt.Sprintf("?(unexpected swizzling: %s)", e.Swizzling)
} }
return e.Ident return e.Swizzling
case Ident: case FunctionExpr:
return e.Ident return fmt.Sprintf("F%d", e.Index)
case Unary: case Unary:
var op string var op string
switch e.Op { switch e.Op {

View File

@ -100,15 +100,15 @@ func builtinFuncExpr(f BuiltinFunc) Expr {
func swizzlingExpr(swizzling string) Expr { func swizzlingExpr(swizzling string) Expr {
return Expr{ return Expr{
Type: SwizzlingExpr, Type: SwizzlingExpr,
Ident: swizzling, Swizzling: swizzling,
} }
} }
func identExpr(ident string) Expr { func functionExpr(index int) Expr {
return Expr{ return Expr{
Type: Ident, Type: FunctionExpr,
Ident: ident, Index: index,
} }
} }
@ -200,7 +200,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
}, },
}, },
}, },
@ -212,7 +212,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
{Main: Vec2}, {Main: Vec2},
@ -235,7 +235,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
}, },
@ -258,7 +258,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
}, },
@ -285,7 +285,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
}, },
@ -326,7 +326,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
{Main: Float}, {Main: Float},
@ -357,7 +357,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Bool}, {Main: Bool},
{Main: Float}, {Main: Float},
@ -389,7 +389,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
{Main: Float}, {Main: Float},
@ -401,13 +401,13 @@ varying vec3 V0;`,
nil, nil,
exprStmt( exprStmt(
callExpr( callExpr(
identExpr("F1"), functionExpr(1),
), ),
), ),
assignStmt( assignStmt(
varNameExpr(Local, 2), varNameExpr(Local, 2),
callExpr( callExpr(
identExpr("F2"), functionExpr(2),
varNameExpr(Local, 0), varNameExpr(Local, 0),
varNameExpr(Local, 1), varNameExpr(Local, 1),
), ),
@ -426,7 +426,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
{Main: Float}, {Main: Float},
@ -457,7 +457,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Vec4}, {Main: Vec4},
}, },
@ -486,7 +486,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
{Main: Float}, {Main: Float},
@ -534,7 +534,7 @@ varying vec3 V0;`,
Program: Program{ Program: Program{
Funcs: []Func{ Funcs: []Func{
{ {
Name: "F0", Index: 0,
InParams: []Type{ InParams: []Type{
{Main: Float}, {Main: Float},
{Main: Float}, {Main: Float},

View File

@ -27,10 +27,8 @@ type Program struct {
structTypes []Type structTypes []Type
} }
// TODO: How to avoid the name with existing functions?
type Func struct { type Func struct {
Name string Index int
InParams []Type InParams []Type
InOutParams []Type InOutParams []Type
OutParams []Type OutParams []Type
@ -89,7 +87,8 @@ type Expr struct {
Int int32 Int int32
Float float32 Float float32
BuiltinFunc BuiltinFunc BuiltinFunc BuiltinFunc
Ident string Swizzling string
Index int
Op Op Op Op
} }
@ -101,7 +100,7 @@ const (
VarName VarName
BuiltinFuncExpr BuiltinFuncExpr
SwizzlingExpr SwizzlingExpr
Ident FunctionExpr
Unary Unary
Binary Binary
Selection Selection