Add support for DocComments that get ignored on parser (useful for big license texts)
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
DataHoarder 2021-08-03 01:49:18 +02:00
parent 5e7360b844
commit e4c90e1c53
6 changed files with 58 additions and 52 deletions

View file

@ -1,5 +1,5 @@
; Definition of registers found on FM10000 official images for comunication back with driver/manager
; Based on Intel datasheet and BSD-3 code.
;; Definition of registers found on FM10000 official images for comunication back with driver/manager
;; Based on Intel datasheet and BSD-3 code.
.reserve api_SPI_LOCK_STATE, 0x000

View file

@ -1,4 +1,4 @@
; Base platform config. These values can be overriden elsewhere.
;; Base platform config. These values can be overriden elsewhere.
.constant rrcc_SPI_TRANSFER_MODE 0
.constant rrcc_SPI_TRANSFER_SPEED 7

View file

@ -1,4 +1,4 @@
; Initialization function (aka crt0)
;; Initialization function (aka crt0)
__rrcc_init:
WRITE rrcc_STACK_POINTER, rrcc_STACK_START ; Reset Stack pointer to its starting position

View file

@ -1,5 +1,5 @@
; Definition of registers found on FM10000 ASIP
; Based on Intel datasheet and BSD-3 code.
;; Definition of registers found on FM10000 ASIP
;; Based on Intel datasheet and BSD-3 code.
.constant FATAL_CODE, %0x0
.constant LAST_FATAL_CODE, %0x1
@ -95,7 +95,7 @@
.constant LED_CFG, %0x000C2B
.constant SCAN_DATA_IN, %0x000C2D
.constant CRM_DATA_START, %0x001000 ; 2048 entries, each one 2 words
.constant CRM_DATA_START, %0x001000 ;; 2048 entries, each one 2 words
.constant CRM_DATA_END, %0x001FFF
.constant CRM_CTRL, %0x002000
.constant CRM_STATUS, %0x002001
@ -107,13 +107,13 @@
.constant CRM_IM, %0x00200C
.constant CRM_COMMAND_START, %0x002080 ; 64 entries, each one 2 words
.constant CRM_COMMAND_START, %0x002080 ;; 64 entries, each one 2 words
.constant CRM_COMMAND_END, %0x0020FF
.constant CRM_REGISTER_START, %0x002100 ; 64 entries, each one 2 words
.constant CRM_REGISTER_START, %0x002100 ;; 64 entries, each one 2 words
.constant CRM_REGISTER_END, %0x00217F
.constant CRM_PERIOD_START, %0x002180 ; 64 entries, each one 2 words
.constant CRM_PERIOD_START, %0x002180 ;; 64 entries, each one 2 words
.constant CRM_PERIOD_END, %0x0021FF
.constant CRM_PARAM_START, %0x002200 ; 64 entries, each one 1 words
.constant CRM_PARAM_START, %0x002200 ;; 64 entries, each one 1 words
.constant CRM_PARAM_END, %0x002240
.constant PLL_PCIE_CTRL, %0x2241
.constant PLL_PCIE_STAT, %0x2242
@ -171,7 +171,7 @@
.constant PM_CLKOBS_CTRL, %0xE8012
; These require offsets to be accessed
;; These require offsets to be accessed
.constant PCIE_PF_BASE, %0x100000
.constant PCIE_IB, PCIE_PF_BASE +0x13002
.constant PCIE_SERDES_CTRL_0, PCIE_PF_BASE +0x19010

View file

