Subversion Repositories pentevo

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1186 savelij 1
/* invaddress.c */
2
/*****************************************************************************/
3
/* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only                     */
4
/*                                                                           */
5
/* Disassembler                                                              */
6
/*                                                                           */
7
/* inverse symbol storage                                                    */
8
/*                                                                           */
9
/*****************************************************************************/
10
 
11
#include "stdinc.h"
12
#include "strutil.h"
13
#include "trees.h"
14
#include "invaddress.h"
15
 
16
typedef struct
17
{
18
  TTree Tree;
19
  char *pSymbolName;
20
} tInvSymbol;
21
 
22
static tInvSymbol *pInvSymbolRoot;
23
static int MaxSymbolNameLen;
24
 
25
static void MakeInvSymbolName(char *pDest, unsigned DestSize, LargeWord Num)
26
{
27
  *pDest = 'I';
28
  SysString(pDest + 1, DestSize - 1, Num, 16, 8, False, HexStartCharacter, SplitByteCharacter);
29
}
30
 
31
static Boolean InvSymbolAdder(PTree *ppDest, PTree pNew, void *pData)
32
{
33
  /*tInvSymbol *pNewInvSymbol = (tInvSymbol*)pNew, *pNode;*/
34
  UNUSED(pData);
35
  UNUSED(pNew);
36
 
37
  /* added to an empty leaf ? */
38
 
39
  if (!ppDest)
40
  {
41
    return True;
42
  }
43
  return False;
44
}
45
 
46
void AddInvSymbol(const char *pSymbolName, LargeWord Value)
47
{
48
  String Name;
49
  tInvSymbol *pNew;
50
  PTree pTreeRoot;
51
  int ThisSymbolNameLen;
52
 
53
  if ((ThisSymbolNameLen = strlen(pSymbolName)) > MaxSymbolNameLen)
54
    MaxSymbolNameLen = ThisSymbolNameLen;
55
 
56
  MakeInvSymbolName(Name, sizeof(Name), Value);
57
  pNew = (tInvSymbol*)calloc(1, sizeof(*pNew));
58
  pNew->Tree.Name = as_strdup(Name);
59
  pNew->pSymbolName = as_strdup(pSymbolName);
60
 
61
  pTreeRoot = &(pInvSymbolRoot->Tree);
62
  EnterTree(&pTreeRoot, &(pNew->Tree), InvSymbolAdder, NULL);
63
  pInvSymbolRoot = (tInvSymbol*)pTreeRoot;
64
}
65
 
66
const char *LookupInvSymbol(LargeWord Value)
67
{
68
  String Name;
69
  TTree *pTree;
70
 
71
  MakeInvSymbolName(Name, sizeof(Name), Value);
72
  pTree = SearchTree(&pInvSymbolRoot->Tree, Name, 0);
73
  if (pTree)
74
    return ((tInvSymbol*)pTree)->pSymbolName;
75
  else
76
    return NULL;
77
}
78
 
79
int GetMaxInvSymbolNameLen(void)
80
{
81
  return MaxSymbolNameLen;
82
}