Get it running for ARB_vertex_shader.

Add experimental print functions to builtin library.
Some functionality missing:
- automatic arrays;
- general constructors;
- local variable initialization;
- texture sampling and noise;
- semantic error checking;
- function prototypes.
This commit is contained in:
Michal Krol
2006-02-13 11:38:37 +00:00
parent 44e9ccc708
commit 02eb9acc5e
27 changed files with 2072 additions and 1358 deletions
File diff suppressed because it is too large Load Diff
+48 -10
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -44,8 +44,16 @@ typedef enum slang_assembly_type_
slang_asm_float_divide,
slang_asm_float_negate,
slang_asm_float_less,
slang_asm_float_equal,
slang_asm_float_equal_exp,
slang_asm_float_equal_int,
slang_asm_float_to_int,
slang_asm_float_sine,
slang_asm_float_arcsine,
slang_asm_float_arctan,
slang_asm_float_power,
slang_asm_float_log2,
slang_asm_float_floor,
slang_asm_float_ceil,
slang_asm_int_copy,
slang_asm_int_move,
slang_asm_int_push,
@@ -72,6 +80,10 @@ typedef enum slang_assembly_type_
slang_asm_return,
slang_asm_discard,
slang_asm_exit,
/* mesa-specific extensions */
slang_asm_float_print,
slang_asm_int_print,
slang_asm_bool_print,
slang_asm__last
} slang_assembly_type;
@@ -86,15 +98,26 @@ typedef struct slang_assembly_file_
{
slang_assembly *code;
unsigned int count;
unsigned int capacity;
} slang_assembly_file;
void slang_assembly_file_construct (slang_assembly_file *);
int slang_assembly_file_construct (slang_assembly_file *);
void slang_assembly_file_destruct (slang_assembly_file *);
int slang_assembly_file_push (slang_assembly_file *, slang_assembly_type);
int slang_assembly_file_push_label (slang_assembly_file *, slang_assembly_type, GLuint);
int slang_assembly_file_push_label2 (slang_assembly_file *, slang_assembly_type, GLuint, GLuint);
int slang_assembly_file_push_literal (slang_assembly_file *, slang_assembly_type, GLfloat);
typedef struct slang_assembly_file_restore_point_
{
unsigned int count;
} slang_assembly_file_restore_point;
int slang_assembly_file_restore_point_save (slang_assembly_file *,
slang_assembly_file_restore_point *);
int slang_assembly_file_restore_point_load (slang_assembly_file *,
slang_assembly_file_restore_point *);
typedef struct slang_assembly_flow_control_
{
unsigned int loop_start; /* for "continue" statement */
@@ -109,19 +132,31 @@ typedef struct slang_assembly_name_space_
struct slang_variable_scope_ *vars;
} slang_assembly_name_space;
slang_function *_slang_locate_function (const char *name, slang_operation *params,
unsigned int num_params, slang_assembly_name_space *space);
slang_function *_slang_locate_function (slang_function_scope *funcs, slang_atom a_name,
slang_operation *params, unsigned int num_params, slang_assembly_name_space *space,
slang_atom_pool *);
int _slang_assemble_function (slang_assembly_file *, struct slang_function_ *,
slang_assembly_name_space *);
slang_assembly_name_space *, struct slang_machine_ *, slang_atom_pool *);
/*
holds a complete information about vector swizzle - the <swizzle> array contains
vector component sources indices, where 0 is "x", 1 is "y", ...
example: "xwz" --> { 3, { 0, 3, 2, n/u } }
*/
typedef struct slang_swizzle_
{
unsigned int num_components;
unsigned int swizzle[4];
} slang_swizzle;
typedef struct slang_assembly_stack_info_
{
unsigned int swizzle_mask;
slang_swizzle swizzle;
} slang_assembly_stack_info;
int _slang_cleanup_stack (slang_assembly_file *, slang_operation *, int ref,
slang_assembly_name_space *);
slang_assembly_name_space *, struct slang_machine_ *, slang_atom_pool *);
typedef struct slang_assembly_local_info_
{
@@ -130,9 +165,12 @@ typedef struct slang_assembly_local_info_
unsigned int swizzle_tmp;
} slang_assembly_local_info;
int _slang_dereference (slang_assembly_file *, slang_operation *, slang_assembly_name_space *,
slang_assembly_local_info *, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_operation (slang_assembly_file *, struct slang_operation_ *, int reference,
slang_assembly_flow_control *, slang_assembly_name_space *, slang_assembly_local_info *,
slang_assembly_stack_info *);
slang_assembly_stack_info *, struct slang_machine_ *, slang_atom_pool *);
#ifdef __cplusplus
}
@@ -29,10 +29,11 @@
*/
#include "imports.h"
#include "slang_utility.h"
#include "slang_assemble_assignment.h"
#include "slang_assemble_typeinfo.h"
#include "slang_storage.h"
#include "slang_utility.h"
#include "slang_execute.h"
/*
_slang_assemble_assignment()
@@ -54,28 +55,45 @@
| addr of variable |
+------------------+
*/
/* TODO: add support for swizzle mask */
static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggregate *agg,
unsigned int *index, unsigned int size, slang_assembly_local_info *info)
unsigned int *index, unsigned int size, slang_assembly_local_info *info,
slang_assembly_stack_info *stk)
{
unsigned int i;
for (i = 0; i < agg->count; i++)
{
const slang_storage_array *arr = agg->arrays + i;
const slang_storage_array *arr = &agg->arrays[i];
unsigned int j;
for (j = 0; j < arr->length; j++)
{
if (arr->type == slang_stor_aggregate)
{
if (!assign_aggregate (file, arr->aggregate, index, size, info))
if (!assign_aggregate (file, arr->aggregate, index, size, info, stk))
return 0;
}
else
{
unsigned int dst_addr_loc, dst_offset;
slang_assembly_type ty;
/* calculate the distance from top of the stack to the destination address */
dst_addr_loc = size - *index;
/* calculate the offset within destination variable to write */
if (stk->swizzle.num_components != 0)
{
/* swizzle the index to get the actual offset */
dst_offset = stk->swizzle.swizzle[*index / 4] * 4;
}
else
{
/* no swizzling - write sequentially */
dst_offset = *index;
}
switch (arr->type)
{
case slang_stor_bool:
@@ -90,7 +108,7 @@ static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggr
default:
break;
}
if (!slang_assembly_file_push_label2 (file, ty, size - *index, *index))
if (!slang_assembly_file_push_label2 (file, ty, dst_addr_loc, dst_offset))
return 0;
*index += 4;
}
@@ -100,22 +118,29 @@ static int assign_aggregate (slang_assembly_file *file, const slang_storage_aggr
}
int _slang_assemble_assignment (slang_assembly_file *file, slang_operation *op,
slang_assembly_name_space *space, slang_assembly_local_info *info)
slang_assembly_name_space *space, slang_assembly_local_info *info, slang_assembly_stack_info *stk,
struct slang_machine_ *mach, slang_atom_pool *atoms)
{
slang_assembly_typeinfo ti;
int result;
slang_storage_aggregate agg;
unsigned int index, size;
slang_assembly_typeinfo_construct (&ti);
if (!_slang_typeof_operation (op, space, &ti))
if (!slang_assembly_typeinfo_construct (&ti))
return 0;
if (!_slang_typeof_operation (op, space, &ti, atoms))
{
slang_assembly_typeinfo_destruct (&ti);
return 0;
}
slang_storage_aggregate_construct (&agg);
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs, space->vars))
if (!slang_storage_aggregate_construct (&agg))
{
slang_assembly_typeinfo_destruct (&ti);
return 0;
}
if (!_slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
space->vars, mach, file, atoms))
{
slang_storage_aggregate_destruct (&agg);
slang_assembly_typeinfo_destruct (&ti);
@@ -124,7 +149,7 @@ int _slang_assemble_assignment (slang_assembly_file *file, slang_operation *op,
index = 0;
size = _slang_sizeof_aggregate (&agg);
result = assign_aggregate (file, &agg, &index, size, info);
result = assign_aggregate (file, &agg, &index, size, info, stk);
slang_storage_aggregate_destruct (&agg);
slang_assembly_typeinfo_destruct (&ti);
@@ -138,17 +163,15 @@ int _slang_assemble_assignment (slang_assembly_file *file, slang_operation *op,
children
*/
int dereference (slang_assembly_file *file, slang_operation *op,
slang_assembly_name_space *space, slang_assembly_local_info *info);
int call_function_name (slang_assembly_file *file, const char *name, slang_operation *params,
unsigned int param_count, int assignment, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms);
int _slang_assemble_assign (slang_assembly_file *file, slang_operation *op, const char *oper,
int ref, slang_assembly_name_space *space, slang_assembly_local_info *info)
int ref, slang_assembly_name_space *space, slang_assembly_local_info *info,
struct slang_machine_ *mach, slang_atom_pool *atoms)
{
slang_assembly_stack_info stk;
slang_assembly_stack_info l_stk, r_stk;
slang_assembly_flow_control flow;
if (!ref)
@@ -159,16 +182,19 @@ int _slang_assemble_assign (slang_assembly_file *file, slang_operation *op, cons
if (slang_string_compare ("=", oper) == 0)
{
if (!_slang_assemble_operation (file, op->children, 1, &flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 1, &flow, space, info, &l_stk, mach,
atoms))
return 0;
if (!_slang_assemble_operation (file, op->children + 1, 0, &flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, &flow, space, info, &r_stk, mach,
atoms))
return 0;
if (!_slang_assemble_assignment (file, op->children, space, info))
if (!_slang_assemble_assignment (file, op->children, space, info, &l_stk, mach, atoms))
return 0;
}
else
{
if (!call_function_name (file, oper, op->children, op->num_children, 1, space, info))
if (!call_function_name (file, oper, op->children, op->num_children, 1, space, info, mach,
atoms))
return 0;
}
@@ -178,7 +204,7 @@ int _slang_assemble_assign (slang_assembly_file *file, slang_operation *op, cons
return 0;
if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))
return 0;
if (!dereference (file, op->children, space, info))
if (!_slang_dereference (file, op->children, space, info, mach, atoms))
return 0;
}
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -32,10 +32,12 @@ extern "C" {
#endif
int _slang_assemble_assignment (slang_assembly_file *, slang_operation *,
slang_assembly_name_space *, slang_assembly_local_info *);
slang_assembly_name_space *, slang_assembly_local_info *, slang_assembly_stack_info *,
struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_assign (slang_assembly_file *, slang_operation *, const char *, int ref,
slang_assembly_name_space *, slang_assembly_local_info *);
slang_assembly_name_space *, slang_assembly_local_info *, struct slang_machine_ *,
slang_atom_pool *);
#ifdef __cplusplus
}
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -32,12 +32,13 @@
#include "slang_utility.h"
#include "slang_assemble_conditional.h"
#include "slang_assemble.h"
#include "slang_execute.h"
/* _slang_assemble_logicaland() */
int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
and:
@@ -54,7 +55,7 @@ int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
slang_assembly_stack_info stk;
/* evaluate left expression */
if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -64,7 +65,7 @@ int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
return 0;
/* evaluate right expression */
if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -75,7 +76,7 @@ int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
/* push 0 on stack */
file->code[zero_jump].param[0] = file->count;
if (!slang_assembly_file_push (file, slang_asm_bool_push))
if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 0))
return 0;
/* the end of the expression */
@@ -88,7 +89,7 @@ int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
or:
@@ -105,7 +106,7 @@ int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
slang_assembly_stack_info stk;
/* evaluate left expression */
if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -115,7 +116,7 @@ int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
return 0;
/* push 1 on stack */
if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, 1.0f))
if (!slang_assembly_file_push_literal (file, slang_asm_bool_push, (GLfloat) 1))
return 0;
/* jump to the end of the expression */
@@ -125,7 +126,7 @@ int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
/* evaluate right expression */
file->code[right_jump].param[0] = file->count;
if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -139,7 +140,7 @@ int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
select:
@@ -156,7 +157,7 @@ int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
slang_assembly_stack_info stk;
/* execute condition expression */
if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -166,7 +167,7 @@ int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
return 0;
/* execute true expression */
if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -179,7 +180,7 @@ int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
file->code[cond_jump].param[0] = file->count;
/* execute false expression */
if (!_slang_assemble_operation (file, op->children + 2, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -193,7 +194,7 @@ int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
for:
@@ -217,10 +218,10 @@ int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
slang_assembly_stack_info stk;
/* execute initialization statement */
if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children, 0, space))
if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))
return 0;
/* skip the "go to the end of the loop" and loop-increment statements */
@@ -238,17 +239,17 @@ int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
cont_label = file->count;
/* execute loop-increment statement */
if (!_slang_assemble_operation (file, op->children + 2, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children + 2, 0, space))
if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))
return 0;
/* resolve the condition point */
file->code[start_jump].param[0] = file->count;
/* execute condition statement */
if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: inspect stk */
@@ -260,10 +261,10 @@ int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
/* execute loop body */
loop_flow.loop_start = cont_label;
loop_flow.loop_end = break_label;
if (!_slang_assemble_operation (file, op->children + 3, 0, &loop_flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[3], 0, &loop_flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children + 3, 0, space))
if (!_slang_cleanup_stack (file, &op->children[3], 0, space, mach, atoms))
return 0;
/* go to the beginning of the loop */
@@ -281,7 +282,7 @@ int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
do:
@@ -327,17 +328,17 @@ int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
/* execute loop body */
loop_flow.loop_start = cont_label;
loop_flow.loop_end = break_label;
if (!_slang_assemble_operation (file, op->children, 0, &loop_flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, &loop_flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children, 0, space))
if (!_slang_cleanup_stack (file, &op->children[0], 0, space, mach, atoms))
return 0;
/* resolve condition point */
file->code[cont_jump].param[0] = file->count;
/* execute condition statement */
if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
@@ -361,7 +362,7 @@ int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
while:
@@ -396,7 +397,7 @@ int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
file->code[skip_jump].param[0] = file->count;
/* execute condition statement */
if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
@@ -408,10 +409,10 @@ int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
/* execute loop body */
loop_flow.loop_start = file->code[skip_jump].param[0];
loop_flow.loop_end = break_label;
if (!_slang_assemble_operation (file, op->children + 1, 0, &loop_flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, &loop_flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children + 1, 0, space))
if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))
return 0;
/* jump to the beginning of the loop */
@@ -429,7 +430,7 @@ int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, slang_machine *mach, slang_atom_pool *atoms)
{
/*
if:
@@ -446,7 +447,7 @@ int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
slang_assembly_stack_info stk;
/* execute condition statement */
if (!_slang_assemble_operation (file, op->children, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[0], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
@@ -456,10 +457,10 @@ int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
return 0;
/* execute true-statement */
if (!_slang_assemble_operation (file, op->children + 1, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[1], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children + 1, 0, space))
if (!_slang_cleanup_stack (file, &op->children[1], 0, space, mach, atoms))
return 0;
/* skip if-false statement */
@@ -471,10 +472,10 @@ int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
file->code[cond_jump].param[0] = file->count;
/* execute false-statement */
if (!_slang_assemble_operation (file, op->children + 2, 0, flow, space, info, &stk))
if (!_slang_assemble_operation (file, &op->children[2], 0, flow, space, info, &stk, mach, atoms))
return 0;
/* TODO: pass-in stk to cleanup */
if (!_slang_cleanup_stack (file, op->children + 2, 0, space))
if (!_slang_cleanup_stack (file, &op->children[2], 0, space, mach, atoms))
return 0;
/* resolve end of if-false statement */
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -33,31 +33,31 @@ extern "C" {
int _slang_assemble_logicaland (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_logicalor (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_select (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_for (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_do (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_while (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
int _slang_assemble_if (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *, slang_atom_pool *);
#ifdef __cplusplus
}
@@ -84,25 +84,23 @@ int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
case 'y':
case 'g':
case 't':
if (rows < 2)
return 0;
swz->swizzle[i] = 1;
break;
case 'z':
case 'b':
case 'p':
if (rows < 3)
return 0;
swz->swizzle[i] = 2;
break;
case 'w':
case 'a':
case 'q':
if (rows < 4)
return 0;
swz->swizzle[i] = 3;
break;
}
/* check if the component is valid for given vector's row count */
if (rows <= swz->swizzle[i])
return 0;
}
/* only one swizzle group can be used */
@@ -116,16 +114,18 @@ int _slang_is_swizzle (const char *field, unsigned int rows, slang_swizzle *swz)
int _slang_is_swizzle_mask (const slang_swizzle *swz, unsigned int rows)
{
unsigned int c, i;
unsigned int i, c = 0;
/* the swizzle may not be longer than the vector dim */
if (swz->num_components > rows)
return 0;
c = swz->swizzle[0];
for (i = 1; i < swz->num_components; i++)
/* the swizzle components cannot be duplicated */
for (i = 0; i < swz->num_components; i++)
{
if (swz->swizzle[i] <= c)
if ((c & (1 << swz->swizzle[i])) != 0)
return 0;
c = swz->swizzle[i];
c |= 1 << swz->swizzle[i];
}
return 1;
}
@@ -136,13 +136,14 @@ void _slang_multiply_swizzles (slang_swizzle *dst, const slang_swizzle *left,
const slang_swizzle *right)
{
unsigned int i;
dst->num_components = right->num_components;
for (i = 0; i < right->num_components; i++)
dst->swizzle[i] = left->swizzle[right->swizzle[i]];
}
/* _slang_assemble_constructor() */
/*
static int constructor_aggregate (slang_assembly_file *file, const slang_storage_aggregate *flat,
unsigned int *index, slang_operation *op, unsigned int size, slang_assembly_flow_control *flow,
slang_assembly_name_space *space, slang_assembly_local_info *info)
@@ -177,10 +178,10 @@ static int constructor_aggregate (slang_assembly_file *file, const slang_storage
if (arr1->type != arr2->type)
{
/* TODO: convert (generic) from arr1 to arr2 */
}
/* }
(*index)++;
/* TODO: watch the index, if it reaches the size, pop off the stack subsequent values */
}
/* }
result = 1;
end:
@@ -192,38 +193,41 @@ end1:
return result;
}
/* XXX: general swizzle! */
int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
/*int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info)
slang_assembly_local_info *info, struct slang_machine_ *pmach)
{
slang_assembly_typeinfo ti;
int result;
slang_storage_aggregate agg, flat;
unsigned int size, index, i;
slang_assembly_typeinfo_construct (&ti);
if (!slang_assembly_typeinfo_construct (&ti))
return 0;
if (!(result = _slang_typeof_operation (op, space, &ti)))
goto end1;
slang_storage_aggregate_construct (&agg);
if (!(result = slang_storage_aggregate_construct (&agg)))
goto end1;
if (!(result = _slang_aggregate_variable (&agg, &ti.spec, NULL, space->funcs, space->structs,
space->vars)))
space->vars, pmach, file)))
goto end2;
size = _slang_sizeof_aggregate (&agg);
slang_storage_aggregate_construct (&flat);
if (!(result = slang_storage_aggregate_construct (&flat)))
goto end2;
if (!(result = _slang_flatten_aggregate (&flat, &agg)))
goto end;
index = 0;
for (i = 0; i < op->num_children; i++)
{
if (!(result = constructor_aggregate (file, &flat, &index, op->children + i, size, flow,
/* if (!(result = constructor_aggregate (file, &flat, &index, op->children + i, size, flow,
space, info)))
goto end;
/* TODO: watch the index, if it reaches the size, raise an error */
}
/* }
result = 1;
end:
@@ -236,66 +240,34 @@ end1:
}
/* _slang_assemble_constructor_from_swizzle() */
/* XXX: wrong */
int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,
slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info)
{
unsigned int master_rows, i;
switch (master_spec->type)
{
case slang_spec_bool:
case slang_spec_int:
case slang_spec_float:
master_rows = 1;
break;
case slang_spec_bvec2:
case slang_spec_ivec2:
case slang_spec_vec2:
master_rows = 2;
break;
case slang_spec_bvec3:
case slang_spec_ivec3:
case slang_spec_vec3:
master_rows = 3;
break;
case slang_spec_bvec4:
case slang_spec_ivec4:
case slang_spec_vec4:
master_rows = 4;
break;
default:
break;
}
master_rows = _slang_type_dim (master_spec->type);
for (i = 0; i < master_rows; i++)
{
switch (master_spec->type)
switch (_slang_type_base (master_spec->type))
{
case slang_spec_bool:
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy, (master_rows - i) * 4,
i * 4))
if (!slang_assembly_file_push_label2 (file, slang_asm_bool_copy,
(master_rows - i) * 4, i * 4))
return 0;
break;
case slang_spec_int:
case slang_spec_ivec2:
case slang_spec_ivec3:
case slang_spec_ivec4:
if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy, (master_rows - i) * 4,
i * 4))
if (!slang_assembly_file_push_label2 (file, slang_asm_int_copy,
(master_rows - i) * 4, i * 4))
return 0;
break;
case slang_spec_float:
case slang_spec_vec2:
case slang_spec_vec3:
case slang_spec_vec4:
if (!slang_assembly_file_push_label2 (file, slang_asm_float_copy,
(master_rows - i) * 4, i * 4))
(master_rows - i) * 4, i * 4))
return 0;
break;
default:
break;
break;
}
}
if (!slang_assembly_file_push_label (file, slang_asm_local_free, 4))
@@ -303,37 +275,29 @@ int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const s
for (i = swz->num_components; i > 0; i--)
{
unsigned int n = i - 1;
if (!slang_assembly_file_push_label2 (file, slang_asm_local_addr, info->swizzle_tmp, 16))
return 0;
if (!slang_assembly_file_push_label (file, slang_asm_addr_push, swz->swizzle[n] * 4))
return 0;
if (!slang_assembly_file_push (file, slang_asm_addr_add))
return 0;
switch (master_spec->type)
switch (_slang_type_base (master_spec->type))
{
case slang_spec_bool:
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
if (!slang_assembly_file_push (file, slang_asm_bool_deref))
return 0;
break;
case slang_spec_int:
case slang_spec_ivec2:
case slang_spec_ivec3:
case slang_spec_ivec4:
if (!slang_assembly_file_push (file, slang_asm_int_deref))
return 0;
break;
case slang_spec_float:
case slang_spec_vec2:
case slang_spec_vec3:
case slang_spec_vec4:
if (!slang_assembly_file_push (file, slang_asm_float_deref))
return 0;
break;
default:
break;
break;
}
}
return 1;
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -32,17 +32,6 @@
extern "C" {
#endif
/*
holds a complete information about vector swizzle - the <swizzle> array contains
vector component sources indices, where 0 is "x", 1 is "y", ...
example: "xwz" --> { 3, { 0, 3, 2, n/u } }
*/
typedef struct slang_swizzle_
{
unsigned int num_components;
unsigned int swizzle[4];
} slang_swizzle;
/*
checks if a field selector is a general swizzle (an r-value swizzle with replicated
components or an l-value swizzle mask) for a vector
@@ -67,7 +56,7 @@ void _slang_multiply_swizzles (slang_swizzle *, const slang_swizzle *, const sla
int _slang_assemble_constructor (slang_assembly_file *file, slang_operation *op,
slang_assembly_flow_control *flow, slang_assembly_name_space *space,
slang_assembly_local_info *info);
slang_assembly_local_info *info, struct slang_machine_ *);
int _slang_assemble_constructor_from_swizzle (slang_assembly_file *file, const slang_swizzle *swz,
slang_type_specifier *spec, slang_type_specifier *master_spec, slang_assembly_local_info *info);
+219 -156
View File
@@ -34,20 +34,37 @@
/* slang_assembly_typeinfo */
void slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *ti)
{
slang_type_specifier_construct (&ti->spec);
if (!slang_type_specifier_construct (&ti->spec))
return 0;
ti->array_size = NULL;
return 1;
}
void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *ti)
{
slang_type_specifier_destruct (&ti->spec);
/* do not free ti->array_size */
}
/* _slang_typeof_operation() */
static int typeof_existing_function (const char *name, slang_operation *params,
unsigned int num_params, slang_assembly_name_space *space, slang_type_specifier *spec,
slang_atom_pool *atoms)
{
slang_atom atom;
int exists;
atom = slang_atom_pool_atom (atoms, name);
if (!_slang_typeof_function (atom, params, num_params, space, spec, &exists, atoms))
return 0;
return exists;
}
int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *space,
slang_assembly_typeinfo *ti)
slang_assembly_typeinfo *ti, slang_atom_pool *atoms)
{
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -77,7 +94,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_divassign:
case slang_oper_preincrement:
case slang_oper_predecrement:
if (!_slang_typeof_operation (op->children, space, ti))
if (!_slang_typeof_operation (op->children, space, ti, atoms))
return 0;
break;
case slang_oper_literal_bool:
@@ -103,17 +120,18 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
{
slang_variable *var;
var = _slang_locate_variable (op->locals, op->identifier, 1);
var = _slang_locate_variable (op->locals, op->a_id, 1);
if (var == NULL)
return 0;
if (!slang_type_specifier_copy (&ti->spec, &var->type.specifier))
return 0;
ti->can_be_referenced = 1;
ti->array_size = var->array_size;
}
break;
case slang_oper_sequence:
/* TODO: check [0] and [1] if they match */
if (!_slang_typeof_operation (op->children + 1, space, ti))
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -126,7 +144,7 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/*case slang_oper_andassign:*/
case slang_oper_select:
/* TODO: check [1] and [2] if they match */
if (!_slang_typeof_operation (op->children + 1, space, ti))
if (!_slang_typeof_operation (&op->children[1], space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -137,107 +155,61 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/*case slang_oper_lshift:*/
/*case slang_oper_rshift:*/
case slang_oper_add:
{
int exists;
if (!_slang_typeof_function ("+", op->children, 2, space, &ti->spec, &exists))
return 0;
if (!exists)
return 0;
}
if (!typeof_existing_function ("+", op->children, 2, space, &ti->spec, atoms))
return 0;
break;
case slang_oper_subtract:
{
int exists;
if (!_slang_typeof_function ("-", op->children, 2, space, &ti->spec, &exists))
return 0;
if (!exists)
return 0;
}
if (!typeof_existing_function ("-", op->children, 2, space, &ti->spec, atoms))
return 0;
break;
case slang_oper_multiply:
{
int exists;
if (!_slang_typeof_function ("*", op->children, 2, space, &ti->spec, &exists))
return 0;
if (!exists)
return 0;
}
if (!typeof_existing_function ("*", op->children, 2, space, &ti->spec, atoms))
return 0;
break;
case slang_oper_divide:
{
int exists;
if (!_slang_typeof_function ("/", op->children, 2, space, &ti->spec, &exists))
return 0;
if (!exists)
return 0;
}
if (!typeof_existing_function ("/", op->children, 2, space, &ti->spec, atoms))
return 0;
break;
/*case slang_oper_modulus:*/
case slang_oper_plus:
{
int exists;
if (!_slang_typeof_function ("+", op->children, 1, space, &ti->spec, &exists))
return 0;
if (!exists)
return 0;
}
if (!_slang_typeof_operation (op->children, space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
break;
case slang_oper_minus:
{
int exists;
if (!_slang_typeof_function ("-", op->children, 1, space, &ti->spec, &exists))
return 0;
if (!exists)
return 0;
}
if (!typeof_existing_function ("-", op->children, 1, space, &ti->spec, atoms))
return 0;
break;
/*case slang_oper_complement:*/
case slang_oper_subscript:
{
slang_assembly_typeinfo _ti;
slang_assembly_typeinfo_construct (&_ti);
if (!_slang_typeof_operation (op->children, space, &_ti))
if (!slang_assembly_typeinfo_construct (&_ti))
return 0;
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
ti->can_be_referenced = _ti.can_be_referenced;
switch (_ti.spec.type)
if (_ti.spec.type == slang_spec_array)
{
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
ti->spec.type = slang_spec_bool;
break;
case slang_spec_ivec2:
case slang_spec_ivec3:
case slang_spec_ivec4:
ti->spec.type = slang_spec_int;
break;
case slang_spec_vec2:
case slang_spec_vec3:
case slang_spec_vec4:
ti->spec.type = slang_spec_float;
break;
case slang_spec_mat2:
ti->spec.type = slang_spec_vec2;
break;
case slang_spec_mat3:
ti->spec.type = slang_spec_vec3;
break;
case slang_spec_mat4:
ti->spec.type = slang_spec_vec4;
break;
case slang_spec_array:
if (!slang_type_specifier_copy (&ti->spec, _ti.spec._array))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
break;
default:
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
else
{
if (!_slang_type_is_vector (_ti.spec.type) && !_slang_type_is_matrix (_ti.spec.type))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
ti->spec.type = _slang_type_base (_ti.spec.type);
}
slang_assembly_typeinfo_destruct (&_ti);
}
@@ -245,12 +217,13 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_call:
{
int exists;
if (!_slang_typeof_function (op->identifier, op->children, op->num_children, space,
&ti->spec, &exists))
if (!_slang_typeof_function (op->a_id, op->children, op->num_children, space, &ti->spec,
&exists, atoms))
return 0;
if (!exists)
{
slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);
/* slang_struct *s = slang_struct_scope_find (space->structs, op->identifier, 1);
if (s != NULL)
{
ti->spec.type = slang_spec_struct;
@@ -267,9 +240,12 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
return 0;
}
else
{
slang_type_specifier_type type = slang_type_specifier_type_from_string (
op->identifier);
*/ {
const char *name;
slang_type_specifier_type type;
name = slang_atom_pool_id (atoms, op->a_id);
type = slang_type_specifier_type_from_string (name);
if (type == slang_spec_void)
return 0;
ti->spec.type = type;
@@ -280,16 +256,19 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
case slang_oper_field:
{
slang_assembly_typeinfo _ti;
slang_assembly_typeinfo_construct (&_ti);
if (!_slang_typeof_operation (op->children, space, &_ti))
if (!slang_assembly_typeinfo_construct (&_ti))
return 0;
if (!_slang_typeof_operation (op->children, space, &_ti, atoms))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
if (_ti.spec.type == slang_spec_struct)
{
slang_variable *field = _slang_locate_variable (_ti.spec._struct->fields,
op->identifier, 0);
slang_variable *field;
field = _slang_locate_variable (_ti.spec._struct->fields, op->a_id, 0);
if (field == NULL)
{
slang_assembly_typeinfo_destruct (&_ti);
@@ -300,112 +279,96 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
ti->can_be_referenced = _ti.can_be_referenced;
}
else
{
unsigned int rows;
switch (_ti.spec.type)
const char *swizzle;
slang_type_specifier_type base;
/* determine the swizzle of the field expression */
if (!_slang_type_is_vector (_ti.spec.type))
{
case slang_spec_vec2:
case slang_spec_ivec2:
case slang_spec_bvec2:
rows = 2;
break;
case slang_spec_vec3:
case slang_spec_ivec3:
case slang_spec_bvec3:
rows = 3;
break;
case slang_spec_vec4:
case slang_spec_ivec4:
case slang_spec_bvec4:
rows = 4;
break;
default:
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
if (!_slang_is_swizzle (op->identifier, rows, &ti->swz))
rows = _slang_type_dim (_ti.spec.type);
swizzle = slang_atom_pool_id (atoms, op->a_id);
if (!_slang_is_swizzle (swizzle, rows, &ti->swz))
{
slang_assembly_typeinfo_destruct (&_ti);
return 0;
}
ti->is_swizzled = 1;
ti->can_be_referenced = _ti.can_be_referenced && _slang_is_swizzle_mask (&ti->swz,
rows);
if (_ti.is_swizzled)
{
slang_swizzle swz;
/* swizzle the swizzle */
_slang_multiply_swizzles (&swz, &_ti.swz, &ti->swz);
ti->swz = swz;
}
switch (_ti.spec.type)
base = _slang_type_base (_ti.spec.type);
switch (ti->swz.num_components)
{
case slang_spec_vec2:
case slang_spec_vec3:
case slang_spec_vec4:
switch (ti->swz.num_components)
case 1:
ti->spec.type = base;
break;
case 2:
switch (base)
{
case 1:
ti->spec.type = slang_spec_float;
break;
case 2:
case slang_spec_float:
ti->spec.type = slang_spec_vec2;
break;
case 3:
ti->spec.type = slang_spec_vec3;
break;
case 4:
ti->spec.type = slang_spec_vec4;
break;
}
break;
case slang_spec_ivec2:
case slang_spec_ivec3:
case slang_spec_ivec4:
switch (ti->swz.num_components)
{
case 1:
ti->spec.type = slang_spec_int;
break;
case 2:
case slang_spec_int:
ti->spec.type = slang_spec_ivec2;
break;
case 3:
ti->spec.type = slang_spec_ivec3;
break;
case 4:
ti->spec.type = slang_spec_ivec4;
case slang_spec_bool:
ti->spec.type = slang_spec_bvec2;
break;
}
break;
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
switch (ti->swz.num_components)
case 3:
switch (base)
{
case 1:
ti->spec.type = slang_spec_bool;
case slang_spec_float:
ti->spec.type = slang_spec_vec3;
break;
case 2:
ti->spec.type = slang_spec_bvec2;
case slang_spec_int:
ti->spec.type = slang_spec_ivec3;
break;
case 3:
case slang_spec_bool:
ti->spec.type = slang_spec_bvec3;
break;
case 4:
}
break;
case 4:
switch (base)
{
case slang_spec_float:
ti->spec.type = slang_spec_vec4;
break;
case slang_spec_int:
ti->spec.type = slang_spec_ivec4;
break;
case slang_spec_bool:
ti->spec.type = slang_spec_bvec4;
break;
}
break;
default:
break;
break;
}
}
slang_assembly_typeinfo_destruct (&_ti);
return 1;
}
break;
case slang_oper_postincrement:
case slang_oper_postdecrement:
if (!_slang_typeof_operation (op->children, space, ti))
if (!_slang_typeof_operation (op->children, space, ti, atoms))
return 0;
ti->can_be_referenced = 0;
ti->is_swizzled = 0;
@@ -418,13 +381,113 @@ int _slang_typeof_operation (slang_operation *op, slang_assembly_name_space *spa
/* _slang_typeof_function() */
int _slang_typeof_function (const char *name, slang_operation *params, unsigned int num_params,
slang_assembly_name_space *space, slang_type_specifier *spec, int *exists)
int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *atoms)
{
slang_function *fun = _slang_locate_function (name, params, num_params, space);
slang_function *fun;
fun = _slang_locate_function (space->funcs, a_name, params, num_params, space, atoms);
*exists = fun != NULL;
if (fun == NULL)
return 1;
return slang_type_specifier_copy (spec, &fun->header.type.specifier);
}
/* _slang_type_is_matrix() */
int _slang_type_is_matrix (slang_type_specifier_type ty)
{
switch (ty)
{
case slang_spec_mat2:
case slang_spec_mat3:
case slang_spec_mat4:
return 1;
default:
return 0;
}
}
/* _slang_type_is_vector() */
int _slang_type_is_vector (slang_type_specifier_type ty)
{
switch (ty)
{
case slang_spec_vec2:
case slang_spec_vec3:
case slang_spec_vec4:
case slang_spec_ivec2:
case slang_spec_ivec3:
case slang_spec_ivec4:
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
return 1;
default:
return 0;
}
}
/* _slang_type_base_of_vector() */
slang_type_specifier_type _slang_type_base (slang_type_specifier_type ty)
{
switch (ty)
{
case slang_spec_float:
case slang_spec_vec2:
case slang_spec_vec3:
case slang_spec_vec4:
return slang_spec_float;
case slang_spec_int:
case slang_spec_ivec2:
case slang_spec_ivec3:
case slang_spec_ivec4:
return slang_spec_int;
case slang_spec_bool:
case slang_spec_bvec2:
case slang_spec_bvec3:
case slang_spec_bvec4:
return slang_spec_bool;
case slang_spec_mat2:
return slang_spec_vec2;
case slang_spec_mat3:
return slang_spec_vec3;
case slang_spec_mat4:
return slang_spec_vec4;
default:
return slang_spec_void;
}
}
/* _slang_type_dim */
unsigned int _slang_type_dim (slang_type_specifier_type ty)
{
switch (ty)
{
case slang_spec_float:
case slang_spec_int:
case slang_spec_bool:
return 1;
case slang_spec_vec2:
case slang_spec_ivec2:
case slang_spec_bvec2:
case slang_spec_mat2:
return 2;
case slang_spec_vec3:
case slang_spec_ivec3:
case slang_spec_bvec3:
case slang_spec_mat3:
return 3;
case slang_spec_vec4:
case slang_spec_ivec4:
case slang_spec_bvec4:
case slang_spec_mat4:
return 4;
default:
return 0;
}
}
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -38,9 +38,10 @@ typedef struct slang_assembly_typeinfo_
int is_swizzled;
slang_swizzle swz;
slang_type_specifier spec;
slang_operation *array_size;
} slang_assembly_typeinfo;
void slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
int slang_assembly_typeinfo_construct (slang_assembly_typeinfo *);
void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
/*
@@ -49,15 +50,20 @@ void slang_assembly_typeinfo_destruct (slang_assembly_typeinfo *);
returns 0 otherwise
*/
int _slang_typeof_operation (slang_operation *, slang_assembly_name_space *,
slang_assembly_typeinfo *);
slang_assembly_typeinfo *, slang_atom_pool *);
/*
retrieves type of a function prototype, if one exists
returns 1 on success, even if the function was not found
returns 0 otherwise
*/
int _slang_typeof_function (const char *name, slang_operation *params, unsigned int num_params,
slang_assembly_name_space *space, slang_type_specifier *spec, int *exists);
int _slang_typeof_function (slang_atom a_name, slang_operation *params, unsigned int num_params,
slang_assembly_name_space *space, slang_type_specifier *spec, int *exists, slang_atom_pool *);
int _slang_type_is_matrix (slang_type_specifier_type);
int _slang_type_is_vector (slang_type_specifier_type);
slang_type_specifier_type _slang_type_base (slang_type_specifier_type);
unsigned int _slang_type_dim (slang_type_specifier_type);
#ifdef __cplusplus
}
File diff suppressed because it is too large Load Diff
+10 -2
View File
@@ -54,10 +54,18 @@ typedef struct slang_translation_unit_
slang_struct_scope structs;
slang_unit_type type;
struct slang_assembly_file_ *assembly;
slang_var_pool global_pool;
int free_assembly;
slang_var_pool *global_pool;
int free_global_pool;
struct slang_machine_ *machine;
int free_machine;
slang_atom_pool *atom_pool;
int free_atom_pool;
} slang_translation_unit;
int slang_translation_unit_construct (slang_translation_unit *);
int slang_translation_unit_construct (slang_translation_unit *);
int slang_translation_unit_construct2 (slang_translation_unit *, struct slang_assembly_file_ *,
slang_var_pool *, struct slang_machine_ *, slang_atom_pool *);
void slang_translation_unit_destruct (slang_translation_unit *);
typedef struct slang_info_log_
@@ -31,7 +31,6 @@
#include "imports.h"
#include "slang_utility.h"
#include "slang_compile_variable.h"
#include "slang_compile_struct.h"
#include "slang_compile_operation.h"
#include "slang_compile_function.h"
@@ -91,15 +90,15 @@ void slang_function_scope_destruct (slang_function_scope *scope)
slang_alloc_free (scope->functions);
}
int slang_function_scope_find_by_name (slang_function_scope *funcs, const char *name, int all_scopes)
int slang_function_scope_find_by_name (slang_function_scope *funcs, slang_atom a_name, int all_scopes)
{
unsigned int i;
for (i = 0; i < funcs->num_functions; i++)
if (slang_string_compare (name, funcs->functions[i].header.name) == 0)
if (a_name == funcs->functions[i].header.a_name)
return 1;
if (all_scopes && funcs->outer_scope != NULL)
return slang_function_scope_find_by_name (funcs->outer_scope, name, 1);
return slang_function_scope_find_by_name (funcs->outer_scope, a_name, 1);
return 0;
}
@@ -110,10 +109,10 @@ slang_function *slang_function_scope_find (slang_function_scope *funcs, slang_fu
for (i = 0; i < funcs->num_functions; i++)
{
slang_function *f = funcs->functions + i;
slang_function *f = &funcs->functions[i];
unsigned int j;
if (slang_string_compare (fun->header.name, f->header.name) != 0)
if (fun->header.a_name != f->header.a_name)
continue;
if (fun->param_count != f->param_count)
continue;
@@ -58,7 +58,7 @@ typedef struct slang_function_scope_
int slang_function_scope_construct (slang_function_scope *);
void slang_function_scope_destruct (slang_function_scope *);
int slang_function_scope_find_by_name (slang_function_scope *, const char *, int);
int slang_function_scope_find_by_name (slang_function_scope *, slang_atom, int);
slang_function *slang_function_scope_find (slang_function_scope *, slang_function *, int);
#ifdef __cplusplus
@@ -31,9 +31,7 @@
#include "imports.h"
#include "slang_utility.h"
#include "slang_compile_variable.h"
#include "slang_compile_struct.h"
#include "slang_compile_operation.h"
#include "slang_compile_function.h"
/* slang_operation */
@@ -43,7 +41,7 @@ int slang_operation_construct (slang_operation *oper)
oper->children = NULL;
oper->num_children = 0;
oper->literal = (float) 0;
oper->identifier = NULL;
oper->a_id = SLANG_ATOM_NULL;
oper->locals = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));
if (oper->locals == NULL)
return 0;
@@ -62,7 +60,6 @@ void slang_operation_destruct (slang_operation *oper)
for (i = 0; i < oper->num_children; i++)
slang_operation_destruct (oper->children + i);
slang_alloc_free (oper->children);
slang_alloc_free (oper->identifier);
slang_variable_scope_destruct (oper->locals);
slang_alloc_free (oper->locals);
}
@@ -94,15 +91,7 @@ int slang_operation_copy (slang_operation *x, const slang_operation *y)
return 0;
}
z.literal = y->literal;
if (y->identifier != NULL)
{
z.identifier = slang_string_duplicate (y->identifier);
if (z.identifier == NULL)
{
slang_operation_destruct (&z);
return 0;
}
}
z.a_id = y->a_id;
if (!slang_variable_scope_copy (z.locals, y->locals))
{
slang_operation_destruct (&z);
@@ -101,7 +101,7 @@ typedef struct slang_operation_
struct slang_operation_ *children;
unsigned int num_children;
float literal; /* type: bool, literal_int, literal_float */
char *identifier; /* type: asm, identifier, call, field */
slang_atom a_id; /* type: asm, identifier, call, field */
slang_variable_scope *locals;
} slang_operation;
+11 -21
View File
@@ -32,8 +32,6 @@
#include "slang_utility.h"
#include "slang_compile_variable.h"
#include "slang_compile_struct.h"
#include "slang_compile_operation.h"
#include "slang_compile_function.h"
/* slang_struct_scope */
@@ -86,15 +84,15 @@ int slang_struct_scope_copy (slang_struct_scope *x, const slang_struct_scope *y)
return 1;
}
slang_struct *slang_struct_scope_find (slang_struct_scope *stru, const char *name, int all_scopes)
slang_struct *slang_struct_scope_find (slang_struct_scope *stru, slang_atom a_name, int all_scopes)
{
unsigned int i;
for (i = 0; i < stru->num_structs; i++)
if (slang_string_compare (name, stru->structs[i].name) == 0)
return stru->structs + i;
if (a_name == stru->structs[i].a_name)
return &stru->structs[i];
if (all_scopes && stru->outer_scope != NULL)
return slang_struct_scope_find (stru->outer_scope, name, 1);
return slang_struct_scope_find (stru->outer_scope, a_name, 1);
return NULL;
}
@@ -102,7 +100,7 @@ slang_struct *slang_struct_scope_find (slang_struct_scope *stru, const char *nam
int slang_struct_construct (slang_struct *stru)
{
stru->name = NULL;
stru->a_name = SLANG_ATOM_NULL;
stru->fields = (slang_variable_scope *) slang_alloc_malloc (sizeof (slang_variable_scope));
if (stru->fields == NULL)
return 0;
@@ -130,7 +128,6 @@ int slang_struct_construct (slang_struct *stru)
void slang_struct_destruct (slang_struct *stru)
{
slang_alloc_free (stru->name);
slang_variable_scope_destruct (stru->fields);
slang_alloc_free (stru->fields);
slang_struct_scope_destruct (stru->structs);
@@ -143,15 +140,7 @@ int slang_struct_copy (slang_struct *x, const slang_struct *y)
if (!slang_struct_construct (&z))
return 0;
if (y->name != NULL)
{
z.name = slang_string_duplicate (y->name);
if (z.name == NULL)
{
slang_struct_destruct (&z);
return 0;
}
}
z.a_name = y->a_name;
if (!slang_variable_scope_copy (z.fields, y->fields))
{
slang_struct_destruct (&z);
@@ -175,15 +164,16 @@ int slang_struct_equal (const slang_struct *x, const slang_struct *y)
return 0;
for (i = 0; i < x->fields->num_variables; i++)
{
slang_variable *varx = x->fields->variables + i;
slang_variable *vary = y->fields->variables + i;
if (slang_string_compare (varx->name, vary->name) != 0)
slang_variable *varx = &x->fields->variables[i];
slang_variable *vary = &y->fields->variables[i];
if (varx->a_name != vary->a_name)
return 0;
if (!slang_type_specifier_equal (&varx->type.specifier, &vary->type.specifier))
return 0;
if (varx->type.specifier.type == slang_spec_array)
{
/* TODO compare array sizes */
/* TODO: compare array sizes */
}
}
return 1;
+2 -2
View File
@@ -39,11 +39,11 @@ typedef struct slang_struct_scope_
int slang_struct_scope_construct (slang_struct_scope *);
void slang_struct_scope_destruct (slang_struct_scope *);
int slang_struct_scope_copy (slang_struct_scope *, const slang_struct_scope *);
struct slang_struct_ *slang_struct_scope_find (slang_struct_scope *, const char *, int);
struct slang_struct_ *slang_struct_scope_find (slang_struct_scope *, slang_atom, int);
typedef struct slang_struct_
{
char *name;
slang_atom a_name;
struct slang_variable_scope_ *fields;
slang_struct_scope *structs;
} slang_struct;
+11 -16
View File
@@ -33,7 +33,6 @@
#include "slang_compile_variable.h"
#include "slang_compile_struct.h"
#include "slang_compile_operation.h"
#include "slang_compile_function.h"
/* slang_type_specifier_type */
@@ -269,17 +268,18 @@ int slang_variable_construct (slang_variable *var)
{
if (!slang_fully_specified_type_construct (&var->type))
return 0;
var->name = NULL;
var->a_name = SLANG_ATOM_NULL;
var->array_size = NULL;
var->initializer = NULL;
var->address = ~0;
var->size = 0;
var->global = 0;
return 1;
}
void slang_variable_destruct (slang_variable *var)
{
slang_fully_specified_type_destruct (&var->type);
slang_alloc_free (var->name);
if (var->array_size != NULL)
{
slang_operation_destruct (var->array_size);
@@ -303,15 +303,7 @@ int slang_variable_copy (slang_variable *x, const slang_variable *y)
slang_variable_destruct (&z);
return 0;
}
if (y->name != NULL)
{
z.name = slang_string_duplicate (y->name);
if (z.name == NULL)
{
slang_variable_destruct (&z);
return 0;
}
}
z.a_name = y->a_name;
if (y->array_size != NULL)
{
z.array_size = (slang_operation *) slang_alloc_malloc (sizeof (slang_operation));
@@ -352,20 +344,23 @@ int slang_variable_copy (slang_variable *x, const slang_variable *y)
return 0;
}
}
z.address = y->address;
z.size = y->size;
z.global = y->global;
slang_variable_destruct (x);
*x = z;
return 1;
}
slang_variable *_slang_locate_variable (slang_variable_scope *scope, const char *name, int all)
slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all)
{
unsigned int i;
for (i = 0; i < scope->num_variables; i++)
if (slang_string_compare (name, scope->variables[i].name) == 0)
return scope->variables + i;
if (a_name == scope->variables[i].a_name)
return &scope->variables[i];
if (all && scope->outer_scope != NULL)
return _slang_locate_variable (scope->outer_scope, name, 1);
return _slang_locate_variable (scope->outer_scope, a_name, 1);
return NULL;
}
@@ -109,17 +109,19 @@ int slang_variable_scope_copy (slang_variable_scope *, const slang_variable_scop
typedef struct slang_variable_
{
slang_fully_specified_type type;
char *name;
slang_atom a_name;
struct slang_operation_ *array_size; /* type: spec_array */
struct slang_operation_ *initializer;
unsigned int address;
unsigned int size;
int global;
} slang_variable;
int slang_variable_construct (slang_variable *);
void slang_variable_destruct (slang_variable *);
int slang_variable_copy (slang_variable *, const slang_variable *);
slang_variable *_slang_locate_variable (slang_variable_scope *scope, const char *name, int all);
slang_variable *_slang_locate_variable (slang_variable_scope *scope, slang_atom a_name, int all);
#ifdef __cplusplus
}
+167 -79
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -34,7 +34,24 @@
#include "slang_storage.h"
#include "slang_execute.h"
#define DEBUG_SLANG 1
#define DEBUG_SLANG 0
void slang_machine_init (slang_machine *mach)
{
mach->ip = 0;
mach->sp = SLANG_MACHINE_STACK_SIZE;
mach->bp = 0;
mach->kill = 0;
mach->exit = 0;
}
int _slang_execute (const slang_assembly_file *file)
{
slang_machine mach;
slang_machine_init (&mach);
return _slang_execute2 (file, &mach);
}
#if DEBUG_SLANG
@@ -44,6 +61,7 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i)
switch (a->type)
{
/* core */
case slang_asm_none:
fprintf (f, "none");
break;
@@ -74,12 +92,36 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i)
case slang_asm_float_less:
fprintf (f, "float_less");
break;
case slang_asm_float_equal:
case slang_asm_float_equal_exp:
fprintf (f, "float_equal");
break;
case slang_asm_float_equal_int:
fprintf (f, "float_equal\t%d, %d", a->param[0], a->param[1]);
break;
case slang_asm_float_to_int:
fprintf (f, "float_to_int");
break;
case slang_asm_float_sine:
fprintf (f, "float_sine");
break;
case slang_asm_float_arcsine:
fprintf (f, "float_arcsine");
break;
case slang_asm_float_arctan:
fprintf (f, "float_arctan");
break;
case slang_asm_float_power:
fprintf (f, "float_power");
break;
case slang_asm_float_log2:
fprintf (f, "float_log2");
break;
case slang_asm_float_floor:
fprintf (f, "float_floor");
break;
case slang_asm_float_ceil:
fprintf (f, "float_ceil");
break;
case slang_asm_int_copy:
fprintf (f, "int_copy\t%d, %d", a->param[0], a->param[1]);
break;
@@ -158,6 +200,16 @@ static void dump_instruction (FILE *f, slang_assembly *a, unsigned int i)
case slang_asm_exit:
fprintf (f, "exit");
break;
/* mesa-specific extensions */
case slang_asm_float_print:
fprintf (f, "float_print");
break;
case slang_asm_int_print:
fprintf (f, "int_print");
break;
case slang_asm_bool_print:
fprintf (f, "bool_print");
break;
default:
break;
}
@@ -186,11 +238,13 @@ static void dump (const slang_assembly_file *file)
#endif
int _slang_execute (const slang_assembly_file *file)
int _slang_execute2 (const slang_assembly_file *file, slang_machine *mach)
{
slang_machine mach;
slang_machine_slot *stack;
#ifdef DEBUG_SLANG
#if DEBUG_SLANG
static unsigned int counter = 0;
char filename[256];
FILE *f;
#endif
@@ -198,161 +252,195 @@ int _slang_execute (const slang_assembly_file *file)
static_assert(sizeof (GLfloat) == 4);
static_assert(sizeof (GLuint) == 4);
mach.ip = 0;
mach.sp = SLANG_MACHINE_STACK_SIZE;
mach.bp = 0;
mach.kill = 0;
mach.exit = 0;
mach.global = mach.mem;
mach.stack = mach.global + SLANG_MACHINE_GLOBAL_SIZE;
#if DEBUG_SLANG
dump (file);
f = fopen ("~mesa-slang-assembly-execution.txt", "w");
counter++;
_mesa_sprintf (filename, "~mesa-slang-assembly-exec-(%u).txt", counter);
f = fopen (filename, "w");
#endif
while (!mach.exit)
stack = mach->mem + SLANG_MACHINE_GLOBAL_SIZE;
while (!mach->exit)
{
slang_assembly *a;
slang_assembly *a = &file->code[mach->ip];
#if DEBUG_SLANG
if (f != NULL)
if (f != NULL && a->type != slang_asm_none)
{
unsigned int i;
dump_instruction (f, file->code + mach.ip, mach.ip);
fprintf (f, "\t\tsp=%u bp=%u\n", mach.sp, mach.bp);
for (i = mach.sp; i < SLANG_MACHINE_STACK_SIZE; i++)
fprintf (f, "\t%.5u\t%6f\t%u\n", i, mach.stack[i]._float, mach.stack[i]._addr);
dump_instruction (f, file->code + mach->ip, mach->ip);
fprintf (f, "\t\tsp=%u bp=%u\n", mach->sp, mach->bp);
for (i = mach->sp; i < SLANG_MACHINE_STACK_SIZE; i++)
fprintf (f, "\t%.5u\t%6f\t%u\n", i, stack[i]._float, stack[i]._addr);
fflush (f);
}
#endif
a = file->code + mach.ip;
mach.ip++;
mach->ip++;
switch (a->type)
{
/* core */
case slang_asm_none:
break;
case slang_asm_float_copy:
case slang_asm_int_copy:
case slang_asm_bool_copy:
mach.mem[mach.stack[mach.sp + a->param[0] / 4]._addr + a->param[1] / 4]._float =
mach.stack[mach.sp]._float;
mach.sp++;
mach->mem[(stack[mach->sp + a->param[0] / 4]._addr + a->param[1]) / 4]._float =
stack[mach->sp]._float;
mach->sp++;
break;
case slang_asm_float_move:
case slang_asm_int_move:
case slang_asm_bool_move:
mach.stack[mach.sp + a->param[0] / 4]._float =
mach.stack[mach.sp + (mach.stack[mach.sp]._addr + a->param[1]) / 4]._float;
stack[mach->sp + a->param[0] / 4]._float =
stack[mach->sp + (stack[mach->sp]._addr + a->param[1]) / 4]._float;
break;
case slang_asm_float_push:
case slang_asm_int_push:
case slang_asm_bool_push:
mach.sp--;
mach.stack[mach.sp]._float = a->literal;
mach->sp--;
stack[mach->sp]._float = a->literal;
break;
case slang_asm_float_deref:
case slang_asm_int_deref:
case slang_asm_bool_deref:
mach.stack[mach.sp]._float = mach.mem[mach.stack[mach.sp]._addr]._float;
stack[mach->sp]._float = mach->mem[stack[mach->sp]._addr / 4]._float;
break;
case slang_asm_float_add:
mach.stack[mach.sp + 1]._float += mach.stack[mach.sp]._float;
mach.sp++;
stack[mach->sp + 1]._float += stack[mach->sp]._float;
mach->sp++;
break;
case slang_asm_float_multiply:
mach.stack[mach.sp + 1]._float *= mach.stack[mach.sp]._float;
mach.sp++;
stack[mach->sp + 1]._float *= stack[mach->sp]._float;
mach->sp++;
break;
case slang_asm_float_divide:
mach.stack[mach.sp + 1]._float /= mach.stack[mach.sp]._float;
mach.sp++;
stack[mach->sp + 1]._float /= stack[mach->sp]._float;
mach->sp++;
break;
case slang_asm_float_negate:
mach.stack[mach.sp]._float = -mach.stack[mach.sp]._float;
stack[mach->sp]._float = -stack[mach->sp]._float;
break;
case slang_asm_float_less:
mach.stack[mach.sp + 1]._float =
mach.stack[mach.sp + 1]._float < mach.stack[mach.sp]._float ? 1.0f : 0.0f;
mach.sp++;
stack[mach->sp + 1]._float =
stack[mach->sp + 1]._float < stack[mach->sp]._float ? (GLfloat) 1 : (GLfloat) 0;
mach->sp++;
break;
case slang_asm_float_equal:
mach.sp--;
mach.stack[mach.sp]._float = mach.stack[mach.sp + 1 + a->param[0] / 4]._float ==
mach.stack[mach.sp + 1 + a->param[1] / 4]._float ? 1.0f : 0.0f;
case slang_asm_float_equal_exp:
stack[mach->sp + 1]._float =
stack[mach->sp + 1]._float == stack[mach->sp]._float ? (GLfloat) 1 : (GLfloat) 0;
mach->sp++;
break;
case slang_asm_float_equal_int:
mach->sp--;
stack[mach->sp]._float = stack[mach->sp + 1 + a->param[0] / 4]._float ==
stack[mach->sp + 1 + a->param[1] / 4]._float ? (GLfloat) 1 : (GLfloat) 0;
break;
case slang_asm_float_to_int:
mach.stack[mach.sp]._float = (GLfloat) (GLint) mach.stack[mach.sp]._float;
stack[mach->sp]._float = (GLfloat) (GLint) stack[mach->sp]._float;
break;
case slang_asm_float_sine:
stack[mach->sp]._float = (GLfloat) _mesa_sin (stack[mach->sp]._float);
break;
case slang_asm_float_arcsine:
stack[mach->sp]._float = _mesa_asinf (stack[mach->sp]._float);
break;
case slang_asm_float_arctan:
stack[mach->sp]._float = _mesa_atanf (stack[mach->sp]._float);
break;
case slang_asm_float_power:
stack[mach->sp + 1]._float =
(GLfloat) _mesa_pow (stack[mach->sp + 1]._float, stack[mach->sp]._float);
mach->sp++;
break;
case slang_asm_float_log2:
stack[mach->sp]._float = LOG2 (stack[mach->sp]._float);
break;
case slang_asm_float_floor:
stack[mach->sp]._float = FLOORF (stack[mach->sp]._float);
break;
case slang_asm_float_ceil:
stack[mach->sp]._float = CEILF (stack[mach->sp]._float);
break;
case slang_asm_int_to_float:
break;
case slang_asm_int_to_addr:
mach.stack[mach.sp]._addr = (GLuint) (GLint) mach.stack[mach.sp]._float;
stack[mach->sp]._addr = (GLuint) (GLint) stack[mach->sp]._float;
break;
case slang_asm_addr_copy:
mach.mem[mach.stack[mach.sp + 1]._addr]._addr = mach.stack[mach.sp]._addr;
mach.sp++;
mach->mem[stack[mach->sp + 1]._addr / 4]._addr = stack[mach->sp]._addr;
mach->sp++;
break;
case slang_asm_addr_push:
mach.sp--;
mach.stack[mach.sp]._addr = a->param[0];
mach->sp--;
stack[mach->sp]._addr = a->param[0];
break;
case slang_asm_addr_deref:
mach.stack[mach.sp]._addr = mach.mem[mach.stack[mach.sp]._addr]._addr;
stack[mach->sp]._addr = mach->mem[stack[mach->sp]._addr / 4]._addr;
break;
case slang_asm_addr_add:
mach.stack[mach.sp + 1]._addr += mach.stack[mach.sp]._addr;
mach.sp++;
stack[mach->sp + 1]._addr += stack[mach->sp]._addr;
mach->sp++;
break;
case slang_asm_addr_multiply:
mach.stack[mach.sp + 1]._addr *= mach.stack[mach.sp]._addr;
mach.sp++;
stack[mach->sp + 1]._addr *= stack[mach->sp]._addr;
mach->sp++;
break;
case slang_asm_jump:
mach.ip = a->param[0];
mach->ip = a->param[0];
break;
case slang_asm_jump_if_zero:
if (mach.stack[mach.sp]._float == 0.0f)
mach.ip = a->param[0];
mach.sp++;
if (stack[mach->sp]._float == 0.0f)
mach->ip = a->param[0];
mach->sp++;
break;
case slang_asm_enter:
mach.sp--;
mach.stack[mach.sp]._addr = mach.bp;
mach.bp = mach.sp + a->param[0] / 4;
mach->sp--;
stack[mach->sp]._addr = mach->bp;
mach->bp = mach->sp + a->param[0] / 4;
break;
case slang_asm_leave:
mach.bp = mach.stack[mach.sp]._addr;
mach.sp++;
mach->bp = stack[mach->sp]._addr;
mach->sp++;
break;
case slang_asm_local_alloc:
mach.sp -= a->param[0] / 4;
mach->sp -= a->param[0] / 4;
break;
case slang_asm_local_free:
mach.sp += a->param[0] / 4;
mach->sp += a->param[0] / 4;
break;
case slang_asm_local_addr:
mach.sp--;
mach.stack[mach.sp]._addr = SLANG_MACHINE_GLOBAL_SIZE * 4 + mach.bp * 4 -
mach->sp--;
stack[mach->sp]._addr = SLANG_MACHINE_GLOBAL_SIZE * 4 + mach->bp * 4 -
(a->param[0] + a->param[1]) + 4;
break;
case slang_asm_call:
mach.sp--;
mach.stack[mach.sp]._addr = mach.ip;
mach.ip = a->param[0];
mach->sp--;
stack[mach->sp]._addr = mach->ip;
mach->ip = a->param[0];
break;
case slang_asm_return:
mach.ip = mach.stack[mach.sp]._addr;
mach.sp++;
mach->ip = stack[mach->sp]._addr;
mach->sp++;
break;
case slang_asm_discard:
mach.kill = 1;
mach->kill = 1;
break;
case slang_asm_exit:
mach.exit = 1;
mach->exit = 1;
break;
/* mesa-specific extensions */
case slang_asm_float_print:
_mesa_printf ("slang print: %f\n", stack[mach->sp]._float);
break;
case slang_asm_int_print:
_mesa_printf ("slang print: %d\n", (GLint) stack[mach->sp]._float);
break;
case slang_asm_bool_print:
_mesa_printf ("slang print: %s\n", (GLint) stack[mach->sp]._float ? "true" : "false");
break;
}
}
@@ -362,6 +450,6 @@ int _slang_execute (const slang_assembly_file *file)
fclose (f);
#endif
return 0;
return 1;
}
+5 -4
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -47,11 +47,12 @@ typedef struct slang_machine_
GLuint kill; /* discard the fragment */
GLuint exit; /* terminate the shader */
slang_machine_slot mem[SLANG_MACHINE_MEMORY_SIZE];
slang_machine_slot *global;
slang_machine_slot *stack;
} slang_machine;
void slang_machine_init (slang_machine *);
int _slang_execute (const slang_assembly_file *);
int _slang_execute2 (const slang_assembly_file *, slang_machine *);
#ifdef __cplusplus
}
+3 -2
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -30,6 +30,7 @@
#include "imports.h"
#include "grammar_mesa.h"
#include "slang_utility.h"
#include "slang_compile.h"
#include "slang_preprocess.h"
+97 -37
View File
@@ -31,15 +31,17 @@
#include "imports.h"
#include "slang_utility.h"
#include "slang_storage.h"
#include "slang_assemble.h"
#include "slang_assemble.h"
#include "slang_execute.h"
/* slang_storage_array */
void slang_storage_array_construct (slang_storage_array *arr)
int slang_storage_array_construct (slang_storage_array *arr)
{
arr->type = slang_stor_aggregate;
arr->aggregate = NULL;
arr->length = 0;
arr->length = 0;
return 1;
}
void slang_storage_array_destruct (slang_storage_array *arr)
@@ -53,15 +55,17 @@ void slang_storage_array_destruct (slang_storage_array *arr)
/* slang_storage_aggregate */
void slang_storage_aggregate_construct (slang_storage_aggregate *agg)
int slang_storage_aggregate_construct (slang_storage_aggregate *agg)
{
agg->arrays = NULL;
agg->count = 0;
agg->count = 0;
return 1;
}
void slang_storage_aggregate_destruct (slang_storage_aggregate *agg)
{
unsigned int i;
unsigned int i;
for (i = 0; i < agg->count; i++)
slang_storage_array_destruct (agg->arrays + i);
slang_alloc_free (agg->arrays);
@@ -75,7 +79,8 @@ static slang_storage_array *slang_storage_aggregate_push_new (slang_storage_aggr
if (agg->arrays != NULL)
{
arr = agg->arrays + agg->count;
slang_storage_array_construct (arr);
if (!slang_storage_array_construct (arr))
return NULL;
agg->count++;
}
return arr;
@@ -97,7 +102,7 @@ static int aggregate_vector (slang_storage_aggregate *agg, slang_storage_type ba
static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type basic_type,
unsigned int dimension)
{
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
slang_storage_array *arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
return 0;
arr->type = slang_stor_aggregate;
@@ -106,26 +111,80 @@ static int aggregate_matrix (slang_storage_aggregate *agg, slang_storage_type ba
slang_storage_aggregate));
if (arr->aggregate == NULL)
return 0;
slang_storage_aggregate_construct (arr->aggregate);
if (!slang_storage_aggregate_construct (arr->aggregate))
{
slang_alloc_free (arr->aggregate);
arr->aggregate = NULL;
return 0;
}
if (!aggregate_vector (arr->aggregate, basic_type, dimension))
return 0;
return 1;
}
static int aggregate_variables (slang_storage_aggregate *agg, slang_variable_scope *vars,
slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals)
slang_function_scope *funcs, slang_struct_scope *structs, slang_variable_scope *globals,
slang_machine *mach, slang_assembly_file *file, slang_atom_pool *atoms)
{
unsigned int i;
for (i = 0; i < vars->num_variables; i++)
if (!_slang_aggregate_variable (agg, &vars->variables[i].type.specifier,
vars->variables[i].array_size, funcs, structs, globals))
vars->variables[i].array_size, funcs, structs, globals, mach, file, atoms))
return 0;
return 1;
}
static int eval_array_size (slang_assembly_file *file, slang_machine *pmach,
slang_assembly_name_space *space, slang_operation *array_size, GLuint *plength,
slang_atom_pool *atoms)
{
slang_assembly_file_restore_point point;
slang_assembly_local_info info;
slang_assembly_flow_control flow;
slang_assembly_stack_info stk;
slang_machine mach;
/* save the current assembly */
if (!slang_assembly_file_restore_point_save (file, &point))
return 0;
/* setup the machine */
mach = *pmach;
mach.ip = file->count;
/* allocate local storage for expression */
info.ret_size = 0;
info.addr_tmp = 0;
info.swizzle_tmp = 4;
if (!slang_assembly_file_push_label (file, slang_asm_local_alloc, 20))
return 0;
if (!slang_assembly_file_push_label (file, slang_asm_enter, 20))
return 0;
/* insert the actual expression */
if (!_slang_assemble_operation (file, array_size, 0, &flow, space, &info, &stk, pmach, atoms))
return 0;
if (!slang_assembly_file_push (file, slang_asm_exit))
return 0;
/* execute the expression */
if (!_slang_execute2 (file, &mach))
return 0;
/* the evaluated expression is on top of the stack */
*plength = (GLuint) mach.mem[mach.sp + SLANG_MACHINE_GLOBAL_SIZE]._float;
/* TODO: check if 0 < arr->length <= 65535 */
/* restore the old assembly */
if (!slang_assembly_file_restore_point_load (file, &point))
return 0;
return 1;
}
int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifier *spec,
slang_operation *array_size, slang_function_scope *funcs, slang_struct_scope *structs,
slang_variable_scope *vars)
slang_variable_scope *vars, slang_machine *mach, slang_assembly_file *file,
slang_atom_pool *atoms)
{
switch (spec->type)
{
@@ -167,15 +226,12 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
case slang_spec_sampler2DShadow:
return aggregate_vector (agg, slang_stor_int, 1);
case slang_spec_struct:
return aggregate_variables (agg, spec->_struct->fields, funcs, structs, vars);
return aggregate_variables (agg, spec->_struct->fields, funcs, structs, vars, mach,
file, atoms);
case slang_spec_array:
{
slang_storage_array *arr;
slang_assembly_file file;
slang_assembly_flow_control flow;
slang_storage_array *arr;
slang_assembly_name_space space;
slang_assembly_local_info info;
slang_assembly_stack_info stk;
arr = slang_storage_aggregate_push_new (agg);
if (arr == NULL)
@@ -185,21 +241,20 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
slang_storage_aggregate));
if (arr->aggregate == NULL)
return 0;
slang_storage_aggregate_construct (arr->aggregate);
if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs, vars))
return 0;
slang_assembly_file_construct (&file);
space.funcs = funcs;
space.structs = structs;
space.vars = vars;
if (!_slang_assemble_operation (&file, array_size, 0, &flow, &space, &info, &stk))
{
slang_assembly_file_destruct (&file);
return 0;
if (!slang_storage_aggregate_construct (arr->aggregate))
{
slang_alloc_free (arr->aggregate);
arr->aggregate = NULL;
return 0;
}
/* TODO: evaluate array size */
slang_assembly_file_destruct (&file);
arr->length = 256;
if (!_slang_aggregate_variable (arr->aggregate, spec->_array, NULL, funcs, structs,
vars, mach, file, atoms))
return 0;
space.funcs = funcs;
space.structs = structs;
space.vars = vars;
if (!eval_array_size (file, mach, &space, array_size, &arr->length, atoms))
return 0;
}
return 1;
default:
@@ -211,10 +266,12 @@ int _slang_aggregate_variable (slang_storage_aggregate *agg, slang_type_specifie
unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
{
unsigned int i, size = 0;
unsigned int i, size = 0;
for (i = 0; i < agg->count; i++)
{
unsigned int element_size;
unsigned int element_size;
if (agg->arrays[i].type == slang_stor_aggregate)
element_size = _slang_sizeof_aggregate (agg->arrays[i].aggregate);
else
@@ -228,10 +285,12 @@ unsigned int _slang_sizeof_aggregate (const slang_storage_aggregate *agg)
int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage_aggregate *agg)
{
unsigned int i;
unsigned int i;
for (i = 0; i < agg->count; i++)
{
unsigned int j;
unsigned int j;
for (j = 0; j < agg->arrays[i].length; j++)
{
if (agg->arrays[i].type == slang_stor_aggregate)
@@ -241,7 +300,8 @@ int _slang_flatten_aggregate (slang_storage_aggregate *flat, const slang_storage
}
else
{
slang_storage_array *arr;
slang_storage_array *arr;
arr = slang_storage_aggregate_push_new (flat);
if (arr == NULL)
return 0;
+4 -3
View File
@@ -66,7 +66,7 @@ typedef struct slang_storage_array_
unsigned int length;
} slang_storage_array;
void slang_storage_array_construct (slang_storage_array *);
int slang_storage_array_construct (slang_storage_array *);
void slang_storage_array_destruct (slang_storage_array *);
/*
@@ -81,12 +81,13 @@ typedef struct slang_storage_aggregate_
unsigned int count;
} slang_storage_aggregate;
void slang_storage_aggregate_construct (slang_storage_aggregate *);
int slang_storage_aggregate_construct (slang_storage_aggregate *);
void slang_storage_aggregate_destruct (slang_storage_aggregate *);
int _slang_aggregate_variable (slang_storage_aggregate *, struct slang_type_specifier_ *,
struct slang_operation_ *, struct slang_function_scope_ *, slang_struct_scope *,
slang_variable_scope *);
slang_variable_scope *, struct slang_machine_ *, struct slang_assembly_file_ *,
slang_atom_pool *);
/*
returns total size (in machine units) of the given aggregate
+70 -31
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -31,43 +31,82 @@
#include "imports.h"
#include "slang_utility.h"
void slang_alloc_free (void *ptr)
{
_mesa_free (ptr);
}
void *slang_alloc_malloc (unsigned int size)
{
return _mesa_malloc (size);
}
void *slang_alloc_realloc (void *ptr, unsigned int old_size, unsigned int size)
{
return _mesa_realloc (ptr, old_size, size);
}
int slang_string_compare (const char *str1, const char *str2)
{
return _mesa_strcmp (str1, str2);
}
char *slang_string_copy (char *dst, const char *src)
{
return _mesa_strcpy (dst, src);
}
char *slang_string_concat (char *dst, const char *src)
{
return _mesa_strcpy (dst + _mesa_strlen (dst), src);
}
char *slang_string_duplicate (const char *src)
/* slang_atom_pool */
void slang_atom_pool_construct (slang_atom_pool *pool)
{
return _mesa_strdup (src);
GLuint i;
for (i = 0; i < SLANG_ATOM_POOL_SIZE; i++)
pool->entries[i] = NULL;
}
unsigned int slang_string_length (const char *str)
void slang_atom_pool_destruct (slang_atom_pool *pool)
{
return _mesa_strlen (str);
GLuint i;
for (i = 0; i < SLANG_ATOM_POOL_SIZE; i++)
{
slang_atom_entry *entry;
entry = pool->entries[i];
while (entry != NULL)
{
slang_atom_entry *next;
next = entry->next;
slang_alloc_free (entry->id);
slang_alloc_free (entry);
entry = next;
}
}
}
slang_atom slang_atom_pool_atom (slang_atom_pool *pool, const char *id)
{
GLuint hash;
const char *p = id;
slang_atom_entry **entry;
hash = 0;
while (*p != '\0')
{
GLuint g;
hash = (hash << 4) + (GLuint) *p++;
g = hash & 0xf0000000;
if (g != 0)
hash ^= g >> 24;
hash &= ~g;
}
hash %= SLANG_ATOM_POOL_SIZE;
entry = &pool->entries[hash];
while (*entry != NULL)
{
if (slang_string_compare ((**entry).id, id) == 0)
return (slang_atom) (**entry).id;
entry = &(**entry).next;
}
*entry = (slang_atom_entry *) slang_alloc_malloc (sizeof (slang_atom_entry));
if (*entry == NULL)
return SLANG_ATOM_NULL;
(**entry).next = NULL;
(**entry).id = slang_string_duplicate (id);
if ((**entry).id == NULL)
return SLANG_ATOM_NULL;
return (slang_atom) (**entry).id;
}
const char *slang_atom_pool_id (slang_atom_pool *pool, slang_atom atom)
{
return (const char *) atom;
}
+32 -9
View File
@@ -1,8 +1,8 @@
/*
* Mesa 3-D graphics library
* Version: 6.3
* Version: 6.5
*
* Copyright (C) 2005 Brian Paul All Rights Reserved.
* Copyright (C) 2005-2006 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -34,14 +34,37 @@ extern "C" {
*/
#define static_assert(expr) do { int _array[(expr) ? 1 : -1]; _array[0]; } while (0)
void slang_alloc_free (void *);
void *slang_alloc_malloc (unsigned int);
void *slang_alloc_realloc (void *, unsigned int, unsigned int);
int slang_string_compare (const char *, const char *);
char *slang_string_copy (char *, const char *);
#define slang_alloc_free(ptr) _mesa_free (ptr)
#define slang_alloc_malloc(size) _mesa_malloc (size)
#define slang_alloc_realloc(ptr, old_size, size) _mesa_realloc (ptr, old_size, size)
#define slang_string_compare(str1, str2) _mesa_strcmp (str1, str2)
#define slang_string_copy(dst, src) _mesa_strcpy (dst, src)
#define slang_string_duplicate(src) _mesa_strdup (src)
#define slang_string_length(str) _mesa_strlen (str)
char *slang_string_concat (char *, const char *);
char *slang_string_duplicate (const char *);
unsigned int slang_string_length (const char *);
typedef GLvoid *slang_atom;
#define SLANG_ATOM_NULL ((slang_atom) 0)
typedef struct slang_atom_entry_
{
char *id;
struct slang_atom_entry_ *next;
} slang_atom_entry;
#define SLANG_ATOM_POOL_SIZE 1023
typedef struct slang_atom_pool_
{
slang_atom_entry *entries[SLANG_ATOM_POOL_SIZE];
} slang_atom_pool;
void slang_atom_pool_construct (slang_atom_pool *);
void slang_atom_pool_destruct (slang_atom_pool *);
slang_atom slang_atom_pool_atom (slang_atom_pool *, const char *);
const char *slang_atom_pool_id (slang_atom_pool *, slang_atom);
#ifdef __cplusplus
}