Commit bf877941 authored by Christoph Reichenbach's avatar Christoph Reichenbach
Browse files

Updated docs

parent 73b8056c
......@@ -81,48 +81,49 @@ The expected deliverables are:
For each variable that is a `nonnull`, you will print:
- One line for each location it *MAY* points to, with
- One line for each location it *MAY* point to, with
- The line and column of allocation site of the variable
- If it can point to null, the line and column where the null was created.
- An error message if the variable may be assigned `null`.
- An suitable marker if the variable may be assigned `null`.
- We consider that integers are objects.
- `nonnull` variables here include formal parameters, return values, and the parameters to the special
operations for array indexing and field load/store.
Note: change the output format to support this?
For example:
The format follows the structure::
```
<update-kind> <line-number> <column-number> -> obj <line-number> <column-number>
<update-kind> <line-number> <column-number> -> null <line-number> <column-number>
<update-kind> <line-number> <column-number> -> obj <pto-line-number> <pto-column-number>
<update-kind> <line-number> <column-number> -> null <pto-line-number> <pto-column-number>
```
Here:
- `<update-kind>` It represents the type non-null variable.
- if the variable is used as an index in array indexing, print `NI`.
- if the variable is an array used in array indexing, print `NA`.
- if you are trying to access the field of an object that is null, print `NO`.
- Otherwise, print `N`
- `<update-kind>` It represents the kind of the non-null operation.
- For array indexes (`i` in `a[i]`), print `NI`.
- For arrays that we are indexing in an array indexing expression (`a` in `a[i]`), print `NA`.
- For the base object in a field access (`o` in`o.x`), print `NO`.
- For writes to `nonnull` fields, print `NF`.
- Otherwise (parameters, returns, local/global variable assignments), print `N`
You may print other lines (e.g. for debugging), as long as they do not start with `N`.
- `obj` means that the variable points to an object
- `null` means that it points to a null literal. You must keep track of the source location of that particular `null` literal. Hence it has a line number and a column number.
- `<line-number>` is the line in which the operation takes place. If there is no line number, instead write the string "`-`" (without quotes) here.
- `<column-number>` is the column in which the operation takes place. If there is no column number, write `BBi` where `i` is the number of the basic block you are in.
- `<line-number>` and `<column-number>` are the start line/column of the relevant operation.
- `<pto-line-number>` and `<pto-column-number>`, analogously, are the line and column of the allocation or the `null` literal in question.
#### Example
If you analyze the following file:
```
type Pair(fst : nonnull int, snd : int);
type Pair(fst : nonnull int, snd : int); // line 1
fun null_producer(n : int) = if (n == 0) { return null; } else { return n; }
fun main(n : int) = {
var p : Pair := new Pair(0, 1);
var p : Pair := new Pair(5, 1);
p.snd := null; // this should be fine
p.fst := null_producer(n);
return p.fst;
......@@ -132,20 +133,21 @@ fun main(n : int) = {
Your analysis should print the following:
```
N 1 10 -> obj 6 29
N 1 10 -> null 3 50
NF 6 29 -> obj 6 29
NF 8 4 -> null 3 50
```
Where:
- `N` means one variable points to null.
- `1 10` refers to the source location of `fst`
- `obj 6 29` refers to the literal `0`
- `null 3 50` is the source location where `null` was created.
- `NF` means that we are talking about an assignment to a nonnull field
- `6 29` refers to the source location that Teal associates with the initial field assignment
- `obj 6 29` refers to the literal number `5`
- `8 4` is the source location of the second assignment
- `null 3 50` is the source location in which `null` occurs in `null_producer` (from which it can make its way into `p.fst`).
Likewise, for the input:
```
fun main() = {
fun main() = { // line 1
var a := null;
a.x := 1;
}
......@@ -154,7 +156,7 @@ fun main() = {
Your analysis should print:
```
NO 2 8 -> null 2 13
NO 3 4 -> null 2 13
```
## Hints and Starting Points
......@@ -163,11 +165,14 @@ The [README.md](README.org) file contains some high-level pieces of
information about Teal and pointers to good starting points. In
addition, you may find the following files worth investigating:
- [Compiler.java](compiler/teal0/java/lang/Compiler.java) is the main
entry point.
- Start small.
- [Compiler.java](compiler/teal0/java/lang/Compiler.java) is the main entry point.
- [NullPointerAnalysis.jrag](ir/teal2/analysis/NonNullPointerAnalysis.jrag) is a skeleton for implementing the Analysis.
- [The IR AST Definition](ir/teal0/ast/ir.ast)
- [The IR Improvements for Teal-2](ir/teal2/ast/object.ast) contains so more AST nodes for the Teal-2 IR.
- [The IR Improvements for Teal-2](ir/teal2/ast/object.ast) contains some more AST nodes for the Teal-2 IR.
- Recall that Andersen's algorithm connects nodes `n` and `n.☐` (used for field accesses).
- Andersen's algorithm collects information about variables and memory locations, while we ask you for information about IR instructions. Note that the latter all operate on IRVars.
Make sure to map all Andersen concepts to Teal.
### Debugging
......@@ -175,7 +180,7 @@ You can print TEAL IR with the line numbers using the flags `-g` and `-s`.
### Arrays in TEAL
Keep in mind that in TEAL, arrays and indexes are automatically `nonnull`.
Keep in mind that in TEAL, arrays and indexes are automatically `nonnull`:
Therefore:
```
......@@ -187,9 +192,11 @@ Can fail because:
- `i` is null
- `x` is null and the element type of `a` is `nonnull <something>`.
The same applies to field accesses.
### Builtin Functions
Builtins should not return null, except `print`, but that case can be ignored.
Builtins don't return `null`, except `print`, but you can ignore this case.
## Resources
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment