Rizin
unix-like reverse engineering framework and cli tools
parse_z80_pseudo.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_flag.h>
#include <rz_analysis.h>
#include <rz_parse.h>
#include "parse_common.c"

Go to the source code of this file.

Functions

static RzListz80_tokenize (const char *assembly, size_t length)
 
static bool parse (RzParse *parse, const char *assembly, RzStrBuf *sb)
 

Variables

static const RzPseudoGrammar z80_lexicon []
 
static const RzPseudoConfig z80_config = RZ_PSEUDO_DEFINE_CONFIG_ONLY_LEXICON(z80_lexicon, 3, z80_tokenize)
 
RzParsePlugin rz_parse_plugin_z80_pseudo
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ parse()

static bool parse ( RzParse parse,
const char *  assembly,
RzStrBuf sb 
)
static

Definition at line 151 of file parse_z80_pseudo.c.

151  {
152  return rz_pseudo_convert(&z80_config, assembly, sb);
153 }
static SblHeader sb
Definition: bin_mbn.c:26
static bool rz_pseudo_convert(const RzPseudoConfig *config, const char *assembly, RzStrBuf *sb)
Definition: parse_common.c:103
static const RzPseudoConfig z80_config

References rz_pseudo_convert(), sb, and z80_config.

◆ z80_tokenize()

RzList * z80_tokenize ( const char *  assembly,
size_t  length 
)
static

Definition at line 95 of file parse_z80_pseudo.c.

95  {
96  size_t i, p;
97  char *buf = NULL;
98  const char *comma_replace = NULL;
99  bool keep = false;
100  RzList *tokens = NULL;
101 
102  buf = rz_str_ndup(assembly, length);
103  if (!buf) {
104  return NULL;
105  }
106 
107  for (i = 0, p = 0; p < length; ++i, ++p) {
108  if (buf[p] == ',') {
109  if (!keep) {
110  p++;
111  } else if (buf[p + 1] == ' ') {
112  buf[i] = buf[p];
113  p++;
114  continue;
115  }
116  } else if (buf[p] == '(') {
117  keep = true;
118  comma_replace = ", ";
119  } else if (buf[p] == ')') {
120  keep = false;
121  }
122  if (p > i) {
123  buf[i] = buf[p];
124  }
125  }
126  buf[i] = 0;
127 
128  tokens = rz_str_split_duplist(buf, " ", true);
129  free(buf);
130  if (!tokens) {
131  return NULL;
132  }
133 
134  if (!strcmp((char *)rz_list_first(tokens), "call") && rz_list_length(tokens) == 3) {
135  void *arg1 = rz_list_get_n(tokens, 1);
136  void *arg2 = rz_list_get_n(tokens, 2);
137  rz_list_set_n(tokens, 1, arg2);
138  rz_list_set_n(tokens, 2, arg1);
139  }
140 
141  if (comma_replace) {
142  RzListIter *it;
143  rz_list_foreach (tokens, it, buf) {
144  it->data = rz_str_replace(buf, ",", comma_replace, 1);
145  }
146  }
147 
148  return tokens;
149 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
RZ_API ut32 rz_list_set_n(RZ_NONNULL RzList *list, ut32 n, void *p)
Sets the N-th element of the list.
Definition: list.c:552
RZ_API RZ_BORROW void * rz_list_first(RZ_NONNULL const RzList *list)
Returns the first element of the list.
Definition: list.c:77
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3464
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
void * data
Definition: rz_list.h:14

References rz_list_iter_t::data, free(), i, length, NULL, p, rz_list_first(), rz_list_get_n(), rz_list_length(), rz_list_set_n(), rz_str_ndup(), rz_str_replace(), and rz_str_split_duplist().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.version = RZ_VERSION
}
RzParsePlugin rz_parse_plugin_z80_pseudo
@ RZ_LIB_TYPE_PARSE
Definition: rz_lib.h:74
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 164 of file parse_z80_pseudo.c.

◆ rz_parse_plugin_z80_pseudo

RzParsePlugin rz_parse_plugin_z80_pseudo
Initial value:
= {
.name = "z80.pseudo",
.desc = "z80 pseudo syntax",
.init = NULL,
.fini = NULL,
.parse = parse,
}
static bool parse(RzParse *parse, const char *assembly, RzStrBuf *sb)

Definition at line 155 of file parse_z80_pseudo.c.

◆ z80_config

Definition at line 93 of file parse_z80_pseudo.c.

Referenced by parse().

◆ z80_lexicon

const RzPseudoGrammar z80_lexicon[]
static

Definition at line 19 of file parse_z80_pseudo.c.