Skip to content

Commit 0aeb5c1

Browse files
author
Sebastien Bourdeauducq
committedNov 24, 2011
fpvm: support source-only binding
1 parent 50436b5 commit 0aeb5c1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed
 

‎software/include/fpvm/fpvm.h

+6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ struct fpvm_tbinding {
5151
char sym[FPVM_MAXSYMLEN];
5252
};
5353

54+
enum {
55+
FPVM_BIND_NONE,
56+
FPVM_BIND_SOURCE,
57+
FPVM_BIND_ALL
58+
};
59+
5460
struct fpvm_fragment {
5561
char last_error[FPVM_MAXERRLEN];
5662
fpvm_bind_callback bind_callback;

‎software/libfpvm/fpvm.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
6868
fragment->next_sur = -3;
6969
fragment->ninstructions = 0;
7070

71-
fragment->bind_mode = 0;
71+
fragment->bind_mode = FPVM_BIND_NONE;
7272
fragment->vector_mode = vector_mode;
7373
}
7474

@@ -172,14 +172,14 @@ static int rename_reg(struct fpvm_fragment *fragment, const char *sym, int reg)
172172
return 1;
173173
}
174174

175-
static int sym_to_reg(struct fpvm_fragment *fragment, const char *sym, int *created)
175+
static int sym_to_reg(struct fpvm_fragment *fragment, const char *sym, int dest, int *created)
176176
{
177177
int r;
178178
if(created) *created = 0;
179179
r = lookup(fragment, sym);
180180
if(r == FPVM_INVALID_REG) {
181181
if(created) *created = 1;
182-
if(fragment->bind_mode)
182+
if((fragment->bind_mode == FPVM_BIND_ALL) || ((fragment->bind_mode == FPVM_BIND_SOURCE) && !dest))
183183
r = fpvm_bind(fragment, sym);
184184
else
185185
r = tbind(fragment, sym);
@@ -332,7 +332,7 @@ static int compile(struct fpvm_fragment *fragment, int reg, struct ast_node *nod
332332
if(node->contents.branches.a == NULL) {
333333
/* AST node is a variable */
334334
if(fragment->bind_mode) {
335-
opa = sym_to_reg(fragment, node->label, NULL);
335+
opa = sym_to_reg(fragment, node->label, 0, NULL);
336336
if(opa == FPVM_INVALID_REG) return FPVM_INVALID_REG;
337337
} else {
338338
opa = lookup(fragment, node->label);
@@ -537,7 +537,7 @@ int fpvm_assign(struct fpvm_fragment *fragment, const char *dest, const char *ex
537537
fragment->next_sur--;
538538
created = 1;
539539
} else
540-
dest_reg = sym_to_reg(fragment, dest, &created);
540+
dest_reg = sym_to_reg(fragment, dest, 1, &created);
541541
if(dest_reg == FPVM_INVALID_REG) {
542542
snprintf(fragment->last_error, FPVM_MAXERRLEN, "Failed to allocate register for destination");
543543
fpvm_parse_free(n);

0 commit comments

Comments
 (0)
Please sign in to comment.