Skip to content

Commit fb3a966

Browse files
committed
LdScript,Asm: extract symbols marked with .global
Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 755ae53 commit fb3a966

File tree

8 files changed

+58
-17
lines changed

8 files changed

+58
-17
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
gfunc0 input.S /^GENTRY(gfunc0)$/;" s
12
gfunc0 input.S /^GENTRY(gfunc0)$/;" l
23
lfunc input.S /^LENTRY(lfunc)$/;" l
34
lfunc input.S /^LENTRY(lfunc)$/;" l
5+
gfunc1 input.S /^GENTRY(gfunc1)$/;" s
46
gfunc1 input.S /^GENTRY(gfunc1)$/;" l

Units/parser-asm.r/asm-cpp-macro-expansion.d/expected.tags

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
ENTRY input.S /^#define ENTRY(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
2+
main input.S /^ENTRY(main):$/;" s
23
main input.S /^ENTRY(main):$/;" l
34
ENTRY2 input.S /^#define ENTRY2(/;" d file: signature:(LABEL,UNUSED) macrodef:.global LABEL ;LABEL
5+
loop0 input.S /^ENTRY2(loop0, "STRING"):$/;" s
46
loop0 input.S /^ENTRY2(loop0, "STRING"):$/;" l
7+
loop1 input.S /^ENTRY2(loop1, 'c'):$/;" s
58
loop1 input.S /^ENTRY2(loop1, 'c'):$/;" l
9+
loop2 input.S /^ENTRY2(loop2, ('c')):$/;" s
610
loop2 input.S /^ENTRY2(loop2, ('c')):$/;" l
711
ASM_NL input.S /^#define ASM_NL /;" d file: macrodef:;
812
SYM_ENTRY input.S /^#define SYM_ENTRY(/;" d file: signature:(name,linkage,align...) macrodef:linkage(name) ASM_NL align ASM_NL name:
@@ -12,8 +16,10 @@ asm_exc_nmi input.S /^SYM_CODE_START(asm_exc_nmi)$/;" l
1216
ENTRY0 input-0.S /^#define ENTRY0(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
1317
exit0 input-0.S /^exit0:$/;" l
1418
ENTRY1 input-1.S /^#define ENTRY1(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
19+
exit1 input-1.S /^ENTRY1(exit1):$/;" s
1520
exit1 input-1.S /^ENTRY1(exit1):$/;" l
1621
ENTRY2 input-2.S /^#define ENTRY2(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
22+
exit2 input-2.S /^ENTRY2(exit2):$/;" s
1723
exit2 input-2.S /^ENTRY2(exit2):$/;" l
1824
ENTRY3 input-3.S /^#define ENTRY3 /;" d file: macrodef:label3:; nop;.section .entry.text,
1925
label3 input-3.S /^ ENTRY3"a"$/;" l
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
labelM input.s /^ .global labelM$/;" s
12
labelM input.s /^labelM:$/;" l
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
labelM input.S /^#define labelM /;" d file:
2+
labelM input.S /^ .global labelM$/;" s
23
labelM input.S /^labelM:$/;" l

Units/parser-asm.r/gas-section.d/expected.tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ machine/asm.h input.s /^#include <machine\/asm.h>/;" header language:CPreProcess
33
one input.s /^one: .double 1.0$/;" label language:Asm roles:def
44
limit input.s /^limit: .double 0.29$/;" label language:Asm roles:def
55
.inittext input-0.s /^ .section ".inittext","ax"$/;" inputSection language:LdScript roles:destination
6+
intcall input-0.s /^ .globl intcall$/;" symbol language:LdScript inputSection:.inittext roles:def
67
intcall input-0.s /^intcall:$/;" label language:Asm roles:def

docs/man/ctags-lang-asm.7.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ with "--options=NONE -o - --param-Asm.useCPreProcessor=1 --param-CPreProcessor._
156156
157157
ENTRY input.S /^#define ENTRY(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
158158
main input.S /^ENTRY(main):$/;" l
159+
main input.S /^ENTRY(main):$/;" s
159160
160161
The definition of `ENTRY` assumes `;` is a line separator in the host assembly language.
161162
``--param-Asm.extraLinesepChars=;`` is for satisfying the assumption in ctags side.

man/ctags-lang-asm.7.rst.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ with "--options=NONE -o - --param-Asm.useCPreProcessor=1 --param-CPreProcessor._
156156

157157
ENTRY input.S /^#define ENTRY(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
158158
main input.S /^ENTRY(main):$/;" l
159+
main input.S /^ENTRY(main):$/;" s
159160

160161
The definition of `ENTRY` assumes `;` is a line separator in the host assembly language.
161162
``--param-Asm.extraLinesepChars=;`` is for satisfying the assumption in ctags side.

