Skip to content

Commit db40074

Browse files
committed
Fix: label strict syntax declaration control. Added documentation.
1 parent eb5ada3 commit db40074

83 files changed

Lines changed: 12284 additions & 77 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
### IntelliJ IDEA ###
22
out/
3+
release/
34
!**/src/main/**/out/
45
!**/src/test/**/out/
6+
.idea/
7+
src/main/resources/META-INF/
8+
bproc-cli.iml
59

610
### Eclipse ###
711
.apt_generated
@@ -25,9 +29,5 @@ bin/
2529
### VS Code ###
2630
.vscode/
2731

28-
### IDEA ###
29-
.idea/
30-
src/main/resources/META-INF/
31-
doc/
3232
### Mac OS ###
3333
.DS_Store

README.md

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,54 @@
1-
# BProC CLI - Basic Processors Compiler Command Line Interface #
2-
## Description ##
3-
BProC is a compiler for basic processor designs, it uses assembly code written in `.baspm`
1+
![](./src/main/resources/img/bproc_logo_h128.png)
2+
# BProC CLI - Basic Processors Compiler Command Line Interface
3+
4+
## Table of contents
5+
* [Table of contents](#table-of-contents)
6+
* [Description](#description)
7+
* [Installation](#installation)
8+
* [Package install](#package-install)
9+
* [JAR run](#jar-run)
10+
* [Prerequisites](#prerequisites)
11+
* [Run the .jar file](#run-the-jar-file)
12+
* [Usage](#usage)
13+
* [Arguments](#arguments)
14+
* [Actions](#actions)
15+
* [Options](#options)
16+
* [Other arguments](#other-arguments)
17+
* [Supported instruction set](#supported-instruction-set)
18+
* [Keywords](#keywords)
19+
* [TODO](#todo)
20+
* [Credit](#credit)
21+
22+
## Description
23+
BProC is a compiler for basic processor designs, it uses assembly code written in `.bpasm`
424
files. BProC-CLI is a simple command line interface for compiling assembler files `.bpasm`
525
for basic processors intended for education use. The vision of the project is to provide
626
simple way to generate RAM programs while designing basic processors.
727
The project, as it is, provide a rigid instruction set, but the goal is to provide a
828
configurable instruction set.
929

10-
## Installation ##
30+
## Installation
1131
Choose one of the options available:
12-
- Pakage install
13-
- JAR run
14-
### Package install ###
15-
1. Download one of the packages suitable for your device in the release
16-
section : <a href="https://github.com/jugubell/bproc-cli/releases">Release section</a>
32+
- [Package install](#package-install)
33+
- [JAR run](#jar-run)
34+
### Package install
35+
1. Download one of the packages suitable for your device in the Release Section
1736
2. Install the package with dnf/apt or execute installer on Windows.
1837
- Supported packages: rpm, deb, exe.
19-
- Supported architectures: x86_64, aarch64
38+
- Supported architectures: x86_64, aarch64/amd64
2039

21-
### JAR run ###
22-
#### Prerequisites ####
40+
### JAR run
41+
#### Prerequisites
2342
Java 8 or later runtime is needed to run the compiler. To verify,
2443
in the terminal run `java -version` or `java --version`.
25-
Otherwise, install the JRE for your device from <a href="https://adoptium.net/en-GB/temurin/releases?version=21">here</a>.
44+
Otherwise, install the JRE for your device from *Eclipse Adoptium* [here](https://adoptium.net/en-GB/temurin/releases?version=21).
2645

27-
#### Run the .jar file ####
46+
#### Run the .jar file
2847
The `.jar` file provided can be used to compile `.bpasm` assembly files in a terminal:
29-
1. Download the `.jar` file from the <a href="https://github.com/jugubell/bproc-cli/releases">Release section</a>
48+
1. Download the `.jar` file from the Release section.
3049
2. Run with: `java -jar bproc-cli.jar <argument(s)>`
3150

32-
## Usage ##
51+
## Usage
3352
Here is how to use the BProC-CLI:
3453
```
3554
bproc [-action <inputFile (*.bpasm)>] [optional -output <outputFileName/outputDirectory>] [optional --option <compileType>]
@@ -38,30 +57,30 @@ If you're using the JAR file:
3857
```
3958
java -jar bproc-cli.jar [-action <inputFile (*.bpasm)>] [optional -output <outputFileName/outputDirectory>] [optional --option <compileType>]
4059
```
41-
#### Arguments ####
42-
- inputFile (*.bpasm): A valid assembler file absolute or relative path with `.bpasm` extension.
43-
- outputFileName/outputDirectory: A valid output directory, if the name file
60+
#### Arguments
61+
- **inputFile (*.bpasm)**: A valid assembler file absolute or relative path with `.bpasm` extension.
62+
- **outputFileName/outputDirectory**: A valid output directory, if the name file
4463
is not provided, it will be generated.
45-
- compileType [binary|hexv3]: Type of compilation : default 'binary'
64+
- **compileType**: Type of compilation : default 'binary'
4665

47-
#### Actions ####
66+
#### Actions
4867
- `-s` : verify syntax.
4968
- `-g` : verify syntax, compile then generate the compiled code.
5069
- `-o` : verify syntax, compile and save the compiled code to a file
5170

52-
#### Options ####
53-
- `--bin` : compiles to binary [value by default]
71+
#### Options
72+
- `--bin` : compiles to binary (value by default)
5473
- `--hex` : compiles to hexadecimal
5574
- `--hexv3` : compiles to hexadecimal version 3 format (compatible for Logisim RAM)
5675
- `--vhdl` : compiles to a portion of VHDL RAM initialization signal
5776
- `--vrlg` : compiles to a portion of Verilog RAM initial bloc
5877

59-
#### Other arguments ####
78+
#### Other arguments
6079
- `--help`, `-h`, `help` : shows the help.
6180
- `--version`, `-v`, `version` : shows the version.
6281
- `--instruction-set`, `--is` : shows the supported instruction set.
6382

64-
## Supported Instruction Set ##
83+
## Supported Instruction Set
6584
This table recapitulate the current supported instruction set.
6685

6786
| Instruction | Op code | Type | Needs an operand | Description |
@@ -89,19 +108,21 @@ This table recapitulate the current supported instruction set.
89108
| ***WOR*** | 0xF400 | Hardware | No | Write output register (GPIO out) |
90109
| ***SFI*** | 0xF200 | Hardware | No | Skip the next instr. if flag FGI = 1 (Input reading flag) |
91110
| ***SFO*** | 0xF100 | Hardware | No | Skip the next instr. if flag FGO = 0 (Output writing flag) |
92-
| ***LDD*** | 0xF080 | Software | No | Load data in immediate mode |
111+
| ***LDD***\* | 0x0000 | Software | Yes | Load data in immediate mode |
93112
| ***JMP*** | 0x0000 | Software | No | Jump to label in assembly code |
113+
\* Not yet supported (instead, use .data declaration combined with LDA)
94114

95-
## Keywords ##
115+
## Keywords
96116
There are 2 keywords :
97117
- `.data` : for data declaration in RAM
98118
- `start:` : label to indicate the program start. This label is put after data declaration
99119
- `0x` prefix or `h` suffix : for addresses and values in hexadecimal
100120

101-
## TODO ##
102-
1. Integrate an SQLite database to manage a custom instruction set and configurations.
103-
2. Extend RAM use to custom RAM capacity.
104-
3. Enable software instruction from one or more hardware instruction.
121+
## TODO
122+
1. Add LDD instruction support for immediate addressing
123+
2. Integrate an SQLite database to manage a custom instruction set and configurations.
124+
3. Extend RAM use to custom RAM capacity.
125+
4. Enable software instruction from one or more hardware instruction.
105126

106-
## Credit ##
127+
## Credit
107128
Default instruction set mostly inspired from PhD lab work at University of Blida.

bproc-cli.iml

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/bpAddInOut.bpasm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
;.data 011h 5D3Ch ; delay: 1000 ms
1313

1414
start:
15-
INP
15+
RIR
1616
STA 012h
1717
CLA
1818
CLE
1919
LDA 010h
2020
ADD 012h
21-
OUT
21+
WOR
2222
CLE
2323
LDA 011h
2424

examples/bpAdd_wrong_syntax.bpasm

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; Basic processor
2+
; This program adds value of addresses
3+
; 010h and 011h and stores the result
4+
; in address 012h
5+
; ./examples/bpAdd.bpasm
6+
7+
; verify syntax with -s argument, correct and uncomment error by error indicated in comments by <<<>>>
8+
9+
.data 10h FFFFh ; <<<address should be explicitly 16bits>>>
10+
;.data 011h 014h ; <<<data should be explicitly 12bits>>>
11+
12+
;start: <<<uncomment, start: should be present when .data is declared>>>
13+
;LDAWRONG 010h ; <<<correct instruction LDA. Load address 010h to AC>>>
14+
ADD 011h ; Add AC and address 011h
15+
STA [012h] ; Store ALU result (AC) to address 012h
16+
17+
;2haltProc: ; <<<label syntax not allowed>>>
18+
HLT ; Halt the processor
19+
; end of program

examples/bpOut.bpasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
start:
1313
LDA 020h
14-
OUT
14+
WOR
1515
HLT

examples/bpShiftOut.bpasm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
start:
1515
LDA 020h ; load address 010h to AC
16-
OUT ; put AC value in GPIO_OUT
16+
WOR ; put AC value in GPIO_OUT
1717

1818
CLE
1919
LDA 021h
@@ -24,8 +24,8 @@ SZA
2424
JMP delay1
2525

2626
LDA 020h
27-
CIL ; shift left AC value
28-
OUT ; put AC value in GPIO_OUT
27+
SLA ; shift left AC value
28+
WOR ; put AC value in GPIO_OUT
2929

3030
CLE
3131
LDA 021h

examples/bpShiftOut500ms.bpasm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ LDA 033h ; init toggle state
2424
STA 034h
2525

2626
LDA 035h ; load OUT ref
27-
OUT
27+
WOR
2828
JMP delay
2929

3030
toggle:
3131
LDA 035h ; load OUT ref
32-
CIL
33-
OUT
32+
SLA
33+
WOR
3434

3535
delay:
3636
LDA 031h ; init counter

src/main/java/com/jugubell/bproccli/compiler/VerifySyntax.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import com.jugubell.bproccli.utils.*;
2828

2929
import java.util.*;
30+
import java.util.regex.Matcher;
31+
import java.util.regex.Pattern;
3032

3133
/**
3234
* The class handling the syntax verification of the code.
@@ -215,12 +217,20 @@ public boolean isSyntaxCorrect() {
215217
*/
216218
public LineType isLabel(String[] label) {
217219
String labelStr = String.join(" ", label);
218-
int indexOfColumn = label[0].indexOf(":");
219-
if(!labelStr.isEmpty() && indexOfColumn != -1) {
220-
if(!String.join(" ", label).isEmpty() && !this.instSet.containsKey(label[0].replace(":", "")) && labelStr.substring(indexOfColumn+1).trim().isEmpty()) {
220+
// int indexOfColumn = label[0].indexOf(":");
221+
222+
if(!labelStr.isEmpty()) {
223+
// if(!String.join(" ", label).isEmpty() && !this.instSet.containsKey(label[0].replace(":", "")) && labelStr.substring(indexOfColumn+1).trim().isEmpty()) {
224+
// return LineType.LABEL;
225+
// } else {
226+
// return LineType.SYNTAX_ERROR;
227+
// }
228+
Pattern labelPattern = Pattern.compile("^[A-Za-z_][A-Za-z0-9_]*:$");
229+
Matcher labelMatcher = labelPattern.matcher(labelStr);
230+
if(labelMatcher.find()) {
221231
return LineType.LABEL;
222232
} else {
223-
return LineType.SYNTAX_ERROR;
233+
return LineType.START;
224234
}
225235
} else {
226236
return LineType.SYNTAX_ERROR;

src/main/java/com/jugubell/bproccli/console/Log.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,12 @@ public static void help() {
6666
System.out.println("*****************************************************");
6767
System.out.println("**************** Help for BProC CLI *****************");
6868
System.out.println("*****************************************************");
69-
System.out.println("* *");
70-
System.out.println("* ;;;; / *");
71-
System.out.println("* ;;;; /_____ ______ _____ ______ ______ *");
72-
System.out.println("* / / / / / / / / *");
73-
System.out.println("* ;;;; /_____/ /_____/ / /_____/ /______ *");
74-
System.out.println("* ;;; / *");
75-
System.out.println("* ;; / *");
76-
System.out.println("*****************************************************");
7769
System.out.println();
7870
System.out.println("Description:");
7971
System.out.println(" BProC is a simple command line interface for compiling assembler files '.bpasm'");
8072
System.out.println(" for basic processors intended for education use.");
81-
System.out.println(" Please find the supported instruction set in: https://github.com/jugubell/bproc-cli");
82-
System.out.println(" This project is free and open source, it is licensed under the GPLv2 license.");
73+
System.out.println(" Please find related info about the project on: https://github.com/jugubell/bproc-cli");
74+
System.out.println(" This project is free and open source, and it is licensed under the GPLv2 license.");
8375
System.out.println();
8476
System.out.println("Usage:");
8577
System.out.println(" bproc [-action <inputFile (*.bpasm)>] [optional -output <outputFileName/outputDirectory>] [optional --option <compileType>]");
@@ -115,7 +107,7 @@ public static void version() {
115107
}
116108

117109
public static void instructionSet() {
118-
Globals glb = new Globals();
110+
// Globals glb = new Globals(); // for future dynamic instruction set fetch
119111
System.out.println("BProC compiler supported instruction set:");
120112
System.out.println("-------------------------------------------------------------------------------------------------------------------");
121113
System.out.println("| Instr. | Op code | Type | Needs an oprd. | Description |");
@@ -129,8 +121,8 @@ public static void instructionSet() {
129121
System.out.println("| ISZ | 0x6000 | Hardware | Yes | Increment value of addr. and skip next instr. if result=0 |");
130122
System.out.println("| CLA | 0x7800 | Hardware | No | Clear accumulator A |");
131123
System.out.println("| CLE | 0x7400 | Hardware | No | Clear flag E (carry out) |");
132-
System.out.println("| CMA | 0x7200 | Hardware | No | Logic `NOT` of accumulator A (A = Ā) |");
133-
System.out.println("| CME | 0x7100 | Hardware | No | Logic `NOT` of flag E (E = Ē) |");
124+
System.out.println("| LNA | 0x7200 | Hardware | No | Logic `NOT` of accumulator A (A = Ā) |");
125+
System.out.println("| LNE | 0x7100 | Hardware | No | Logic `NOT` of flag E (E = Ē) |");
134126
System.out.println("| SRA | 0x7080 | Hardware | No | Shift right of the accumulator A through the flag E |");
135127
System.out.println("| SLA | 0x7040 | Hardware | No | Shift left of the accumulator A through the flag E |");
136128
System.out.println("| INC | 0x7020 | Hardware | No | Increment accumulator A |");
@@ -143,9 +135,10 @@ public static void instructionSet() {
143135
System.out.println("| WOR | 0xF400 | Hardware | No | Write output register (GPIO out) |");
144136
System.out.println("| SFI | 0xF200 | Hardware | No | Skip the next instr. if flag FGI = 1 (Input reading flag) |");
145137
System.out.println("| SFO | 0xF100 | Hardware | No | Skip the next instr. if flag FGO = 0 (Output writing flag) |");
146-
System.out.println("| LDI | 0xF080 | Hardware | Yes | Load data in immediate mode |");
138+
System.out.println("| LDD* | 0xF080 | Hardware | Yes | Load data in immediate addressing mode |");
147139
System.out.println("| JMP | 0x0000 | Software | No | Jump to label in assembly code |");
148140
System.out.println("-------------------------------------------------------------------------------------------------------------------");
141+
System.out.println("* Not yet supported (instead, use .data declaration combined with LDA)");
149142
System.out.println();
150143
System.out.println("Keywords:");
151144
System.out.println("------------------------------------------------------------------------------------------------------------------");

0 commit comments

Comments
 (0)