[hackers] [scc] Add stub of cc2 || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Fri, 22 Jan 2016 15:06:56 +0100 (CET)

commit 296d4035d72e6c58a6ec532468a73eaeda4e42b5
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Jan 21 10:45:54 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Jan 21 10:45:54 2016 +0100

    Add stub of cc2
    
    This is the begin of the back end version 2.

diff --git a/Makefile b/Makefile
index 5a23e20..af19d87 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -5,7 +5,8 @@ include config.mk
 
 SUBDIRS = \
         lib \
- cc1
+ cc1 \
+ cc2
 
 all clean:
         _AT_echo scc build options:
diff --git a/cc2/Makefile b/cc2/Makefile
new file mode 100644
index 0000000..2651d3a
--- /dev/null
+++ b/cc2/Makefile
_AT_@ -0,0 +1,22 @@
+.POSIX:
+
+include ../config.mk
+
+OBJS = main.o parser.o code.o optm.o peep.o cgen.o
+
+all: cc2
+
+
+$(OBJS): cc2.h
+main.o: error.h
+
+error.h: cc2.h
+ rm -f $_AT_; trap 'rm -f $$$$.h' EXIT INT QUIT
+ awk -f generror cc2.h > $$$$.h && mv $$$$.h $_AT_
+
+cc2: $(OBJS) ../lib/libcc.a
+ $(CC) $(LDFLAGS) $(OBJS) ../lib/libcc.a -o $_AT_
+
+clean:
+ rm -f $(OBJS)
+ rm -f cc2 error.h
diff --git a/cc2/cc2.h b/cc2/cc2.h
new file mode 100644
index 0000000..9a52f3c
--- /dev/null
+++ b/cc2/cc2.h
_AT_@ -0,0 +1,31 @@
+
+enum nerrors {
+ ELNLINE, /* line too long */
+ EFERROR, /* error reading from file:%s*/
+ ENUMERR
+};
+
+typedef struct node Node;
+
+struct node {
+ unsigned char op;
+};
+
+/* main.c */
+extern void error(unsigned nerror, ...);
+
+/* parse.c */
+extern void parse(void);
+
+/* optm.c */
+extern void optimize(void);
+
+/* cgen.c */
+extern void addable(void);
+extern void generate(void);
+
+/* peep.c */
+extern void peephole(void);
+
+/* code.c */
+extern void writeout(void);
diff --git a/cc2/cgen.c b/cc2/cgen.c
new file mode 100644
index 0000000..8dc1915
--- /dev/null
+++ b/cc2/cgen.c
_AT_@ -0,0 +1,12 @@
+
+#include "cc2.h"
+
+void
+generate(void)
+{
+}
+
+void
+addable(void)
+{
+}
diff --git a/cc2/code.c b/cc2/code.c
new file mode 100644
index 0000000..48fbf84
--- /dev/null
+++ b/cc2/code.c
_AT_@ -0,0 +1,7 @@
+
+#include "cc2.h"
+
+void
+writeout(void)
+{
+}
diff --git a/cc2/generror b/cc2/generror
new file mode 100755
index 0000000..d618a0c
--- /dev/null
+++ b/cc2/generror
_AT_@ -0,0 +1,12 @@
+
+BEGIN {
+ print "char *errlist[] = {"
+}
+/^enum nerrors \{/ {inhome = 1}
+inhome && /E[A-Z]*, / {sub(/,/, "", $1)
+ printf("\t[%s] = \"", $1)
+ for (i = 3; i < NF-1; ++i)
+ printf("%s ", $i)
+ printf("%s\",\n", $(NF-1));}
+inhome && /^}/ {print "};" ; inhome = 0}
+
diff --git a/cc2/main.c b/cc2/main.c
new file mode 100644
index 0000000..3e4b3f0
--- /dev/null
+++ b/cc2/main.c
_AT_@ -0,0 +1,46 @@
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "cc2.h"
+#include "error.h"
+
+void
+error(unsigned nerror, ...)
+{
+ va_list va;
+ va_start(va, nerror);
+ vfprintf(stderr, errlist[nerror], va);
+ va_end(va);
+ putc('\n', stderr);
+ exit(1);
+}
+
+static int
+moreinput(void)
+{
+ int c;
+
+repeat:
+ if (feof(stdin))
+ return 0;
+ if ((c = getchar()) == '\n' || c == EOF)
+ goto repeat;
+ ungetc(c, stdin);
+ return 1;
+}
+
+int
+main(void)
+{
+ while (moreinput()) {
+ parse();
+ optimize();
+ addable();
+ generate();
+ peephole();
+ writeout();
+ }
+ return 0;
+}
diff --git a/cc2/optm.c b/cc2/optm.c
new file mode 100644
index 0000000..3583bbd
--- /dev/null
+++ b/cc2/optm.c
_AT_@ -0,0 +1,7 @@
+
+#include "cc2.h"
+
+void
+optimize(void)
+{
+}
diff --git a/cc2/parser.c b/cc2/parser.c
new file mode 100644
index 0000000..23a0e88
--- /dev/null
+++ b/cc2/parser.c
_AT_@ -0,0 +1,62 @@
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "cc2.h"
+
+#define MAXLINE 200
+
+static void
+push(Node * np)
+{
+}
+
+static Node *
+pop(void)
+{
+}
+
+static void
+expr(char *tok)
+{
+}
+
+static void
+stmt(Node *np)
+{
+}
+
+static void
+decl(char *tok)
+{
+}
+
+void
+parse(void)
+{
+ char line[MAXLINE];
+ size_t len;
+
+ for (;;) {
+ if (fgets(line, sizeof(line), stdin))
+ break;
+ if ((len = strlen(line)) == 0 || line[0] == '\n')
+ continue;
+ if (line[len-1] != '\n')
+ error(ELNLINE);
+ line[len-1] = '\0';
+ switch (*line) {
+ case '\t':
+ expr(strtok(line, "\t"));
+ stmt(pop());
+ break;
+ default:
+ decl(strtok(line, "\t"));
+ break;
+ }
+ }
+
+ if (ferror(stdin))
+ error(EFERROR, strerror(errno));
+}
diff --git a/cc2/peep.c b/cc2/peep.c
new file mode 100644
index 0000000..2558a58
--- /dev/null
+++ b/cc2/peep.c
_AT_@ -0,0 +1,7 @@
+
+#include "cc2.h"
+
+void
+peephole(void)
+{
+}
Received on Fri Jan 22 2016 - 15:06:56 CET

This archive was generated by hypermail 2.3.0 : Fri Jan 22 2016 - 15:12:21 CET