4 * Functions for managing instruction labels.
5 * Basically, this is used to manage the problem of forward branches where
6 * we have a branch instruciton but don't know the target address yet.
10 #include "slang_label.h"
11 #include "slang_mem.h"
16 _slang_label_new(const char *name
)
18 slang_label
*l
= (slang_label
*) _slang_alloc(sizeof(slang_label
));
20 l
->Name
= _slang_strdup(name
);
27 * As above, but suffix the name with a unique number.
30 _slang_label_new_unique(const char *name
)
33 slang_label
*l
= (slang_label
*) _slang_alloc(sizeof(slang_label
));
35 l
->Name
= (char *) _slang_alloc(_mesa_strlen(name
) + 10);
40 _mesa_sprintf(l
->Name
, "%s_%d", name
, id
);
48 _slang_label_delete(slang_label
*l
)
55 _slang_free(l
->References
);
63 _slang_label_add_reference(slang_label
*l
, GLuint inst
)
65 const GLuint oldSize
= l
->NumReferences
* sizeof(GLuint
);
66 assert(l
->Location
< 0);
67 l
->References
= _slang_realloc(l
->References
,
68 oldSize
, oldSize
+ sizeof(GLuint
));
70 l
->References
[l
->NumReferences
] = inst
;
77 _slang_label_get_location(const slang_label
*l
)
84 _slang_label_set_location(slang_label
*l
, GLint location
,
85 struct gl_program
*prog
)
89 assert(l
->Location
< 0);
90 assert(location
>= 0);
92 l
->Location
= location
;
94 /* for the instructions that were waiting to learn the label's location: */
95 for (i
= 0; i
< l
->NumReferences
; i
++) {
96 const GLuint j
= l
->References
[i
];
97 prog
->Instructions
[j
].BranchTarget
= location
;
101 _slang_free(l
->References
);
102 l
->References
= NULL
;