[hackers] [scc] [cc2] Add basic implementation of defsym() || Roberto E. Vargas Caballero
commit 70a260148ff33185ce8e70b3dbd46a15c0ff5aaf
Author: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
AuthorDate: Mon Apr 4 09:27:01 2016 +0200
Commit: Roberto E. Vargas Caballero <roberto.vargas_AT_igrid-td.com>
CommitDate: Mon Apr 4 09:27:01 2016 +0200
[cc2] Add basic implementation of defsym()
This is a first implementation which a limited implementation of
sigil() and of size2asm() that, for instance, does not support
strings.
diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index 7c75e3a..1d3d0d7 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
_AT_@ -6,10 +6,71 @@
#include "../../cc2.h"
#include "../../../inc/sizes.h"
+/*
+ * : is for user-defined Aggregate Types
+ * $ is for globals (represented by a pointer)
+ * % is for function-scope temporaries
+ * _AT_ is for block labels
+ */
+static char
+sigil(Symbol *sym)
+{
+ switch (sym->kind) {
+ case EXTRN:
+ case GLOB:
+ case PRIVAT:
+ case LOCAL:
+ return '$';
+ case AUTO:
+ case REG:
+ return '%';
+ default:
+ abort();
+ }
+}
+
+static void
+size2asm(Type *tp)
+{
+ char *s;
+
+ if (tp->flags & STRF) {
+ abort();
+ } else {
+ switch (tp->size) {
+ case 1:
+ s = "b\t";
+ break;
+ case 2:
+ s = "h\t";
+ break;
+ case 4:
+ s = "w\t";
+ break;
+ case 8:
+ s = "q\t";
+ break;
+ default:
+ s = "z\t%llu\t";
+ break;
+ }
+ }
+ printf(s, (unsigned long long) tp->size);
+}
void
defsym(Symbol *sym, int alloc)
{
+ if (!alloc)
+ return;
+ if (sym->kind == GLOB)
+ fputs("export ", stdout);
+ printf("data %c%s = {\n", sigil(sym), sym->name);
+ if (sym->type.flags & INITF)
+ return;
+ putchar('\t');
+ size2asm(&sym->type);
+ puts("0\n}");
}
void
Received on Mon Apr 04 2016 - 09:40:36 CEST
This archive was generated by hypermail 2.3.0
: Mon Apr 04 2016 - 09:48:20 CEST