Fix shift behavior to better match C standard

This commit is contained in:
Jeremiah Orians 2020-10-16 22:07:06 -04:00
parent e9da9c802e
commit c4a636c99d
No known key found for this signature in database
GPG Key ID: 5410E91C14959E87
5 changed files with 41 additions and 35 deletions

View File

@ -808,8 +808,8 @@ void additive_expr_stub()
arithmetic_recursion(postfix_expr, "MUL R0 R1 R0\n", "MULU R0 R1 R0\n", "*", additive_expr_stub);
arithmetic_recursion(postfix_expr, "DIV R0 R1 R0\n", "DIVU R0 R1 R0\n", "/", additive_expr_stub);
arithmetic_recursion(postfix_expr, "MOD R0 R1 R0\n", "MODU R0 R1 R0\n", "%", additive_expr_stub);
arithmetic_recursion(postfix_expr, "SAL R0 R1 R0\n", "SAL R0 R1 R0\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "SAR R0 R1 R0\n", "SAR R0 R1 R0\n", ">>", additive_expr_stub);
arithmetic_recursion(postfix_expr, "SAL R0 R1 R0\n", "SL0 R0 R1 R0\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "SAR R0 R1 R0\n", "SR0 R0 R1 R0\n", ">>", additive_expr_stub);
}
else if(X86 == Architecture)
{
@ -818,8 +818,8 @@ void additive_expr_stub()
arithmetic_recursion(postfix_expr, "MULTIPLYS_eax_by_ebx_into_eax\n", "MULTIPLY_eax_by_ebx_into_eax\n", "*", additive_expr_stub);
arithmetic_recursion(postfix_expr, "XCHG_eax_ebx\nCDTQ\nDIVIDES_eax_by_ebx_into_eax\n", "XCHG_eax_ebx\nLOAD_IMMEDIATE_edx %0\nDIVIDE_eax_by_ebx_into_eax\n", "/", additive_expr_stub);
arithmetic_recursion(postfix_expr, "XCHG_eax_ebx\nCDTQ\nMODULUSS_eax_from_ebx_into_ebx\nMOVE_edx_to_eax\n", "XCHG_eax_ebx\nCDTQ\nMODULUS_eax_from_ebx_into_ebx\nMOVE_edx_to_eax\n", "%", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSAL_eax_cl\n", "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSAL_eax_cl\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSAR_eax_cl\n", "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSAR_eax_cl\n", ">>", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSAL_eax_cl\n", "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSHL_eax_cl\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSAR_eax_cl\n", "COPY_eax_to_ecx\nCOPY_ebx_to_eax\nSHR_eax_cl\n", ">>", additive_expr_stub);
}
else if(AMD64 == Architecture)
{
@ -828,8 +828,8 @@ void additive_expr_stub()
arithmetic_recursion(postfix_expr, "MULTIPLYS_rax_by_rbx_into_rax\n", "MULTIPLY_rax_by_rbx_into_rax\n", "*", additive_expr_stub);
arithmetic_recursion(postfix_expr, "XCHG_rax_rbx\nCQTO\nDIVIDES_rax_by_rbx_into_rax\n", "XCHG_rax_rbx\nLOAD_IMMEDIATE_rdx %0\nDIVIDE_rax_by_rbx_into_rax\n", "/", additive_expr_stub);
arithmetic_recursion(postfix_expr, "XCHG_rax_rbx\nCQTO\nMODULUSS_rax_from_rbx_into_rbx\nMOVE_rdx_to_rax\n", "XCHG_rax_rbx\nCQTO\nMODULUS_rax_from_rbx_into_rbx\nMOVE_rdx_to_rax\n", "%", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSAL_rax_cl\n", "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSAL_rax_cl\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSAR_rax_cl\n", "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSAR_rax_cl\n", ">>", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSAL_rax_cl\n", "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSHL_rax_cl\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSAR_rax_cl\n", "COPY_rax_to_rcx\nCOPY_rbx_to_rax\nSHR_rax_cl\n", ">>", additive_expr_stub);
}
else if(ARMV7L == Architecture)
{
@ -839,7 +839,7 @@ void additive_expr_stub()
arithmetic_recursion(postfix_expr, "{LR} PUSH_ALWAYS\n^~divides CALL_ALWAYS\n{LR} POP_ALWAYS\n", "{LR} PUSH_ALWAYS\n^~divide CALL_ALWAYS\n{LR} POP_ALWAYS\n", "/", additive_expr_stub);
arithmetic_recursion(postfix_expr, "{LR} PUSH_ALWAYS\n^~moduluss CALL_ALWAYS\n{LR} POP_ALWAYS\n", "{LR} PUSH_ALWAYS\n^~modulus CALL_ALWAYS\n{LR} POP_ALWAYS\n", "%", additive_expr_stub);
arithmetic_recursion(postfix_expr, "LEFT R1 R0 R0 SHIFT AUX_ALWAYS\n", "LEFT R1 R0 R0 SHIFT AUX_ALWAYS\n", "<<", additive_expr_stub);
arithmetic_recursion(postfix_expr, "RIGHT R1 R0 R0 SHIFT AUX_ALWAYS\n", "RIGHT R1 R0 R0 SHIFT AUX_ALWAYS\n", ">>", additive_expr_stub);
arithmetic_recursion(postfix_expr, "ARITH_RIGHT R1 R0 R0 SHIFT AUX_ALWAYS\n", "RIGHT R1 R0 R0 SHIFT AUX_ALWAYS\n", ">>", additive_expr_stub);
}
else if(AARCH64 == Architecture)
{
@ -1649,10 +1649,12 @@ void collect_arguments()
{
global_token = global_token->next;
require(NULL != global_token, "Recieved EOF when attempting to collect arguments\n");
struct type* type_size;
struct token_list* a;
while(!match(")", global_token->s))
{
struct type* type_size = type_name();
type_size = type_name();
if(global_token->s[0] == ')')
{
/* foo(int,char,void) doesn't need anything done */
@ -1661,7 +1663,7 @@ void collect_arguments()
else if(global_token->s[0] != ',')
{
/* deal with foo(int a, char b) */
struct token_list* a = sym_declare(global_token->s, type_size, function->arguments);
a = sym_declare(global_token->s, type_size, function->arguments);
if(NULL == function->arguments)
{
if((KNIGHT_POSIX == Architecture) || (KNIGHT_NATIVE == Architecture)) a->depth = 0;

View File

@ -76,8 +76,10 @@ DEFINE PUSH_RBX 53
DEFINE PUSH_RDI 57
DEFINE RETURN C3
DEFINE SAL_rax_Immediate8 48C1E0
DEFINE SAL_rax_cl 48D3E0
DEFINE SAR_rax_cl 48D3E8
DEFINE SHL_rax_cl 48D3E0
DEFINE SAL_rax_cl 48D3F0
DEFINE SHR_rax_cl 48D3E8
DEFINE SAR_rax_cl 48D3F8
DEFINE SETE 0F94C0
DEFINE SETG 0F9FC0
DEFINE SETGE 0F9DC0

View File

@ -79,7 +79,9 @@ DEFINE PUSH_ebp 55
DEFINE PUSH_edi 57
DEFINE RETURN C3
DEFINE SAL_eax_Immediate8 C1E0
DEFINE SAL_eax_cl D3E0
DEFINE SHL_eax_cl D3E0
DEFINE SAL_eax_cl D3F0
DEFINE SHR_eax_cl D3E8
DEFINE SAR_eax_cl D3F8
DEFINE SETE 0F94C0
DEFINE SETLE 0F9EC0

View File

@ -47,8 +47,8 @@ a7e4ed6b2d5c0e3e375f9141f6c4934c58b94fcbd2d860b23b1b53812fd3dc8e test/results/t
9159c4ba8196b24ec78bc9ebfbc7066d510ddbf03461736e7795a48634134dc5 test/results/test0007-knight-posix-binary
b62cfbf5653df5e26fd184c012697aed4bba48d434b68ccedeedd1ad749ec92f test/results/test0007-x86-binary
a7bb65722a9a5365721e32ac4ec3aa0f79ba170f0406aeb746f5b296185b0493 test/results/test0008-aarch64-binary
7a6509e9c4803e40993e681cb2b713deff663e98b2ec4814da35a3395d0c3faa test/results/test0008-amd64-binary
355b48c8475adc29581049dada08f7858fbece832b8888b335f7f9a14b1299a2 test/results/test0008-armv7l-binary
2d0f89e696b4526f71887f2d3a5d0d14d79b811dea436821d3d876a23fb24f20 test/results/test0008-amd64-binary
371e2c7b12829e9081c720eea917dc78c039996b7881f799882c59c89eb22cdd test/results/test0008-armv7l-binary
16c6a5a8f3723fd464d8bded94ceaeef96e95a83e38caa380bd2d5cc375415c4 test/results/test0008-knight-native-binary
b824859fd0e39f1417742a1b9a1cec18ade78afdd80ce2c64cb54cdf7683f53a test/results/test0008-knight-posix-binary
0e73537c5c41d94395e6a626c7f0846935de5ff9ca25b004750b9798d539ae92 test/results/test0008-x86-binary
@ -59,8 +59,8 @@ e046d0be9ebb80c6053682f37af5ed18fece5afb089f67ecf98556700d7e85f0 test/results/t
990e82bccca98e6393f72b659abc2eb6069f272202286ce2ca51e9d8a941f3cd test/results/test0009-knight-posix-binary
7e073eac439a8aa7e8ec109eddd7104830cd38b7fe410b91e8050ea6dc32e9c7 test/results/test0009-x86-binary
f8e123ac44a5443bf335ec3e7e767649eb29e5b60b36588206c7f8fbc69ed0a5 test/results/test0010-aarch64-binary
2dde3ab1087deed424f1aa17999567854b9882ef704705f9b6044aaa6b851bca test/results/test0010-amd64-binary
0cdb664ad5e405b12d2be0d8976cf73bb0768da36950bc806b42da560ef96cc1 test/results/test0010-armv7l-binary
2ee9411b7f04829e892b2a3c818bf21268d91e3d0fefc438f10e6d6b06802dfa test/results/test0010-amd64-binary
17e884aa93ac8230f8d1e1388d315a5840f9883232bb8040eeee9e9dfdc53862 test/results/test0010-armv7l-binary
e01b615db5df31392bd1054c45141dcff936b11dfb1cad270edc0aa67653f5a1 test/results/test0010-knight-native-binary
c1b5a2a3cd46c5e95e5540e871c2a916e028684ca80f51c001ef489342e27625 test/results/test0010-knight-posix-binary
df9a8884564339e469d5dc1bea19880f3865ebcd324abd1187c17c172c4a9c15 test/results/test0010-x86-binary
@ -115,8 +115,8 @@ b5d23f9cb31ecef662b3f599413c08b3a07d69d1e5fc1b2b9316b757eacef282 test/results/t
1368524fad579144cf693b528a19448f8dad7fb51ffa6e64bd046fc628eceba5 test/results/test0019-knight-posix-binary
33bf6f2f89c39abd283bb447a66b6cfb06588b7117cfeff6929dd8843045ed20 test/results/test0019-x86-binary
e4a810211a2b1f4bd3bb8c329c7f15e18a7a76df03a808a838e103a0f59f90c5 test/results/test0020-aarch64-binary
47e645d71c0a7d870f0a256793fecf32c9abf04928a285e066eea4b6bbefad1a test/results/test0020-amd64-binary
215b2d2b1e128b0e4610991d0792e030cb2ef365b1a3ffcd3d835a1db091c06e test/results/test0020-armv7l-binary
6b2956b106dd16bb55d8d011b48e674ee3b70bbb0bb83efadca01d446666e21e test/results/test0020-amd64-binary
b29aca7f0b63659915fe431e290f821cf17071983613021aacb8985d376bb206 test/results/test0020-armv7l-binary
d9d40f64041a02b6a403fd3c07550cf53f9383e0ec7f7208c9c263d06ea3ce8f test/results/test0020-knight-native-binary
6a59795dbb4397d0efaf1ad613d646ec435eec62db30eb758bcf2499d651520e test/results/test0020-knight-posix-binary
1183247a4f714b9d1b0ec78b40f49631df3769ae95b0303fa9996208193c4ec9 test/results/test0020-x86-binary
@ -141,13 +141,13 @@ da64739046a84214ee6ee3edbec864bfd1c702a22a063a39ee83abe09c008393 test/results/t
7b439e2b7297f165cebbd17477924a077d713ed2313609c77015f9321a2d5738 test/results/test0100-knight-posix-binary
ee0fe808b0d79b8fcfdbf3e21fba95d96d6c89b56f43c9c579473784f88cca63 test/results/test0100-x86-binary
86dd73d63bd484400be8f0dacc1bf5b27a08851b58cab0e3a77209a123e5a17a test/results/test0101-aarch64-binary
68516969344407b95c6980ff12cb8268ed72110f5c7df2a9dcdccaba1a3e2507 test/results/test0101-amd64-binary
cda06143f1c4a80d7dac19e54d81539ffceae32664d77673309223053ec53497 test/results/test0101-armv7l-binary
206af573a171e1209e96ed74b0d036a29c5a12082dab5851d45ec2a3ef90fc7c test/results/test0101-knight-posix-binary
309020afea8966630203c91562ae134808d8848a21e6f4c5d131bae8a6f769d6 test/results/test0101-x86-binary
33f5fa27de5dd7f81976c50ff900062ba4fb6a89f157fd13bf3f45903b926f8f test/results/test0101-amd64-binary
06f49d4acc84feeec133f9736841b7bd2f9702bc93b5de5f5b303aaa603d7a69 test/results/test0101-armv7l-binary
10077e30c5754affd18880b8b70b6e8ca424b0383944555dd0b1d4b1268cc0b2 test/results/test0101-knight-posix-binary
5de130a152c382fe4eda6d0b6b7697a26af6bffc30117c84cfc6ab9e74521663 test/results/test0101-x86-binary
7624de3657ba7f662c2d560128aeab979e36005c8af7dfaef2aef9114820599b test/results/test0102-aarch64-binary
ca70074a2816a15b28c9d09a6e350985fa0866f136b884e62bdd48fdab751142 test/results/test0102-amd64-binary
dccced73ffdc874d7d07f6c7920604f98182290779e540445af6e504863f0e94 test/results/test0102-armv7l-binary
f1b89393aaa7f349950462939b2e61b4404e731134e689e86d5e7012866f3f87 test/results/test0102-amd64-binary
413f429d5a5dfed9c254d5e9f5f87a3f4b240002cab7f2ecc60700d47adf8c81 test/results/test0102-armv7l-binary
2fd1859cf73d3785a39409a559818e2043f07dcc0e87c38d73a1ffb606946e57 test/results/test0102-knight-posix-binary
ae505ccf9cc5e1976c3a0f0e18ddd3a3752d15f36e4a58855323501b8edf2994 test/results/test0102-x86-binary
368f12e4e708439156a5d3f777efd2c09130dd0ea6d6959f9400e905fe3c23e1 test/results/test0103-aarch64-binary
@ -164,13 +164,13 @@ b2d50750bbf78a780475c1c30c16d448504bcc92ad6f0ae094d8edf32aea59c2 test/results/t
04ac97e210a0d3b48c9a8ac4b0d6720325d787ab4dad2fdafc1d3bcfcd3da2ca test/results/test0105-armv7l-binary
107b2d27dd779d0d954cca657b2f909863448cbf2045dee1875e13facf10bc3d test/results/test0105-x86-binary
6ebfeb72ea3c0bb5a88bef45dbb3cbabd506c7063db7438d93126d2d8fa4a367 test/results/test0106-aarch64-binary
7eb6b7a08d993af23a0fa419a7cbb74c2aae192db2cde0f1c81ae076ba56ccb8 test/results/test0106-amd64-binary
8aae4a1a5d3bd94642cc95d65517cdf4bf15c637c4c9cb27e9c5743880bc9913 test/results/test0106-armv7l-binary
4f364313b48803b40f19f22953dd5614f13b797d4a449badc0811e8dfaa0ecb6 test/results/test0106-knight-native-binary
da0e33264fcaee00e4fb653012d3ff7940b9c73155f2876984f21b730c2ea3a2 test/results/test0106-knight-posix-binary
e1585d905c0629b717adb8b35e1d6fa61cbeca450b1678e1c099c2c4382ff4bf test/results/test0106-x86-binary
4a2dfa59d339cd19b4f55ce18072f75862f913d323ebd67be6c674c2b069a3dc test/results/test1000-aarch64-binary
85bd4d0eba8e09b67e1146c19b52829c69b29fa45da219299e2d8259dce71de4 test/results/test1000-amd64-binary
01532c380df654182916395aca98f7cb87a659884a1e3c28e667f782162fcd8a test/results/test1000-armv7l-binary
090b139722727e549ea425e2e648660f148cedb5f6fcfabd013e367ee7521c14 test/results/test1000-knight-posix-binary
3eb3a6d00cdd8c5967b54b1ce101d52496c153e7e531263d8d626c114dd0a2f9 test/results/test1000-x86-binary
5f5b00c90e77da4ffebb6ebc7607a1ad0db02c0c0d85770efedaca8088d59287 test/results/test0106-amd64-binary
c22dabd4d371e23ed10389080eaa241f31a3822f08c64c934776c80b2e376a51 test/results/test0106-armv7l-binary
6eb826151abe3ea2d7c1f16079e61f1b80d651a20f8341fbb77574f7b5c41fb3 test/results/test0106-knight-native-binary
61cdce452cb287467efbf315da67f3d107f5d3a9c3cf5b086bf51dcc67d78971 test/results/test0106-knight-posix-binary
55804110c3b2d5a5e5130a8ed11f0888f4460ee32ad6a86fde877ec914624a6d test/results/test0106-x86-binary
33408d9b3370af357dd4cbdbbe8afaa8ef2b3d178dd889bb18b4d332ea073e5c test/results/test1000-aarch64-binary
20c40ff607486a267e7d97efb3b085ada3ab047d7275d2cce3bab1e5fbfeceb7 test/results/test1000-amd64-binary
79aa352c954cbf5a8ad97a2065114342acd20ae71ee33af1adb73eedb380557f test/results/test1000-armv7l-binary
4b513e582ab3686c996052930a6af88d2ad176a81223f8d3d99e6617ba501277 test/results/test1000-knight-posix-binary
8f89602bc7e66f4c228f97c04054b2d8613b81dabed3796bd9486f98756de806 test/results/test1000-x86-binary

View File

@ -1 +1 @@
d5bd98e95153a8693722387edc2165f215b5c8d405b779c3f9d04b360cac4ed8 test/test1000/proof
c3442a08ff63c1520c84e6f4cc3e97e379e0d87fedd300b14c5f38f0fce65e55 test/test1000/proof