Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,193 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program Strip block comments */
/*******************************************/
/* Constantes */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ BUFFERSIZE, 200
/*******************************************/
/* macros */
/*******************************************/
//.include "../../ficmacros64.inc" // for developper debugging
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessDebutPgm: .asciz "Program 64 bits start. \n"
szCarriageReturn: .asciz "\n"
szMessFinOK: .asciz "Program normal end. \n"
szMessBufferError: .asciz "Error : Buffer too small !!\n"
szStartComm: .asciz "/*"
szEndComm: .asciz "*/"
szString1: .asciz "/**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*/
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
/**
* Another comment.
*/
function something() {
}"
szString2: .asciz "/* toto */tutu/*truc*/etc"
.align 4
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sBuffer: .skip BUFFERSIZE
.align 4
/*********************************/
/* code section */
/*********************************/
.text
.global main
main:
ldr x0,qAdrszMessDebutPgm
bl affichageMess // start message
ldr x0,qAdrszString1
ldr x1,qAdrszStartComm
ldr x2,qAdrszEndComm
ldr x3,qAdrsBuffer
mov x4,#BUFFERSIZE
bl suppComment
ldr x0,qAdrsBuffer
bl affichageMess
ldr x0,qAdrszCarriageReturn
bl affichageMess
ldr x0,qAdrszMessFinOK
bl affichageMess
100:
mov x8,EXIT
svc #0 // system call
qAdrszMessDebutPgm: .quad szMessDebutPgm
qAdrszMessFinOK: .quad szMessFinOK
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrszMessBufferError: .quad szMessBufferError
qAdrszString1: .quad szString1
qAdrszString2: .quad szString2
qAdrszStartComm: .quad szStartComm
qAdrszEndComm: .quad szEndComm
qAdrsBuffer: .quad sBuffer
/******************************************************************/
/* test execution */
/******************************************************************/
/* x0 contains string address */
/* x1 contains start comment address */
/* x2 contains end comment address */
/* x3 contains buffer address */
/* x4 contains buffer length */
suppComment:
stp x5,lr,[sp,-16]!
stp x6,x7,[sp,-16]!
stp x8,x9,[sp,-16]!
stp x10,x11,[sp,-16]!
mov x5,#0 // indice string
mov x6,#0 // indice start comment
mov x7,#0 // comment
mov x8,#0 // indice write buffer
1:
ldrb w9,[x1,x6] // load first byte of comment start
2:
ldrb w10,[x0,x5] // load byte string
cmp x10,#0 // end string ?
beq 20f
cmp x7,#1 // comment
beq 6f
cmp x10,x9 // compare first byte and byte string
bne 5f
3:
add x6,x6,#1
ldrb w9,[x1,x6] // load oher byte of comment start
cmp x9,#0
beq 4f // end comment ?
strb w10,[x3,x8] // store byte in buffer
add x8,x8,#1
cmp x8,x4 // error size buffer ?
bge 99f
add x5,x5,#1 // load byte string
ldrb w10,[x0,x5]
cmp x10,#0 // end string ?
beq 20f
cmp x10,x9 // compare byte
beq 3b // loop other char start comment
strb w10,[x3,x8] // else store char string
add x8,x8,#1
cmp x8,x4 // end buffer ?
bge 99f
add x5,x5,#1 // increment indice string
mov x6,#0 // raz indice start comment
b 1b
4: // start comment found
sub x6,x6,#1
sub x8,x8,x6 // supp write byte buffer
mov x7,#1 // comment
add x5,x5,#1 // increment indice string
b 2b // and loop
5: // bytes inequals
strb w10,[x3,x8] // store char string
add x8,x8,#1
cmp x8,x4 // end buffer ?
bge 99f
add x5,x5,#1 // increment indice string
b 2b // and loop
6: // is comment
mov x6,#0
8:
ldrb w9,[x2,x6] // load end comment first char
9:
cmp x10,x9 // equal byte string ?
bne 10f
add x5,x5,#1
ldrb w10,[x0,x5] // load other byte
cmp x10,#0 // end string
beq 20f
add x6,x6,#1
ldrb w9,[x2,x6] // load other byte end comment
cmp x9,#0 // end end comment ?
bne 9b // no -> loop
// comment end
mov x7,#0 // raz comment
mov x6,#0 // raz indice start comment
b 1b
10: // comment not end
add x5,x5,#1
b 2b
20:
mov x10,#0 // final zero
strb w10,[x3,x8] // store char string
b 100f
99: // error
ldr x0,qAdrszMessBufferError
bl affichageMess
mov x0,#-1
100:
ldp x10,x11,[sp],16
ldp x8,x9,[sp],16
ldp x6,x7,[sp],16
ldp x5,lr,[sp],16
ret
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeARM64.inc"

