#include #include #include #include "psl.h" #define new(t) \ ((t *)malloc (sizeof (t))) typedef struct instruction_list_t instruction_list_t; typedef enum { TEX, ADD, MAD, CMP_LT, LABEL } instruction_type_t; struct psl_instruction_t { instruction_type_t type; union { struct { } tex; struct { } add; struct { } mad; struct { } cmp_lt; struct { char *name; } label; } u; }; struct instruction_list_t { int n_instructions; psl_instruction_t *instructions; }; struct psl_program_t { instruction_list_t *instructions; }; typedef enum { VARIABLE, IMMEDIATE } var_type_t; typedef enum { UN8, SP, DP } type_t; struct psl_var_t { var_type_t var_type; type_t type; union { struct { char *name; } variable; struct { } immediate; } u; }; psl_program_t * psl_program_create (psl_statement_t *statement) { psl_program_t *program = new (psl_program_t); program->instructions = statement; return program; } psl_instruction_t * psl_tex (psl_var_t *dest, psl_var_t *img, psl_var_t *u, psl_var_t *v) { } static psl_instruction_t * add (psl_instruction_t *insts, int i, psl_instruction_t *inst) { psl_instruction_t *result; int pot; pot = 1; while (i >= pot) pot *= 2; result = realloc (insts, pot * sizeof (psl_instruction_t)); result[i] = *inst; return result; } psl_statement_t * psl_asm (psl_instruction_t *instruction, ...) { psl_statement_t *stmt; va_list va; stmt = new (psl_statement_t); stmt->instructions = NULL; stmt->n_instructions = 0; va_start (va, instruction); while (instruction) { stmt->instructions = add ( stmt->instructions, stmt->n_instructions++, instruction); instruction = va_arg (va, psl_instruction_t *); } va_end (va); return stmt; } static void run_box (pixman_box32_t *box, pixman_image_t *destination, instruction_list_t *instructions, pixman_image_t **sources) { int width, height; height = box->y2 - box->y1; width = box->x2 - box->x1; while (height--) { int w = width; while (w--) { int i; for (i = 0; i < instructions->n_instructions; ++i) { psl_instruction_t *instruction = &(instructions->instructions[i]); switch (instruction->type) { case TEX: { &(instruction->u.tex); break; } case ADD: { break; } case MAD: { break; } case CMP_LT: { break; } case LABEL: { break; } } } } } } void psl_program_run (psl_program_t *program, pixman_region32_t *clip, pixman_image_t *destination, pixman_image_t **sources) { int n_rects; pixman_box32_t *boxes; boxes = pixman_region32_rectangles (clip, &n_rects); while (n_rects--) run_box (boxes++, destination, program->instructions, sources); } void psl_program_destroy (psl_program_t *program) { } psl_var_t * psl_imm_un8 (int value) { } psl_var_t * psl_imm_sp (float f) { } psl_instruction_t * psl_label (const char *name) { } psl_var_t * psl_var (const char *name) { psl_var_t *result = new (psl_var_t); result->type = VARIABLE; result->u.variable.name = strdup (name); return result; } int main () { psl_program_t *program = psl_program_create ( psl_asm ( psl_tex ( psl_var ("fish"), psl_imm_un8 (0), psl_imm_sp (0.7), psl_imm_sp (0.3)), psl_label ("restart:"), NULL)); return 0; }