-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Refactoring the RISCV architecture to Auto-Sync on LLVM #2756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
moste00
wants to merge
16
commits into
capstone-engine:next
Choose a base branch
from
moste00:refactor_riscv_autosync
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
aa8e587
Refactoring RISCV: INC generatione done, RISCV added to arch_config.j…
moste00 fb08d9d
the C++ translator runs successfully and first output under arch/RISC…
moste00 0c2cc3b
fixed Disassembler.c, in the process of fixing InstPrinter
moste00 ad513b1
more compile errors fixed, RISCVInstPrinter error-free
moste00 8a9626c
plugins compiles and runs, several test failures were fixed, current …
moste00 a275efd
compressed instructions compression and uncompression logic was gener…
moste00 cfc5ef8
massive fix handling various issues, test failures down to 35
moste00 012099c
test failures down to 2, related to inline option arch directives
moste00 b4d9e1b
added options to `cstool`, and started working on details test, 39/10…
moste00 e074c3d
more successful details test, added CSR operand type and changed csto…
moste00 0949896
more progress
moste00 0d8581c
failures decreased to 2
moste00 e1eaf2e
milestone: test failures 0
moste00 1d59145
add additional files generated from ASUpdate and update CMakeLists
moste00 e15a39b
fix most issues tests except the one about c_srli allowing illegal sh…
moste00 7f45480
fixed c_srli bug by updating the generated files from a fixed LLVM ve…
moste00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| /* Capstone Disassembly Engine, http://www.capstone-engine.org */ | ||
| /* By Nguyen Anh Quynh <[email protected]>, 2013-2022, */ | ||
| /* Rot127 <[email protected]> 2022-2023 */ | ||
| /* Automatically translated source file from LLVM. */ | ||
|
|
||
| /* LLVM-commit: <commit> */ | ||
| /* LLVM-tag: <tag> */ | ||
|
|
||
| /* Only small edits allowed. */ | ||
| /* For multiple similar edits, please create a Patch for the translator. */ | ||
|
|
||
| /* Capstone's C++ file translator: */ | ||
| /* https://github.com/capstone-engine/capstone/tree/next/suite/auto-sync */ | ||
|
|
||
| //===-- RISCVBaseInfo.cpp - Top level definitions for RISC-V MC -----------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This file contains small standalone enum definitions for the RISC-V target | ||
| // useful for the compiler back-end and the MC libraries. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <stdlib.h> | ||
| #include <capstone/platform.h> | ||
|
|
||
| #include "RISCVBaseInfo.h" | ||
|
|
||
| #define CONCAT(a, b) CONCAT_(a, b) | ||
| #define CONCAT_(a, b) a##_##b | ||
|
|
||
| typedef struct { | ||
| unsigned value; | ||
| bool isFractional; | ||
| } VLMULDecodeResult; | ||
| VLMULDecodeResult decodeVLMUL(RISCVII_VLMUL VLMUL) | ||
| { | ||
| switch (VLMUL) { | ||
| default: | ||
| CS_ASSERT(0 && "Unexpected LMUL value!"); | ||
| case RISCVII_LMUL_1: | ||
| case RISCVII_LMUL_2: | ||
| case RISCVII_LMUL_4: | ||
| case RISCVII_LMUL_8: { | ||
| VLMULDecodeResult result = { | ||
| .value = 1 << (unsigned)(VLMUL), | ||
| .isFractional = false | ||
| }; | ||
| return result; | ||
| } | ||
| case RISCVII_LMUL_F2: | ||
| case RISCVII_LMUL_F4: | ||
| case RISCVII_LMUL_F8: { | ||
| VLMULDecodeResult result = { | ||
| .value = 1 << (8 - (unsigned)(VLMUL)), | ||
| .isFractional = true | ||
| }; | ||
| return result; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void printVType(unsigned VType, SStream *OS) | ||
| { | ||
| unsigned Sew = RISCVVType_getSEW(VType); | ||
| SStream_concat(OS, "%s", "e"); | ||
| printUInt64(OS, Sew); | ||
|
|
||
| unsigned LMul; | ||
| bool Fractional; | ||
| VLMULDecodeResult result = decodeVLMUL(RISCVVType_getVLMUL(VType)); | ||
| LMul = result.value; | ||
| Fractional = result.isFractional; | ||
|
|
||
| if (Fractional) | ||
| SStream_concat0(OS, ", mf"); | ||
| else | ||
| SStream_concat0(OS, ", m"); | ||
| printUInt64(OS, LMul); | ||
|
|
||
| if (RISCVVType_isTailAgnostic(VType)) | ||
| SStream_concat0(OS, ", ta"); | ||
| else | ||
| SStream_concat0(OS, ", tu"); | ||
|
|
||
| if (RISCVVType_isMaskAgnostic(VType)) | ||
| SStream_concat0(OS, ", ma"); | ||
| else | ||
| SStream_concat0(OS, ", mu"); | ||
| } | ||
|
|
||
| typedef struct { | ||
| uint8_t first; | ||
| uint8_t second; | ||
| } LoadFP32ImmArrElement; | ||
|
|
||
| // Lookup table for fli.s for entries 2-31. | ||
| static const LoadFP32ImmArrElement LoadFP32ImmArr[] = { | ||
| { 0b01101111, 0b00 }, { 0b01110000, 0b00 }, { 0b01110111, 0b00 }, | ||
| { 0b01111000, 0b00 }, { 0b01111011, 0b00 }, { 0b01111100, 0b00 }, | ||
| { 0b01111101, 0b00 }, { 0b01111101, 0b01 }, { 0b01111101, 0b10 }, | ||
| { 0b01111101, 0b11 }, { 0b01111110, 0b00 }, { 0b01111110, 0b01 }, | ||
| { 0b01111110, 0b10 }, { 0b01111110, 0b11 }, { 0b01111111, 0b00 }, | ||
| { 0b01111111, 0b01 }, { 0b01111111, 0b10 }, { 0b01111111, 0b11 }, | ||
| { 0b10000000, 0b00 }, { 0b10000000, 0b01 }, { 0b10000000, 0b10 }, | ||
| { 0b10000001, 0b00 }, { 0b10000010, 0b00 }, { 0b10000011, 0b00 }, | ||
| { 0b10000110, 0b00 }, { 0b10000111, 0b00 }, { 0b10001110, 0b00 }, | ||
| { 0b10001111, 0b00 }, { 0b11111111, 0b00 }, { 0b11111111, 0b10 }, | ||
| }; | ||
|
|
||
| float getFPImm(unsigned Imm) | ||
| { | ||
| CS_ASSERT(Imm != 1 && Imm != 30 && Imm != 31 && | ||
| "Unsupported immediate"); | ||
|
|
||
| // Entry 0 is -1.0, the only negative value. Entry 16 is 1.0. | ||
| uint32_t Sign = 0; | ||
| if (Imm == 0) { | ||
| Sign = 0b1; | ||
| Imm = 16; | ||
| } | ||
|
|
||
| uint32_t Exp = LoadFP32ImmArr[Imm - 2].first; | ||
| uint32_t Mantissa = LoadFP32ImmArr[Imm - 2].second; | ||
|
|
||
| uint32_t I = Sign << 31 | Exp << 23 | Mantissa << 21; | ||
| float result; | ||
| memcpy(&result, &I, sizeof(float)); | ||
| return result; | ||
| } | ||
|
|
||
| void RISCVZC_printSpimm(int64_t Spimm, SStream *OS) | ||
| { | ||
| printInt32(OS, Spimm); | ||
| } | ||
|
|
||
| // namespace llvm | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immcan still be greater than the array boundaries.Please check this as well.