Skip to content

Commit

Permalink
Merge pull request #42 from Kray-G/develop
Browse files Browse the repository at this point in the history
issue #7: updated README, and so on.
  • Loading branch information
Kray-G authored Nov 5, 2019
2 parents d234f72 + 5df333e commit 34f51b3
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 9 deletions.
78 changes: 71 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,41 @@ Here is the basic block diagram of KCCI.

## Usage

### Run on the x64 JIT
### Command Line Interface

#### Run Options

The option `-x` will be used by default when no option specified.

```
-x Run by VM code. (use this when no options specified)
-j Run by x64 JIT code.
```

#### Input Options

```
-I Add directory to search for included files.
-D X[=] Define macro, optionally with a value.
```

#### Output Options

The program will be not run when using one of output options.

```
-E Output preprocessed code to stdout.
-J Output x64 code assembled by JIT to stdout.
-X Output VM code to stdout.
-s Output GNU style textual x64 assembly to `.s` file.
-dot Output IR call flow graph in dot format to `.dot` file.
```

## Examples

### How to Run

#### Run on the x64 JIT

For JIT use the option `-j`.
Use the option `-J` if you want to see the x64 assembly code.
Expand All @@ -141,7 +175,7 @@ $ kcc -j program.c
$ kcc -J program.c
```

### Run on the VM
#### Run on the VM

No options or use the option `-x` to run on the VM.
Use the option `-X` if you want to see the VM instructions.
Expand All @@ -154,7 +188,13 @@ $ kcc -x program.c
$ kcc -X program.c
```

## Examples
### Output Call Flow Graph

This is `lacc`'s functionality, but `kcc` can do it also.
Here is the output of call flow graph for switch-case assembled as a jump table.
Please see [here](doc/technical.md) for the detail of a jump table.

![JumpTable](doc/images/switch-case3.png)

### Fibonacci

Expand All @@ -175,6 +215,30 @@ int main()
}
```
#### Dot Output
Although the labels, variable names, and line breaks have been changed for easy to understand,
the output is like below.
```c
digraph {
node [fontname="Courier_New",fontsize=10,style="setlinewidth(0.1)",shape=record];
edge [fontname="Courier_New",fontsize=10,style="setlinewidth(0.1)"];
label="fib"
labelloc="t"
L1 [label="{ \.L1 | if 3 \> n goto \.L2 }"];
L3 [label="{ \.L3 | .t1 = n - 2 | param .t1 | .t2 = call &fib |
.t3 = n - 1 | param .t3 | .t4 = call &fib | return .t2 + .t4 }"];
L2 [label="{ \.L2 | return n }"];
L1:s -> L3:n;
L1:s -> L2:n;
}
```

The image is like this.

![fib.c](doc/images/fib.png)

#### Execution Sample

The results are below.
Expand All @@ -195,9 +259,11 @@ For the reference, it shows a result of Ruby and Python.

| | KCCI VM(64bit) | KCCI JIT(x64) | Ruby 2.4.0 | Ruby 2.6.3 | Python 2.7.13 |
| --------- | :------------: | :-----------: | :--------: | :--------: | :-----------: |
| `fib(34)` | 0.718 | **0.062** | 1.171 | 0.734 | 1.578 |
| `fib(34)` | 0.453 | **0.062** | 1.171 | 0.734 | 1.578 |

Ruby 2.6.3 is very fast against my expectations.
I was able to make my VM faster than Ruby this time,
but Ruby 2.6.3 is very fast against my expectations in spite of no type information.
Of course x64 JIT code is 7x or 8x faster than that VM code.

#### Compiled Code

Expand Down Expand Up @@ -303,8 +369,6 @@ I have a plan to do the followings when I have a time.
* [ ] Adding a library of JSON Parser.
* [ ] Adding a library with libCurl.
* [ ] Supporting encryption of Zip/Unzip.
* [ ] One instruction for increment and decrement.
* [ ] Combining VM instructions to improve the performance.

## License

Expand Down
Binary file modified doc/images/fib.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions doc/technical.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ The above example code is compiled as below.
> Don't care about a big label number and a difference label between the graph and the assemble code.
As you see, I also added the code to output the dot.
Note that the values from 1 to 8 is mapped to the values from 0 to 7
because it subtract the minimum value, which is 1.
![BinarySearch](images/switch-case3.png)
Expand Down Expand Up @@ -216,7 +218,7 @@ When it is the VM code, see below.
```

Notes: The threshold between items are that the interval each item is less than 16 now.
If there is the interval over threshold, then use binary search algorithm.
If there is the interval over threshold, then use a binary search algorithm.
Threfore I prefer you change the code if you write the code like below.

```c
Expand Down Expand Up @@ -254,7 +256,7 @@ I may try the improvement for this, if I have time.

## Calling convention between Microsoft x64 and System V

This is only for Windows, and not for Linux.
This is only for Windows, and not necessary for Linux.
Basically, the differences between conventions are below.

| | Arg(1) | Arg(2) | Arg(3) | Arg(4) | Arg(5) | Arg(6) | ... and more |
Expand Down
12 changes: 12 additions & 0 deletions samples/fib.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
digraph {
node [fontname="Courier_New",fontsize=10,style="setlinewidth(0.1)",shape=record];
edge [fontname="Courier_New",fontsize=10,style="setlinewidth(0.1)"];
label="fib"
labelloc="t"
L1 [label="{ \.L1 | if 3 \> n goto \.L2 }"];
L3 [label="{ \.L3 | .t1 = n - 2 | param .t1 | .t2 = call &fib |
.t3 = n - 1 | param .t3 | .t4 = call &fib | return .t2 + .t4 }"];
L2 [label="{ \.L2 | return n }"];
L1:s -> L3:n;
L1:s -> L2:n;
}

0 comments on commit 34f51b3

Please sign in to comment.