mirror of
https://github.com/Ed94/perfaware.git
synced 2026-08-08 00:28:42 +00:00
Wiping repo clean, starting anew
This commit is contained in:
@@ -1,11 +0,0 @@
|
|||||||
[*.md]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 4
|
|
||||||
|
|
||||||
[*.c]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 4
|
|
||||||
|
|
||||||
[*.cpp]
|
|
||||||
indent_style = tab
|
|
||||||
indent_size = 4
|
|
||||||
Vendored
-19
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Win32",
|
|
||||||
"includePath": [
|
|
||||||
"${workspaceFolder}/**"
|
|
||||||
],
|
|
||||||
"defines": [
|
|
||||||
"_DEBUG",
|
|
||||||
"UNICODE",
|
|
||||||
"_UNICODE"
|
|
||||||
],
|
|
||||||
"windowsSdkVersion": "10.0.22621.0",
|
|
||||||
"compilerPath": "cl.exe",
|
|
||||||
"compileCommands": "${workspaceFolder}/part_1/build/compile_commands.json"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"version": 4
|
|
||||||
}
|
|
||||||
Vendored
-19
@@ -1,19 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "(Windows) Launch",
|
|
||||||
"type": "cppvsdbg",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "${workspaceRoot}/part_1/build/sim_8086.exe",
|
|
||||||
"args": [],
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"cwd": "${workspaceRoot}/part_1",
|
|
||||||
"environment": [],
|
|
||||||
"console": "externalTerminal"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
Vendored
-9
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"files.associations": {
|
|
||||||
"*.rmd": "markdown",
|
|
||||||
"zpl.h": "c",
|
|
||||||
"cstddef": "cpp",
|
|
||||||
"xtr1common": "cpp",
|
|
||||||
"*.inline": "cpp"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-51
@@ -1,51 +0,0 @@
|
|||||||
#include "bloat.hpp"
|
|
||||||
|
|
||||||
namespace Op
|
|
||||||
{
|
|
||||||
enum Code : u8
|
|
||||||
{
|
|
||||||
#define D_Entry( Entry_ ) Entry,
|
|
||||||
#include "opcodes.inline"
|
|
||||||
Num,
|
|
||||||
#undef D_Entry
|
|
||||||
};
|
|
||||||
|
|
||||||
char const* str( Code code )
|
|
||||||
{
|
|
||||||
static
|
|
||||||
char const* code_to_str[ Num] =
|
|
||||||
{
|
|
||||||
#define D_Entry( Entry_ ) ZPL_STRINGIFY( Entry_ ),
|
|
||||||
#include "opcodes.inline"
|
|
||||||
#undef D_Entry
|
|
||||||
};
|
|
||||||
|
|
||||||
return code_to_str[ code ];
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* meumonic( Code code )
|
|
||||||
{
|
|
||||||
static
|
|
||||||
char const* code_to_str[ Num] =
|
|
||||||
{
|
|
||||||
#define D_Entry( Entry_ ) ZPL_STRINGIFY( Entry_ ),
|
|
||||||
#include "opcodes.meumonics.inline"
|
|
||||||
#undef D_Entry
|
|
||||||
};
|
|
||||||
|
|
||||||
return code_to_str[ code ];
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* intuitive( Code code )
|
|
||||||
{
|
|
||||||
static
|
|
||||||
char const* code_to_str[ Num] =
|
|
||||||
{
|
|
||||||
#define D_Entry( Entry_ ) ZPL_STRINGIFY( Entry_ ),
|
|
||||||
#include "opcodes.intuitive.inline"
|
|
||||||
#undef D_Entry
|
|
||||||
};
|
|
||||||
|
|
||||||
return code_to_str[ Num];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,146 +0,0 @@
|
|||||||
D_Entry( add_00 )
|
|
||||||
D_Entry( add_01 )
|
|
||||||
D_Entry( add_02 )
|
|
||||||
D_Entry( add_04 )
|
|
||||||
D_Entry( add_05 )
|
|
||||||
D_Entry( push_06 )
|
|
||||||
D_Entry( pop_07 )
|
|
||||||
D_Entry( or_10 )
|
|
||||||
D_Entry( or_11 )
|
|
||||||
D_Entry( or_12 )
|
|
||||||
D_Entry( or_13 )
|
|
||||||
D_Entry( or_14 )
|
|
||||||
D_Entry( or_15 )
|
|
||||||
D_Entry( push_16 )
|
|
||||||
D_Entry( _17 )
|
|
||||||
D_Entry( adc_20 )
|
|
||||||
D_Entry( adc_21 )
|
|
||||||
D_Entry( adc_22 )
|
|
||||||
D_Entry( adc_23 )
|
|
||||||
D_Entry( adc_24 )
|
|
||||||
D_Entry( adc_25 )
|
|
||||||
D_Entry( push_26 )
|
|
||||||
D_Entry( pop_27 )
|
|
||||||
D_Entry( sbb_30 )
|
|
||||||
D_Entry( sbb_31 )
|
|
||||||
D_Entry( sbb_32 )
|
|
||||||
D_Entry( sbb_33 )
|
|
||||||
D_Entry( sbb_34 )
|
|
||||||
D_Entry( sbb_35 )
|
|
||||||
D_Entry( push_36 )
|
|
||||||
D_Entry( pop_37 )
|
|
||||||
D_Entry( and_40 )
|
|
||||||
D_Entry( and_41 )
|
|
||||||
D_Entry( and_42 )
|
|
||||||
D_Entry( and_43 )
|
|
||||||
D_Entry( and_44 )
|
|
||||||
D_Entry( and_45 )
|
|
||||||
D_Entry( es_46 )
|
|
||||||
D_Entry( daa_47 )
|
|
||||||
D_Entry( sub_50 )
|
|
||||||
D_Entry( sub_51 )
|
|
||||||
D_Entry( sub_52 )
|
|
||||||
D_Entry( sub_53 )
|
|
||||||
D_Entry( sub_54 )
|
|
||||||
D_Entry( sub_55 )
|
|
||||||
D_Entry( cs_56 )
|
|
||||||
D_Entry( das_57 )
|
|
||||||
D_Entry( xor_60 )
|
|
||||||
D_Entry( xor_61 )
|
|
||||||
D_Entry( xor_62 )
|
|
||||||
D_Entry( xor_63 )
|
|
||||||
D_Entry( xor_64 )
|
|
||||||
D_Entry( xor_65 )
|
|
||||||
D_Entry( ss_66 )
|
|
||||||
D_Entry( aaa_67 )
|
|
||||||
D_Entry( cmp_70 )
|
|
||||||
D_Entry( cmp_71 )
|
|
||||||
D_Entry( cmp_72 )
|
|
||||||
D_Entry( cmp_73 )
|
|
||||||
D_Entry( cmp_74 )
|
|
||||||
D_Entry( cmp_75 )
|
|
||||||
D_Entry( ds_75 )
|
|
||||||
D_Entry( ds_76 )
|
|
||||||
D_Entry( aas_107 )
|
|
||||||
D_Entry( inc_100 )
|
|
||||||
D_Entry( inc_101 )
|
|
||||||
D_Entry( inc_102 )
|
|
||||||
D_Entry( inc_103 )
|
|
||||||
D_Entry( inc_104 )
|
|
||||||
D_Entry( inc_105 )
|
|
||||||
D_Entry( inc_106 )
|
|
||||||
D_Entry( inc_107 )
|
|
||||||
D_Entry( dec_100 )
|
|
||||||
D_Entry( dec_101 )
|
|
||||||
D_Entry( dec_102 )
|
|
||||||
D_Entry( dec_103 )
|
|
||||||
D_Entry( dec_104 )
|
|
||||||
D_Entry( dec_105 )
|
|
||||||
D_Entry( dec_106 )
|
|
||||||
D_Entry( dec_107 )
|
|
||||||
D_Entry( push_110 )
|
|
||||||
D_Entry( push_111 )
|
|
||||||
D_Entry( push_112 )
|
|
||||||
D_Entry( push_113 )
|
|
||||||
D_Entry( push_114 )
|
|
||||||
D_Entry( push_115 )
|
|
||||||
D_Entry( push_116 )
|
|
||||||
D_Entry( push_117 )
|
|
||||||
D_Entry( pop_120 )
|
|
||||||
D_Entry( pop_121 )
|
|
||||||
D_Entry( pop_122 )
|
|
||||||
D_Entry( pop_123 )
|
|
||||||
D_Entry( pop_124 )
|
|
||||||
D_Entry( pop_125 )
|
|
||||||
D_Entry( pop_126 )
|
|
||||||
D_Entry( pop_127 )
|
|
||||||
D_Entry( pop_130 )
|
|
||||||
D_Entry( pop_131 )
|
|
||||||
D_Entry( pop_132 )
|
|
||||||
D_Entry( pop_133 )
|
|
||||||
D_Entry( pop_134 )
|
|
||||||
D_Entry( pop_135 )
|
|
||||||
D_Entry( pop_136 )
|
|
||||||
D_Entry( pop_137 )
|
|
||||||
D_Entry( _140 )
|
|
||||||
D_Entry( _141 )
|
|
||||||
D_Entry( _142 )
|
|
||||||
D_Entry( _143 )
|
|
||||||
D_Entry( _144 )
|
|
||||||
D_Entry( _145 )
|
|
||||||
D_Entry( _146 )
|
|
||||||
D_Entry( _147 )
|
|
||||||
D_Entry( _150 )
|
|
||||||
D_Entry( _151 )
|
|
||||||
D_Entry( _152 )
|
|
||||||
D_Entry( _153 )
|
|
||||||
D_Entry( _154 )
|
|
||||||
D_Entry( _155 )
|
|
||||||
D_Entry( _156 )
|
|
||||||
D_Entry( _157 )
|
|
||||||
D_Entry( jo_160 )
|
|
||||||
D_Entry( jno_161 )
|
|
||||||
D_Entry( jb_jnae_jc_162 )
|
|
||||||
D_Entry( jnb_jae_jnc_163 )
|
|
||||||
D_Entry( je_jz_164 )
|
|
||||||
D_Entry( jne_jnz_165 )
|
|
||||||
D_Entry( jbe_jna_166 )
|
|
||||||
D_Entry( jnbe_ja_167 )
|
|
||||||
D_Entry( js_170 )
|
|
||||||
D_Entry( jns_171 )
|
|
||||||
D_Entry( jp_jpe_172 )
|
|
||||||
D_Entry( jnp_jpo_173 )
|
|
||||||
D_Entry( jl_jnge_174 )
|
|
||||||
D_Entry( jnl_jge_175 )
|
|
||||||
D_Entry( jle_jng_176 )
|
|
||||||
D_Entry( jnle_jg_177 )
|
|
||||||
D_Entry( add_200 )
|
|
||||||
D_Entry( or_201 )
|
|
||||||
D_Entry( adc_201 )
|
|
||||||
D_Entry( sbb_202 )
|
|
||||||
D_Entry( sub_203 )
|
|
||||||
D_Entry( cmp_204 )
|
|
||||||
D_Entry( add_205 )
|
|
||||||
D_Entry( adc_206 )
|
|
||||||
D_Entry( sbb_207 )
|
|
||||||
D_Entry( sub_210 )
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
# perfaware
|
|
||||||
Homework for Casey's [Performance Aware Programming course](https://www.computerenhance.com/p/table-of-contents)
|
|
||||||
|
|
||||||
[Material Source](https://github.com/cmuratori/computer_enhance)
|
|
||||||
|
|
||||||
Thirdparty Libraries:
|
|
||||||
* [zpl](https://github.com/zpl-c) - Used instead of the C/C++ standard library.
|
|
||||||
|
|
||||||
Tools:
|
|
||||||
* [scoop](https://scoop.sh) : Windows package manager
|
|
||||||
* clang : C/C++ compiler
|
|
||||||
```scoop install llvm```
|
|
||||||
* meson : Build system
|
|
||||||
```scoop install meson```
|
|
||||||
* nasm : x86 Assembler
|
|
||||||
```scoop install nasm```
|
|
||||||
@@ -1,208 +0,0 @@
|
|||||||
#if __clang__
|
|
||||||
# pragma clang diagnostic ignored "-Wunused-const-variable"
|
|
||||||
# pragma clang diagnostic ignored "-Wswitch"
|
|
||||||
# pragma clang diagnostic ignored "-Wunused-variable"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region ZPL INCLUDE
|
|
||||||
|
|
||||||
#if __clang__
|
|
||||||
# pragma clang diagnostic push
|
|
||||||
# pragma clang diagnostic ignored "-Wmissing-braces"
|
|
||||||
# pragma clang diagnostic ignored "-Wbraced-scalar-init"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ZPL_IMPLEMENTATION
|
|
||||||
// # define ZPL_HEAP_ANALYSIS
|
|
||||||
# define ZPL_NO_MATH_H
|
|
||||||
# define ZPL_CUSTOM_MODULES
|
|
||||||
# define ZPL_MODULE_ESSENTIALS
|
|
||||||
# define ZPL_MODULE_CORE
|
|
||||||
# define ZPL_MODULE_TIMER
|
|
||||||
// # define ZPL_MODULE_HASHING
|
|
||||||
// # define ZPL_MODULE_REGEX
|
|
||||||
// # define ZPL_MODULE_EVENT
|
|
||||||
// # define ZPL_MODULE_DLL
|
|
||||||
// # define ZPL_MODULE_OPTS
|
|
||||||
// # define ZPL_MODULE_PROCESS
|
|
||||||
// # define ZPL_MODULE_MATH
|
|
||||||
// # define ZPL_MODULE_THREADING
|
|
||||||
// # define ZPL_MODULE_JOBS
|
|
||||||
// # define ZPL_MODULE_PARSER
|
|
||||||
// extern "C" {
|
|
||||||
#include "zpl.h"
|
|
||||||
// }
|
|
||||||
|
|
||||||
#if __clang__
|
|
||||||
# pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#pragma endregion ZPL INCLUDE
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
zpl_arena Global_Arena {};
|
|
||||||
#define g_allocator zpl_arena_allocator( & Global_Arena)
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
zpl_arena_init_from_allocator( & Global_Arena, zpl_heap(), zpl_megabytes(10) );
|
|
||||||
|
|
||||||
if ( Global_Arena.total_size == 0 )
|
|
||||||
{
|
|
||||||
zpl_assert_crash( "Failed to reserve memory for Tests:: Global_Arena" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanup()
|
|
||||||
{
|
|
||||||
zpl_arena_free( & Global_Arena);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma region ZPL Expose
|
|
||||||
zpl_string string_make(zpl_isize capacity)
|
|
||||||
{
|
|
||||||
zpl_isize header_size = zpl_size_of(zpl_string_header);
|
|
||||||
void *ptr = zpl_alloc(g_allocator, header_size + capacity + 1);
|
|
||||||
|
|
||||||
zpl_string str;
|
|
||||||
zpl_string_header *header;
|
|
||||||
|
|
||||||
if (ptr == NULL) return NULL;
|
|
||||||
zpl_zero_size(ptr, header_size + capacity + 1);
|
|
||||||
|
|
||||||
str = cast(char *) ptr + header_size;
|
|
||||||
header = ZPL_STRING_HEADER(str);
|
|
||||||
header->allocator = g_allocator;
|
|
||||||
header->length = 0;
|
|
||||||
header->capacity = capacity;
|
|
||||||
str[capacity] = '\0';
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
zpl_string string_make(const char *str)
|
|
||||||
{
|
|
||||||
zpl_isize len = str ? zpl_strlen(str) : 0;
|
|
||||||
return zpl_string_make_length(g_allocator, str, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
zpl_string string_append(zpl_string str, zpl_string const other)
|
|
||||||
{
|
|
||||||
return zpl_string_append_length(str, other, zpl_string_length(other));
|
|
||||||
}
|
|
||||||
|
|
||||||
zpl_string string_format( char const* fmt, ... )
|
|
||||||
{
|
|
||||||
zpl_local_persist zpl_thread_local char buf[ZPL_PRINTF_MAXLEN] = { 0 };
|
|
||||||
va_list va;
|
|
||||||
va_start(va, fmt);
|
|
||||||
zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va);
|
|
||||||
va_end(va);
|
|
||||||
|
|
||||||
return zpl_string_make(g_allocator, buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
zpl_string string_format( char* buffer, zpl_isize size, char const* fmt, ... )
|
|
||||||
{
|
|
||||||
va_list va;
|
|
||||||
va_start(va, fmt);
|
|
||||||
zpl_snprintf_va(buffer, size, fmt, va);
|
|
||||||
va_end(va);
|
|
||||||
|
|
||||||
return zpl_string_make(g_allocator, buffer);
|
|
||||||
}
|
|
||||||
#pragma endregion ZPL Expose
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define bit( Value_ ) ( 1 << Value_ )
|
|
||||||
#define bitfield_is_equal( Field_, Mask_ ) ( ( Mask_ & Field_ ) == Mask_ )
|
|
||||||
#undef cast
|
|
||||||
#define cast( Type_ , Value_ ) ( ( Type_ )( Value_ ) )
|
|
||||||
#define ct constexpr
|
|
||||||
#define gen( ... ) template< __VA_ARGS__ >
|
|
||||||
#define forceinline ZPL_ALWAYS_INLINE
|
|
||||||
#define print_nl( _) zpl_printf("\n")
|
|
||||||
#define Msg_Invalid_Value "INVALID VALUE PROVIDED"
|
|
||||||
#define scast static_cast
|
|
||||||
#define rcast reinterpret_cast
|
|
||||||
#define pcast( Type_, Value_ ) ( * (Type_*)( & Value_ ) )
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using s8 = zpl_i8;
|
|
||||||
using u8 = zpl_u8;
|
|
||||||
using u16 = zpl_u16;
|
|
||||||
using u32 = zpl_u32;
|
|
||||||
using f64 = zpl_f64;
|
|
||||||
using uw = zpl_usize;
|
|
||||||
using sw = zpl_isize;
|
|
||||||
|
|
||||||
struct u16_Split
|
|
||||||
{
|
|
||||||
u8 Low;
|
|
||||||
u8 High;
|
|
||||||
|
|
||||||
operator u16()
|
|
||||||
{
|
|
||||||
return * cast( u16*, this );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ct inline
|
|
||||||
char char_binary( u8 value, u8 pos )
|
|
||||||
{
|
|
||||||
u8 mask = 1 << pos ;
|
|
||||||
|
|
||||||
return ( (1 << pos) & value) == mask ? '1' : '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
void str_binary( char* result, u8 value )
|
|
||||||
{
|
|
||||||
#if 0
|
|
||||||
result[0] = char_binary( value, 0);
|
|
||||||
result[1] = char_binary( value, 1);
|
|
||||||
result[2] = char_binary( value, 2);
|
|
||||||
result[3] = char_binary( value, 3);
|
|
||||||
result[4] = char_binary( value, 4);
|
|
||||||
result[5] = char_binary( value, 5);
|
|
||||||
result[6] = char_binary( value, 6);
|
|
||||||
result[7] = char_binary( value, 7);
|
|
||||||
#else
|
|
||||||
result[0] = char_binary( value, 7);
|
|
||||||
result[1] = char_binary( value, 6);
|
|
||||||
result[2] = char_binary( value, 5);
|
|
||||||
result[3] = char_binary( value, 4);
|
|
||||||
result[4] = char_binary( value, 3);
|
|
||||||
result[5] = char_binary( value, 2);
|
|
||||||
result[6] = char_binary( value, 1);
|
|
||||||
result[7] = char_binary( value, 0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
void print_as_binary( u8* data, uw size, char const* byte_term )
|
|
||||||
{
|
|
||||||
char
|
|
||||||
binary_string[9];
|
|
||||||
binary_string[8] = '\0';
|
|
||||||
|
|
||||||
while ( size-- )
|
|
||||||
{
|
|
||||||
str_binary( binary_string, data[0]);
|
|
||||||
|
|
||||||
printf( "%s%s", binary_string, byte_term );
|
|
||||||
|
|
||||||
data += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
@echo off
|
|
||||||
|
|
||||||
if not exist build\nul (
|
|
||||||
meson setup build
|
|
||||||
)
|
|
||||||
|
|
||||||
echo:
|
|
||||||
if not exist tests\listing_0037_single_register_mov (
|
|
||||||
echo Assembling: listing_0037_single_register_mov.asm
|
|
||||||
call nasm ".\tests\listing_0037_single_register_mov.asm"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not exist tests\listing_0038_many_register_mov (
|
|
||||||
echo Assembling: listing_0038_many_register_mov.asm
|
|
||||||
call nasm ".\tests\listing_0038_many_register_mov.asm"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not exist tests\listing_0039_more_movs (
|
|
||||||
echo Assembling: listing_0039_more_movs.asm
|
|
||||||
call nasm ".\tests\listing_0039_more_movs.asm"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not exist tests\listing_0040_challenge_movs (
|
|
||||||
echo Assembling: listing_0040_challenge_movs.asm
|
|
||||||
call nasm ".\tests\listing_0040_challenge_movs.asm"
|
|
||||||
)
|
|
||||||
|
|
||||||
echo:
|
|
||||||
ninja -C build
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
@echo off
|
|
||||||
|
|
||||||
if exist build\nul (
|
|
||||||
@RD /S /Q "build"
|
|
||||||
)
|
|
||||||
|
|
||||||
if exist tests\listing_0037_single_register_mov (
|
|
||||||
DEL /Q tests\listing_0037_single_register_mov
|
|
||||||
)
|
|
||||||
|
|
||||||
if exist tests\listing_0038_many_register_mov (
|
|
||||||
DEL /Q tests\listing_0038_many_register_mov
|
|
||||||
)
|
|
||||||
|
|
||||||
if exist tests\listing_0039_more_movs (
|
|
||||||
DEL /Q tests\listing_0039_more_movs
|
|
||||||
)
|
|
||||||
|
|
||||||
if exist tests\listing_0040_challenge_movs (
|
|
||||||
DEL /Q tests\listing_0040_challenge_movs
|
|
||||||
)
|
|
||||||
|
|
||||||
Binary file not shown.
@@ -1,13 +0,0 @@
|
|||||||
project( 'sim_8086', 'c', 'cpp', default_options : ['buildtype=debug'] )
|
|
||||||
|
|
||||||
include_thirdparty = include_directories( '../thirdparty' )
|
|
||||||
|
|
||||||
# add_global_arguments('-E', language : 'cpp')
|
|
||||||
|
|
||||||
if get_option('buildtype').startswith('debug')
|
|
||||||
|
|
||||||
add_project_arguments('-DBuild_Debug', language : 'cpp')
|
|
||||||
|
|
||||||
endif
|
|
||||||
|
|
||||||
executable( 'sim_8086', 'sim_8086.cpp', include_directories : include_thirdparty )
|
|
||||||
@@ -1,756 +0,0 @@
|
|||||||
#include "bloat.hpp"
|
|
||||||
|
|
||||||
// Octal formatting is used heavily throughout
|
|
||||||
// See: https://gist.github.com/seanjensengrey/f971c20d05d4d0efc0781f2f3c0353da
|
|
||||||
// (x86 is an octal machine)
|
|
||||||
|
|
||||||
namespace Op
|
|
||||||
{
|
|
||||||
ct u8 Mask = 00210;
|
|
||||||
ct u8 Mask_Low = 0b11110000;
|
|
||||||
ct u8 Mask_High = 0b00001111;
|
|
||||||
ct u8 Mask_Imme = 0b00111000;
|
|
||||||
|
|
||||||
#define D_Opcodes \
|
|
||||||
D_Entry( mov_RM_R ) \
|
|
||||||
D_Entry( mov_Im_RM ) \
|
|
||||||
D_Entry( mov_Im_R ) \
|
|
||||||
D_Entry( mov_M_Acc ) \
|
|
||||||
D_Entry( mov_Acc_M ) \
|
|
||||||
D_Entry( mov_RM_SR ) \
|
|
||||||
D_Entry( mov_SR_RM ) \
|
|
||||||
|
|
||||||
enum Code : u8
|
|
||||||
{
|
|
||||||
mov_RM_R = 0b10001000,
|
|
||||||
mov_Im_RM = 0b11001100,
|
|
||||||
mov_Im_R = 0b10110000,
|
|
||||||
mov_M_Acc = 0b10100000,
|
|
||||||
mov_Acc_M = 0b10100010,
|
|
||||||
mov_RM_SR = 0b10001110,
|
|
||||||
mov_SR_RM = 0b10001100
|
|
||||||
};
|
|
||||||
|
|
||||||
char const* str( Code type )
|
|
||||||
{
|
|
||||||
switch ( type )
|
|
||||||
{
|
|
||||||
#define D_Entry( Entry_ ) \
|
|
||||||
case Entry_: \
|
|
||||||
return ZPL_STRINGIFY(Entry_); \
|
|
||||||
|
|
||||||
D_Opcodes
|
|
||||||
#undef D_Entry
|
|
||||||
}
|
|
||||||
|
|
||||||
return Msg_Invalid_Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* meumonic( Code type )
|
|
||||||
{
|
|
||||||
switch ( type )
|
|
||||||
{
|
|
||||||
case mov_RM_R :
|
|
||||||
case mov_Im_RM :
|
|
||||||
case mov_Im_R :
|
|
||||||
case mov_M_Acc :
|
|
||||||
case mov_Acc_M :
|
|
||||||
case mov_RM_SR :
|
|
||||||
case mov_SR_RM :
|
|
||||||
return "mov";
|
|
||||||
}
|
|
||||||
|
|
||||||
return Msg_Invalid_Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* intuitive( Code type )
|
|
||||||
{
|
|
||||||
switch ( type )
|
|
||||||
{
|
|
||||||
case mov_RM_R :
|
|
||||||
case mov_Im_RM :
|
|
||||||
case mov_Im_R :
|
|
||||||
case mov_M_Acc :
|
|
||||||
case mov_Acc_M :
|
|
||||||
case mov_RM_SR :
|
|
||||||
case mov_SR_RM :
|
|
||||||
return "move";
|
|
||||||
}
|
|
||||||
|
|
||||||
return Msg_Invalid_Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef D_Opcodes
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Field
|
|
||||||
{
|
|
||||||
inline
|
|
||||||
u8 offset_left_reg( u8 reg )
|
|
||||||
{
|
|
||||||
return reg << 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://i.imgur.com/drsyYnM.png
|
|
||||||
enum Direction : u8
|
|
||||||
{
|
|
||||||
Mask_Dir = 0b00000010,
|
|
||||||
Dir_Src = 0b00,
|
|
||||||
Dir_Dest = 0b10,
|
|
||||||
};
|
|
||||||
|
|
||||||
inline
|
|
||||||
char const* str_direction( Direction direction )
|
|
||||||
{
|
|
||||||
switch ( direction )
|
|
||||||
{
|
|
||||||
case Dir_Dest:
|
|
||||||
return "Destination";
|
|
||||||
|
|
||||||
case Dir_Src:
|
|
||||||
return "Source";
|
|
||||||
}
|
|
||||||
|
|
||||||
return Msg_Invalid_Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://i.imgur.com/9Op8Lnd.png
|
|
||||||
enum Width : u8
|
|
||||||
{
|
|
||||||
Mask_Width = 0b00000001,
|
|
||||||
Mask_Width_Imme = 0b00001000,
|
|
||||||
Width_Byte = 0b00,
|
|
||||||
Width_Word = 0b01,
|
|
||||||
};
|
|
||||||
|
|
||||||
inline
|
|
||||||
char const* str_width( Width width )
|
|
||||||
{
|
|
||||||
switch ( width )
|
|
||||||
{
|
|
||||||
case Width_Byte:
|
|
||||||
return "Byte";
|
|
||||||
|
|
||||||
case Width_Word:
|
|
||||||
return "Word";
|
|
||||||
}
|
|
||||||
|
|
||||||
return Msg_Invalid_Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// https://i.imgur.com/Job2oPd.png
|
|
||||||
enum Mode : u8
|
|
||||||
{
|
|
||||||
Mask_Mode = 0b11000000,
|
|
||||||
Mode_Mem = 0b00000000,
|
|
||||||
Mode_Mem8 = 0b01000000,
|
|
||||||
Mode_Mem16 = 0b10000000,
|
|
||||||
Mode_Reg = 0b11000000,
|
|
||||||
};
|
|
||||||
|
|
||||||
char const* str_mode( Mode mode )
|
|
||||||
{
|
|
||||||
switch (mode)
|
|
||||||
{
|
|
||||||
case Mode_Mem:
|
|
||||||
return "Memory: No Displacement";
|
|
||||||
|
|
||||||
case Mode_Mem8:
|
|
||||||
return "Memory: 8-bit Displacment";
|
|
||||||
|
|
||||||
case Mode_Mem16:
|
|
||||||
return "Memory: 16-bit Displacement";
|
|
||||||
|
|
||||||
case Mode_Reg:
|
|
||||||
return "Register";
|
|
||||||
}
|
|
||||||
|
|
||||||
return Msg_Invalid_Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
ct u8 Mask_Memory = 0b00000111;
|
|
||||||
|
|
||||||
// https://i.imgur.com/Tm5roJu.png
|
|
||||||
enum Memory : u8
|
|
||||||
{
|
|
||||||
Add_BX_SI = 0b000,
|
|
||||||
Add_BX_DI = 0b001,
|
|
||||||
Add_BP_SI = 0b010,
|
|
||||||
Add_BP_DI = 0b011,
|
|
||||||
Add_SI = 0b100,
|
|
||||||
Add_DI = 0b101,
|
|
||||||
Add_Direct = 0b110,
|
|
||||||
Add_BX = 0b111,
|
|
||||||
|
|
||||||
Num_Memory
|
|
||||||
};
|
|
||||||
|
|
||||||
char const* str_memory( Memory mem )
|
|
||||||
{
|
|
||||||
char const* mem_to_str[Num_Memory] =
|
|
||||||
{
|
|
||||||
"BX + SI",
|
|
||||||
"BX + DI",
|
|
||||||
"BP + SI",
|
|
||||||
"BP + DI",
|
|
||||||
"SI",
|
|
||||||
"DI",
|
|
||||||
"BP",
|
|
||||||
"BX"
|
|
||||||
};
|
|
||||||
|
|
||||||
return mem_to_str[ mem ];
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* str_memory_intuitive( Memory mem )
|
|
||||||
{
|
|
||||||
char const* mem_to_str[Num_Memory] =
|
|
||||||
{
|
|
||||||
"Base.16 + Stack.Index",
|
|
||||||
"Base.16 + Destination.Index",
|
|
||||||
"Stack.Base + Stack.Index",
|
|
||||||
"Stack.Base + Destination.Index",
|
|
||||||
"Stack.Index",
|
|
||||||
"Destination.Index",
|
|
||||||
"Stack.Base",
|
|
||||||
"BX"
|
|
||||||
};
|
|
||||||
|
|
||||||
return mem_to_str[ mem ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace Register
|
|
||||||
{
|
|
||||||
ct u8 Mask_Imme = 0b00000111;
|
|
||||||
ct u8 Mask_Left = 0b00111000;
|
|
||||||
ct u8 Mask_Right = 0b00000111;
|
|
||||||
|
|
||||||
#define D_Opcodes \
|
|
||||||
D_Entry( AL ) \
|
|
||||||
D_Entry( CL ) \
|
|
||||||
D_Entry( DL ) \
|
|
||||||
D_Entry( BL ) \
|
|
||||||
D_Entry( AH ) \
|
|
||||||
D_Entry( CH ) \
|
|
||||||
D_Entry( DH ) \
|
|
||||||
D_Entry( BH ) \
|
|
||||||
D_Entry( AX ) \
|
|
||||||
D_Entry( CX ) \
|
|
||||||
D_Entry( DX ) \
|
|
||||||
D_Entry( BX ) \
|
|
||||||
D_Entry( SP ) \
|
|
||||||
D_Entry( BP ) \
|
|
||||||
D_Entry( SI ) \
|
|
||||||
D_Entry( DI ) \
|
|
||||||
|
|
||||||
enum Type : u8
|
|
||||||
{
|
|
||||||
AL = 0b000,
|
|
||||||
CL = 0b001,
|
|
||||||
DL = 0b010,
|
|
||||||
BL = 0b011,
|
|
||||||
|
|
||||||
AH = 0b100,
|
|
||||||
CH = 0b101,
|
|
||||||
DH = 0b110,
|
|
||||||
BH = 0b111,
|
|
||||||
|
|
||||||
AX = 0b000,
|
|
||||||
CX = 0b001,
|
|
||||||
DX = 0b010,
|
|
||||||
BX = 0b011,
|
|
||||||
|
|
||||||
SP = 0b100,
|
|
||||||
BP = 0b101,
|
|
||||||
SI = 0b110,
|
|
||||||
DI = 0b111,
|
|
||||||
|
|
||||||
Num = 16
|
|
||||||
};
|
|
||||||
|
|
||||||
char const* meumonic( Type type, u8 Width )
|
|
||||||
{
|
|
||||||
static char const*
|
|
||||||
Type_To_Meumonic[ Num ] =
|
|
||||||
{
|
|
||||||
#define D_Entry( Entry_ ) #Entry_,
|
|
||||||
D_Opcodes
|
|
||||||
#undef D_Entry
|
|
||||||
};
|
|
||||||
|
|
||||||
return Type_To_Meumonic[ type + Width * ( 7 + 1 ) ];
|
|
||||||
}
|
|
||||||
|
|
||||||
char const* intuitive( Type type, u8 Width )
|
|
||||||
{
|
|
||||||
static char const*
|
|
||||||
Type_To_Intuitive[ Num ] =
|
|
||||||
{
|
|
||||||
"Accumulator.Low",
|
|
||||||
"Count.Low",
|
|
||||||
"Data.Low",
|
|
||||||
"Base.Low",
|
|
||||||
"Accumulator.High",
|
|
||||||
"Count.High",
|
|
||||||
"Data.High",
|
|
||||||
"Base.High",
|
|
||||||
"Accumulator.16",
|
|
||||||
"Count.16",
|
|
||||||
"Data.16",
|
|
||||||
"Base.16",
|
|
||||||
"Stack.Pointer",
|
|
||||||
"Stack.Base",
|
|
||||||
"Source.Index",
|
|
||||||
"Destination.Index",
|
|
||||||
};
|
|
||||||
|
|
||||||
return Type_To_Intuitive[ type + Width * ( 7 + 1 ) ];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct Octal
|
|
||||||
{
|
|
||||||
u8 Low : 3;
|
|
||||||
u8 High : 3;
|
|
||||||
u8 Dir : 1;
|
|
||||||
u8 Write : 1;
|
|
||||||
|
|
||||||
operator u8()
|
|
||||||
{
|
|
||||||
return * cast( u8*, this);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
struct POD_Instruction
|
|
||||||
{
|
|
||||||
// 8086 Instructions are 1 to 6 bytes in length.
|
|
||||||
union
|
|
||||||
{
|
|
||||||
u8* Ptr;
|
|
||||||
u8 Byte[6];
|
|
||||||
|
|
||||||
Octal Instr;
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
u8 Pad[2];
|
|
||||||
u16_Split Disp;
|
|
||||||
u16_Split Data;
|
|
||||||
}
|
|
||||||
EffAddr;
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
u8 Pad[1];
|
|
||||||
u16_Split Data;
|
|
||||||
}
|
|
||||||
Imme;
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
u8 Pad;
|
|
||||||
u16_Split Data;
|
|
||||||
}
|
|
||||||
Addr;
|
|
||||||
};
|
|
||||||
|
|
||||||
// If directly referencing blob data:
|
|
||||||
// Part of next instruction, do not use as stratch memory.
|
|
||||||
u16 Pad;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Instruction : public POD_Instruction
|
|
||||||
{
|
|
||||||
using Code = Op::Code;
|
|
||||||
using Direction = Field::Direction;
|
|
||||||
using Mode = Field::Mode;
|
|
||||||
using Memory = Field::Memory;
|
|
||||||
using Width = Field::Width;
|
|
||||||
using Reg = Register::Type;
|
|
||||||
|
|
||||||
inline
|
|
||||||
Direction get_direction()
|
|
||||||
{
|
|
||||||
Direction direction = cast(Direction, Byte[0] & Field::Mask_Dir);
|
|
||||||
|
|
||||||
return direction;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
Mode get_mode()
|
|
||||||
{
|
|
||||||
Mode mode = cast( Mode, Byte[1] & Field::Mask_Mode );
|
|
||||||
|
|
||||||
return mode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
Code get_opcode( u8 mask )
|
|
||||||
{
|
|
||||||
Op::Code opcode = cast( Op::Code, Byte[0] & mask );
|
|
||||||
|
|
||||||
return opcode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
Width get_width( u8 mask )
|
|
||||||
{
|
|
||||||
Width width = cast( Width, Byte[0] & mask );
|
|
||||||
|
|
||||||
return width;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
Reg mode_operand_left_reg()
|
|
||||||
{
|
|
||||||
u8
|
|
||||||
operand = Byte[1] & Register::Mask_Left;
|
|
||||||
operand >>= 3;
|
|
||||||
|
|
||||||
return cast(Reg, operand);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline
|
|
||||||
Reg mode_operand_right_reg()
|
|
||||||
{
|
|
||||||
u8 operand = Byte[1] & Register::Mask_Right;
|
|
||||||
|
|
||||||
return cast( Reg, operand );
|
|
||||||
}
|
|
||||||
|
|
||||||
forceinline
|
|
||||||
void dissassemble_mode( char const*& str_operand, Width& width, u8& length )
|
|
||||||
{
|
|
||||||
using namespace Field;
|
|
||||||
using namespace Op;
|
|
||||||
using namespace Register;
|
|
||||||
|
|
||||||
switch ( get_mode() )
|
|
||||||
{
|
|
||||||
case Mode_Mem:
|
|
||||||
{
|
|
||||||
Memory operand_right = cast( Memory, Byte[1] & Mask_Memory );
|
|
||||||
|
|
||||||
length += 2;
|
|
||||||
|
|
||||||
if ( operand_right == Add_Direct )
|
|
||||||
{
|
|
||||||
u16 address = EffAddr.Disp;
|
|
||||||
|
|
||||||
str_operand = string_format( "[ %u ]", address );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
str_operand = str_memory( operand_right );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Mode_Mem8:
|
|
||||||
{
|
|
||||||
Memory operand_right = cast( Memory, Byte[1] & Mask_Memory );
|
|
||||||
|
|
||||||
length += 1;
|
|
||||||
|
|
||||||
str_operand = string_format( "[ %s + %u ]", str_memory( operand_right), EffAddr.Disp.Low );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Mode_Mem16:
|
|
||||||
{
|
|
||||||
length += 2;
|
|
||||||
|
|
||||||
Memory operand_right = cast( Memory, Byte[1] & Mask_Memory );
|
|
||||||
u16 address = EffAddr.Disp;
|
|
||||||
|
|
||||||
str_operand = string_format( "[ %s + %u ]", str_memory( operand_right), address );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case Mode_Reg:
|
|
||||||
str_operand = Register::meumonic( mode_operand_right_reg(), width );
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 dissassemble( zpl_string* result_out )
|
|
||||||
{
|
|
||||||
using namespace Field;
|
|
||||||
using namespace Op;
|
|
||||||
using namespace Register;
|
|
||||||
|
|
||||||
u8 length = 1;
|
|
||||||
|
|
||||||
zpl_string assembly = string_make( 32);
|
|
||||||
|
|
||||||
Code code = get_opcode( Op::Mask );
|
|
||||||
Direction dir = get_direction();
|
|
||||||
|
|
||||||
char const* str_operand_left = nullptr;
|
|
||||||
char const* str_operand_right = nullptr;
|
|
||||||
|
|
||||||
const u8 code_low = Byte[0] & Op::Mask_Low;
|
|
||||||
const u8 code_high = Byte[0] & Op::Mask_High;
|
|
||||||
const u8 sig_imme = Byte[0] & Op::Mask_Imme;
|
|
||||||
|
|
||||||
if ( get_opcode( Op::Mask_Low ) == mov_Im_R )
|
|
||||||
{
|
|
||||||
Width width = get_width( Mask_Width_Imme );
|
|
||||||
Reg reg = cast(Reg, Byte[0] & Register::Mask_Right );
|
|
||||||
u16 immediate = width == Width_Byte ?
|
|
||||||
Imme.Data.Low : Imme.Data;
|
|
||||||
|
|
||||||
str_operand_left = Register::meumonic( reg, width );
|
|
||||||
str_operand_right = string_format( "%u", immediate );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
switch ( code )
|
|
||||||
{
|
|
||||||
#pragma region mov
|
|
||||||
case mov_RM_R:
|
|
||||||
{
|
|
||||||
length++;
|
|
||||||
|
|
||||||
Width width = get_width( Mask_Width );
|
|
||||||
|
|
||||||
str_operand_left = Register::meumonic( mode_operand_left_reg(), width );
|
|
||||||
|
|
||||||
dissassemble_mode( str_operand_right, width, length );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case mov_Im_RM:
|
|
||||||
{
|
|
||||||
Width width = get_width( Mask_Width_Imme );
|
|
||||||
|
|
||||||
Memory operand_left = cast( Memory, Byte[1] & Mask_Memory );
|
|
||||||
u16 address = EffAddr.Disp;
|
|
||||||
u16 immediate = width == Width_Byte ?
|
|
||||||
EffAddr.Data.Low : EffAddr.Data;
|
|
||||||
|
|
||||||
dissassemble_mode( str_operand_left, width, length );
|
|
||||||
|
|
||||||
str_operand_right = string_format( "%u", immediate );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case mov_M_Acc:
|
|
||||||
{
|
|
||||||
Width width = get_width( Mask_Width );
|
|
||||||
u16 address = width == Width_Byte ?
|
|
||||||
Addr.Data.Low : Addr.Data;
|
|
||||||
|
|
||||||
str_operand_left = Register::meumonic( Reg::AX, Width_Word );
|
|
||||||
str_operand_right = string_format( "%u", address );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case mov_Acc_M:
|
|
||||||
{
|
|
||||||
Width width = get_width( Mask_Width );
|
|
||||||
u16 address = width == Width_Byte ?
|
|
||||||
Addr.Data.Low : Addr.Data;
|
|
||||||
|
|
||||||
str_operand_right = string_format( "%u", address );
|
|
||||||
str_operand_left = Register::meumonic( Reg::AX, Width_Word );
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case mov_RM_SR:
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case mov_SR_RM:
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#pragma endregion mov
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assembly = string_format( assembly, 32, "\n%s %s, %s"
|
|
||||||
// opcode operand_right, operand_left
|
|
||||||
, Op::meumonic( code)
|
|
||||||
, str_operand_right
|
|
||||||
, str_operand_left
|
|
||||||
);
|
|
||||||
|
|
||||||
if ( result_out == nullptr )
|
|
||||||
return length;
|
|
||||||
|
|
||||||
if ( * result_out == nullptr )
|
|
||||||
* result_out = string_make( zpl_kilobytes(1) );
|
|
||||||
|
|
||||||
* result_out = string_append( * result_out, assembly );
|
|
||||||
|
|
||||||
zpl_printf("\n\nAssembly: %s\n\n", assembly);
|
|
||||||
|
|
||||||
return length;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Tests
|
|
||||||
{
|
|
||||||
void try_mock_instruction()
|
|
||||||
{
|
|
||||||
using namespace Field;
|
|
||||||
using namespace Op;
|
|
||||||
using namespace Register;
|
|
||||||
|
|
||||||
Instruction
|
|
||||||
mock; // mov CX, BX
|
|
||||||
mock.Byte[0] = mov_RM_R | Dir_Src | Field::Width_Word;
|
|
||||||
mock.Byte[1] = Field::Mode_Reg | offset_left_reg(BX) | CX;
|
|
||||||
|
|
||||||
zpl_printf("\n\nAttempting Mock Instruction: mov CX, BX");
|
|
||||||
|
|
||||||
print_nl();
|
|
||||||
print_as_binary( & mock.Byte[0], 1, " " );
|
|
||||||
print_as_binary( & mock.Byte[1], 1, " " );
|
|
||||||
print_nl();
|
|
||||||
|
|
||||||
zpl_string dissasembly = nullptr;
|
|
||||||
|
|
||||||
mock.dissassemble( & dissasembly);
|
|
||||||
}
|
|
||||||
|
|
||||||
void try_blob_single_move()
|
|
||||||
{
|
|
||||||
zpl_printf("\n\nAttempting to read blob: listing_0037_single_register_mov");
|
|
||||||
|
|
||||||
zpl_file_contents
|
|
||||||
blob = zpl_file_read_contents( g_allocator, false, "tests/listing_0037_single_register_mov" );
|
|
||||||
|
|
||||||
if (blob.data == nullptr )
|
|
||||||
return;
|
|
||||||
|
|
||||||
u32 left = blob.size;
|
|
||||||
u8* data = cast( u8*, blob.data );
|
|
||||||
|
|
||||||
print_nl();
|
|
||||||
print_as_binary( data, left, " " );
|
|
||||||
print_nl();
|
|
||||||
|
|
||||||
zpl_string dissasembly = nullptr;
|
|
||||||
|
|
||||||
Instruction
|
|
||||||
instr;
|
|
||||||
instr.Byte[0] = data[0];
|
|
||||||
instr.Byte[1] = data[1];
|
|
||||||
instr.dissassemble( & dissasembly);
|
|
||||||
}
|
|
||||||
|
|
||||||
void try_blob_many_moves()
|
|
||||||
{
|
|
||||||
zpl_printf("\n\nAttempting to read blob: listing_0038_many_register_mov");
|
|
||||||
|
|
||||||
zpl_file_contents
|
|
||||||
blob = zpl_file_read_contents( g_allocator, false, "tests/listing_0038_many_register_mov" );
|
|
||||||
|
|
||||||
if (blob.data == nullptr )
|
|
||||||
return;
|
|
||||||
|
|
||||||
u32 left = blob.size;
|
|
||||||
u8* data = cast( u8*, blob.data );
|
|
||||||
|
|
||||||
print_nl();
|
|
||||||
print_as_binary( data, left, " " );
|
|
||||||
print_nl();
|
|
||||||
|
|
||||||
zpl_string dissasembly = string_make( "bits 16\n");
|
|
||||||
|
|
||||||
while ( left )
|
|
||||||
{
|
|
||||||
Instruction
|
|
||||||
instr;
|
|
||||||
instr.Byte[0] = data[0];
|
|
||||||
instr.Byte[1] = data[1];
|
|
||||||
instr.dissassemble( & dissasembly);
|
|
||||||
|
|
||||||
data += 2;
|
|
||||||
left -= 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
zpl_printf("\n\nDissassemlby:\n%s", dissasembly);
|
|
||||||
dissasembly = zpl_string_append_fmt( dissasembly, "\n" );
|
|
||||||
|
|
||||||
zpl_printf("\n\nSaving to file");
|
|
||||||
zpl_file_write_contents("tests/listing_0038_many_register_mov.out.asm"
|
|
||||||
, dissasembly
|
|
||||||
, zpl_string_length(dissasembly)
|
|
||||||
, nullptr
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void try_blob_more_moves()
|
|
||||||
{
|
|
||||||
zpl_printf("\n\nAttempting to read blob: listing_0039_more_movs");
|
|
||||||
|
|
||||||
zpl_file_contents
|
|
||||||
blob = zpl_file_read_contents( g_allocator, false, "tests/listing_0039_more_movs" );
|
|
||||||
|
|
||||||
if (blob.data == nullptr )
|
|
||||||
return;
|
|
||||||
|
|
||||||
u32 left = blob.size;
|
|
||||||
u8* data = cast( u8*, blob.data );
|
|
||||||
|
|
||||||
print_nl();
|
|
||||||
print_as_binary( data, left, " " );
|
|
||||||
print_nl();
|
|
||||||
|
|
||||||
zpl_string dissasembly = string_make( "bits 16\n");
|
|
||||||
|
|
||||||
while ( left )
|
|
||||||
{
|
|
||||||
Instruction
|
|
||||||
instr;
|
|
||||||
instr.Ptr = data;
|
|
||||||
|
|
||||||
u8 length = instr.dissassemble( & dissasembly);
|
|
||||||
|
|
||||||
data += length;
|
|
||||||
left -= length;
|
|
||||||
}
|
|
||||||
|
|
||||||
zpl_printf("\n\nDissassemlby:\n%s", dissasembly);
|
|
||||||
dissasembly = zpl_string_append_fmt( dissasembly, "\n" );
|
|
||||||
|
|
||||||
zpl_printf("\n\nSaving to file");
|
|
||||||
zpl_file_write_contents("tests/listing_0039_more_movs.asm.out.asm"
|
|
||||||
, dissasembly
|
|
||||||
, zpl_string_length(dissasembly)
|
|
||||||
, nullptr
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
zpl_printf("sim 8086!");
|
|
||||||
|
|
||||||
setup();
|
|
||||||
|
|
||||||
f64 start = zpl_time_rel();
|
|
||||||
|
|
||||||
// Tests::try_blob_single_move();
|
|
||||||
// Tests::try_blob_many_moves();
|
|
||||||
Tests::try_blob_more_moves();
|
|
||||||
|
|
||||||
f64 end = zpl_time_rel();
|
|
||||||
f64 ms = (end - start) * 100;
|
|
||||||
|
|
||||||
printf("\n\nElapsed Time: %lf ms", ms);
|
|
||||||
printf("\n\n");
|
|
||||||
|
|
||||||
cleanup();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
��
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
; ========================================================================
|
|
||||||
;
|
|
||||||
; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
|
|
||||||
;
|
|
||||||
; This software is provided 'as-is', without any express or implied
|
|
||||||
; warranty. In no event will the authors be held liable for any damages
|
|
||||||
; arising from the use of this software.
|
|
||||||
;
|
|
||||||
; Please see https://computerenhance.com for further information
|
|
||||||
;
|
|
||||||
; ======================================================================== */
|
|
||||||
|
|
||||||
; ========================================================================
|
|
||||||
; LISTING 37
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
mov cx, bx
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
‰Ùˆå‰Ú‰Þ‰ûˆÈˆí‰Ã‰ó‰ü‰Å
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
; ========================================================================
|
|
||||||
;
|
|
||||||
; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
|
|
||||||
;
|
|
||||||
; This software is provided 'as-is', without any express or implied
|
|
||||||
; warranty. In no event will the authors be held liable for any damages
|
|
||||||
; arising from the use of this software.
|
|
||||||
;
|
|
||||||
; Please see https://computerenhance.com for further information
|
|
||||||
;
|
|
||||||
; ======================================================================== */
|
|
||||||
|
|
||||||
; ========================================================================
|
|
||||||
; LISTING 38
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
mov cx, bx
|
|
||||||
mov ch, ah
|
|
||||||
mov dx, bx
|
|
||||||
mov si, bx
|
|
||||||
mov bx, di
|
|
||||||
mov al, cl
|
|
||||||
mov ch, ch
|
|
||||||
mov bx, ax
|
|
||||||
mov bx, si
|
|
||||||
mov sp, di
|
|
||||||
mov bp, ax
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
bits 16
|
|
||||||
|
|
||||||
mov CX, BX
|
|
||||||
mov CH, AH
|
|
||||||
mov DX, BX
|
|
||||||
mov SI, BX
|
|
||||||
mov BX, DI
|
|
||||||
mov AL, CL
|
|
||||||
mov CH, CH
|
|
||||||
mov BX, AX
|
|
||||||
mov BX, SI
|
|
||||||
mov SP, DI
|
|
||||||
mov BP, AX
|
|
||||||
Binary file not shown.
@@ -1,47 +0,0 @@
|
|||||||
; ========================================================================
|
|
||||||
;
|
|
||||||
; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
|
|
||||||
;
|
|
||||||
; This software is provided 'as-is', without any express or implied
|
|
||||||
; warranty. In no event will the authors be held liable for any damages
|
|
||||||
; arising from the use of this software.
|
|
||||||
;
|
|
||||||
; Please see https://computerenhance.com for further information
|
|
||||||
;
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
; ========================================================================
|
|
||||||
; LISTING 39
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
; Register-to-register
|
|
||||||
mov si, bx
|
|
||||||
mov dh, al
|
|
||||||
|
|
||||||
; 8-bit immediate-to-register
|
|
||||||
mov cl, 12
|
|
||||||
mov ch, -12
|
|
||||||
|
|
||||||
; 16-bit immediate-to-register
|
|
||||||
mov cx, 12
|
|
||||||
mov cx, -12
|
|
||||||
mov dx, 3948
|
|
||||||
mov dx, -3948
|
|
||||||
|
|
||||||
; Source address calculation
|
|
||||||
mov al, [bx + si]
|
|
||||||
mov bx, [bp + di]
|
|
||||||
mov dx, [bp]
|
|
||||||
|
|
||||||
; Source address calculation plus 8-bit displacement
|
|
||||||
mov ah, [bx + si + 4]
|
|
||||||
|
|
||||||
; Source address calculation plus 16-bit displacement
|
|
||||||
mov al, [bx + si + 4999]
|
|
||||||
|
|
||||||
; Dest address calculation
|
|
||||||
mov [bx + di], cx
|
|
||||||
mov [bp + si], cl
|
|
||||||
mov [bp], ch
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
bits 16
|
|
||||||
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
INVALID VALUE PROVIDED (null),
|
|
||||||
Binary file not shown.
@@ -1,38 +0,0 @@
|
|||||||
; ========================================================================
|
|
||||||
;
|
|
||||||
; (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
|
|
||||||
;
|
|
||||||
; This software is provided 'as-is', without any express or implied
|
|
||||||
; warranty. In no event will the authors be held liable for any damages
|
|
||||||
; arising from the use of this software.
|
|
||||||
;
|
|
||||||
; Please see https://computerenhance.com for further information
|
|
||||||
;
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
; ========================================================================
|
|
||||||
; LISTING 40
|
|
||||||
; ========================================================================
|
|
||||||
|
|
||||||
bits 16
|
|
||||||
|
|
||||||
; Signed displacements
|
|
||||||
mov ax, [bx + di - 37]
|
|
||||||
mov [si - 300], cx
|
|
||||||
mov dx, [bx - 32]
|
|
||||||
|
|
||||||
; Explicit sizes
|
|
||||||
mov [bp + di], byte 7
|
|
||||||
mov [di + 901], word 347
|
|
||||||
|
|
||||||
; Direct address
|
|
||||||
mov bp, [5]
|
|
||||||
mov bx, [3458]
|
|
||||||
|
|
||||||
; Memory-to-accumulator test
|
|
||||||
mov ax, [2555]
|
|
||||||
mov ax, [16]
|
|
||||||
|
|
||||||
; Accumulator-to-memory test
|
|
||||||
mov [2554], ax
|
|
||||||
mov [15], ax
|
|
||||||
@@ -1,58 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<N10X>
|
|
||||||
<Workspace>
|
|
||||||
<IncludeFilter>*.*,</IncludeFilter>
|
|
||||||
<ExcludeFilter>*.obj,*.lib,*.pch,*.dll,*.pdb,.vs,Debug,Release,x64,obj,*.user,Intermediate,</ExcludeFilter>
|
|
||||||
<SyncFiles>true</SyncFiles>
|
|
||||||
<Recursive>true</Recursive>
|
|
||||||
<ShowEmptyFolders>true</ShowEmptyFolders>
|
|
||||||
<IsVirtual>false</IsVirtual>
|
|
||||||
<IsFolder>false</IsFolder>
|
|
||||||
<BuildCommand>.\build.bat</BuildCommand>
|
|
||||||
<RebuildCommand></RebuildCommand>
|
|
||||||
<BuildFileCommand></BuildFileCommand>
|
|
||||||
<CleanCommand>.\clean.bat</CleanCommand>
|
|
||||||
<BuildWorkingDirectory>.\part_1</BuildWorkingDirectory>
|
|
||||||
<CancelBuild></CancelBuild>
|
|
||||||
<RunCommand>part_1/build/sim_8086.exe</RunCommand>
|
|
||||||
<DebugCommand>part_1/build/sim_8086.exe</DebugCommand>
|
|
||||||
<ExePathCommand>part_1/build/sim_8086.exe</ExePathCommand>
|
|
||||||
<DebugSln></DebugSln>
|
|
||||||
<UseVisualStudioEnvBat>false</UseVisualStudioEnvBat>
|
|
||||||
<Configurations>
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
</Configurations>
|
|
||||||
<Platforms>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</Platforms>
|
|
||||||
<AdditionalIncludePaths>
|
|
||||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\include</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.35.32215\ATLMFC\include</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\VS\include</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\include\10.0.22621.0\ucrt</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\um</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\shared</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\winrt</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\10\\include\10.0.22621.0\\cppwinrt</AdditionalIncludePath>
|
|
||||||
<AdditionalIncludePath>C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um</AdditionalIncludePath>
|
|
||||||
</AdditionalIncludePaths>
|
|
||||||
<Defines></Defines>
|
|
||||||
<ConfigProperties>
|
|
||||||
<ConfigAndPlatform>
|
|
||||||
<Name>Debug:x64</Name>
|
|
||||||
<Defines></Defines>
|
|
||||||
<ForceIncludes></ForceIncludes>
|
|
||||||
</ConfigAndPlatform>
|
|
||||||
<Config>
|
|
||||||
<Name>Debug</Name>
|
|
||||||
<Defines></Defines>
|
|
||||||
</Config>
|
|
||||||
<Platform>
|
|
||||||
<Name>x64</Name>
|
|
||||||
<Defines></Defines>
|
|
||||||
</Platform>
|
|
||||||
</ConfigProperties>
|
|
||||||
<Children></Children>
|
|
||||||
</Workspace>
|
|
||||||
</N10X>
|
|
||||||
Vendored
-100
@@ -1,100 +0,0 @@
|
|||||||
# Format Style Options - Created with Clang Power Tools
|
|
||||||
---
|
|
||||||
AccessModifierOffset: -4
|
|
||||||
AlignAfterOpenBracket: BlockIndent
|
|
||||||
AlignArrayOfStructures: Right
|
|
||||||
AlignConsecutiveAssignments:
|
|
||||||
Enabled: true
|
|
||||||
AcrossEmptyLines: false
|
|
||||||
AcrossComments: true
|
|
||||||
AlignCompound: true
|
|
||||||
PadOperators: true
|
|
||||||
AlignConsecutiveBitFields: AcrossComments
|
|
||||||
AlignConsecutiveDeclarations: AcrossComments
|
|
||||||
AlignConsecutiveMacros: AcrossComments
|
|
||||||
AlignEscapedNewlines: Right
|
|
||||||
AlignOperands: DontAlign
|
|
||||||
AlignTrailingComments: false
|
|
||||||
AllowAllArgumentsOnNextLine: true
|
|
||||||
AllowAllConstructorInitializersOnNextLine: true
|
|
||||||
AllowAllParametersOfDeclarationOnNextLine: true
|
|
||||||
AllowShortBlocksOnASingleLine: Never
|
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
|
||||||
AllowShortLambdasOnASingleLine: None
|
|
||||||
AllowShortEnumsOnASingleLine: false
|
|
||||||
AllowShortFunctionsOnASingleLine: None
|
|
||||||
AllowShortIfStatementsOnASingleLine: Never
|
|
||||||
AllowShortLoopsOnASingleLine: false
|
|
||||||
AlwaysBreakBeforeMultilineStrings: true
|
|
||||||
AlwaysBreakTemplateDeclarations: Yes
|
|
||||||
BinPackArguments: true
|
|
||||||
BinPackParameters: true
|
|
||||||
BitFieldColonSpacing: Both
|
|
||||||
BraceWrapping:
|
|
||||||
AfterCaseLabel: false
|
|
||||||
AfterClass: false
|
|
||||||
AfterControlStatement: false
|
|
||||||
AfterEnum: false
|
|
||||||
AfterFunction: false
|
|
||||||
AfterNamespace: false
|
|
||||||
AfterObjCDeclaration: false
|
|
||||||
AfterStruct: false
|
|
||||||
AfterUnion: false
|
|
||||||
AfterExternBlock: false
|
|
||||||
BeforeCatch: false
|
|
||||||
BeforeElse: false
|
|
||||||
IndentBraces: false
|
|
||||||
SplitEmptyFunction: false
|
|
||||||
SplitEmptyRecord: false
|
|
||||||
SplitEmptyNamespace: false
|
|
||||||
BeforeLambdaBody: false
|
|
||||||
BeforeWhile: false
|
|
||||||
BreakBeforeBinaryOperators: NonAssignment
|
|
||||||
BreakBeforeBraces: Allman
|
|
||||||
BreakBeforeInheritanceComma: true
|
|
||||||
BreakInheritanceList: BeforeColon
|
|
||||||
BreakBeforeConceptDeclarations: true
|
|
||||||
BreakBeforeTernaryOperators: true
|
|
||||||
BreakConstructorInitializers: BeforeColon
|
|
||||||
ColumnLimit: 180
|
|
||||||
CompactNamespaces: true
|
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
|
||||||
ConstructorInitializerIndentWidth : 4
|
|
||||||
ContinuationIndentWidth: 4
|
|
||||||
DeriveLineEnding: true
|
|
||||||
ExperimentalAutoDetectBinPacking: false
|
|
||||||
FixNamespaceComments: true
|
|
||||||
IncludeBlocks: Preserve
|
|
||||||
IndentCaseBlocks: true
|
|
||||||
IndentCaseLabels: true
|
|
||||||
IndentExternBlock: Indent
|
|
||||||
IndentGotoLabels: false
|
|
||||||
IndentPPDirectives: None
|
|
||||||
IndentRequires: false
|
|
||||||
IndentWidth: 4
|
|
||||||
IndentWrappedFunctionNames: false
|
|
||||||
Language: Cpp
|
|
||||||
NamespaceIndentation: All
|
|
||||||
PointerAlignment: Left
|
|
||||||
SortIncludes: true
|
|
||||||
SortUsingDeclarations: true
|
|
||||||
SpaceAfterCStyleCast: false
|
|
||||||
SpaceAfterLogicalNot: true
|
|
||||||
SpaceAfterTemplateKeyword: true
|
|
||||||
SpaceAroundPointerQualifiers: After
|
|
||||||
SpaceBeforeCaseColon: true
|
|
||||||
SpaceBeforeCpp11BracedList: true
|
|
||||||
SpaceBeforeCtorInitializerColon: true
|
|
||||||
SpaceBeforeInheritanceColon: true
|
|
||||||
SpaceBeforeRangeBasedForLoopColon: true
|
|
||||||
SpaceInEmptyBlock: true
|
|
||||||
SpaceInEmptyParentheses: false
|
|
||||||
SpacesInAngles: true
|
|
||||||
SpacesInCStyleCastParentheses: false
|
|
||||||
SpacesInConditionalStatement: true
|
|
||||||
SpacesInParentheses: true
|
|
||||||
SpacesInSquareBrackets: true
|
|
||||||
Standard: c++17
|
|
||||||
TabWidth: 4
|
|
||||||
UseTab: ForIndentation
|
|
||||||
...
|
|
||||||
Vendored
-82
@@ -1,82 +0,0 @@
|
|||||||
<#
|
|
||||||
.DESCRIPTION
|
|
||||||
Helper script to format all header and source files in the repository.
|
|
||||||
By default, the script will recursively search under the repo root for
|
|
||||||
files to format. Users can give explicit parameters indicating how the
|
|
||||||
search should include and exclude filetypes.
|
|
||||||
If users don't want the search functionality, they can instead provide
|
|
||||||
an explicit list of files to format.
|
|
||||||
.PARAMETER RepoRoot
|
|
||||||
Full path to the root of the repository which is the target of the search.
|
|
||||||
Will default to the root of the current working directory.
|
|
||||||
.PARAMETER Include
|
|
||||||
Array of filetype extensions to target for formatting.
|
|
||||||
By default, targets standard extensions for header and source files.
|
|
||||||
Follows the same rules as the -Include parameter for Get-ChildItem.
|
|
||||||
.PARAMETER Exclude
|
|
||||||
Array of filetype extensions to exclude from formatting.
|
|
||||||
By default, excludes generated XAML files.
|
|
||||||
Follows the same rules as the -Exclude paramter for Get-ChildItem.
|
|
||||||
.PARAMETER Files
|
|
||||||
Array of files to format. The script will exit if one of the provided
|
|
||||||
filepaths does not exist.
|
|
||||||
.EXAMPLE
|
|
||||||
.\clang-format-all.ps1
|
|
||||||
Formats all header and source files under the repository root.
|
|
||||||
.EXAMPLE
|
|
||||||
.\clang-format-all.ps1 -RepoRoot 'S:\repos\calculator' -Include '*.h', '*.cpp' -Exclude '*.g.*'
|
|
||||||
Formats all *.h and *.cpp files under 'S:\repos\calculator', excluding files with an extension
|
|
||||||
like *.g.*
|
|
||||||
.EXAMPLE
|
|
||||||
.\clang-format-all.ps1 -File 'S:\repos\calculator\src\CalcViewModel\UnitConverterViewModel.h', 'S:\repos\calculator\src\CalcViewModel\MemoryItemViewModel.cpp'
|
|
||||||
Formats the specified files.
|
|
||||||
#>
|
|
||||||
[CmdletBinding( DefaultParameterSetName = 'Search' )]
|
|
||||||
param(
|
|
||||||
[Parameter( ParameterSetName = 'Search' )]
|
|
||||||
[ValidateScript({ Test-Path -PathType Container -Path $_ })]
|
|
||||||
[string] $RepoRoot = "$( (Get-Item .).FullName )/thirdparty",
|
|
||||||
|
|
||||||
[Parameter( ParameterSetName = 'Search' )]
|
|
||||||
[string[]] $Include = ( '*.h', '*.hh', '*.hpp', '*.c', '*.cc', '*.cpp' ),
|
|
||||||
|
|
||||||
[Parameter( ParameterSetName = 'Search' )]
|
|
||||||
[string[]] $Exclude = ( '*.g.*', "zpl.h" ),
|
|
||||||
|
|
||||||
[Parameter(
|
|
||||||
ParameterSetName = 'Explicit',
|
|
||||||
Mandatory)]
|
|
||||||
[ValidateScript({
|
|
||||||
$_ | Where-Object { -not (Test-Path -PathType Leaf -Path $_) } |
|
|
||||||
ForEach-Object { throw "Could not find file: [$_]" }
|
|
||||||
|
|
||||||
return $true
|
|
||||||
})]
|
|
||||||
[string[]] $Files
|
|
||||||
)
|
|
||||||
|
|
||||||
if ($PSCmdlet.ParameterSetName -eq 'Explicit')
|
|
||||||
{
|
|
||||||
# Use the file paths we were given.
|
|
||||||
$targetFiles = @($Files)
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
# Gather the files to be formatted.
|
|
||||||
$targetFiles = @(
|
|
||||||
Get-ChildItem -Recurse -Path $RepoRoot -Include $Include -Exclude $Exclude |
|
|
||||||
Select-Object -ExpandProperty FullName
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
# Format the files.
|
|
||||||
$formatParams = @(
|
|
||||||
'-i' # In-place
|
|
||||||
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
|
|
||||||
'-verbose'
|
|
||||||
)
|
|
||||||
|
|
||||||
if ( $targetFiles )
|
|
||||||
{
|
|
||||||
clang-format $formatParams $targetFiles
|
|
||||||
}
|
|
||||||
Vendored
-18369
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user