Code Monkey home page Code Monkey logo

cminus's Issues

[Project 3] Exception handling

  • 선언되지 않은 변수나 함수는 사용 불가
  • 함수, 함수 파라미터 선언 시 중복된 이름 check
  • 변수나 parameter 선언 시 void type으로 선언할 수 없음.
  • 변수나 parameter 선언 시 array 변수인지 확인해야 함.
  • 변수에 값을 assign 하는 경우 type에 대한 check
  • 변수가 array인 경우 array index가 int가 아닌 경우
  • array가 아닌 변수를 array처럼 사용하려 하는 경우
  • 함수 호출 시 parameter의 개수와 type이 일치하는지 check
  • 함수 호출 시 호출된 것이 함수가 맞는지 (즉 변수 등이 아니었는지) 확인해야
  • 함수의 return 값과 return type이 일치하는지 check
  • 함수의 return type이 void일 경우 return이 없어야 함
  • main함수는 가장 마지막에 선언되어야 함
  • main함수는 반드시 void로 선언되어야 함
  • main함수는 반드시 parameter가 존재하지 않는다.
  • loop문의 반복 조건을 표시하는 부분에 오는 statement는 int값을 가질 수 있어야 한다.

[Project 3] Makefile 고치기 & 개선

현재 폴더 구조를 바꿈으로서 make가 작동하지 않음.

+) 그리고 태승이가 원래 makefile 짰던 것 처럼 뭔가 더 다듬어지면 좋을 것 같기도함.

return 시점에 stack 정리하는 문제

현재 코드가 틀림.
고쳐야 하는 부분:
void codeGen()의 FunctionDeclarationK
int localCodeGen()의 ReturnStatementK

현재 코드는 개판으로 되어있으니, 저 두 부분은 사실상 갈아엎어야 하는데,
localCodeGen()의 type이 int고 parameter으로 stack size를 받는 이유는 그래야지 해당 cmpd stmt에서 스택을 얼마나 썼는지 알 수 있고, return 시점에서 해당 stack을 모두 비울 수 있음
원래는 return 시점마다 stack clean하는 코드가 박히게 되는데, 현재 해당 설계상 이론적으로도 불가능하고, 사실 말도 안됨. 그러므로 현재 구현해야 하는 것은

  • FunctionDeclarationK의 stack cleanup 시점에 label 하나 더 추가 (main_cleanup, main_end 등...)
  • ReturnStatementK에서는 이상한 헛 짓 말고 위 label로 Jump하는 코드 한 줄만 generate되게 함
  • CompoundStatementK에서는 현재 코드 그대로 가도 괜찮을 것 같음. cmpd_stmt 내에서 선언된 local variable들만 날려주면 됨. 그러면 FunctionDeclarationK의 line 91에 안들어오는게 보장됨. (<-- 확인필요)

Makefile 관련 issue들

  1. –std=iso9899:1999 flag 붙이는게 좋을 듯.
    std별로 가능한게 달라서 확실히 픽스해야 할 듯.

  2. Warning 가능한거 다 띄우는게 개발하기 편할 듯.
    솔직히 -Wtraditional까지는 필요없는데, 나머지는 흔히 하는 실수들을 컴파일 중에 잡아줄 수 있어서 좋은 듯.
    ex) make debug 라고 할 경우 해당 flag 다 붙여서 빌드
    –Wall
    –pedantic
    -Wtraditional
    -Wshadow
    -Wpointer-arith
    -Wcast-qual
    -Wcast-align
    -Wstrict-prototypes
    -Wmissing-prototypes
    -Wconversion

어떻게 생각함? @taeguk @taeseunglee

input, output 문제

매우 짜증나는 문제임.

  1. 입출력 형태
    주어진 문서에서는 콘솔창에서 아래 코드를
output(100);
output(10);

아래와 같이 출력하라고 되어있다.

Output : 100
Output : 10

Input은 안써있다 ㅡㅡ
조교님한테 메일을 보내던, Input : 도 출력해주던, 해결을 봐야 할 듯.

  1. input, output 함수를 쓰면 현재 코드 베이스에서는 semantic analysis 시점에서 걸림
int input(void);
void output(int);
  • input, output 두 함수를 마치 이미 선언되어있는 것과 같이 해야 함. hash table에 전역으로 넣어놓으면 될 것 같은데, semantic analysis 후 출력될 때는 두 함수가 나오면 안되나? 이상하니까 그냥 hash table을 출력하지 않는 걸로 하자.
  • cgen의 localCodeGen 함수에서 CallK case에서, 해당 함수 이름이 input이나 output인 경우 따로 빼내야 함. asm으로 어떻게 구현할지는 #20 참고.

Bug들...

int intFunc(void)
{
  int a;
 if (a)
 {
      a;
 }
}

프로그램 사망.(더블 프리 에러)
st_pop_scope()를 주석처리 해봤더니, a;에서 선언하지 않았다고 함.

그리고

  • 함수의 리턴타입과 실제 리턴 타입이 다르다고 나온다는 문제
  • 첫번째 함수 이후로 함수의 nodekind가 단순히 compound statement로 나옴.

SPIM Implementations

If

if(test_expr) {
  true_stmt;
}
else {
  false_stmt;
}
test_expr               ; returns to Rsrc
beqz Rsrc, L_false      ; if zero, goto L_false
true_stmt               ; fallthrough
J L_exit                ; exit if-else stmt
L_false:
false_stmt
L_exit:

While

while(test_expr) {
  stmt;
}
J L_cmp      ; jump only first time
L_loop:
stmt;
L_cmp:
test_expr     ; returns to Rsrc
bnez Rsrc, L_loop

Function call

f(arr, var);  // array: arr, variable: var
# 1. Parameter pushing: 뒤에서부터 차례대로 sp-4, sp-8, sp-12... 
# var: 원본 값을 푸쉬
 

System call

i = input(); // integer input
output(i);   // integer output
.data
newline: .asciiz "\n"
.text

; input
li $v0, 5 ; read_int
syscall   ; returns value as int

; output
li $a0, $v0
li $v0, 1 ; print_int
syscall
li $v0, 4 ; print_str
la $a0, newline
syscall

Misc.

main 함수 explicit하게 불러주어야 하나?

.globl main # Is this necessary?
.text
; Every code ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.