[hackers] [scc] [cc2-qbe] Add basic function definition support || Roberto E. Vargas Caballero
commit a0b3a0df6a6a6ff2c2e5cdc190428bb5e1e47f4c
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jul 7 16:26:32 2016 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Jul 7 16:26:32 2016 +0200
[cc2-qbe] Add basic function definition support
With this small commit we can begin to do tests, because
we can parse full functions and see what is the code generated.
diff --git a/cc2/arch/qbe/cgen.c b/cc2/arch/qbe/cgen.c
index e70ee2b..1eb0997 100644
--- a/cc2/arch/qbe/cgen.c
+++ b/cc2/arch/qbe/cgen.c
_AT_@ -130,12 +130,40 @@ bool(Node *np, Node *new, Symbol *true, Symbol *false)
}
static Node *
+function(void)
+{
+ Symbol *p;
+
+ /* allocate stack space for parameters */
+ for (p = locals; p && (p->type.flags & PARF) != 0; p = p->next)
+ code(ASALLOC, label2node(p), NULL, NULL);
+
+ /* allocate stack space for local variables) */
+ for ( ; p && p->id != TMPSYM; p = p->next) {
+ if (p->kind != SAUTO)
+ continue;
+ code(ASALLOC, label2node(p), NULL, NULL);
+ }
+ /* store formal parameters in parameters */
+ for (p = locals; p; p = p->next) {
+ if ((p->type.flags & PARF) == 0)
+ break;
+ code(ASFORM, label2node(p), NULL, NULL);
+ }
+ return NULL;
+}
+
+static Node *
rhs(Node *np, Node *new)
{
Node aux;
Symbol *label1, *label2;
switch (np->op) {
+ case OBFUN:
+ return function();
+ case OEFUN:
+ return NULL;
case OMEM:
case OAUTO:
return load(np, new);
Received on Thu Jul 07 2016 - 16:27:48 CEST
This archive was generated by hypermail 2.3.0
: Thu Jul 07 2016 - 16:36:15 CEST