Skip to content

Commit be61c4d

Browse files
committed
added license and added compressed decoding files, still didn't fix stringfication (printer_t)
1 parent 2861a7b commit be61c4d

13 files changed

+1132
-34
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ if(CAPSTONE_RISCV_SUPPORT)
577577
arch/RISCV/RISCVDisassembler.c
578578
arch/RISCV/RISCVDetails.c
579579
arch/RISCV/RISCVModule.c
580+
arch/RISCV/RISCVPrinter.c
580581
)
581582
set(HEADERS_RISCV
582583
arch/RISCV/riscv_ast.gen.inc
@@ -591,6 +592,7 @@ if(CAPSTONE_RISCV_SUPPORT)
591592
arch/RISCV/riscv_helpers_ast2str.h
592593
arch/RISCV/riscv_helpers_rvconf.h
593594
arch/RISCV/RISCVModule.h
595+
arch/RISCV/RISCVPrinter.h
594596
)
595597
endif()
596598

arch/RISCV/RISCVDisassembler.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include "riscv_decode.gen.inc"
55
#include "riscv_insn_mapping.gen.inc"
6-
#include "riscv_ast2str.gen.inc"
76

87
bool riscv_get_instruction(csh handle,
98
const uint8_t *code, size_t code_len, MCInst *instr,
@@ -24,27 +23,6 @@ bool riscv_get_instruction(csh handle,
2423
insn->address = address;
2524
*size = insn->size;
2625
memcpy(insn->bytes, code, insn->size);
27-
28-
char instruction_as_str[RISCV_MAX_INSTRUCTION_STR_LEN];
29-
riscv_conf conf;
30-
conf.sys_enable_fdext = NULL;
31-
conf.sys_enable_zfinx = NULL;
32-
33-
ast2str(&instruction, instruction_as_str, &conf);
34-
35-
char *curr = instruction_as_str;
36-
uint16_t mnemonic_len = 0;
37-
while (*curr != ' ') {
38-
mnemonic_len++;
39-
curr++;
40-
}
41-
uint16_t operand_len = 0;
42-
while (*curr) {
43-
operand_len++;
44-
curr++;
45-
}
46-
memcpy(insn->mnemonic, instruction_as_str, mnemonic_len);
47-
memcpy(insn->op_str, instruction_as_str + mnemonic_len + 1, operand_len);
4826
return true;
4927
} else {
5028

arch/RISCV/RISCVModule.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@
66

77
#include "RISCVModule.h"
88

9-
void noop_printer(MCInst *MI, SStream *OS, void *info) {
10-
11-
}
12-
13-
void noop_postprinter(csh handle, cs_insn *, SStream *mnem, MCInst *mci) {
14-
15-
}
16-
179
const char *noop_getname(csh handle, unsigned int id) {
1810
return "";
1911
}
@@ -24,11 +16,11 @@ void noop_getid(cs_struct *h, cs_insn *insn, unsigned int id) {
2416

2517
cs_err RISCV_global_init(cs_struct * ud)
2618
{
27-
ud->printer = noop_printer;
19+
ud->printer = riscv_printer;
2820
ud->printer_info = NULL;
2921
ud->getinsn_info = NULL;
3022
ud->disasm = riscv_get_instruction;
31-
ud->post_printer = noop_postprinter;
23+
ud->post_printer = NULL;
3224

3325
ud->reg_name = noop_getname;
3426
ud->insn_id = noop_getid;

arch/RISCV/RISCVModule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include "../../utils.h"
88
#include "RISCVDisassembler.h"
9+
#include "RISCVPrinter.h"
910

1011
cs_err RISCV_global_init(cs_struct * ud);
1112
cs_err RISCV_option(cs_struct * handle, cs_opt_type type, size_t value);

arch/RISCV/RISCVPrinter.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "RISCVPrinter.h"
2+
3+
void riscv_printer(MCInst *MI, SStream *OS, void *info) {
4+
// FIXME: add the ast struct as a member in the riscv_details
5+
//( stringification can't happen unless ast is available)
6+
7+
// char instruction_as_str[RISCV_MAX_INSTRUCTION_STR_LEN];
8+
// riscv_conf conf;
9+
// conf.sys_enable_fdext = NULL;
10+
// conf.sys_enable_zfinx = NULL;
11+
// ast2str(&instruction, instruction_as_str, &conf);
12+
}

arch/RISCV/RISCVPrinter.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef __RISCV_PRINTER__H_
2+
#define __RISCV_PRINTER__H_
3+
4+
#include "../../cs_priv.h"
5+
6+
//#include "riscv_ast2str.gen.inc" FIXME: uncomment when printer is implemented
7+
8+
void riscv_printer(MCInst *MI, SStream *OS, void *info);
9+
10+
#endif

arch/RISCV/riscv_ast.gen.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*=======================================================================*/
2+
/*This code was generated by the tool riscv_disasm_from_sail (see
3+
* https://github.com/moste00/riscv_disasm_from_sail)*/
4+
/*from the sail model of RISC-V (see https://github.com/riscv/sail-riscv) @
5+
* version 0b9c639f19da48734cbf14b61f6ad200b7c70de9.*/
6+
/*DO NOT MODIFY THIS CODE MANUALLY.*/
7+
/* */
8+
/*SPDX-License-Identifier: BSD-3-Clause*/
9+
/*=======================================================================*/
10+
111
#ifndef __Riscv_ast_gen_inc__
212
#define __Riscv_ast_gen_inc__
313
#include <stdint.h>

arch/RISCV/riscv_ast2str.gen.inc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*=======================================================================*/
2+
/*This code was generated by the tool riscv_disasm_from_sail (see
3+
* https://github.com/moste00/riscv_disasm_from_sail)*/
4+
/*from the sail model of RISC-V (see https://github.com/riscv/sail-riscv) @
5+
* version 0b9c639f19da48734cbf14b61f6ad200b7c70de9.*/
6+
/*DO NOT MODIFY THIS CODE MANUALLY.*/
7+
/* */
8+
/*SPDX-License-Identifier: BSD-3-Clause*/
9+
/*=======================================================================*/
10+
111
#ifndef __Riscv_ast2str_gen_inc__
212
#define __Riscv_ast2str_gen_inc__
313
#include <stdint.h>
@@ -67,7 +77,7 @@
6777
s7_len + s8_len + s9_len + s10_len + s11_len + s12_len, \
6878
s13, s13_len)
6979

70-
static void ast2str(struct ast *tree, char *buff, riscv_conf *conf) {
80+
void ast2str(struct ast *tree, char *buff, riscv_conf *conf) {
7181
memset(buff, 0, RISCV_MAX_INSTRUCTION_STR_LEN);
7282
switch (tree->ast_node_type) {
7383
case RISCV_UTYPE: {

arch/RISCV/riscv_ast2str_tbls.gen.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*=======================================================================*/
2+
/*This code was generated by the tool riscv_disasm_from_sail (see
3+
* https://github.com/moste00/riscv_disasm_from_sail)*/
4+
/*from the sail model of RISC-V (see https://github.com/riscv/sail-riscv) @
5+
* version 0b9c639f19da48734cbf14b61f6ad200b7c70de9.*/
6+
/*DO NOT MODIFY THIS CODE MANUALLY.*/
7+
/* */
8+
/*SPDX-License-Identifier: BSD-3-Clause*/
9+
/*=======================================================================*/
10+
111
#ifndef __Riscv_ast2str_tbls_gen_inc__
212
#define __Riscv_ast2str_tbls_gen_inc__
313
#include <stdint.h>

arch/RISCV/riscv_decode.gen.inc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*=======================================================================*/
2+
/*This code was generated by the tool riscv_disasm_from_sail (see
3+
* https://github.com/moste00/riscv_disasm_from_sail)*/
4+
/*from the sail model of RISC-V (see https://github.com/riscv/sail-riscv) @
5+
* version 0b9c639f19da48734cbf14b61f6ad200b7c70de9.*/
6+
/*DO NOT MODIFY THIS CODE MANUALLY.*/
7+
/* */
8+
/*SPDX-License-Identifier: BSD-3-Clause*/
9+
/*=======================================================================*/
10+
111
#ifndef __Riscv_decode_gen_inc__
212
#define __Riscv_decode_gen_inc__
313
#include <stdint.h>

0 commit comments

Comments
 (0)