Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

fpvm: support source-only binding

  • Loading branch information...
commit 0aeb5c121000b3e035c0f33dc203dfe17a44f3df 1 parent 50436b5
Sébastien Bourdeauducq authored
6  software/include/fpvm/fpvm.h
@@ -51,6 +51,12 @@ struct fpvm_tbinding {
51 51
 	char sym[FPVM_MAXSYMLEN];
52 52
 };
53 53
 
  54
+enum {
  55
+	FPVM_BIND_NONE,
  56
+	FPVM_BIND_SOURCE,
  57
+	FPVM_BIND_ALL
  58
+};
  59
+
54 60
 struct fpvm_fragment {
55 61
 	char last_error[FPVM_MAXERRLEN];
56 62
 	fpvm_bind_callback bind_callback;
10  software/libfpvm/fpvm.c
@@ -68,7 +68,7 @@ void fpvm_init(struct fpvm_fragment *fragment, int vector_mode)
68 68
 	fragment->next_sur = -3;
69 69
 	fragment->ninstructions = 0;
70 70
 
71  
-	fragment->bind_mode = 0;
  71
+	fragment->bind_mode = FPVM_BIND_NONE;
72 72
 	fragment->vector_mode = vector_mode;
73 73
 }
74 74
 
@@ -172,14 +172,14 @@ static int rename_reg(struct fpvm_fragment *fragment, const char *sym, int reg)
172 172
 	return 1;
173 173
 }
174 174
 
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)
176 176
 {
177 177
 	int r;
178 178
 	if(created) *created = 0;
179 179
 	r = lookup(fragment, sym);
180 180
 	if(r == FPVM_INVALID_REG) {
181 181
 		if(created) *created = 1;
182  
-		if(fragment->bind_mode)
  182
+		if((fragment->bind_mode == FPVM_BIND_ALL) || ((fragment->bind_mode == FPVM_BIND_SOURCE) && !dest))
183 183
 			r = fpvm_bind(fragment, sym);
184 184
 		else
185 185
 			r = tbind(fragment, sym);
@@ -332,7 +332,7 @@ static int compile(struct fpvm_fragment *fragment, int reg, struct ast_node *nod
332 332
 	if(node->contents.branches.a == NULL) {
333 333
 		/* AST node is a variable */
334 334
 		if(fragment->bind_mode) {
335  
-			opa = sym_to_reg(fragment, node->label, NULL);
  335
+			opa = sym_to_reg(fragment, node->label, 0, NULL);
336 336
 			if(opa == FPVM_INVALID_REG) return FPVM_INVALID_REG;
337 337
 		} else {
338 338
 			opa = lookup(fragment, node->label);
@@ -537,7 +537,7 @@ int fpvm_assign(struct fpvm_fragment *fragment, const char *dest, const char *ex
537 537
 		fragment->next_sur--;
538 538
 		created = 1;
539 539
 	} else
540  
-		dest_reg = sym_to_reg(fragment, dest, &created);
  540
+		dest_reg = sym_to_reg(fragment, dest, 1, &created);
541 541
 	if(dest_reg == FPVM_INVALID_REG) {
542 542
 		snprintf(fragment->last_error, FPVM_MAXERRLEN, "Failed to allocate register for destination");
543 543
 		fpvm_parse_free(n);

0 notes on commit 0aeb5c1

Please sign in to comment.
Something went wrong with that request. Please try again.