View file

@ -0,0 +1,189 @@
/* ARM assembly Raspberry PI */
/* program Strip block comments */
/* REMARK 1 : this program use routines in a include file
see task Include a file language arm assembly
for the routine affichageMess conversion10
see at end of this program the instruction include */
/*******************************************/
/* Constantes */
/*******************************************/
.include "../constantes.inc"
.equ BUFFERSIZE, 200
/*******************************************/
/* macros */
/*******************************************/
//.include "../../ficmacros32.inc" @ for developper debugging
/*********************************/
/* Initialized data */
/*********************************/
.data
szMessDebutPgm: .asciz "Program 32 bits start. \n"
szCarriageReturn: .asciz "\n"
szMessFinOK: .asciz "Program normal end. \n"
szMessBufferError: .asciz "Error : Buffer too small !!\n"
szStartComm: .asciz "/*"
szEndComm: .asciz "*/"
szString1: .asciz "/**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*/
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
/**
* Another comment.
*/
function something() {
}"
szString2: .asciz "/* toto */tutu/*truc*/etc"
.align 4
/*********************************/
/* UnInitialized data */
/*********************************/
.bss
sBuffer: .skip BUFFERSIZE
.align 4
/*********************************/
/* code section */
/*********************************/
.text
.global main
main:
ldr r0,iAdrszMessDebutPgm
bl affichageMess @ start message
ldr r0,iAdrszString1
ldr r1,iAdrszStartComm
ldr r2,iAdrszEndComm
ldr r3,iAdrsBuffer
mov r4,#BUFFERSIZE
bl suppComment
ldr r0,iAdrsBuffer
bl affichageMess
ldr r0,iAdrszCarriageReturn
bl affichageMess
ldr r0,iAdrszMessFinOK
bl affichageMess
100:
mov r7,#EXIT @ program end
svc #0 @ system call
iAdrszMessDebutPgm: .int szMessDebutPgm
iAdrszMessFinOK: .int szMessFinOK
iAdrszCarriageReturn: .int szCarriageReturn
iAdrszMessBufferError: .int szMessBufferError
iAdrszString1: .int szString1
iAdrszString2: .int szString2
iAdrszStartComm: .int szStartComm
iAdrszEndComm: .int szEndComm
iAdrsBuffer: .int sBuffer
/******************************************************************/
/* test execution */
/******************************************************************/
/* r0 contains string address */
/* r1 contains start comment address */
/* r2 contains end comment address */
/* r3 contains buffer address */
/* r4 contains buffer length */
suppComment:
push {r1-r10,lr} @ save registers
mov r5,#0 @ indice string
mov r6,#0 @ indice start comment
mov r7,#0 @ comment
mov r8,#0 @ indice write buffer
1:
ldrb r9,[r1,r6] @ load first byte of comment start
2:
ldrb r10,[r0,r5] @ load byte string
cmp r10,#0 @ end string ?
beq 20f
cmp r7,#1 @ comment
beq 6f
cmp r10,r9 @ compare first byte and byte string
bne 5f
3:
add r6,r6,#1
ldrb r9,[r1,r6] @ load oher byte of comment start
cmp r9,#0
beq 4f @ end comment ?
strb r10,[r3,r8] @ store byte in buffer
add r8,r8,#1
cmp r8,r4 @ error size buffer ?
bge 99f
add r5,r5,#1 @ load byte string
ldrb r10,[r0,r5]
cmp r10,#0 @ end string ?
beq 20f
cmp r10,r9 @ compare byte
beq 3b @ loop other char start comment
strb r10,[r3,r8] @ else store char string
add r8,r8,#1
cmp r8,r4 @ end buffer ?
bge 99f
add r5,r5,#1 @ increment indice string
mov r6,#0 @ raz indice start comment
b 1b
4: @ start comment found
sub r6,r6,#1
sub r8,r8,r6 @ supp write byte buffer
mov r7,#1 @ comment
add r5,r5,#1 @ increment indice string
b 2b @ and loop
5: @ bytes inequals
strb r10,[r3,r8] @ store char string
add r8,r8,#1
cmp r8,r4 @ end buffer ?
bge 99f
add r5,r5,#1 @ increment indice string
b 2b @ and loop
6: @ is comment
mov r6,#0
8:
ldrb r9,[r2,r6] @ load end comment first char
9:
cmp r10,r9 @ equal byte string ?
bne 10f
add r5,r5,#1
ldrb r10,[r0,r5] @ load other byte
cmp r10,#0 @ end string
beq 20f
add r6,r6,#1
ldrb r9,[r2,r6] @ load other byte end comment
cmp r9,#0 @ end end comment ?
bne 9b @ no -> loop
@ comment end
mov r7,#0 @ raz comment
mov r6,#0 @ raz indice start comment
b 1b
10: @ comment not end
add r5,r5,#1
b 2b
20:
mov r10,#0 @ final zero
strb r10,[r3,r8] @ store char string
b 100f
99: @ error
ldr r0,iAdrszMessBufferError
bl affichageMess
mov r0,#-1
100:
pop {r1-r10,pc}
/***************************************************/
/* ROUTINES INCLUDE */
/***************************************************/
.include "../affichage.inc"