parsers/asm.c

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* DATA DECLARATIONS
3333
*/
3434
typedef enum {
35+
K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL = -4,
3536
K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION = -3,
3637
K_PSUEDO_MACRO_END = -2,
3738
K_NONE = -1, K_DEFINE, K_LABEL, K_MACRO, K_TYPE,
@@ -49,6 +50,7 @@ typedef enum {
4950
OP_ENDS,
5051
OP_EQU,
5152
OP_EQUAL,
53+
OP_GLOBAL,
5254
OP_LABEL,
5355
OP_MACRO,
5456
OP_PROC,
@@ -96,6 +98,8 @@ static const keywordTable AsmKeywords [] = {
9698
{ "endp", OP_ENDP },
9799
{ "ends", OP_ENDS },
98100
{ "equ", OP_EQU },
101+
{ "global", OP_GLOBAL },
102+
{ "globl", OP_GLOBAL },
99103
{ "label", OP_LABEL },
100104
{ "macro", OP_MACRO },
101105
{ ":=", OP_COLON_EQUAL },
@@ -124,6 +128,7 @@ static const opKind OpKinds [] = {
124128
{ OP_ENDS, K_NONE },
125129
{ OP_EQU, K_DEFINE },
126130
{ OP_EQUAL, K_DEFINE },
131+
{ OP_GLOBAL, K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL },
127132
{ OP_LABEL, K_LABEL },
128133
{ OP_MACRO, K_MACRO },
129134
{ OP_PROC, K_LABEL },
@@ -203,7 +208,7 @@ static bool isDefineOperator (const vString *const operator)
203208
return result;
204209
}
205210

206-
static int makeTagForLdScriptSection (const char * section)
211+
static int makeTagForLdScript (const char * name, int kind, int *scope)
207212
{
208213
tagEntryInfo e;
209214
static langType lang = LANG_AUTO;
@@ -213,20 +218,36 @@ static int makeTagForLdScriptSection (const char * section)
213218
if(lang == LANG_IGNORE)
214219
return CORK_NIL;
215220

216-
static kindDefinition * kdef = NULL;
217-
if(kdef == NULL)
218-
kdef = getLanguageKindForName (lang, "inputSection");
219-
if(kdef == NULL)
220-
return CORK_NIL;
221-
222-
static roleDefinition *rdef = NULL;
223-
if(rdef == NULL)
224-
rdef = getLanguageRoleForName (lang, kdef->id, "destination");
225-
if (rdef == NULL)
226-
return CORK_NIL;
227-
228-
initForeignRefTagEntry(&e, section, lang, kdef->id, rdef->id);
229-
return makeTagEntry (&e);
221+
if (kind == K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL)
222+
{
223+
static kindDefinition * kdef = NULL;
224+
if(kdef == NULL)
225+
kdef = getLanguageKindForName (lang, "symbol");
226+
if(kdef == NULL)
227+
return CORK_NIL;
228+
229+
initForeignTagEntry(&e, name, lang, kdef->id);
230+
e.extensionFields.scopeIndex = *scope;
231+
return makeTagEntry (&e);
232+
}
233+
else
234+
{
235+
static kindDefinition * kdef = NULL;
236+
if(kdef == NULL)
237+
kdef = getLanguageKindForName (lang, "inputSection");
238+
if(kdef == NULL)
239+
return CORK_NIL;
240+
241+
static roleDefinition *rdef = NULL;
242+
if(rdef == NULL)
243+
rdef = getLanguageRoleForName (lang, kdef->id, "destination");
244+
if (rdef == NULL)
245+
return CORK_NIL;
246+
247+
initForeignRefTagEntry(&e, name, lang, kdef->id, rdef->id);
248+
*scope = makeTagEntry (&e);
249+
return *scope;
250+
}
230251
}
231252

232253
static int makeAsmTag (
@@ -235,6 +256,7 @@ static int makeAsmTag (
235256
const bool labelCandidate,
236257
const bool nameFollows,
237258
const bool directive,
259+
int *sectionScope,
238260
int *macroScope)
239261
{
240262
int r = CORK_NIL;
@@ -258,7 +280,9 @@ static int makeAsmTag (
258280
{
259281
operatorKind (name, &found);
260282
if (! found)
283+
{
261284
r = makeSimpleTag (name, K_LABEL);
285+
}
262286
}
263287
else if (directive)
264288
{
@@ -288,8 +312,10 @@ static int makeAsmTag (
288312
*macroScope = macro_tag->extensionFields.scopeIndex;
289313
}
290314
break;
315+
case K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL:
291316
case K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION:
292-
r = makeTagForLdScriptSection (vStringValue (operator));
317+
r = makeTagForLdScript (vStringValue (operator),
318+
kind_for_directive, sectionScope);
293319
break;
294320
default:
295321
r = makeSimpleTag (operator, kind_for_directive);
@@ -718,6 +744,7 @@ static void findAsmTagsCommon (bool useCpp)
718744
KIND_GHOST_INDEX, 0, 0, KIND_GHOST_INDEX, KIND_GHOST_INDEX, 0, 0,
719745
FIELD_UNKNOWN);
720746

747+
int sectionScope = CORK_NIL;
721748
int macroScope = CORK_NIL;
722749

723750
while ((line = asmReadLineFromInputFile (commentCharsInMOL, useCpp)) != NULL)
@@ -782,7 +809,8 @@ static void findAsmTagsCommon (bool useCpp)
782809
cp = readSymbol (cp, name);
783810
nameFollows = true;
784811
}
785-
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive, &macroScope);
812+
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive,
813+
&sectionScope, &macroScope);
786814
tagEntryInfo *e = getEntryInCorkQueue (r);
787815
if (e && e->langType == Lang_asm
788816
&& e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX))

0 commit comments

Comments
 (0)