@ -1,36 +1,36 @@
; Standard Library
;; Standard Library
; These registers are used when passing the first two parameters to a function via FastCall
;; These registers are used when passing the first two parameters to a function via FastCall
.constant std_PARAMETER_0 MGMT_SCRATCH_0
.constant std_PARAMETER_1 MGMT_SCRATCH_1
; Also used as single return value
;; Also used as single return value
.constant std_RETURN_VALUE MGMT_SCRATCH_0
.constant std_RETURN_VALUE_EXTRA MGMT_SCRATCH_1
.constant RRET std_RETURN_VALUE ;Alias
.constant RRET_X std_RETURN_VALUE_EXTRA ;Alias
.constant RRET std_RETURN_VALUE ;;Alias
.constant RRET_X std_RETURN_VALUE_EXTRA ;;Alias
.constant P0 std_PARAMETER_0
.constant P1 std_PARAMETER_1
; These are offset registers to be called with <OP>~2 to access stack frame parameters
.constant P2 %0, +1 ; Equivalent to same address in GET <Reg>, 1
.constant P3 %0, +2 ; Equivalent to same address in GET <Reg>, 2
.constant P4 %0, +3 ; Equivalent to same address in GET <Reg>, 3
.constant P5 %0, +4 ; Equivalent to same address in GET <Reg>, 4
.constant P6 %0, +5 ; Equivalent to same address in GET <Reg>, 5
.constant P7 %0, +6 ; Equivalent to same address in GET <Reg>, 6
.constant P8 %0, +7 ; Equivalent to same address in GET <Reg>, 7
.constant P9 %0, +8 ; Equivalent to same address in GET <Reg>, 8
.constant P10 %0, +9 ; Equivalent to same address in GET <Reg>, 9
.constant P11 %0, +10 ; Equivalent to same address in GET <Reg>, 10
.constant P12 %0, +11 ; Equivalent to same address in GET <Reg>, 11
.constant P13 %0, +12 ; Equivalent to same address in GET <Reg>, 12
.constant P14 %0, +13 ; Equivalent to same address in GET <Reg>, 13
.constant P15 %0, +14 ; Equivalent to same address in GET <Reg>, 14
.constant P16 %0, +15 ; Equivalent to same address in GET <Reg>, 15
;; These are offset registers to be called with <OP>~2 to access stack frame parameters
.constant P2 %0, +1 ;; Equivalent to same address in GET <Reg>, 1
.constant P3 %0, +2 ;; Equivalent to same address in GET <Reg>, 2
.constant P4 %0, +3 ;; Equivalent to same address in GET <Reg>, 3
.constant P5 %0, +4 ;; Equivalent to same address in GET <Reg>, 4
.constant P6 %0, +5 ;; Equivalent to same address in GET <Reg>, 5
.constant P7 %0, +6 ;; Equivalent to same address in GET <Reg>, 6
.constant P8 %0, +7 ;; Equivalent to same address in GET <Reg>, 7
.constant P9 %0, +8 ;; Equivalent to same address in GET <Reg>, 8
.constant P10 %0, +9 ;; Equivalent to same address in GET <Reg>, 9
.constant P11 %0, +10 ;; Equivalent to same address in GET <Reg>, 10
.constant P12 %0, +11 ;; Equivalent to same address in GET <Reg>, 11
.constant P13 %0, +12 ;; Equivalent to same address in GET <Reg>, 12
.constant P14 %0, +13 ;; Equivalent to same address in GET <Reg>, 13
.constant P15 %0, +14 ;; Equivalent to same address in GET <Reg>, 14
.constant P16 %0, +15 ;; Equivalent to same address in GET <Reg>, 15
; Ephemeral registers to be used within functions. These values may not be kept when calling other functions. They can be used when returning values if necessary.
; Some std functions might restore these values.
;; Ephemeral registers to be used within functions. These values may not be kept when calling other functions. They can be used when returning values if necessary.
;; Some std functions might restore these values.
.constant std_EPHEMERAL_REGISTER_0 BSM_SCRATCH_START +0x1F0
.constant std_EPHEMERAL_REGISTER_1 std_EPHEMERAL_REGISTER_0 +0x1
.constant std_EPHEMERAL_REGISTER_2 std_EPHEMERAL_REGISTER_0 +0x2
@ -47,7 +47,7 @@
.constant std_EPHEMERAL_REGISTER_13 std_EPHEMERAL_REGISTER_0 +0xd
.constant std_EPHEMERAL_REGISTER_14 std_EPHEMERAL_REGISTER_0 +0xe
.constant std_EPHEMERAL_REGISTER_15 std_EPHEMERAL_REGISTER_0 +0xf
; Abbreviations
;; Abbreviations
.constant R0 std_EPHEMERAL_REGISTER_0
.constant R1 std_EPHEMERAL_REGISTER_1
.constant R2 std_EPHEMERAL_REGISTER_2
@ -66,24 +66,24 @@
.constant R15 std_EPHEMERAL_REGISTER_15
; FASTCALL uint std_multiply(uint A, uint B). Return value on RRET
; Uses simple addition
; TODO: use add + shift
;; FASTCALL uint std_multiply(uint A, uint B). Return value on RRET
;; Uses simple addition
;; TODO: use add + shift
.constant std_mul @std_multiply
.constant std_multiply @std_multiply
std_multiply:
PUSH BSM_COUNTER_0 ; Save old value of counter
MOV BSM_COUNTER_0, P0 ; Move A to counter
PUSH BSM_COUNTER_0 ;; Save old value of counter
MOV BSM_COUNTER_0, P0 ;; Move A to counter
MOV RRET, 0
JUMP @.loop ; Skip first iteration
JUMP @.loop ;; Skip first iteration
.multiply:
ADD RRET, RRET, P1 ; Add B to itself A times
.loop: LOOP @.multiply ; Check if 0, if not, decrease A and go back. Use COUNTER[0]
POP BSM_COUNTER_0 ; Restore old value of counter
RET ; Return, no need to get rid of stack as fastcall passed them on registers
ADD RRET, RRET, P1 ;; Add B to itself A times
.loop: LOOP @.multiply ;; Check if 0, if not, decrease A and go back. Use COUNTER[0]
POP BSM_COUNTER_0 ;; Restore old value of counter
RET ;; Return, no need to get rid of stack as fastcall passed them on registers
; x86-like definitions
;; x86-like definitions
.constant ebp, rrcc_FRAME_POINTER
.constant esp, rrcc_STACK_POINTER
.constant eax, RRET

View file

@ -63,6 +63,7 @@ void Parser::parse() {
Function currentFunction;
Declaration currentDeclaration;
std::string currentComment;
bool isDocComment = false;
while (true) {
try{
@ -213,14 +214,12 @@ void Parser::parse() {
if (c == '\n' || c == '\0') {
isComment = false;
isDocComment = false;
if (resetStateIndex < currentStateIndex) {
currentStateIndex = resetStateIndex;
}
if (!currentDeclaration.tokens.empty()) {
currentDeclaration.comment = currentComment;
currentComment.clear();
if (currentDeclaration.tokens.size() >= 3 &&
currentDeclaration.tokens.at(0).getType() == Token::Type::Directive) {
@ -246,6 +245,9 @@ void Parser::parse() {
currentDeclaration = Declaration();
currentStateIndex = 0;
} else {
currentDeclaration.comment = currentComment;
currentComment.clear();
currentFunction.declarations.emplace_back(std::move(currentDeclaration));
currentDeclaration = Declaration();
}
@ -265,8 +267,12 @@ void Parser::parse() {
}
} else if (!isComment) {
currentValue += c;
} else {
currentComment += c;
} else if (!isDocComment){
if(currentComment.empty() && c == ';'){ //DocComment, should not appear
isDocComment = true;
}else{
currentComment += c;
}
}
}catch (const std::exception& e){
std::cerr << "Exception: " << e.what() << " on " << currentFunction.label << " (line# " << std::dec << lineNumber << ")\n";