Skip to content

Commit

Permalink
quick fix with gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
garc0 committed Jul 10, 2022
1 parent df09349 commit 9b39f18
Show file tree
Hide file tree
Showing 5 changed files with 27,824 additions and 27,786 deletions.
7 changes: 3 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ project(ctasm VERSION 0.1.0)
include(CTest)
enable_testing()

add_subdirectory("zydis")
add_subdirectory("include")
include_directories("include")

add_executable(ctasm headonlyx86asm.cpp)
add_executable(ctasm examples/example01.cpp)

target_link_libraries(ctasm PRIVATE "Zydis")
target_link_libraries(ctasm)

set_property(TARGET ctasm PROPERTY CXX_STANDARD 17)

Expand Down
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ Ctasm is fully implemented in C++ templates (they are turing complete) and allow

### Example
``` c++
auto bytes = ctasm(
"example: "
"movdqu xmm0, zword ptr [rdi];"
"paddd xmm0, zword ptr [rsi];"
"movups zword ptr [rdi], xmm0;"
"ret 0;"
);
auto bytes = ctasm(R"(
movdqu xmm0, zword ptr [rdi]
paddd xmm0, zword ptr [rsi]
movups zword ptr [rdi], xmm0
ret
)");

for (auto &i : bytes)
std::cout << std::hex << (int)i << ' ';
Expand Down
13 changes: 6 additions & 7 deletions examples/example01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
#include <ctasm.hpp>

int main() {
auto bytes = ctasm(
"example: "
"movdqu xmm0, zword ptr [rdi];"
"paddd xmm0, zword ptr [rsi];"
"movups zword ptr [rdi], xmm0;"
"ret 0;"
);
auto bytes = ctasm(R"(
movdqu xmm0, zword ptr [rdi]
paddd xmm0, zword ptr [rsi]
movups zword ptr [rdi], xmm0
ret
)");

for (auto &i : bytes)
std::cout << std::hex << (int)i << ' ';
Expand Down
58 changes: 50 additions & 8 deletions include/ctasm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ namespace {
((Symbol >= 'a') && (Symbol <= 'z'))>;

template <char Symbol>
using is_digit_v = std::bool_constant<(Symbol >= '0') && (Symbol <= '9')>;
using is_digit_v = std::bool_constant<((Symbol >= '0') && (Symbol <= '9')) || (Symbol == '_')>;

template <char Symbol>
using is_space_v =
Expand Down Expand Up @@ -1019,7 +1019,7 @@ struct parse_num_impl<char_seq<first, str...>, N> {
template <char first, uint64_t N>
struct parse_num_impl<char_seq<first>, N> {
static constexpr uint64_t value =
((first >= 'A') && (first <= 'F')) ? (first - 'A' + 10) : (first - '0');
((first >= 'A') && (first <= 'F')) ? (first - 'A' + 10) : ((first == '_') ? 0 : (first - '0'));
};

template <typename T>
Expand Down Expand Up @@ -1225,6 +1225,7 @@ namespace {
Identifier,
SizeWord,
Number,
Void,
LeftParen,
RightParen,
LeftSquare,
Expand Down Expand Up @@ -1281,6 +1282,7 @@ namespace {
template <> constexpr std::string_view TokenName<Tokens::Identifier> = "Identifier";
template <> constexpr std::string_view TokenName<Tokens::SizeWord> = "SizeWord";
template <> constexpr std::string_view TokenName<Tokens::Number> = "Number";
template <> constexpr std::string_view TokenName<Tokens::Void> = "VoidSpace";
template <> constexpr std::string_view TokenName<Tokens::LeftParen> = "LeftParen";
template <> constexpr std::string_view TokenName<Tokens::RightParen> = "RightParen";
template <> constexpr std::string_view TokenName<Tokens::LeftSquare> = "LeftSquare";
Expand Down Expand Up @@ -1471,6 +1473,10 @@ namespace {
struct lex<N, 1, char_seq<';', Str...>>
: tok_templ<N, Tokens::End, Str...> {};

template <std::size_t N, char... Str>
struct lex<N, 1, char_seq<'\n', Str...>>
: tok_templ<N, Tokens::End, Str...> {};

template <std::size_t N, char... Str>
struct lex<N, 1, char_seq<'\x00', Str...>>
: tok_templ<N, Tokens::End, Str...> {};
Expand Down Expand Up @@ -1553,6 +1559,18 @@ namespace {
struct parse_primary<hold<Token<Tokens::Identifier, data>, Toks...>>{
using type = primary_node<Token<Tokens::Identifier, data>>;
using next = hold<Toks...>;
};


template<class ...Toks, class data>
struct parse_primary<hold<Token<Tokens::End, data>, Toks...>>:
parse_primary<hold<Toks...>> {
};
template<class data>
struct parse_primary<hold<Token<Tokens::End, data>>>
{
using type = hold<>;
using nenx = hold<>;
};

template<class ...Toks, class data>
Expand Down Expand Up @@ -1911,12 +1929,6 @@ namespace {
using type = hold<>;
};

template <std::size_t Prefix, class Data, class... Toks>
struct parse_label_or_data<Prefix, hold<Token<Tokens::End, Data>, Toks...>> {
using next = hold<Toks...>;
using type = hold<>;
};

template<class Toks>
using parse_global = parse_label_or_data<0, Toks>;
}
Expand Down Expand Up @@ -2140,6 +2152,10 @@ namespace {
using type = hold<>;
using has_labelref = std::false_type;
};
template<typename First, typename... Data, class Context>
struct map_nodes<hold<unary_node<Tokens::End, First>, Data...>, Context>:map_nodes<hold<>, Context> {
};


template<typename First, typename... Data, class Context>
struct map_nodes<hold<First, Data...>, Context> {
Expand Down Expand Up @@ -2386,6 +2402,21 @@ namespace {
};
}

namespace {
template<typename ...T>
struct paste_const {};

template<class Name, class F, class... Data>
struct paste_const<label_node<Name, hold<F, Data...>>>{
using type = typename paste_const<F>::type;
};

template<class Name, class Ops>
struct paste_const<instr_node<primary_node<Token<Tokens::Identifier, Name>>, Ops>>{

};
}

// second stage
namespace {
template<typename... T>
Expand Down Expand Up @@ -2876,6 +2907,17 @@ namespace {

}

//PoC "times" thing like "dx" thing(loeld)
/*namespace {
template<std::size_t N, class... T> struct _times_impl{};
template<char ...Str, class Times, class... T>
struct parse_instr_name<char_seq<'t', 'i', 'm', 'e', 's', Str...>, hold<Times, T...>> {
using type = _times_impl<>;
};
}*/

template <std::size_t N, const char (&s)[N], typename T>
struct make_char_sequence_impl;

Expand Down
Loading

0 comments on commit 9b39f18

Please sign in to comment.