summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2010-04-16 06:14:44 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2010-04-16 06:14:44 -0400
commitceb929cc66dfc141efdd02b3b095c20582eed7c6 (patch)
tree1d11cc164a4187e04105ee20a33179255d6ff625
parent63f4bf4508ca7b7f97ab6e5755dc127d98364d03 (diff)
Store instructions
-rw-r--r--psl.c44
-rw-r--r--psl.h2
2 files changed, 37 insertions, 9 deletions
diff --git a/psl.c b/psl.c
index 731ef72..f3f1958 100644
--- a/psl.c
+++ b/psl.c
@@ -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
diff --git a/psl.h b/psl.h
index a1bd156..6e6b865 100644
--- a/psl.h
+++ b/psl.h
@@ -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);