[09ababb7] | 1 | /*
|
---|
| 2 | * Copyright (c) 2010 Jiri Svoboda
|
---|
| 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 9 | * - Redistributions of source code must retain the above copyright
|
---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 13 | * documentation and/or other materials provided with the distribution.
|
---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
---|
| 15 | * derived from this software without specific prior written permission.
|
---|
| 16 | *
|
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @file Main module. */
|
---|
| 30 |
|
---|
| 31 | #include <stdio.h>
|
---|
| 32 | #include <stdlib.h>
|
---|
| 33 | #include "ancr.h"
|
---|
| 34 | #include "builtin.h"
|
---|
[37f527b] | 35 | #include "imode.h"
|
---|
[09ababb7] | 36 | #include "mytypes.h"
|
---|
| 37 | #include "strtab.h"
|
---|
| 38 | #include "stree.h"
|
---|
[39e8406] | 39 | #include "stype.h"
|
---|
[09ababb7] | 40 | #include "input.h"
|
---|
| 41 | #include "lex.h"
|
---|
| 42 | #include "parse.h"
|
---|
| 43 | #include "run.h"
|
---|
| 44 |
|
---|
| 45 | void syntax_print(void);
|
---|
| 46 |
|
---|
| 47 | int main(int argc, char *argv[])
|
---|
| 48 | {
|
---|
| 49 | input_t *input;
|
---|
| 50 | lex_t lex;
|
---|
| 51 | parse_t parse;
|
---|
| 52 | stree_program_t *program;
|
---|
[39e8406] | 53 | stype_t stype;
|
---|
[09ababb7] | 54 | run_t run;
|
---|
| 55 | int rc;
|
---|
| 56 |
|
---|
[37f527b] | 57 | if (argc == 1) {
|
---|
| 58 | /* Enter interactive mode */
|
---|
| 59 | strtab_init();
|
---|
| 60 | imode_run();
|
---|
| 61 | return 0;
|
---|
| 62 | }
|
---|
| 63 |
|
---|
[09ababb7] | 64 | if (argc != 2) {
|
---|
| 65 | syntax_print();
|
---|
| 66 | exit(1);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[37f527b] | 69 | rc = input_new_file(&input, argv[1]);
|
---|
[09ababb7] | 70 | if (rc != EOK) {
|
---|
[fa36f29] | 71 | printf("Failed opening source file '%s'.\n", argv[1]);
|
---|
[09ababb7] | 72 | exit(1);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | strtab_init();
|
---|
| 76 | program = stree_program_new();
|
---|
| 77 | program->module = stree_module_new();
|
---|
| 78 |
|
---|
| 79 | /* Declare builtin symbols. */
|
---|
| 80 | builtin_declare(program);
|
---|
| 81 |
|
---|
| 82 | /* Parse input file. */
|
---|
| 83 | lex_init(&lex, input);
|
---|
| 84 | parse_init(&parse, program, &lex);
|
---|
| 85 | parse_module(&parse);
|
---|
| 86 |
|
---|
| 87 | /* Resolve ancestry. */
|
---|
| 88 | ancr_module_process(program, parse.cur_mod);
|
---|
| 89 |
|
---|
[39e8406] | 90 | /* Type program. */
|
---|
| 91 | stype.program = program;
|
---|
| 92 | stype_module(&stype, program->module);
|
---|
| 93 |
|
---|
[09ababb7] | 94 | /* Run program. */
|
---|
| 95 | run_init(&run);
|
---|
| 96 | run_program(&run, program);
|
---|
| 97 |
|
---|
| 98 | return 0;
|
---|
| 99 | }
|
---|
| 100 |
|
---|
| 101 | void syntax_print(void)
|
---|
| 102 | {
|
---|
| 103 | printf("Missing or invalid arguments.\n");
|
---|
| 104 | printf("Syntax: sbi <source_file.sy>\n");
|
---|
| 105 | }
|
---|