#include "slang_preprocess.h"
#include "slang_storage.h"
#include "slang_error.h"
+#include "slang_emit.h"
+#include "slang_vartable.h"
#include "slang_print.h"
for (i = 0; i < SLANG_BUILTIN_TOTAL; i++)
_slang_code_unit_ctr(&self->builtin[i], self);
_slang_code_unit_ctr(&self->unit, self);
+#if 01
_slang_assembly_file_ctr(&self->assembly);
+#endif
slang_machine_ctr(&self->machine);
self->varpool.next_addr = 0;
slang_atom_pool_construct(&self->atompool);
for (i = 0; i < SLANG_BUILTIN_TOTAL; i++)
_slang_code_unit_dtr(&self->builtin[i]);
_slang_code_unit_dtr(&self->unit);
+#if 01
slang_assembly_file_destruct(&self->assembly);
+#endif
slang_machine_dtr(&self->machine);
slang_atom_pool_destruct(&self->atompool);
slang_export_data_table_dtr(&self->expdata);
int parsing_builtin;
GLboolean global_scope; /**< Is object being declared a global? */
slang_atom_pool *atoms;
+ slang_unit_type type; /**< Vertex vs. Fragment */
} slang_parse_ctx;
/* slang_output_ctx */
slang_var_pool *global_pool;
slang_machine *machine;
struct gl_program *program;
+ slang_var_table *vartable;
} slang_output_ctx;
/* _slang_compile() */
slang_operation *ch;
/* grow child array */
-#if 000
- oper->children = (slang_operation *)
- slang_alloc_realloc(oper->children,
- oper->num_children * sizeof(slang_operation),
- (oper->num_children + 1) * sizeof(slang_operation));
- if (oper->children == NULL) {
- slang_info_log_memory(C->L);
- return 0;
- }
-
- ch = &oper->children[oper->num_children];
- if (!slang_operation_construct(ch)) {
- slang_info_log_memory(C->L);
- return 0;
- }
- oper->num_children++;
-#else
ch = slang_operation_grow(&oper->num_children, &oper->children);
-#endif
if (statement)
return parse_statement(C, O, ch);
return parse_expression(C, O, ch);
/* local variable declaration, individual declarators are stored as
* children identifiers
*/
-#if 000
- oper->type = slang_oper_variable_decl;
- {
- const unsigned int first_var = O->vars->num_variables;
-
- /* parse the declaration, note that there can be zero or more
- * than one declarators
- */
- if (!parse_declaration(C, O))
- return 0;
- if (first_var < O->vars->num_variables) {
- const unsigned int num_vars = O->vars->num_variables - first_var;
- unsigned int i;
-
- oper->children = (slang_operation *)
- slang_alloc_malloc(num_vars * sizeof(slang_operation));
- if (oper->children == NULL) {
- slang_info_log_memory(C->L);
- return 0;
- }
- for (oper->num_children = 0; oper->num_children < num_vars;
- oper->num_children++) {
- if (!slang_operation_construct
- (&oper->children[oper->num_children])) {
- slang_info_log_memory(C->L);
- return 0;
- }
- }
- for (i = first_var; i < O->vars->num_variables; i++) {
- slang_operation *o = &oper->children[i - first_var];
- o->type = slang_oper_identifier;
- o->locals->outer_scope = O->vars;
- o->a_id = O->vars->variables[i].a_name;
- }
- }
- }
-#else
-
oper->type = slang_oper_block_no_new_scope;
{
const unsigned int first_var = O->vars->num_variables;
slang_operation *o = &oper->children[i - first_var];
o->type = slang_oper_variable_decl;
o->locals->outer_scope = O->vars;
- o->a_id = O->vars->variables[i].a_name;
+ o->a_id = O->vars->variables[i]->a_name;
}
}
}
-
-
-#endif
break;
case OP_ASM:
/* the __asm statement, parse the mnemonic and all its arguments
*/
oper->type = slang_oper_asm;
oper->a_id = parse_identifier(C);
- if (strcmp((char*)oper->a_id, "dot") == 0) {
- printf("Assemble dot! **************************\n");
- }
if (oper->a_id == SLANG_ATOM_NULL)
return 0;
while (*C->I != OP_END) {
static GLboolean
initialize_global(slang_assemble_ctx * A, slang_variable * var)
{
+#if 01
slang_assembly_file_restore_point point;
+#endif
slang_machine mach;
slang_assembly_local_info save_local = A->local;
slang_operation op_id, op_assign;
GLboolean result;
+#if 01
/* save the current assembly */
if (!slang_assembly_file_restore_point_save(A->file, &point))
return GL_FALSE;
+#endif
/* setup the machine */
mach = *A->mach;
/* put the variable into operation's scope */
op_id.locals->variables =
- (slang_variable *) slang_alloc_malloc(sizeof(slang_variable));
+ (slang_variable **) slang_alloc_malloc(sizeof(slang_variable *));
if (op_id.locals->variables == NULL) {
slang_operation_destruct(&op_id);
return GL_FALSE;
}
op_id.locals->num_variables = 1;
- op_id.locals->variables[0] = *var;
+ op_id.locals->variables[0] = var;
/* construct the assignment expression */
if (!slang_operation_construct(&op_assign)) {
op_assign.children[0] = op_id;
op_assign.children[1] = *var->initializer;
+#if 0 /* this should go away */
/* insert the actual expression */
result = _slang_assemble_operation(A, &op_assign, slang_ref_forbid);
+#else
+ result = 1;
+#endif
/* carefully destroy the operations */
op_assign.num_children = 0;
return GL_FALSE;
/* execute the expression */
+#if 0
if (!_slang_execute2(A->file, &mach))
return GL_FALSE;
+#endif
+#if 01
/* restore the old assembly */
if (!slang_assembly_file_restore_point_load(A->file, &point))
return GL_FALSE;
+#endif
A->local = save_local;
/* now we copy the contents of the initialized variable back to the original machine */
return 0;
}
+#if 1
+ if (C->global_scope) {
+ slang_assemble_ctx A;
+
+ A.file = O->assembly;
+ A.mach = O->machine;
+ A.atoms = C->atoms;
+ A.space.funcs = O->funs;
+ A.space.structs = O->structs;
+ A.space.vars = O->vars;
+ A.program = O->program;
+#if 0
+ A.codegen = O->codegen;
+#endif
+ A.vartable = O->vartable;
+
+ _slang_codegen_global_variable(&A, var, C->type);
+ }
+#endif
+
/* allocate global address space for a variable with a known size */
if (C->global_scope
&& !(var->type.specifier.type == slang_spec_array
A.space.structs = O->structs;
A.space.vars = O->vars;
A.program = O->program;
+#if 0
+ A.codegen = O->codegen;
+#endif
+ A.vartable = O->vartable;
_slang_reset_error();
(*parsed_func_ret)->param_count);
#endif
-
+#if 0
if (!_slang_assemble_function(&A, *parsed_func_ret)) {
/* propogate the error message back through the info log */
C->L->text = _mesa_strdup(_slang_error_text());
C->L->dont_free_text = GL_FALSE;
return GL_FALSE;
}
-
+#endif
#if 0
printf("**************************************\n");
struct gl_program *program)
{
slang_output_ctx o;
+ GLboolean success;
/* setup output context */
o.funs = &unit->funs;
o.global_pool = &unit->object->varpool;
o.machine = &unit->object->machine;
o.program = program;
+ o.vartable = _slang_push_var_table(NULL);
/* parse individual functions and declarations */
while (*C->I != EXTERNAL_NULL) {
case EXTERNAL_FUNCTION_DEFINITION:
{
slang_function *func;
-
- if (!parse_function(C, &o, 1, &func))
- return GL_FALSE;
+ success = parse_function(C, &o, 1, &func);
}
break;
case EXTERNAL_DECLARATION:
- if (!parse_declaration(C, &o))
- return GL_FALSE;
+ success = parse_declaration(C, &o);
break;
default:
+ success = GL_FALSE;
+ }
+
+ if (!success) {
+ /* xxx free codegen */
+ _slang_pop_var_table(o.vartable);
return GL_FALSE;
}
}
C->I++;
+
+ _slang_pop_var_table(o.vartable);
return GL_TRUE;
}
C.parsing_builtin = (builtin == NULL);
C.global_scope = GL_TRUE;
C.atoms = &unit->object->atompool;
+ C.type = type;
if (!check_revision(&C))
return GL_FALSE;
= (struct gl_program **) malloc(sizeof(struct gl_program*));
shader->Programs[0] = _mesa_new_program(ctx, progTarget, 1);
shader->NumPrograms = 1;
+
+ shader->Programs[0]->Parameters = _mesa_new_parameter_list();
+ shader->Programs[0]->Varying = _mesa_new_parameter_list();
+ shader->Programs[0]->Attributes = _mesa_new_parameter_list();
}
slang_info_log_construct(&info_log);