mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +01:00
Generate temporary io_bind variables
This commit is contained in:
1 parent
4588cdcf5f
commit
3d1bb5e2a9
4 files changed
+40
-1
No files matched your search
@@ -52,6 +52,7 @@ const (
|
||||
cPrefix = "c_" // Coroutine state.
|
||||
fPrefix = "f_" // Struct field.
|
||||
iPrefix = "i_" // Iterate variable.
|
||||
oPrefix = "o_" // Temporary io_bind variable.
|
||||
tPrefix = "t_" // Temporary local variable.
|
||||
vPrefix = "v_" // Local variable.
|
||||
)
|
||||
@@ -145,7 +146,11 @@ const (
|
||||
priOnly
|
||||
)
|
||||
|
||||
const maxTemp = 10000
|
||||
const (
|
||||
maxIOBinds = 100
|
||||
maxIOBindInFields = 100
|
||||
maxTemp = 10000
|
||||
)
|
||||
|
||||
type status struct {
|
||||
name string
|
||||
|
||||
@@ -34,6 +34,7 @@ type funk struct {
|
||||
derivedVars map[t.ID]struct{}
|
||||
jumpTargets map[a.Loop]uint32
|
||||
coroSuspPoint uint32
|
||||
ioBinds uint32
|
||||
tempW uint32
|
||||
tempR uint32
|
||||
public bool
|
||||
|
||||
@@ -130,12 +130,41 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
|
||||
case a.KIOBind:
|
||||
n := n.IOBind()
|
||||
inFields := n.InFields()
|
||||
|
||||
if g.currFunk.ioBinds > maxIOBinds || len(inFields) > maxIOBindInFields {
|
||||
return fmt.Errorf("too many temporary variables required")
|
||||
}
|
||||
ioBindNum := g.currFunk.ioBinds
|
||||
g.currFunk.ioBinds++
|
||||
|
||||
// TODO: do these variables need to be func-scoped (bigger scope)
|
||||
// instead of block-scoped (smaller scope) if the coro_susp_point
|
||||
// switch can jump past this initialization??
|
||||
b.writes("{\n")
|
||||
for i := 0; i < len(inFields); i++ {
|
||||
e := inFields[i].Expr()
|
||||
name := e.Ident().Str(g.tm)
|
||||
for j := 0; j < 2; j++ {
|
||||
b.printf("uint8_t* %s%d_bounds%d_%s = %s%s.private_impl.bounds[%d];\n",
|
||||
oPrefix, ioBindNum, j, name, aPrefix, name, j)
|
||||
}
|
||||
}
|
||||
|
||||
for _, o := range n.Body() {
|
||||
if err := g.writeStatement(b, o, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
for i := len(inFields) - 1; i >= 0; i-- {
|
||||
e := inFields[i].Expr()
|
||||
name := e.Ident().Str(g.tm)
|
||||
for j := 1; j >= 0; j-- {
|
||||
b.printf("%s%s.private_impl.bounds[%d] = %s%d_bounds%d_%s;\n",
|
||||
aPrefix, name, j, oPrefix, ioBindNum, j, name)
|
||||
}
|
||||
}
|
||||
b.writes("}\n")
|
||||
return nil
|
||||
|
||||
|
||||
@@ -2956,6 +2956,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
|
||||
while (true) {
|
||||
wuffs_base__io_reader__mark(&a_src, b_rptr_src);
|
||||
{
|
||||
uint8_t* o_0_bounds0_src = a_src.private_impl.bounds[0];
|
||||
uint8_t* o_0_bounds1_src = a_src.private_impl.bounds[1];
|
||||
v_r = a_src;
|
||||
{
|
||||
WUFFS_BASE__COROUTINE_SUSPENSION_POINT(15);
|
||||
@@ -2980,6 +2982,8 @@ static wuffs_gif__status wuffs_gif__decoder__decode_id(
|
||||
}
|
||||
v_z = t_14;
|
||||
}
|
||||
a_src.private_impl.bounds[1] = o_0_bounds1_src;
|
||||
a_src.private_impl.bounds[0] = o_0_bounds0_src;
|
||||
}
|
||||
if (v_z == 0) {
|
||||
goto label_1_break;
|
||||
|
||||
Reference in new issue
Block a user