Skip to content

Commit

Permalink
enh(armasm) support // and # style line comments (#2410)
Browse files Browse the repository at this point in the history
* enh(armasm) support line comments // and #

Fixes #2408.

* fix(armasm) instructions should not include the space after
* fix(armasm) symbols should not include prior newline
* add generic test case
* comment should not include whitespace at beginning
* also accept tabs as white space
  • Loading branch information
joshgoebel committed Feb 19, 2020
1 parent fb6181a commit a34abcb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/languages/armasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ Category: assembler

export default function(hljs) {
//local labels: %?[FB]?[AT]?\d{1,2}\w+

const COMMENT = {
variants: [
hljs.COMMENT('^[ \\t]*(?=#)', '$', {relevance: 0, excludeBegin: true }),
hljs.COMMENT('[;@]', '$', {relevance: 0}),
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
]
}

return {
case_insensitive: true,
aliases: ['arm'],
Expand Down Expand Up @@ -56,11 +66,10 @@ export default function(hljs) {
'wfe|wfi|yield'+
')'+
'(eq|ne|cs|cc|mi|pl|vs|vc|hi|ls|ge|lt|gt|le|al|hs|lo)?'+ //condition codes
'[sptrx]?' , //legal postfixes
end: '\\s'
'[sptrx]?' + //legal postfixes
'(?=\\s)' // followed by space
},
hljs.COMMENT('[;@]', '$', {relevance: 0}),
hljs.C_BLOCK_COMMENT_MODE,
COMMENT,
hljs.QUOTE_STRING_MODE,
{
className: 'string',
Expand All @@ -87,8 +96,8 @@ export default function(hljs) {
{
className: 'symbol',
variants: [
{begin: '^[ \\t]*[a-z_\\.\\$][a-z0-9_\\.\\$]+:'}, //GNU ARM syntax
{begin: '^[a-z_\\.\\$][a-z0-9_\\.\\$]+'}, //ARM syntax
{begin: '^\\s*[a-z_\\.\\$][a-z0-9_\\.\\$]+:'}, //GNU ARM syntax
{begin: '[=#]\\w+' } //label reference
],
relevance: 0
Expand Down
24 changes: 24 additions & 0 deletions test/markup/armasm/default.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<span class="hljs-comment">//=================== YOUR CODE GOES IN THE SECTION BELOW ===================//</span>

<span class="hljs-comment"># check for and handle zero</span>
<span class="hljs-keyword">orr</span> <span class="hljs-built_in">r1</span>, <span class="hljs-built_in">r0</span>, <span class="hljs-number">#128</span> <span class="hljs-comment">// r1 = r0 | 128</span>
<span class="hljs-keyword">cmp</span> <span class="hljs-built_in">r1</span>, <span class="hljs-number">#128</span> <span class="hljs-comment">// if r1 == 128 {</span>
<span class="hljs-keyword">bne</span> notZero <span class="hljs-comment">// .</span>
<span class="hljs-keyword">bl</span> zeroQuidFP2float <span class="hljs-comment">// zeroQuidFP2float() }</span>
<span class="hljs-keyword">b</span> <span class="hljs-meta">end</span> <span class="hljs-comment">// else {</span>

<span class="hljs-symbol">notZero:</span> <span class="hljs-comment">// .</span>
<span class="hljs-comment"># extract fields from quidfp</span>
<span class="hljs-keyword">and</span> <span class="hljs-built_in">r1</span>, <span class="hljs-built_in">r0</span>, <span class="hljs-number">#128</span> <span class="hljs-comment">// r1 = r0 &amp; 128 // sign</span>
<span class="hljs-keyword">and</span> <span class="hljs-built_in">r2</span>, <span class="hljs-built_in">r0</span>, <span class="hljs-number">#112</span> <span class="hljs-comment">// r2 = r0 &amp; 112 // exponent</span>
<span class="hljs-keyword">and</span> <span class="hljs-built_in">r3</span>, <span class="hljs-built_in">r0</span>, <span class="hljs-number">#15</span> <span class="hljs-comment">// r3 = r0 &amp; 15 // mantissa</span>

<span class="hljs-comment">// ...</span>

<span class="hljs-comment"># combine into r0</span>
<span class="hljs-keyword">orr</span> <span class="hljs-built_in">r0</span>, <span class="hljs-built_in">r1</span>, <span class="hljs-built_in">r2</span> <span class="hljs-comment">// r0 = r1 | r2</span>
<span class="hljs-keyword">orr</span> <span class="hljs-built_in">r0</span>, <span class="hljs-built_in">r0</span>, <span class="hljs-built_in">r3</span> <span class="hljs-comment">// r0 = r0 | r3 }</span>

<span class="hljs-symbol">end:</span> <span class="hljs-comment">// return r0</span>

<span class="hljs-comment">//===========================================================================//</span>
24 changes: 24 additions & 0 deletions test/markup/armasm/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//=================== YOUR CODE GOES IN THE SECTION BELOW ===================//

# check for and handle zero
orr r1, r0, #128 // r1 = r0 | 128
cmp r1, #128 // if r1 == 128 {
bne notZero // .
bl zeroQuidFP2float // zeroQuidFP2float() }
b end // else {

notZero: // .
# extract fields from quidfp
and r1, r0, #128 // r1 = r0 & 128 // sign
and r2, r0, #112 // r2 = r0 & 112 // exponent
and r3, r0, #15 // r3 = r0 & 15 // mantissa

// ...

# combine into r0
orr r0, r1, r2 // r0 = r1 | r2
orr r0, r0, r3 // r0 = r0 | r3 }

end: // return r0

//===========================================================================//

0 comments on commit a34abcb

Please sign in to comment.