*/
#include "imports.h"
-#include "grammar_mesa.h"\r
-#include "slang_compile.h"\r
-#include "slang_preprocess.h"\r
-#include "slang_storage.h"\r
+#include "grammar_mesa.h"
+#include "slang_compile.h"
+#include "slang_preprocess.h"
+#include "slang_storage.h"
/*
* This is a straightforward implementation of the slang front-end compiler.
unit->machine = mach;
unit->free_machine = 0;
unit->atom_pool = atoms;
- unit->free_atom_pool = 0;\r
- slang_export_data_table_ctr (&unit->exp_data);\r
+ unit->free_atom_pool = 0;
+ slang_export_data_table_ctr (&unit->exp_data);
slang_export_code_table_ctr (&unit->exp_code);
return 1;
}
}
if (unit->free_global_pool)
slang_alloc_free (unit->global_pool);
- if (unit->free_machine)\r
- {\r
+ if (unit->free_machine)
+ {
slang_machine_dtr (unit->machine);
- slang_alloc_free (unit->machine);\r
+ slang_alloc_free (unit->machine);
}
if (unit->free_atom_pool)
{
slang_atom_pool_destruct (unit->atom_pool);
slang_alloc_free (unit->atom_pool);
- }\r
- slang_export_data_table_dtr (&unit->exp_data);\r
+ }
+ slang_export_data_table_dtr (&unit->exp_data);
slang_export_code_table_ctr (&unit->exp_code);
}
static int parse_statement (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
static int parse_expression (slang_parse_ctx *, slang_output_ctx *, slang_operation *);
-static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);\r
-\r
-static GLboolean parse_array_len (slang_parse_ctx *C, slang_output_ctx *O, GLuint *len)\r
-{\r
- slang_operation array_size;\r
- slang_assembly_name_space space;\r
- GLboolean result;\r
-\r
- if (!slang_operation_construct (&array_size))\r
- return GL_FALSE;\r
- if (!parse_expression (C, O, &array_size))\r
- {\r
- slang_operation_destruct (&array_size);\r
- return GL_FALSE;\r
- }\r
-\r
- space.funcs = O->funs;\r
- space.structs = O->structs;\r
- space.vars = O->vars;\r
- result = _slang_evaluate_int (O->assembly, O->machine, &space, &array_size, len, C->atoms);\r
- slang_operation_destruct (&array_size);\r
- return result;\r
-}\r
-\r
-static GLboolean calculate_var_size (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)\r
-{\r
- slang_storage_aggregate agg;\r
-\r
- if (!slang_storage_aggregate_construct (&agg))\r
- return GL_FALSE;\r
- if (!_slang_aggregate_variable (&agg, &var->type.specifier, var->array_len, O->funs, O->structs,\r
- O->vars, O->machine, O->assembly, C->atoms))\r
- {\r
- slang_storage_aggregate_destruct (&agg);\r
- return GL_FALSE;\r
- }\r
- var->size = _slang_sizeof_aggregate (&agg);\r
- slang_storage_aggregate_destruct (&agg);\r
- return GL_TRUE;\r
-}\r
-\r
-static GLboolean convert_to_array (slang_parse_ctx *C, slang_variable *var,\r
- const slang_type_specifier *sp)\r
-{\r
- /* sized array - mark it as array, copy the specifier to the array element and\r
- * parse the expression */\r
- var->type.specifier.type = slang_spec_array;\r
- var->type.specifier._array = (slang_type_specifier *) slang_alloc_malloc (sizeof (\r
- slang_type_specifier));\r
- if (var->type.specifier._array == NULL)\r
- {\r
- slang_info_log_memory (C->L);\r
- return GL_FALSE;\r
- }\r
- slang_type_specifier_ctr (var->type.specifier._array);\r
- return slang_type_specifier_copy (var->type.specifier._array, sp);\r
+static int parse_type_specifier (slang_parse_ctx *, slang_output_ctx *, slang_type_specifier *);
+
+static GLboolean parse_array_len (slang_parse_ctx *C, slang_output_ctx *O, GLuint *len)
+{
+ slang_operation array_size;
+ slang_assembly_name_space space;
+ GLboolean result;
+
+ if (!slang_operation_construct (&array_size))
+ return GL_FALSE;
+ if (!parse_expression (C, O, &array_size))
+ {
+ slang_operation_destruct (&array_size);
+ return GL_FALSE;
+ }
+
+ space.funcs = O->funs;
+ space.structs = O->structs;
+ space.vars = O->vars;
+ result = _slang_evaluate_int (O->assembly, O->machine, &space, &array_size, len, C->atoms);
+ slang_operation_destruct (&array_size);
+ return result;
+}
+
+static GLboolean calculate_var_size (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var)
+{
+ slang_storage_aggregate agg;
+
+ if (!slang_storage_aggregate_construct (&agg))
+ return GL_FALSE;
+ if (!_slang_aggregate_variable (&agg, &var->type.specifier, var->array_len, O->funs, O->structs,
+ O->vars, O->machine, O->assembly, C->atoms))
+ {
+ slang_storage_aggregate_destruct (&agg);
+ return GL_FALSE;
+ }
+ var->size = _slang_sizeof_aggregate (&agg);
+ slang_storage_aggregate_destruct (&agg);
+ return GL_TRUE;
+}
+
+static GLboolean convert_to_array (slang_parse_ctx *C, slang_variable *var,
+ const slang_type_specifier *sp)
+{
+ /* sized array - mark it as array, copy the specifier to the array element and
+ * parse the expression */
+ var->type.specifier.type = slang_spec_array;
+ var->type.specifier._array = (slang_type_specifier *) slang_alloc_malloc (sizeof (
+ slang_type_specifier));
+ if (var->type.specifier._array == NULL)
+ {
+ slang_info_log_memory (C->L);
+ return GL_FALSE;
+ }
+ slang_type_specifier_ctr (var->type.specifier._array);
+ return slang_type_specifier_copy (var->type.specifier._array, sp);
}
/* structure field */
#define FIELD_NEXT 1
#define FIELD_ARRAY 2
-static GLboolean parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var,\r
+static GLboolean parse_struct_field_var (slang_parse_ctx *C, slang_output_ctx *O, slang_variable *var,
const slang_type_specifier *sp)
-{\r
+{
var->a_name = parse_identifier (C);
if (var->a_name == SLANG_ATOM_NULL)
return GL_FALSE;
switch (*C->I++)
{
- case FIELD_NONE:\r
- if (!slang_type_specifier_copy (&var->type.specifier, sp))\r
+ case FIELD_NONE:
+ if (!slang_type_specifier_copy (&var->type.specifier, sp))
return GL_FALSE;
break;
- case FIELD_ARRAY:\r
- if (!convert_to_array (C, var, sp))\r
+ case FIELD_ARRAY:
+ if (!convert_to_array (C, var, sp))
+ return GL_FALSE;
+ if (!parse_array_len (C, O, &var->array_len))
return GL_FALSE;
- if (!parse_array_len (C, O, &var->array_len))\r
- return GL_FALSE;\r
break;
default:
return GL_FALSE;
{
slang_type_specifier_dtr (&sp);
return 0;
- }\r
+ }
slang_type_specifier_dtr (&sp);
}
while (*C->I++ != FIELD_NONE);
/* if the parameter is an array, parse its size (the size must be explicitly defined */
if (*C->I++ == PARAMETER_ARRAY_PRESENT)
- {\r
- slang_type_specifier p;\r
-\r
- slang_type_specifier_ctr (&p);\r
- if (!slang_type_specifier_copy (&p, ¶m->type.specifier))\r
- {\r
- slang_type_specifier_dtr (&p);\r
- return GL_FALSE;\r
- }\r
- if (!convert_to_array (C, param, &p))\r
- {\r
- slang_type_specifier_dtr (&p);\r
- return GL_FALSE;\r
- }\r
- slang_type_specifier_dtr (&p);\r
- if (!parse_array_len (C, O, ¶m->array_len))\r
+ {
+ slang_type_specifier p;
+
+ slang_type_specifier_ctr (&p);
+ if (!slang_type_specifier_copy (&p, ¶m->type.specifier))
+ {
+ slang_type_specifier_dtr (&p);
+ return GL_FALSE;
+ }
+ if (!convert_to_array (C, param, &p))
+ {
+ slang_type_specifier_dtr (&p);
+ return GL_FALSE;
+ }
+ slang_type_specifier_dtr (&p);
+ if (!parse_array_len (C, O, ¶m->array_len))
return GL_FALSE;
}
/* calculate the parameter size */
if (!calculate_var_size (C, O, param))
- return GL_FALSE;\r
+ return GL_FALSE;
/* TODO: allocate the local address here? */
return 1;
#if 0
case VARIABLE_ARRAY_UNKNOWN:
/* unsized array - mark it as array and copy the specifier to the array element */
- if (!convert_to_array (C, var, &type->specifier))\r
+ if (!convert_to_array (C, var, &type->specifier))
return GL_FALSE;
break;
#endif
case VARIABLE_ARRAY_EXPLICIT:
- if (!convert_to_array (C, var, &type->specifier))\r
- return GL_FALSE;\r
- if (!parse_array_len (C, O, &var->array_len))\r
+ if (!convert_to_array (C, var, &type->specifier))
+ return GL_FALSE;
+ if (!parse_array_len (C, O, &var->array_len))
return GL_FALSE;
break;
default:
/* allocate global address space for a variable with a known size */
if (C->global_scope && !(var->type.specifier.type == slang_spec_array && var->array_len == 0))
{
- if (!calculate_var_size (C, O, var))\r
+ if (!calculate_var_size (C, O, var))
return GL_FALSE;
var->address = slang_var_pool_alloc (O->global_pool, var->size);
}
return 0;
return 1;
-}\r
-\r
-#if defined(USE_X86_ASM) || defined(SLANG_X86)\r
-/* XXX */\r
-GLboolean _slang_x86_codegen (slang_machine *, slang_assembly_file *, GLuint);\r
-#endif
+}
int _slang_compile (const char *source, slang_translation_unit *unit, slang_unit_type type,
slang_info_log *log)
slang_translation_unit_destruct (&builtin_units[i]);
}*/
if (id != 0)
- grammar_destroy (id);\r
-\r
- if (!success)\r
- return 0;\r
-\r
- unit->exp_data.atoms = unit->atom_pool;\r
- if (!_slang_build_export_data_table (&unit->exp_data, &unit->globals))\r
- return 0;\r
-\r
- unit->exp_code.atoms = unit->atom_pool;\r
- if (!_slang_build_export_code_table (&unit->exp_code, &unit->functions, unit))\r
- return 0;\r
-\r
-#if defined(USE_X86_ASM) || defined(SLANG_X86)\r
- /* XXX: lookup the @main label */\r
- if (!_slang_x86_codegen (unit->machine, unit->assembly, unit->exp_code.entries[0].address))\r
- return 0;\r
-#endif\r
+ grammar_destroy (id);
+
+ if (!success)
+ return 0;
+
+ unit->exp_data.atoms = unit->atom_pool;
+ if (!_slang_build_export_data_table (&unit->exp_data, &unit->globals))
+ return 0;
+
+ unit->exp_code.atoms = unit->atom_pool;
+ if (!_slang_build_export_code_table (&unit->exp_code, &unit->functions, unit))
+ return 0;
+
+#if defined(USE_X86_ASM) || defined(SLANG_X86)
+ /* XXX: lookup the @main label */
+ if (!_slang_x86_codegen (unit->machine, unit->assembly, unit->exp_code.entries[0].address))
+ return 0;
+#endif
return 1;
}
_mesa_printf ("slang print: %s\n", (GLint) x ? "true" : "false");\r
}\r
\r
+#define FLOAT_ONE 0x3f800000\r
+#define FLOAT_ZERO 0\r
+\r
static GLvoid codegen_assem (codegen_ctx *G, slang_assembly *a)\r
{\r
GLint disp;\r
x86_mov_reg_imm (&G->f, G->r_ecx, 0x100);\r
x86_test (&G->f, G->r_eax, G->r_ecx);\r
{\r
- GLfloat one = 1.0f, zero = 0.0f;\r
GLubyte *lab0, *lab1;\r
\r
/* TODO: use jcc rel8 */\r
lab0 = x86_jcc_forward (&G->f, cc_E);\r
- x86_mov_reg_imm (&G->f, G->r_ecx, *((GLint *) &one));\r
+ x86_mov_reg_imm (&G->f, G->r_ecx, FLOAT_ONE);\r
/* TODO: use jmp rel8 */\r
lab1 = x86_jmp_forward (&G->f);\r
x86_fixup_fwd_jump (&G->f, lab0);\r
- x86_mov_reg_imm (&G->f, G->r_ecx, *((GLint *) &zero));\r
+ x86_mov_reg_imm (&G->f, G->r_ecx, FLOAT_ZERO);\r
x86_fixup_fwd_jump (&G->f, lab1);\r
x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4));\r
x86_mov (&G->f, x86_deref (G->r_esp), G->r_ecx);\r
x86_mov_reg_imm (&G->f, G->r_ecx, 0x4000);\r
x86_test (&G->f, G->r_eax, G->r_ecx);\r
{\r
- GLfloat one = 1.0f, zero = 0.0f;\r
GLubyte *lab0, *lab1;\r
\r
/* TODO: use jcc rel8 */\r
lab0 = x86_jcc_forward (&G->f, cc_E);\r
- x86_mov_reg_imm (&G->f, G->r_ecx, *((GLint *) &one));\r
+ x86_mov_reg_imm (&G->f, G->r_ecx, FLOAT_ONE);\r
/* TODO: use jmp rel8 */\r
lab1 = x86_jmp_forward (&G->f);\r
x86_fixup_fwd_jump (&G->f, lab0);\r
- x86_mov_reg_imm (&G->f, G->r_ecx, *((GLint *) &zero));\r
+ x86_mov_reg_imm (&G->f, G->r_ecx, FLOAT_ZERO);\r
x86_fixup_fwd_jump (&G->f, lab1);\r
x86_lea (&G->f, G->r_esp, x86_make_disp (G->r_esp, 4));\r
x86_mov (&G->f, x86_deref (G->r_esp), G->r_ecx);\r
x86_mov_reg_imm (&G->f, G->r_ecx, 0x4000);\r
x86_test (&G->f, G->r_eax, G->r_ecx);\r
{\r
- GLfloat one = 1.0f, zero = 0.0f;\r
GLubyte *lab0, *lab1;\r
\r
/* TODO: use jcc rel8 */\r
lab0 = x86_jcc_forward (&G->f, cc_E);\r
- x86_mov_reg_imm (&G->f, G->r_ecx, *((GLint *) &one));\r
+ x86_mov_reg_imm (&G->f, G->r_ecx, FLOAT_ONE);\r
/* TODO: use jmp rel8 */\r
lab1 = x86_jmp_forward (&G->f);\r
x86_fixup_fwd_jump (&G->f, lab0);\r
- x86_mov_reg_imm (&G->f, G->r_ecx, *((GLint *) &zero));\r
+ x86_mov_reg_imm (&G->f, G->r_ecx, FLOAT_ZERO);\r
x86_fixup_fwd_jump (&G->f, lab1);\r
x86_mov (&G->f, x86_deref (G->r_esp), G->r_ecx);\r
}\r