Skip to content

Commit

Permalink
cppfront compilation works
Browse files Browse the repository at this point in the history
  • Loading branch information
matgla committed Mar 29, 2024
1 parent e7b6a3a commit c29d51b
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@ if(${configuration_is_ready})

preinitialize_cpu()
project(Yasboot ASM C CXX)
include_directories(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/libstd)
# This will be extracted to external repository

set(CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD 23)
initialize_cpu()

add_library(yasboot_public_flags INTERFACE)
Expand Down
1 change: 1 addition & 0 deletions cmake/cppfront.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function(cppfront_generate_source input output)
add_custom_command(
OUTPUT ${output}
COMMAND ${CPPFRONT_BINARY_DIR}/cppfront ${input} -fno-rtti -fno-exceptions -o ${output}
DEPENDS ${input}
VERBATIM
)
endfunction()
Expand Down
4 changes: 2 additions & 2 deletions cmake/cppfront/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ include(FetchContent)

FetchContent_Declare(
cppfront
GIT_REPOSITORY https://github.com/hsutter/cppfront.git
GIT_TAG main
GIT_REPOSITORY https://github.com/matgla/cppfront.git
GIT_TAG fixNoRtti
)

FetchContent_MakeAvailable(cppfront)
Expand Down
7 changes: 7 additions & 0 deletions cpu/arm/v6-m/common/source/system_stubs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ extern "C"
{
auto [fs, path] =
yasboot::fs::FilesystemMountPoints::get().get_mount_point(pathname);

if (!fs)
{
printf("Responding with -1\n");
errno = ENOENT;
return -1;
}

return fs->open(path, flags);
}
Expand Down
4 changes: 2 additions & 2 deletions hal/interface/include/hal/system_stubs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

#include <string_view>

#include <eul/functional/function.hpp>
#include <functional>

namespace yasboot::hal
{

using WriteCallback = eul::function<size_t(const std::string_view &data), sizeof(void *)>;
using WriteCallback = std::function<size_t(const std::string_view &data)>;

void setGlobalWrite(const WriteCallback &write);
WriteCallback &getGlobalWrite();
Expand Down
37 changes: 37 additions & 0 deletions libstd/iostream
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <cstdio>
#include <string>
#include <string_view>

namespace std
{

class stream
{
public:
stream& operator<<(const auto& t)
{
printf("%s", std::to_string(t).c_str());
return *this;
}

stream& operator<<(const std::string_view& t)
{
printf("%s", t.data());
return *this;
}
stream& operator<<(const char* t)
{
printf("%s", t);
return *this;
}



};

[[maybe_unused]] static inline stream cerr;
[[maybe_unused]] static inline stream cout;

}
8 changes: 7 additions & 1 deletion source/main.cpp2
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include "hal/uart.hpp"
#include "hal/system_stubs.hpp"

main: () = {
uart: yasboot::hal::Uart<0> = 115200;
vec: std::vector<uint8_t> = 0;
yasboot::hal::setGlobalWrite(: (str: std::string_view) -> std::size_t =
uart$.write(str));
printf("Hello from Yasboot in CPP2\n");
}
f := cpp2::fopen("Non existing file", "r");
buf: std::array<uint8_t, 10> = ();
ret := f.fscanf("%s", buf);
printf("File: %s, %d\n", buf.data(), ret);
}

0 comments on commit c29d51b

Please sign in to comment.