Skip to content

Commit

Permalink
LdScript,Asm: extract symbols marked with .global
Browse files Browse the repository at this point in the history
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Jan 4, 2023
1 parent 5d9d5b7 commit 9195354
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
gfunc0 input.S /^GENTRY(gfunc0)$/;" s
gfunc0 input.S /^GENTRY(gfunc0)$/;" l
lfunc input.S /^LENTRY(lfunc)$/;" l
lfunc input.S /^LENTRY(lfunc)$/;" l
gfunc1 input.S /^GENTRY(gfunc1)$/;" s
gfunc1 input.S /^GENTRY(gfunc1)$/;" l
6 changes: 6 additions & 0 deletions Units/parser-asm.r/asm-cpp-macro-expansion.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
ENTRY input.S /^#define ENTRY(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
main input.S /^ENTRY(main):$/;" s
main input.S /^ENTRY(main):$/;" l
ENTRY2 input.S /^#define ENTRY2(/;" d file: signature:(LABEL,UNUSED) macrodef:.global LABEL ;LABEL
loop0 input.S /^ENTRY2(loop0, "STRING"):$/;" s
loop0 input.S /^ENTRY2(loop0, "STRING"):$/;" l
loop1 input.S /^ENTRY2(loop1, 'c'):$/;" s
loop1 input.S /^ENTRY2(loop1, 'c'):$/;" l
loop2 input.S /^ENTRY2(loop2, ('c')):$/;" s
loop2 input.S /^ENTRY2(loop2, ('c')):$/;" l
ASM_NL input.S /^#define ASM_NL /;" d file: macrodef:;
SYM_ENTRY input.S /^#define SYM_ENTRY(/;" d file: signature:(name,linkage,align...) macrodef:linkage(name) ASM_NL align ASM_NL name:
Expand All @@ -12,8 +16,10 @@ asm_exc_nmi input.S /^SYM_CODE_START(asm_exc_nmi)$/;" l
ENTRY0 input-0.S /^#define ENTRY0(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
exit0 input-0.S /^exit0:$/;" l
ENTRY1 input-1.S /^#define ENTRY1(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
exit1 input-1.S /^ENTRY1(exit1):$/;" s
exit1 input-1.S /^ENTRY1(exit1):$/;" l
ENTRY2 input-2.S /^#define ENTRY2(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
exit2 input-2.S /^ENTRY2(exit2):$/;" s
exit2 input-2.S /^ENTRY2(exit2):$/;" l
ENTRY3 input-3.S /^#define ENTRY3 /;" d file: macrodef:label3:; nop;.section .entry.text,
label3 input-3.S /^ ENTRY3"a"$/;" l
Expand Down
1 change: 1 addition & 0 deletions Units/parser-asm.r/cpp-parameter-false.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
labelM input.s /^ .global labelM$/;" s
labelM input.s /^labelM:$/;" l
1 change: 1 addition & 0 deletions Units/parser-asm.r/cpp-parameter-true.d/expected.tags
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
labelM input.S /^#define labelM /;" d file:
labelM input.S /^ .global labelM$/;" s
labelM input.S /^labelM:$/;" l
1 change: 1 addition & 0 deletions Units/parser-asm.r/gas-section.d/expected.tags
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ machine/asm.h input.s /^#include <machine\/asm.h>/;" header language:CPreProcess
one input.s /^one: .double 1.0$/;" label language:Asm roles:def
limit input.s /^limit: .double 0.29$/;" label language:Asm roles:def
.inittext input-0.s /^ .section ".inittext","ax"$/;" inputSection language:LdScript roles:destination
intcall input-0.s /^ .globl intcall$/;" symbol language:LdScript inputSection:.inittext roles:def
intcall input-0.s /^intcall:$/;" label language:Asm roles:def
1 change: 1 addition & 0 deletions docs/man/ctags-lang-asm.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ with "--options=NONE -o - --param-Asm.useCPreProcessor=1 --param-CPreProcessor._
ENTRY input.S /^#define ENTRY(/;" d file: signature:(LABEL) macrodef:.global LABEL ;LABEL
main input.S /^ENTRY(main):$/;" l
main input.S /^ENTRY(main):$/;" s
The definition of `ENTRY` assumes `;` is a line separator in the host assembly language.
``--param-Asm.extraLinesepChars=;`` is for satisfying the assumption in ctags side.
Expand Down
1 change: 1 addition & 0 deletions man/ctags-lang-asm.7.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ with "--options=NONE -o - --param-Asm.useCPreProcessor=1 --param-CPreProcessor._

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

