Commit edcf6806 authored by Masahiko Sakai's avatar Masahiko Sakai

initial

parent 9e456b9b
Translator of Psudo-Instruction Sequences (with control) into Low-Level-Assembly language.
Mar 24, 2017:
SimpleConverter recoded by Genki Sakanashi.
Also implemented a facility for array, proposed by Shohei Kobe.
Installation:
make
Execution:
./parser [-cimds] test.mg > test.mc
# Malbolge20/ternary
- Translator of Psudo-Instruction Sequences (with control) into Low-Level-Assembly language.
- An improved SimpleConverter re-coded by Genki Sakanashi on Mar 24, 2017.
### New facilities from SimpleConverter
- Array([[1]](#References)
- Function([[2]](#References)
# Getting Started
### Required packages
- [flex](https://github.com/westes/flex)
- [Bison](https://www.gnu.org/software/bison/manual/)
### Installation
```bash
make
```
### Execution
```bash
./parser [-mdcis] test.mg > test.mc
```
#### Options for code generation
- `-m`/`-d`
Specifying the control style for successive `ROT` and `OPR`-module calls.
- `-m`: Return to the main control flow before the next call
- `-d`: Shortcut to the next call
Without these options, the control style is chosen randomly for each module.
See [1] for the detail on modules
- `-c`/`-i`
Code style for `OUTPUT`, `INPUT`, `SET`, and `RESET` instructions
- `-c`: Creats modules for these instructions
- `-i`: Expands codes for these instructions into the main control flow
Without these options, the style is chosen randomly for each instruction appearences
- `-s <integer>`
Gives a random seed
# References
1. Shohei Kobe, Masahiko Sakai, Naoki Nishida, Hiroyuki Seki,
An intermediate language for a compiler generating highly obfuscated Malbolge codesm
IEICE Technical Report, Vol.116, No.127, pp.105-110 (2016). (in Japanese)
[full document (copyright(C)2016 IEICE)](https://www.trs.css.i.nagoya-u.ac.jp/Malbolge/papers/IEICE-Tech-Rep-2016Jul-Malbolge.pdf)
2. Genki Sakanashi, Shohei Kobe, Masahiko Sakai, Naoki Nishida, Kenji Hashimoto,
A compiler that translates to Malbolge from a C-language subset containing recursive calls,
IEICE Technical Report, Vol.117, No.136, pp.145-150 (2017). (in Japanese)
[full document (copyright(C)2017 IEICE)](https://www.trs.css.i.nagoya-u.ac.jp/Malbolge/papers/IEICE-Tech-Rep-2017Jul-Malbolge.pdf)
# Example of outputs
## Ex.1
A pseudo-instruction sequence
```
DEF MAIN
OUTPUT
OUTPUT
END
```
##### The resulted Low-level-assembly code generated with `-i`
```
PROGRAM_START_TO ENTRY@MAIN
FLAG 0/2, FLAG_CASE0
FLAG 0/2, FLAG_CASE1
FLAG 0/2, FLAG_CASE2
FLAG 1/2, FLAG_JMP
FLAG 0/2, FLAG_REV_OPR_ROT
ROUTINE GLOBAL{
ENTRY:
BASE:0
CON0:0
CON1:1743392200
CON2:3486784400
}
ROUTINE MAIN{
ENTRY:
OUTPUT
DUP
REV OUTPUT
OUTPUT
DUP
REV OUTPUT
END
}
```
##### The resulted Low-level-assembly code generated with `-mc`
```
PROGRAM_START_TO ENTRY@MAIN
FLAG 1/2, FLAG0
FLAG 1/2, FLAG1
FLAG 0/2, FLAG_CASE0
FLAG 0/2, FLAG_CASE1
FLAG 0/2, FLAG_CASE2
FLAG 1/2, FLAG_JMP
FLAG 0/2, FLAG_REV_OPR_ROT
ROUTINE GLOBAL{
ENTRY:
BASE:0
CON0:0
CON1:1743392200
CON2:3486784400
}
ROUTINE MAIN{
ENTRY:
NEXT FLAG0
NEXT FLAG_JMP
IF FLAG_JMP
BRANCH L_OUTPUT
JMP_BACK0:
NEXT FLAG_JMP
IF FLAG_JMP
BRANCH L_OUTPUT
LABEL0:
END
# OUTPUT-module generated due to -c
L_OUTPUT:
OUTPUT
DUP
REV OUTPUT
NEXT FLAG1
# Returns to MAIN due to -m
IF FLAG0
BRANCH JMP_BACK0
NEXT FLAG0
NEXT FLAG1
IF FLAG1
BRANCH LABEL0
NEXT FLAG1
}
```
##### The resulted Low-level-assembly code generated with `-dc`
```
PROGRAM_START_TO ENTRY@MAIN
FLAG 1/2, FLAG0
FLAG 1/2, FLAG1
FLAG 0/2, FLAG_CASE0
FLAG 0/2, FLAG_CASE1
FLAG 0/2, FLAG_CASE2
FLAG 1/2, FLAG_JMP
FLAG 0/2, FLAG_REV_OPR_ROT
ROUTINE GLOBAL{
ENTRY:
BASE:0
CON0:0
CON1:1743392200
CON2:3486784400
}
ROUTINE MAIN{
ENTRY:
NEXT FLAG0
NEXT FLAG_JMP
IF FLAG_JMP
BRANCH L_OUTPUT
LABEL0:
END
# OUTPUT-module generated due to -c
L_OUTPUT:
OUTPUT
DUP
REV OUTPUT
NEXT FLAG1
# Jump directly to the next module L_OUTPUT due to -d
IF FLAG0
BRANCH L_OUTPUT
NEXT FLAG0
NEXT FLAG1
IF FLAG1
BRANCH LABEL0
NEXT FLAG1
}
```
## Ex.2
Another pseudo-instruction sequence
```
VAR X = 300
DEF MAIN
ROT X
OPR X
END
```
##### The resulted Low-level-assembly code generated with `-i`
```
PROGRAM_START_TO ENTRY@MAIN
FLAG 1/2, FLAG0
FLAG 1/2, FLAG1
FLAG 0/2, FLAG_CASE0
FLAG 0/2, FLAG_CASE1
FLAG 0/2, FLAG_CASE2
FLAG 1/2, FLAG_JMP
FLAG 0/2, FLAG_REV_OPR_ROT
ROUTINE GLOBAL{
ENTRY:
BASE:0
CON0:0
CON1:1743392200
CON2:3486784400
OPR_U_X:
OPR U_X
ROT_U_X:
NEXT FLAG_REV_OPR_ROT
ROT
U_X:300
IF FLAG_REV_OPR_ROT
BRANCH REV_OPR_U_X
REV ROT
SKIP END_REV_U_X
REV_OPR_U_X:
REV OPR
NEXT FLAG_REV_OPR_ROT
END_REV_U_X:
NEXT FLAG1
# Jump directly to the next module OPR_U_X due to -d
IF FLAG0
BRANCH OPR_U_X
NEXT FLAG0
NEXT FLAG1
IF FLAG1
BRANCH LABEL0@MAIN
NEXT FLAG1
}
ROUTINE MAIN{
ENTRY:
NEXT FLAG0
NEXT FLAG_JMP
IF FLAG_JMP
BRANCH ROT_U_X@GLOBAL
LABEL0:
END
}
```
##### The resulted Low-level-assembly code generated with `-m`
```
PROGRAM_START_TO ENTRY@MAIN
FLAG 1/2, FLAG0
FLAG 1/2, FLAG1
FLAG 0/2, FLAG_CASE0
FLAG 0/2, FLAG_CASE1
FLAG 0/2, FLAG_CASE2
FLAG 1/2, FLAG_JMP
FLAG 0/2, FLAG_REV_OPR_ROT
ROUTINE GLOBAL{
ENTRY:
BASE:0
CON0:0
CON1:1743392200
CON2:3486784400
OPR_U_X:
OPR U_X
ROT_U_X:
NEXT FLAG_REV_OPR_ROT
ROT
U_X:300
IF FLAG_REV_OPR_ROT
BRANCH REV_OPR_U_X
REV ROT
SKIP END_REV_U_X
REV_OPR_U_X:
REV OPR
NEXT FLAG_REV_OPR_ROT
END_REV_U_X:
NEXT FLAG1
# Returns to MAIN due to -m
IF FLAG0
BRANCH JMP_BACK0@MAIN
NEXT FLAG0
NEXT FLAG1
IF FLAG1
BRANCH LABEL0@MAIN
NEXT FLAG1
}
ROUTINE MAIN{
ENTRY:
NEXT FLAG0
NEXT FLAG_JMP
IF FLAG_JMP
BRANCH ROT_U_X@GLOBAL
JMP_BACK0:
NEXT FLAG_JMP
IF FLAG_JMP
BRANCH OPR_U_X@GLOBAL
LABEL0:
END
}
```
Markdown is supported
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