-
Notifications
You must be signed in to change notification settings - Fork 0
Midterm #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
|
||
| TIP (Tiny Imperative Programming) 언어를 파싱하여 AST를 생성하고, CFG/ICFG를 구성한 뒤 Interval Analysis(Widening/Narrowing 포함)를 수행합니다. 결과는 Graphviz DOT(및 선택적 PDF)와 JSON으로 출력됩니다. | ||
|
|
||
| ## 구현 내용 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구현 언어 - Typescript
추가 1, 2, 3, 4 - 구현
추가 5 - 미구현
데모 보여주기
테스트 파일과 분석 결과를 동시에 보여주면서 설명
사실 코드를 잘 짜면 TIP 코드에 assert 없이 control sensitive analysis를 수행하도록 할 수 있음
| @@ -0,0 +1,73 @@ | |||
| TIP { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIP 문법 명시파일
기존 TIP 구문에서 포인터 & 레코드 제외
ohm 파일로 문법을 작성해놓으면 parser에서 ohm-js 라이브러리를 통해 ast로 파싱
| @@ -0,0 +1,468 @@ | |||
| import TIPParser from "./parser"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
visit count를 계산하여 widening을 하는 방법.
정확도는 떨어질 수 있어도 구현이 간단
각 노드마다 방문한 횟수를 기록
만약 k번 이상 방문한 노드일 때
-> 범위가 증가하면 [..., inf]로 설정
-> 범위가 감소하면 [-inf, ...]로 설정
하지만 정확도가 상수추출 방법보다 떨어진다는 단점이 있음
| @@ -0,0 +1,368 @@ | |||
| import * as ohm from "ohm-js"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드를 AST 형태로 바꾸는 코드
코드를 CFG로 바꾸던, ICFG로 바꾸던 AST는 동일하기 때문에 2, 3주차 내용과 겹치므로 예시 하나만 보여주고 설명은 넘어감
| - Ubuntu: `sudo apt-get install graphviz` | ||
| - Windows: `https://graphviz.org/download/` | ||
|
|
||
| ## 실행 방법 (통합) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
설명 순서: grammar -> parser -> tip-icfg-converter -> interval analysis (iteration) -> interval analysis
| } | ||
| } | ||
| } | ||
| env.set(ns(calleeName, "@ret"), Interval.bottom()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ret 변수는 bottom으로 초기화
| env.set(ns(calleeName, "@ret"), Interval.bottom()); | ||
| return env; | ||
| } | ||
| if (label === "return") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엣지 라벨이 return일 때 @ret값만 저장된 env를 반환
| return outEnv; | ||
| } | ||
|
|
||
| while (worklist.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
worklist를 순회하며 빌 때까지 반복 (상수 추출을 한 값으로만 범위를 표현해 Widening)
| out: ser(newOut), | ||
| }); | ||
| outMap.set(n, newOut); | ||
| for (const s of succs.get(n) || []) worklist.push(s.to); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약 노드의 succ가 있을 경우 worklist에 푸시
|
|
||
| // Narrowing phase: when widening reached a fixed point, re-run without widening | ||
| // until a (potentially) more precise fixed point is reached. | ||
| let changed = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Narrowing단계
상수 추출한 범위로 표현하지 않고(normalize 하지 않고) 범위 계산
Narrowing이 안끝날수도 있지만 현재 분석기에서는 그런 경우는 없다고 가정
MGPOCKY
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional comments
| const worklist: number[] = Array.from(icfg.nodes.keys()); | ||
| const trace: any[] = []; | ||
|
|
||
| function transfer(nodeId: number, inEnv: Env): Env { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transfer - Assignment 등 구문에서 interval 업데이트
| return env; | ||
| } | ||
|
|
||
| function edgeTransfer(from: number, to: number, outEnv: Env): Env { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이전 노드로부터 값(env) 복사
| return outPath; | ||
| } | ||
|
|
||
| export default analyzeIntervals; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
구현 시 느낀점
- 현재 TIP 문법은 함수의 맨 마지막에 유일한 return이 있다고 가정함.
- 조건문이나 반복문에서 return이 있을 경우 고려해야 할 사항이 더 많아짐 (특히 ICFG에서, 특히특히 Context-sensitive한 분석에서)
| if (id.sourceString === "assert") { | ||
| return { | ||
| type: "AssertStatement", | ||
| condition: args.children[0].toAST()[0], | ||
| } as AssertStatement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
만약 호출한 함수의 이름이 assert일 경우 assert statement로 취급
No description provided.