The definition of `ENTRY` assumes `;` is a line separator in the host assembly language.
``--param-Asm.extraLinesepChars=;`` is for satisfying the assumption in ctags side.
Expand Down
62 changes: 45 additions & 17 deletions parsers/asm.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* DATA DECLARATIONS
*/
typedef enum {
K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL = -4,
K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION = -3,
K_PSUEDO_MACRO_END = -2,
K_NONE = -1, K_DEFINE, K_LABEL, K_MACRO, K_TYPE,
Expand All @@ -49,6 +50,7 @@ typedef enum {
OP_ENDS,
OP_EQU,
OP_EQUAL,
OP_GLOBAL,
OP_LABEL,
OP_MACRO,
OP_PROC,
Expand Down Expand Up @@ -96,6 +98,8 @@ static const keywordTable AsmKeywords [] = {
{ "endp", OP_ENDP },
{ "ends", OP_ENDS },
{ "equ", OP_EQU },
{ "global", OP_GLOBAL },
{ "globl", OP_GLOBAL },
{ "label", OP_LABEL },
{ "macro", OP_MACRO },
{ ":=", OP_COLON_EQUAL },
Expand Down Expand Up @@ -124,6 +128,7 @@ static const opKind OpKinds [] = {
{ OP_ENDS, K_NONE },
{ OP_EQU, K_DEFINE },
{ OP_EQUAL, K_DEFINE },
{ OP_GLOBAL, K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL },
{ OP_LABEL, K_LABEL },
{ OP_MACRO, K_MACRO },
{ OP_PROC, K_LABEL },
Expand Down Expand Up @@ -203,7 +208,7 @@ static bool isDefineOperator (const vString *const operator)
return result;
}

static int makeTagForLdScriptSection (const char * section)
static int makeTagForLdScript (const char * name, int kind, int *scope)
{
tagEntryInfo e;
static langType lang = LANG_AUTO;
Expand All @@ -213,20 +218,36 @@ static int makeTagForLdScriptSection (const char * section)
if(lang == LANG_IGNORE)
return CORK_NIL;

static kindDefinition * kdef = NULL;
if(kdef == NULL)
kdef = getLanguageKindForName (lang, "inputSection");
if(kdef == NULL)
return CORK_NIL;

static roleDefinition *rdef = NULL;
if(rdef == NULL)
rdef = getLanguageRoleForName (lang, kdef->id, "destination");
if (rdef == NULL)
return CORK_NIL;

initForeignRefTagEntry(&e, section, lang, kdef->id, rdef->id);
return makeTagEntry (&e);
if (kind == K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL)
{
static kindDefinition * kdef = NULL;
if(kdef == NULL)
kdef = getLanguageKindForName (lang, "symbol");
if(kdef == NULL)
return CORK_NIL;

initForeignTagEntry(&e, name, lang, kdef->id);
e.extensionFields.scopeIndex = *scope;
return makeTagEntry (&e);
}
else
{
static kindDefinition * kdef = NULL;
if(kdef == NULL)
kdef = getLanguageKindForName (lang, "inputSection");
if(kdef == NULL)
return CORK_NIL;

static roleDefinition *rdef = NULL;
if(rdef == NULL)
rdef = getLanguageRoleForName (lang, kdef->id, "destination");
if (rdef == NULL)
return CORK_NIL;

initForeignRefTagEntry(&e, name, lang, kdef->id, rdef->id);
*scope = makeTagEntry (&e);
return *scope;
}
}

static int makeAsmTag (
Expand All @@ -235,6 +256,7 @@ static int makeAsmTag (
const bool labelCandidate,
const bool nameFollows,
const bool directive,
int *sectionScope,
int *macroScope)
{
int r = CORK_NIL;
Expand All @@ -258,7 +280,9 @@ static int makeAsmTag (
{
operatorKind (name, &found);
if (! found)
{
r = makeSimpleTag (name, K_LABEL);
}
}
else if (directive)
{
Expand Down Expand Up @@ -288,8 +312,10 @@ static int makeAsmTag (
*macroScope = macro_tag->extensionFields.scopeIndex;
}
break;
case K_PSUEDO_FOREIGN_LD_SCRIPT_SYMBOL:
case K_PSUEDO_FOREIGN_LD_SCRIPT_SECTION:
r = makeTagForLdScriptSection (vStringValue (operator));
r = makeTagForLdScript (vStringValue (operator),
kind_for_directive, sectionScope);
break;
default:
r = makeSimpleTag (operator, kind_for_directive);
Expand Down Expand Up @@ -715,6 +741,7 @@ static void findAsmTagsCommon (bool useCpp)
KIND_GHOST_INDEX, 0, 0, KIND_GHOST_INDEX, KIND_GHOST_INDEX, 0, 0,
FIELD_UNKNOWN);

int sectionScope = CORK_NIL;
int macroScope = CORK_NIL;

while ((line = asmReadLineFromInputFile (commentCharsInMOL, useCpp)) != NULL)
Expand Down Expand Up @@ -779,7 +806,8 @@ static void findAsmTagsCommon (bool useCpp)
cp = readSymbol (cp, name);
nameFollows = true;
}
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive, &macroScope);
int r = makeAsmTag (name, operator, labelCandidate, nameFollows, directive,
&sectionScope, &macroScope);
tagEntryInfo *e = getEntryInCorkQueue (r);
if (e && e->langType == Lang_asm
&& e->kindIndex == K_MACRO && isRoleAssigned(e, ROLE_DEFINITION_INDEX))
Expand Down

0 comments on commit 9195354

Please sign in to comment.