Skip to content

Commit

Permalink
Update args in gcc_lite
Browse files Browse the repository at this point in the history
  • Loading branch information
nirmal-suthar committed May 13, 2021
1 parent f022e7e commit 50301f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@ $ pip install --ignore-installed -r ./requirements.txt
```
### For building executable
```bash
$ make
$ make clean # For removing the build
$ make
```

###For running the compiler:
### For running the compiler:

```bash
./bin/gcc_lite [-o outfile] <input_file>` eg. `./bin/parser tests/helloworld.c`
./bin/gcc_lite [-o outfile] tests/helloworld.c
```

### For more informations about usage
```bash
usage: gcc_lite [-h] [--input INPUT] [-d] [-o OUT] [-l] [-D] [-p] [-I] [--sym] [-S] [-R]
usage: gcc_lite [-h] [-d] [-o OUT] [-l] [-D] [-p] [-I] [--sym] [-S] [-R] input

Compiler for C programs

positional arguments:
input C program file to compile

optional arguments:
-h, --help show this help message and exit
--input INPUT C program file to parse
-d, --debug Generate assembly with extra information (for debugging purposes)
-o OUT, --out OUT File name to store generated executable
-l, --lex Store output of lexer
Expand All @@ -47,7 +49,6 @@ optional arguments:
-R, --exec Execute the generated program
```


## Features

### Basic Features
Expand Down
30 changes: 15 additions & 15 deletions src/gcc_lite.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def arg_parser():
argparser = ArgumentParser(prog='gcc_lite',
description='Compiler for C programs')

argparser.add_argument('--input', type=str,
help='C program file to parse', default='../test/helloworld.c')
argparser.add_argument('input', type=str,
help='C program file to compile')

argparser.add_argument('-d', '--debug', action="store_true",
help='Generate assembly with extra information (for debugging purposes)')
Expand Down Expand Up @@ -101,12 +101,12 @@ def arg_parser():
graph.write_png(png_file)

# try generating IR and symbol table
# try:
syntax_tree.gen()
# except:
# print(bcolors.BOLD+f'{lexer.filename}:0:0'+bcolors.ENDC,end='')
# print(bcolors.FAIL+' IR Error'+bcolors.ENDC)
# exit(1)
try:
syntax_tree.gen()
except:
print(bcolors.BOLD+f'{lexer.filename}:0:0'+bcolors.ENDC,end='')
print(bcolors.FAIL+' IR Error'+bcolors.ENDC)
exit(1)

if args.sym:
sym_file = ofile + '.csv'
Expand All @@ -116,13 +116,13 @@ def arg_parser():
tac.dump_code(ir_file)

# try generating assembly from IR
# try:
asm = AssemblyGen(tac.func_code, debug=args.debug)
asm.gen_assembly()
# except:
# print(bcolors.BOLD+f'{lexer.filename}:0:0'+bcolors.ENDC,end='')
# print(bcolors.FAIL+' Code Generation Error'+bcolors.ENDC)
# exit(1)
try:
asm = AssemblyGen(tac.func_code, debug=args.debug)
asm.gen_assembly()
except:
print(bcolors.BOLD+f'{lexer.filename}:0:0'+bcolors.ENDC,end='')
print(bcolors.FAIL+' Code Generation Error'+bcolors.ENDC)
exit(1)

# dump the assembly!

Expand Down

0 comments on commit 50301f6

Please sign in to comment.