diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2010-04-16 06:14:44 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2010-04-16 06:14:44 -0400 |
commit | ceb929cc66dfc141efdd02b3b095c20582eed7c6 (patch) | |
tree | 1d11cc164a4187e04105ee20a33179255d6ff625 | |
parent | 63f4bf4508ca7b7f97ab6e5755dc127d98364d03 (diff) |
Store instructions
-rw-r--r-- | psl.c | 44 | ||||
-rw-r--r-- | psl.h | 2 |
2 files changed, 37 insertions, 9 deletions
@@ -2,6 +2,9 @@ #include <stdarg.h> #include "psl.h" +#define new(t) \ + ((t *)malloc (sizeof (t))) + typedef struct instruction_list_t instruction_list_t; typedef enum @@ -43,12 +46,7 @@ struct psl_instruction_t struct instruction_list_t { - psl_instruction_t inst[255]; - instruction_list_t *next; -}; - -struct psl_statement_t -{ + int n_instructions; psl_instruction_t *instructions; }; @@ -60,6 +58,11 @@ struct psl_program_t psl_program_t * psl_program_create (psl_statement_t *statement) { + psl_program_t *program = new (psl_program_t); + + program->inst = statement; + + return program; } psl_instruction_t * @@ -68,25 +71,50 @@ psl_tex (psl_var_t *dest, 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, void *); + instruction = va_arg (va, psl_instruction_t *); } va_end (va); + + return stmt; } void @@ -20,9 +20,9 @@ */ typedef struct psl_program_t psl_program_t; -typedef struct psl_statement_t psl_statement_t; typedef struct psl_var_t psl_var_t; typedef struct psl_instruction_t psl_instruction_t; +typedef struct instruction_list_t psl_statement_t; psl_program_t * psl_program_create (psl_statement_t *statement); psl_var_t * psl_imm_un8 (int value); |