|
@ -46,7 +46,8 @@ namespace molasses { |
|
|
return builder.str(); |
|
|
return builder.str(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
parser_context register_integers(parser_context ctx) requires(architecture == architecture_t::x86_64_linux) |
|
|
|
|
|
|
|
|
// TODO: move to a platform independent file
|
|
|
|
|
|
parser_context register_integers(parser_context ctx) |
|
|
{ |
|
|
{ |
|
|
ctx.types.push_back(std::make_shared<primitive_type>("i8", 1)); |
|
|
ctx.types.push_back(std::make_shared<primitive_type>("i8", 1)); |
|
|
ctx.types.push_back(std::make_shared<primitive_type>("i16", 2)); |
|
|
ctx.types.push_back(std::make_shared<primitive_type>("i16", 2)); |
|
@ -60,8 +61,8 @@ namespace molasses { |
|
|
return ctx; |
|
|
return ctx; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n">parser_context register_i32_operations(parser_context ctx) |
|
|
|
|
|
requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
k">template<> |
|
|
|
|
|
parser_context register_i32_operations<architecture_t::x86_64_linux>(parser_context ctx) { |
|
|
ctx.operations.emplace_back( |
|
|
ctx.operations.emplace_back( |
|
|
std::make_shared<molasses::primitive_operation>( |
|
|
std::make_shared<molasses::primitive_operation>( |
|
|
std::string{"+"}, |
|
|
std::string{"+"}, |
|
@ -261,51 +262,52 @@ namespace molasses { |
|
|
|
|
|
|
|
|
return ctx; |
|
|
return ctx; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n">std::vector<std::string> generate_call(const std::string& target) |
|
|
|
|
|
requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k">template<> |
|
|
|
|
|
std::vector<std::string> generate_call<architecture_t::x86_64_linux>(const std::string& target) { |
|
|
return { |
|
|
return { |
|
|
" call "+marshal(target)+"\n", |
|
|
" call "+marshal(target)+"\n", |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n">std::vector<std::string> generate_string(const symbol& representation, const std::string& string_value) |
|
|
|
|
|
requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
k">template<> |
|
|
|
|
|
std::vector<std::string> generate_string<architecture_t::x86_64_linux>(const symbol& representation, const std::string& string_value) { |
|
|
return { |
|
|
return { |
|
|
"__EMITED_STRING_____"+std::to_string(representation.id)+"___:\n", |
|
|
"__EMITED_STRING_____"+std::to_string(representation.id)+"___:\n", |
|
|
" .asciz \""+escape(string_value)+"\"\n", |
|
|
" .asciz \""+escape(string_value)+"\"\n", |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<std::string> generate_push_string_ptr(const symbol& representation) { |
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
std::vector<std::string> generate_push_string_ptr<architecture_t::x86_64_linux>(const symbol& representation) { |
|
|
return { |
|
|
return { |
|
|
" pushq $__EMITED_STRING_____"+std::to_string(representation.id)+"___\n" |
|
|
" pushq $__EMITED_STRING_____"+std::to_string(representation.id)+"___\n" |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n">std::vector<std::string> generate_push_int32(int32_t target) |
|
|
|
|
|
requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k">template<> |
|
|
|
|
|
std::vector<std::string> generate_push_int32<architecture_t::x86_64_linux>(int32_t target) { |
|
|
return { |
|
|
return { |
|
|
" pushq $" +std::to_string(target)+ "\n" |
|
|
" pushq $" +std::to_string(target)+ "\n" |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
n">std::vector<std::string> generate_push_int64(int64_t target) |
|
|
|
|
|
requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
k">template<> |
|
|
|
|
|
std::vector<std::string> generate_push_int64<architecture_t::x86_64_linux>(int64_t target) { |
|
|
return { |
|
|
return { |
|
|
" pushq $" +std::to_string(target)+ "\n" |
|
|
" pushq $" +std::to_string(target)+ "\n" |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<std::string> generate_label(const std::string& target) |
|
|
|
|
|
k">requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
n">std::vector<std::string> generate_label<architecture_t::x86_64_linux>(const std::string& target) { |
|
|
return { |
|
|
return { |
|
|
marshal(target)+":\n" |
|
|
marshal(target)+":\n" |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<std::string> generate_return() |
|
|
|
|
|
k">requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
n">std::vector<std::string> generate_return<architecture_t::x86_64_linux>() { |
|
|
return { |
|
|
return { |
|
|
" // Return to caller\n", |
|
|
" // Return to caller\n", |
|
|
" addq $-8, %r10\n", |
|
|
" addq $-8, %r10\n", |
|
@ -313,18 +315,18 @@ namespace molasses { |
|
|
" retq\n" |
|
|
" retq\n" |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<std::string> generate_enter() |
|
|
|
|
|
k">requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
n">std::vector<std::string> generate_enter<architecture_t::x86_64_linux>() { |
|
|
return { |
|
|
return { |
|
|
" // Prepare the function stack\n", |
|
|
" // Prepare the function stack\n", |
|
|
" popq (%r10)\n" |
|
|
" popq (%r10)\n" |
|
|
" addq $8, %r10\n", |
|
|
" addq $8, %r10\n", |
|
|
}; |
|
|
}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<std::string> initialize_stack() |
|
|
|
|
|
k">requires (architecture == architecture_t::x86_64_linux) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<> |
|
|
|
|
|
n">std::vector<std::string> initialize_stack<architecture_t::x86_64_linux>() { |
|
|
std::vector<std::string> operations = { |
|
|
std::vector<std::string> operations = { |
|
|
"code:\n", |
|
|
"code:\n", |
|
|
" .skip 1000000\n", |
|
|
" .skip 1000000\n", |
|
|