-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds basic legv8 snippets #8
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are great! This is not specific to LSP; therefore, it belongs in the vscode extension repository.
https://github.com/patrickdemers6/legv8-vscode/
Ideas for other snippets that would be nice to have:
- call a procedure
- for loop
- return (it could just be an alias for
BR LR
)
snippets/legv8.json
Outdated
"body": ["EOR ${1:target reg}, $1, $1", "$2"], | ||
"description": "equivalent of CLEAR. It clears the content of a target register" | ||
}, | ||
"increment offset by 8 bits": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a command for incrementing by immediate?
Something like:
"increment by immediate": {
"prefix": "inci",
"body": ["ADDI ${1:reg}, ${1}, #${2:amount}"],
"description": "..."
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not finding this in the PR.
snippets/legv8.json
Outdated
"body": ["ADD ${1:dest reg}, XZR, $2", "$3"] | ||
}, | ||
"increment register": { | ||
"prefix": "increg", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it is only incrementing by one, would a prefix of reg++
or inc_1
make more sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed that snippet also
"set register to": { | ||
"prefix": "sreg", | ||
"body": ["ADD ${1:dest reg}, XZR, $2", "$3"] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add description for all of them. Also try to make it easy to realize what the command does.
So if the code inserted is something to the effect of ADDI reg, reg, #1
, show how to think of it in basic math terms, like reg = reg + 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good comment! It`s implemented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! In addition to the math part, could you add a small text description? Also, having the description and placeholder text be the same may be useful. Such as:
"set register": {
"prefix": "sreg",
"body": ["ADD ${1:Rd}, XZR, ${2:Rm}", "$3"],
"description": "Rd = Rm. Set one register (Rd) to the value of another (Rm)."
}
Thoughts?
I transferred the issue to the proper repository. If you could create a PR using these comments to the proper repo, that would be great! |
The issue: patrickdemers6/legv8-vscode#2 |
Hey, thank you for the detailed comments and feedback!
I will be taking a better look at them and also implement some of the
necessary changes, which you rightly pointed out, by tomorrow
Best,
Joao
Em ter., 22 de nov. de 2022 às 20:58, Patrick Demers <
***@***.***> escreveu:
… ***@***.**** requested changes on this pull request.
There are great! This is not specific to LSP; therefore, it belongs in the
vscode extension repository.
https://github.com/patrickdemers6/legv8-vscode/
Ideas for other snippets that would be nice to have:
- call a procedure
- for loop
- return (it could just be an alias for BR LR)
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> @@ -0,0 +1,185 @@
+{
+ "set register to": {
+ "prefix": "sreg",
+ "body": ["ADD ${1:dest reg}, XZR, $2", "$3"]
Consistent use of placeholders
<https://code.visualstudio.com/docs/editor/userdefinedsnippets#_placeholders>
would make these more useful. Also, having consistent and short
placeholder, where possible.
My proposal for this one:
"body": ["ADD ${1:dest} XZR, ${2:src}"]
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> @@ -0,0 +1,185 @@
+{
+ "set register to": {
+ "prefix": "sreg",
+ "body": ["ADD ${1:dest reg}, XZR, $2", "$3"]
+ },
+ "increment register": {
+ "prefix": "increg",
+ "body": ["ADDI ${1:dest reg}, ${1}, #1", "$2"]
+ },
+ "decrement register": {
+ "prefix": "decreg",
+ "body": ["SUBI ${1:dest reg}, ${1}, #1", "$2"]
+ },
+ "copy register content to another register": {
Is this different than the "set register to" snippet?
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + },
+ "clear register content": {
+ "prefix": "clearReg",
+ "body": ["EOR ${1:target reg}, $1, $1", "$2"],
+ "description": "equivalent of CLEAR. It clears the content of a target register"
+ },
+ "increment offset by 8 bits": {
+ "prefix": "inc8",
+ "body": ["ADDI ${1:offset to increment}, $1, #8"],
+ "description": "incrementing according to offset allignment standard, in order to properly traverse through an array"
+ },
+
+ "store 2 registers to save on stack": {
+ "prefix": "st2",
+ "body": [
+ "//storing registers in stack before changing them",
all comments should have a space after them.
//text should change to // text
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + "clear register content": {
+ "prefix": "clearReg",
+ "body": ["EOR ${1:target reg}, $1, $1", "$2"],
+ "description": "equivalent of CLEAR. It clears the content of a target register"
+ },
+ "increment offset by 8 bits": {
+ "prefix": "inc8",
+ "body": ["ADDI ${1:offset to increment}, $1, #8"],
+ "description": "incrementing according to offset allignment standard, in order to properly traverse through an array"
+ },
+
+ "store 2 registers to save on stack": {
+ "prefix": "st2",
+ "body": [
+ "//storing registers in stack before changing them",
+ "SUBI X28, X28, #16 //make room on stack (X28) for 2 registers",
Can SP be used instead of X28? Or is that specific to the emulator being
used at ISU?
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + "STUR $reg6, [X28, #8] //store register 6",
+ "STUR $reg7, [X28, #0] //store register 7",
+ "//body of the procedure",
+ "$body",
+ "//restoring saved registers from stack before function return (in a LIFO manner)",
+ "LDUR $reg7, [X28, #0] //restore $reg7",
+ "LDUR $reg6, [X28, #8] //restore $reg6",
+ "LDUR $reg5, [X28, #16] //restore $reg5",
+ "LDUR $reg4, [X28, #24] //restore $reg4",
+ "LDUR $reg3, [X28, #32] //restore $reg3",
+ "LDUR $reg2, [X28, #40] //restore $reg2",
+ "LDUR $reg1, [X28, #48] //restore $reg1",
+ "LDUR X30, [X28, #56] //restore X30",
+ "ADDI X28, X28, #64 //restore previous space on stack"
+ ],
+ "description": "use this to save 8 registers in the stack pointer, including the return address of the function/procedure (where the function was called)"
We aren't saving registers in the stack pointer since the SP is just a
reference to a specific position in memory. It would be better to state
"use this to store 8 registers to the stack..."
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + "STUR $reg3, [X28, #32] //store register 3",
+ "STUR $reg4, [X28, #24] //store register 4",
+ "STUR $reg5, [X28, #16] //store register 5",
+ "STUR $reg6, [X28, #8] //store register 6",
+ "STUR $reg7, [X28, #0] //store register 7",
+ "//body of the procedure",
+ "$body",
+ "//restoring saved registers from stack before function return (in a LIFO manner)",
+ "LDUR $reg7, [X28, #0] //restore $reg7",
+ "LDUR $reg6, [X28, #8] //restore $reg6",
+ "LDUR $reg5, [X28, #16] //restore $reg5",
+ "LDUR $reg4, [X28, #24] //restore $reg4",
+ "LDUR $reg3, [X28, #32] //restore $reg3",
+ "LDUR $reg2, [X28, #40] //restore $reg2",
+ "LDUR $reg1, [X28, #48] //restore $reg1",
+ "LDUR X30, [X28, #56] //restore X30",
What is X30? Could we say LR?
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + "store 8 registers to save on stack": {
+ "prefix": "st8",
+ "body": [
+ "//storing registers in stack before changing them",
+ "SUBI X28, X28, #64 //make room on stack (X28) for 2 registers",
+ "STUR X30, [X28, #56] //store Return adress (X30) of procedure",
+ "STUR $reg1, [X28, #48] //store register 1",
+ "STUR $reg2, [X28, #40] //store register 2",
+ "STUR $reg3, [X28, #32] //store register 3",
+ "STUR $reg4, [X28, #24] //store register 4",
+ "STUR $reg5, [X28, #16] //store register 5",
+ "STUR $reg6, [X28, #8] //store register 6",
+ "STUR $reg7, [X28, #0] //store register 7",
+ "//body of the procedure",
+ "$body",
+ "//restoring saved registers from stack before function return (in a LIFO manner)",
In Legv8, there are not functions. They are procedures.
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + "LDUR $reg4, [X28, #16] //restore $reg4",
+ "LDUR $reg3, [X28, #24] //restore $reg3",
+ "LDUR $reg2, [X28, #32] //restore $reg2",
+ "LDUR $reg1, [X28, #40] //restore $reg1",
+ "LDUR X30, [X28, #48] //restore X30",
+ "ADDI X28, X28, #56 //restore previous space on stack"
+ ],
+ "description": "use this to save 7 registers in the stack pointer, including the return address of the function/procedure (where the function was called)"
+ },
+ "store 8 registers to save on stack": {
+ "prefix": "st8",
+ "body": [
+ "//storing registers in stack before changing them",
+ "SUBI X28, X28, #64 //make room on stack (X28) for 2 registers",
+ "STUR X30, [X28, #56] //store Return adress (X30) of procedure",
+ "STUR $reg1, [X28, #48] //store register 1",
Can you make the comment use a placeholder to say the actual register name?
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> + },
+ "decrement register": {
+ "prefix": "decreg",
+ "body": ["SUBI ${1:dest reg}, ${1}, #1", "$2"]
+ },
+ "copy register content to another register": {
+ "prefix": "copy",
+ "body": ["ORR ${1:dest reg}, XZR, ${2:reg to copy from}", "$3"],
+ "description": "equivalent to 'MOV Xd, Xm'"
+ },
+ "clear register content": {
+ "prefix": "clearReg",
+ "body": ["EOR ${1:target reg}, $1, $1", "$2"],
+ "description": "equivalent of CLEAR. It clears the content of a target register"
+ },
+ "increment offset by 8 bits": {
What about adding a command for incrementing by immediate?
Something like:
"increment by immediate": {
"prefix": "inci",
"body": ["ADDI ${1:reg}, ${1}, #${2:amount}"],
"description": "..."
}
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> @@ -0,0 +1,185 @@
+{
+ "set register to": {
+ "prefix": "sreg",
+ "body": ["ADD ${1:dest reg}, XZR, $2", "$3"]
+ },
+ "increment register": {
+ "prefix": "increg",
Since it is only incrementing by one, would a prefix of reg++ or inc_1
make more sense?
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> @@ -0,0 +1,185 @@
+{
+ "set register to": {
+ "prefix": "sreg",
+ "body": ["ADD ${1:dest reg}, XZR, $2", "$3"]
+ },
+ "increment register": {
+ "prefix": "increg",
+ "body": ["ADDI ${1:dest reg}, ${1}, #1", "$2"]
+ },
+ "decrement register": {
+ "prefix": "decreg",
+ "body": ["SUBI ${1:dest reg}, ${1}, #1", "$2"]
Why do your "body" arrays have the parameter at the end? To put the cursor
to the next line?
------------------------------
In snippets/legv8.json
<#8 (comment)>
:
> @@ -0,0 +1,185 @@
+{
+ "set register to": {
+ "prefix": "sreg",
+ "body": ["ADD ${1:dest reg}, XZR, $2", "$3"]
+ },
Add description for all of them. Also try to make it easy to realize what
the command does.
So if the code inserted is something to the effect of ADDI reg, reg, #1,
show how to think of it in basic math terms, like reg = reg + 1
—
Reply to this email directly, view it on GitHub
<#8 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AZM2N4OH265FD4D5ZE4U3ADWJWB4JANCNFSM6AAAAAASIK76U4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
No rush. Happy Thanksgiving! |
I`m not sure how and where to do this. Do you know? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! A few more suggestions with the modifications.
"set register to": { | ||
"prefix": "sreg", | ||
"body": ["ADD ${1:dest reg}, XZR, $2", "$3"] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! In addition to the math part, could you add a small text description? Also, having the description and placeholder text be the same may be useful. Such as:
"set register": {
"prefix": "sreg",
"body": ["ADD ${1:Rd}, XZR, ${2:Rm}", "$3"],
"description": "Rd = Rm. Set one register (Rd) to the value of another (Rm)."
}
Thoughts?
snippets/legv8.json
Outdated
"description": "R[1] = R[1] - R[2]" | ||
}, | ||
|
||
"stack manipulation with 2 registers": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I were to use this, I would expect to be able to to manipulate two registers when using st2
. I completely get that there are two being manipulated here since it automatically includes LR
. Do you think st2
would be more intuitive if it deals with LR
and one custom register or LR
and two custom registers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking the same thing, but like you said I was stuck on the technicality of it since LR is also a register. But I think that being more intuitive is more important!
], | ||
"description": "use this to save 8 registers in the Stack, including the return address of the procedure (where the procedure was called)" | ||
}, | ||
"incremental for loop": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few suggestions for the loop.
ifl
isn't immediately understandable so being a bit more explicit makes it easier to grasp and remember.- The use of a temporary register is annoying when writing legv8 code as it requires use of another register. Using flags, this can be simplified.
- Also not using the term
arr_len
and using a generic upper limit makes it clearer that this can be used for any need, not just arrays. - I've also modified the description to include the equivalent C code.
"increasing for loop": {
"prefix": "for_increasing",
"body": [
"${1:loop name}_loop:",
"// if counter ($2) greater than or equal to limit ($3), then exit",
"SUBS XZR, ${2:counter}, ${3:upper_limit}",
"B.GE ${1}_loop_done",
"// loop body",
"",
"// increment counter ($2) by $4",
"ADDI $2, $2, #${4:increment_amount}",
"B $1_loop",
"$1_loop_done:"
],
"description": "Creates a for loop from counter to upper_limit. for (; counter < upper_limit; counter += increment_amount); Note: the counter and array size must be initialized before the loop."
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, It`s Implemented
snippets/legv8.json
Outdated
"return statement": { | ||
"prefix": "rtn", | ||
"body": ["BR LR"], | ||
"description": "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return from this procedure to the calling procedure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the description you mean? I was thinking of putting a bit more compact phrase like "return to the caller". What do you think?
snippets/legv8.json
Outdated
"description": "creates an incremental for loop. Obs: the register for the loop counter is not created with the snippet, so they must be set" | ||
}, | ||
"return statement": { | ||
"prefix": "rtn", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to not say the full return
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it`s just that i have a tendency to abbreviate things, but I changed to "return"
Yep, in the other VS Code extension's repository, create a pull request. You will need to:
"snippets": [
{
"language": "legv8",
"path": "./snippets/legv8.snippets.json"
}
By "with these comments", I just meant to still work on my suggestions - just like you have been doing! Thanks for all your hard work! |
Trying to add PR to issue patrickdemers6/legv8-vscode#2