summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2015-12-03 02:10:52 +0800
committerTing-Wei Lan <lantw44@gmail.com>2015-12-03 02:10:52 +0800
commit5835f4537ae210f83391c5d8344aa7d461de7095 (patch)
tree5ddb2750e59c58b2a2908e374ae3eb1420851e60 /src/main.c
parentf2a04b9f3810d1c19f8359bf3f1dbbe38bf07097 (diff)
downloadcompiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.gz
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.bz2
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.lz
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.xz
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.tar.zst
compiler2015-5835f4537ae210f83391c5d8344aa7d461de7095.zip
Drop all non-namespaced symbols
1. All data types and macros in headers, global variables and functions that have external linkage are namespaced. The only two files that allow non-namespaced symbols are main.c and common.h. common.h should not be included by any other headers. 2. Coding style is fixed when possible. 3. Drop unused variables or struct members. 4. 'name' macro is renamed to 'prog_name' to prevent conflicts with ast.h. 5. %union includes a CON_Type (now CcmmcValueConst) instead of a pointer to it. This prevents an unnecessary malloc. 6. Fix buffer overflow in draw.c. draw.c should not modify the input AST while generating the graph.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 77cfcc7..69acdd4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,6 +6,7 @@ typedef void* yyscan_t;
#include "ast.h"
#include "common.h"
+#include "draw.h"
#include "state.h"
#include "libparser_a-parser.h"
@@ -27,18 +28,18 @@ int main (int argc, char **argv)
{
ERR_DECL;
setlocale (LC_ALL, "");
- name = strrchr (argv[0], '/');
- name = name == NULL ? name : name + 1;
+ prog_name = strrchr (argv[0], '/');
+ prog_name = prog_name == NULL ? prog_name : prog_name + 1;
if (argc != 2) {
- fprintf(stderr, "Usage: %s SOURCE\n", name);
+ fprintf(stderr, "Usage: %s SOURCE\n", prog_name);
exit(1);
}
const char *source_name = argv[1];
FILE *source_handle = fopen(source_name, "r");
if (source_handle == NULL) {
- fprintf(stderr, "%s: %s: %s\n", name, source_name, ERR_MSG);
+ fprintf(stderr, "%s: %s: %s\n", prog_name, source_name, ERR_MSG);
exit(1);
}
@@ -51,17 +52,18 @@ int main (int argc, char **argv)
ccmmc_parser_set_in(source_handle, scanner);
switch (ccmmc_parser_parse(scanner, state)) {
case 1:
- fprintf(stderr, "%s: failed because of invalid input\n", name);
+ fprintf(stderr, "%s: failed because of invalid input\n", prog_name);
exit(1);
case 2:
- fprintf(stderr, "%s: failed because of memory exhaustion\n", name);
+ fprintf(stderr, "%s: failed because of memory exhaustion\n", prog_name);
exit(1);
default:
; // silence warnings
}
ccmmc_parser_lex_destroy(scanner);
- printGV(state->ast, NULL);
+ // Dump the AST
+ ccmmc_draw_ast(stdout, source_name, state->ast);
ccmmc_state_fini(state);
fclose(source_handle);