View file

@ -0,0 +1,19 @@
# by Artyom Bologov
H
,p
# Join all the lines to make multi-line comments searchable
g/./s/$/|/
,j
# A nice separator
a
----------------------
.
p
d
# Remove blocks comments
# (faulty heuristic, searches for non-/ chars)
g/./s/\/\*[^/]*\*\///g
g/|/s//\
/g
,p
Q

View file

@ -0,0 +1,75 @@
// Strips first nest of block comments
fn _commentstripper(mut txt: String, deliml: &str, delimr: &str) -> String {
let mut out = String::new();
if txt.contains(deliml) {
let mut indx = txt.find(deliml).unwrap();
out += &txt[..indx];
txt = txt[indx + deliml.len()..].to_string();
txt = _commentstripper(txt, deliml, delimr);
assert!(txt.contains(delimr), "Missing closing comment delimiter");
indx = txt.find(delimr).unwrap();
out += &txt[indx + delimr.len()..];
} else {
out = txt;
}
return out;
}
// Strips nests of block comments
fn commentstripper(mut txt: String, deliml: &str, delimr: &str) -> String {
while txt.contains(deliml) {
txt = _commentstripper(txt, deliml, delimr);
}
return txt.to_string();
}
fn main() {
let deliml = "/*";
let delimr = "*/";
println!("\nNON-NESTED BLOCK COMMENT EXAMPLE:");
let mut sample = r#"
/**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*/
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
/**
* Another comment.
*/
function something() {
}
"#
.to_string();
println!("{}", commentstripper(sample, deliml, delimr));
println!("\nNESTED BLOCK COMMENT EXAMPLE:");
sample = r#"
/**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*//*
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
*/
/**
* Another comment.
*/
function something() {
}
"#
.to_string();
println!("{}", commentstripper(sample, deliml, delimr));
}

View file

@ -0,0 +1,45 @@
string 0;
proc Strip(Prog); \Show Prog with comments stripped out
char Prog;
int Ch, Showing;
func GetCh;
[Ch:= Prog(0);
if Ch = 0 then exit;
Prog:= Prog+1;
];
[Showing:= true;
loop [GetCh;
if Showing then
[if Ch = ^/ then
[GetCh;
if Ch = ^* then Showing:= false
else [ChOut(0, ^/); ChOut(0, Ch)]
]
else ChOut(0, Ch);
]
else [if Ch = ^* then
[GetCh;
if Ch =^/ then Showing:= true;
];
];
];
];
Strip(" /**
* Some comments
* longer comments here that we can parse.
*
* Rahoo
*/
function subroutine() {
a = /* inline comment */ b + c ;
}
/*/ <-- tricky comments */
/**
* Another comment.
*/
function something() {
}")