Skip to content

Commit d5a67aa

Browse files
committed
feat: better support for arm-none-eabi-objdump output
1 parent 28d3b2e commit d5a67aa

File tree

5 files changed

+1359
-938
lines changed

5 files changed

+1359
-938
lines changed

grammar.js

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = grammar(
4444
$.label_line,
4545
$.memory_offset,
4646
$.source_location,
47+
'...',
4748
),
4849

4950
header: $ => seq($.file_path, ":", "file", "format", $.identifier),
@@ -94,18 +95,28 @@ module.exports = grammar(
9495
optional($.file_offset),
9596
)
9697
),
97-
instruction: $ => /[^\n#<]+/,
98-
bad_instruction: $ => "(bad)",
98+
instruction: _ => /([^\n#;<]|#-?\d+)+/,
99+
bad_instruction: _ => "(bad)",
99100

100101
comment: $ => seq(
101-
"#",
102+
choice("#", ';'),
102103
choice(
103104
$._comment_with_address,
104105
$._comment_with_label,
105106
),
106107
),
107108

108-
_comment_with_label: $ => seq($.address, $.code_location, optional($.file_offset)),
109+
_comment_with_label: $ => choice(
110+
seq(
111+
'(',
112+
optional(seq(alias(/[^\d,][^,]+/, $.instruction), ',')),
113+
$.address,
114+
$.code_location,
115+
optional($.file_offset),
116+
')'
117+
),
118+
seq($.address, $.code_location, optional($.file_offset)),
119+
),
109120
_comment_with_address: $ => $.hexadecimal,
110121

111122
code_location: $ => seq(
@@ -117,11 +128,11 @@ module.exports = grammar(
117128

118129
label_line: $ => seq(alias($._label_identifier, $.label), ":"),
119130

120-
hexadecimal: $ => /0[xh][0-9a-fA-F]+/,
121-
byte: $ => /[0-9a-fA-F]{2}/,
131+
hexadecimal: _ => /0[xh][0-9a-fA-F]+/,
132+
byte: _ => /[0-9a-fA-F]{2}|[0-9a-fA-F]{4}|[0-9a-fA-F]{8}/,
122133
machine_code_bytes: $ => space_separated1($.byte),
123134

124-
address: $ => /[0-9a-fA-F]+/,
135+
address: _ => /[0-9a-fA-F]+/,
125136

126137
file_offset: $ => seq("(", "File", "Offset:", $.hexadecimal, ")"),
127138

@@ -131,15 +142,15 @@ module.exports = grammar(
131142
":",
132143
),
133144

134-
integer: $ => /\d+/,
145+
integer: _ => /\d+/,
135146

136147
// TODO: Support windows paths, later. Also make sure Linux paths work
137-
file_path: $ => /[\/\w\-\.\+]+/,
148+
file_path: _ => /[\/\w\-\.\+]+/,
138149

139-
_label_identifier: $ => /[A-Za-z.@_][A-Za-z0-9.@_$-\(\)]*/, // Test this, later
140-
identifier: $ => /[^\n]+/,
150+
_label_identifier: _ => /[A-Za-z.@_][A-Za-z0-9.@_$-\(\)]*/, // Test this, later
151+
identifier: _ => /[^\n]+/,
141152

142-
_section_name: $ => /[^:]+/,
153+
_section_name: _ => /[^:]+/,
143154
}
144155
}
145156
)

src/grammar.json

Lines changed: 91 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
{
3535
"type": "SYMBOL",
3636
"name": "source_location"
37+
},
38+
{
39+
"type": "STRING",
40+
"value": "..."
3741
}
3842
]
3943
},
@@ -275,7 +279,7 @@
275279
},
276280
"instruction": {
277281
"type": "PATTERN",
278-
"value": "[^\\n#<]+"
282+
"value": "([^\\n#;<]|#-?\\d+)+"
279283
},
280284
"bad_instruction": {
281285
"type": "STRING",
@@ -285,8 +289,17 @@
285289
"type": "SEQ",
286290
"members": [
287291
{
288-
"type": "STRING",
289-
"value": "#"
292+
"type": "CHOICE",
293+
"members": [
294+
{
295+
"type": "STRING",
296+
"value": "#"
297+
},
298+
{
299+
"type": "STRING",
300+
"value": ";"
301+
}
302+
]
290303
},
291304
{
292305
"type": "CHOICE",
@@ -304,25 +317,89 @@
304317
]
305318
},
306319
"_comment_with_label": {
307-
"type": "SEQ",
320+
"type": "CHOICE",
308321
"members": [
309322
{
310-
"type": "SYMBOL",
311-
"name": "address"
312-
},
313-
{
314-
"type": "SYMBOL",
315-
"name": "code_location"
323+
"type": "SEQ",
324+
"members": [
325+
{
326+
"type": "STRING",
327+
"value": "("
328+
},
329+
{
330+
"type": "CHOICE",
331+
"members": [
332+
{
333+
"type": "SEQ",
334+
"members": [
335+
{
336+
"type": "ALIAS",
337+
"content": {
338+
"type": "PATTERN",
339+
"value": "[^\\d,][^,]+"
340+
},
341+
"named": true,
342+
"value": "instruction"
343+
},
344+
{
345+
"type": "STRING",
346+
"value": ","
347+
}
348+
]
349+
},
350+
{
351+
"type": "BLANK"
352+
}
353+
]
354+
},
355+
{
356+
"type": "SYMBOL",
357+
"name": "address"
358+
},
359+
{
360+
"type": "SYMBOL",
361+
"name": "code_location"
362+
},
363+
{
364+
"type": "CHOICE",
365+
"members": [
366+
{
367+
"type": "SYMBOL",
368+
"name": "file_offset"
369+
},
370+
{
371+
"type": "BLANK"
372+
}
373+
]
374+
},
375+
{
376+
"type": "STRING",
377+
"value": ")"
378+
}
379+
]
316380
},
317381
{
318-
"type": "CHOICE",
382+
"type": "SEQ",
319383
"members": [
320384
{
321385
"type": "SYMBOL",
322-
"name": "file_offset"
386+
"name": "address"
323387
},
324388
{
325-
"type": "BLANK"
389+
"type": "SYMBOL",
390+
"name": "code_location"
391+
},
392+
{
393+
"type": "CHOICE",
394+
"members": [
395+
{
396+
"type": "SYMBOL",
397+
"name": "file_offset"
398+
},
399+
{
400+
"type": "BLANK"
401+
}
402+
]
326403
}
327404
]
328405
}
@@ -399,7 +476,7 @@
399476
},
400477
"byte": {
401478
"type": "PATTERN",
402-
"value": "[0-9a-fA-F]{2}"
479+
"value": "[0-9a-fA-F]{2}|[0-9a-fA-F]{4}|[0-9a-fA-F]{8}"
403480
},
404481
"machine_code_bytes": {
405482
"type": "SEQ",

src/node-types.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
{
4242
"type": "hexadecimal",
4343
"named": true
44+
},
45+
{
46+
"type": "instruction",
47+
"named": true
4448
}
4549
]
4650
}
@@ -291,10 +295,22 @@
291295
"type": "+",
292296
"named": false
293297
},
298+
{
299+
"type": ",",
300+
"named": false
301+
},
302+
{
303+
"type": "...",
304+
"named": false
305+
},
294306
{
295307
"type": ":",
296308
"named": false
297309
},
310+
{
311+
"type": ";",
312+
"named": false
313+
},
298314
{
299315
"type": "<",
300316
"named": false

0 commit comments

Comments
 (0)