Skip to content

Commit

Permalink
input lib (a5) partial
Browse files Browse the repository at this point in the history
  • Loading branch information
SantriptaSharma committed Dec 6, 2023
1 parent ab74829 commit 06ef9c6
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 15_A5.y
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ compound_statement:

block_item_list:
block_item
| block_item_list marker block_item { Backpatch($1, $2); $$ = $3; Backpatch($$, quads_size); Emit(JmpLabel()); }
| block_item_list marker block_item { Backpatch($1, $2); $$ = $3; Backpatch($$, quads_size); }

block_item:
declaration { $$ = NULL; }
Expand Down
1 change: 1 addition & 0 deletions A4_tests/testsimple.nc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ char ithmetic2 = charithmetic - 'd';
int arithmetic = ithmetic2 + 5;
char d = +'c';
char f = -'f';
void *thing = &GLOB;

void printf(char *c, int argv);

Expand Down
4 changes: 2 additions & 2 deletions A5_Tests/test4.nc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
int sum(int n){
int fun(int n){
if(n == 0) return n;
return sum(n-1) + n;
return fun(n-1) + n;
}

int main(){
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ l=flex
yy=bison
CFLAGS=-Werror -lfl -g

o=translator
o=compiler
lx=lexer

team=15
Expand All @@ -15,8 +15,9 @@ fname=$(team)_A$(assignment)

build: $(o)

test: build
./$(o) < $(testfile)
# TODO: write this according to spec
# test: build
# ./$(o) < $(testfile)

$(o): $(fname)_translator.o $(fname).tab.o $(lx).o compiler.o
$(CC) -o $@ $^ $(CFLAGS)
Expand All @@ -34,7 +35,8 @@ $(lx).c: $(fname).l $(fname).tab.c
$(CC) -c $^ $(CFLAGS)

clean:
rm -rf $(o)*
rm -rf $(o)
rm -rf $(o).exe
rm -rf $(lx)*
rm -rf *.o
rm -rf $(fname).tab.*
Expand Down
2 changes: 1 addition & 1 deletion createa5.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cp tex_build/15_A5.pdf .
tar -c 15_A5_translator.c 15_A5_translator.h compiler.c compiler.h 15_A5.l 15_A5.nc 15_A5.y Makefile 15_A5.pdf 15_A5_quads* -f 15_A5.tar
tar -c 15_A5_translator.c 15_A5_translator.h compiler.c compiler.h 15_A5.l 15_A5.nc 15_A5.y Makefile 15_A5.pdf 15_A5_quads* inputlib.asm -f 15_A5.tar
rm 15_A5.pdf
48 changes: 48 additions & 0 deletions inputlib.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.data
STRING1:
.string "Hello, world!\n"
.text
.globl _main
.globl printStr

_main:
# write string1 to stdout
pushl $STRING1
call printStr
addl $4, %esp

# exit w code 0
xorl %edi, %edi
movl $0x3c, %eax
syscall

printStr:
# prologue, no callee-saved registers
pushl %ebp
movl %esp, %ebp

# let's get the (32-bit) pointer out of the stack
movl 8(%ebp), %ecx
# edx will calc strlen
xorl %edx, %edx
_lenloop:
cmpb $0, (%ecx, %edx, 1)
je _lenloop_end
incl %edx
jmp _lenloop
_lenloop_end:
# edx now contains strlen
# need to write to stdout, fd = 1
movl $1, %ebx
# syscall number for write is 4 on 32-bit
movl $4, %eax

int $4
# eax contains return value from write, no. of written characters
# our calling convention dictates eax as the return value, so all
# done

# epilogue
movl %esp, %ebp
popl %ebp
ret
1 change: 1 addition & 0 deletions lexmain.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>

extern int yylex();
int y = 10;

int main() {
int c;
Expand Down

0 comments on commit 06ef9c6

Please sign in to comment.