ref: 867af16e5a690b302707c010ca5b4b8f41a28845
parent: 33cced33c6e25614b230c0d6e53edfba1e36fc9e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Apr 21 12:11:44 EDT 2015
Simplify main in cc1 (even more) init_expression was not needed, and the goto loop could be written better with an infinite loop and a break.
--- a/cc1/expr.c
+++ b/cc1/expr.c
@@ -8,23 +8,11 @@
#define BTYPE(np) ((np)->type->op)
#define TYPE(tp) node(OTYP, (tp), NULL, NULL)
-static Symbol *zero, *one;
+extern Symbol *zero, *one;
Node *expr(void);
/* TODO: Change np1 and np2 to left and right (or l, r) */
-
-void
-init_expr(void)
-{
- static Symbol dummy0, dummy1;
-
- dummy0.type = dummy1.type = inttype;
- dummy0.u.i = 0;
- dummy1.u.i = 1;
- zero = &dummy0;
- one = &dummy1;
-}
static Node *
promote(Node *np)
--- a/cc1/lex.c
+++ b/cc1/lex.c
@@ -390,7 +390,7 @@
}
void
-open_file(const char *file)
+lexfile(const char *file)
{
if (yyin != NULL)
fclose(yyin);
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -9,8 +9,7 @@
#include "../inc/cc.h"
#include "cc1.h"
-extern void init_keywords(void),
- open_file(const char *file), init_expr(void);
+extern void ikeywords(void), lexfile(char *file);
uint8_t npromote, warnings;
jmp_buf recover;
@@ -36,13 +35,14 @@
int
main(int argc, char *argv[])
{
- char c, *input, *cp;
+ char c, *cp;
atexit(clean);
-repeat:
- --argc, ++argv;
- if (*argv && argv[0][0] == '-' && argv[0][1] != '-') {
+ for (;;) {
+ --argc, ++argv;
+ if (!*argv || argv[0][0] != '-' || argv[0][1] == '-')
+ break;
for (cp = &argv[0][1]; (c = *cp); cp++) {
switch (c) {
case 'w':
@@ -58,19 +58,15 @@
usage();
}
}
- goto repeat;
}
- if (output) {
- if (!freopen(output, "w", stdout))
- die("error opening output:%s", strerror(errno));
- }
- input = *argv;
+ if (output && !freopen(output, "w", stdout))
+ die("error opening output:%s", strerror(errno));
if (argc > 1)
usage();
- init_keywords();
- init_expr();
- open_file(input);
+
+ ikeywords();
+ lexfile(*argv);
setjmp(recover);
next();
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -105,7 +105,7 @@
}
void
-init_keywords(void)
+ikeywords(void)
{
static struct {
char *str;
--- a/cc1/types.c
+++ b/cc1/types.c
@@ -129,6 +129,11 @@
*floattype = &types[14], *doubletype = &types[15],
*ldoubletype = &types[16];
+static Symbol dummy0 = {.u.i = 0, .type = &types[9]},
+ dummy1 = {.u.i = 1, .type = &types[9]};
+Symbol *zero = &dummy0, *one = &dummy1;
+
+
Type *
ctype(int8_t type, int8_t sign, int8_t size)
{