AK: Apply changes for the Bootstrapper environment

This commit is contained in:
Liav A 2020-02-09 16:50:13 +02:00 committed by Andreas Kling
parent 88cf46dc98
commit 8bdb08c354
11 changed files with 43 additions and 37 deletions

View file

@ -28,16 +28,17 @@
#ifndef AK_TEST_SUITE
#ifdef KERNEL
# include <Kernel/Assertions.h>
#else
# include <assert.h>
# ifndef __serenity__
# define ASSERT assert
# define ASSERT_NOT_REACHED() assert(false)
# define RELEASE_ASSERT assert
# if defined(KERNEL)
# include <Kernel/Assertions.h>
# elif defined(BOOTSTRAPPER)
# include <Bootstrapper/Output/Assertions.h>
# else
# include <assert.h>
# ifndef __serenity__
# define ASSERT assert
# define ASSERT_NOT_REACHED() assert(false)
# define RELEASE_ASSERT assert
# endif
# endif
#endif
#endif

View file

@ -26,11 +26,11 @@
#pragma once
#include <AK/String.h>
#include <AK/HashMap.h>
#include <AK/JsonArray.h>
#include <AK/JsonObjectSerializer.h>
#include <AK/JsonValue.h>
#include <AK/String.h>
namespace AK {
@ -119,7 +119,7 @@ inline void JsonObject::serialize(Builder& builder) const
{
JsonObjectSerializer serializer { builder };
for_each_member([&](auto& key, auto& value) {
serializer.add(key, value);
serializer.add(key, value);
});
}
@ -147,7 +147,7 @@ inline void JsonValue::serialize(Builder& builder) const
case Type::Bool:
builder.append(m_value.as_bool ? "true" : "false");
break;
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
case Type::Double:
builder.appendf("%g", m_value.as_double);
break;

View file

@ -118,7 +118,7 @@ JsonValue::JsonValue(const char* cstring)
{
}
#ifndef KERNEL
#if !defined(BOOTSTRAPPER) && !defined(KERNEL)
JsonValue::JsonValue(double value)
: m_type(Type::Double)
{

View file

@ -46,7 +46,7 @@ public:
UnsignedInt32,
Int64,
UnsignedInt64,
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
Double,
#endif
Bool,
@ -71,7 +71,7 @@ public:
JsonValue(i64);
JsonValue(u64);
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
JsonValue(double);
#endif
JsonValue(bool);
@ -175,7 +175,7 @@ public:
return *m_value.as_array;
}
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
double as_double() const
{
ASSERT(is_double());
@ -196,7 +196,7 @@ public:
bool is_u32() const { return m_type == Type::UnsignedInt32; }
bool is_i64() const { return m_type == Type::Int64; }
bool is_u64() const { return m_type == Type::UnsignedInt64; }
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
bool is_double() const
{
return m_type == Type::Double;
@ -214,7 +214,7 @@ public:
case Type::UnsignedInt32:
case Type::Int64:
case Type::UnsignedInt64:
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
case Type::Double:
#endif
return true;
@ -226,7 +226,7 @@ public:
template<typename T>
T to_number(T default_value = 0) const
{
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
if (is_double())
return (T)as_double();
#endif
@ -251,7 +251,7 @@ private:
StringImpl* as_string { nullptr };
JsonArray* as_array;
JsonObject* as_object;
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
double as_double;
#endif
i32 as_i32;

View file

@ -82,7 +82,7 @@ const LogStream& operator<<(const LogStream& stream, const void* value)
return stream << String::format("%p", value);
}
#if defined(__serenity__) && !defined(KERNEL)
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
static TriState got_process_name = TriState::Unknown;
static char process_name_buffer[256];
#endif
@ -90,7 +90,7 @@ static char process_name_buffer[256];
DebugLogStream dbg()
{
DebugLogStream stream;
#if defined(__serenity__) && !defined(KERNEL)
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
if (got_process_name == TriState::Unknown) {
if (get_process_name(process_name_buffer, sizeof(process_name_buffer)) == 0)
got_process_name = TriState::True;
@ -100,11 +100,14 @@ DebugLogStream dbg()
if (got_process_name == TriState::True)
stream << "\033[33;1m" << process_name_buffer << '(' << getpid() << ")\033[0m: ";
#endif
#if defined(__serenity__) && defined(KERNEL)
#if defined(__serenity__) && defined(KERNEL) && !defined(BOOTSTRAPPER)
if (current)
stream << "\033[34;1m[" << *current << "]\033[0m: ";
else
stream << "\033[36;1m[Kernel]\033[0m: ";
#endif
#if defined(BOOTSTRAPPER) && !defined(__serenity__) && !defined(KERNEL)
stream << "\033[36;1m[Bootstrapper]\033[0m: ";
#endif
return stream;
}

View file

@ -29,7 +29,7 @@
#include <AK/Types.h>
#include <AK/kstdio.h>
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
# include <AK/ScopedValueRollback.h>
# include <AK/StringView.h>
# include <errno.h>
@ -44,7 +44,7 @@ class StringView;
class LogStream {
public:
LogStream()
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
: m_errno_restorer(errno)
#endif
{
@ -54,7 +54,7 @@ public:
virtual void write(const char*, int) const = 0;
private:
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
ScopedValueRollback<int> m_errno_restorer;
#endif
};

View file

@ -352,7 +352,7 @@ template<typename PutChFunc>
ret += print_hex(putch, bufptr, va_arg(ap, u64), false, false, left_pad, zeroPad, 16);
break;
#ifndef KERNEL
#if !defined(BOOTSTRAPPER) && !defined(KERNEL)
case 'g':
case 'f':
// FIXME: Print as float!

View file

@ -26,8 +26,8 @@
#pragma once
#include "Assertions.h"
#include "StdLibExtras.h"
#include <AK/Assertions.h>
#include <AK/StdLibExtras.h>
namespace AK {

View file

@ -26,8 +26,8 @@
#pragma once
#ifdef KERNEL
# include <Kernel/StdLib.h>
#if defined(KERNEL) || defined(BOOTSTRAPPER)
# include <LibBareMetal/StdLib.h>
#else
# include <stdlib.h>
# include <string.h>
@ -37,13 +37,13 @@
#include <AK/Types.h>
#if defined(__serenity__) && !defined(KERNEL)
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
extern "C" void* mmx_memcpy(void* to, const void* from, size_t);
#endif
[[gnu::always_inline]] inline void fast_u32_copy(u32* dest, const u32* src, size_t count)
{
#if defined(__serenity__) && !defined(KERNEL)
#if defined(__serenity__) && !defined(KERNEL) && !defined(BOOTSTRAPPER)
if (count >= 256) {
mmx_memcpy(dest, src, count * sizeof(count));
return;
@ -323,12 +323,12 @@ struct IsSame<T, T> {
}
using AK::ceil_div;
using AK::clamp;
using AK::exchange;
using AK::forward;
using AK::IsSame;
using AK::max;
using AK::min;
using AK::clamp;
using AK::move;
using AK::RemoveConst;
using AK::swap;

View file

@ -36,8 +36,10 @@
# define AK_MAKE_ETERNAL
#endif
#ifdef KERNEL
#if defined(KERNEL)
# include <Kernel/Heap/kmalloc.h>
#elif defined(BOOTSTRAPPER)
# include <Bootstrapper/Memory/malloc.h>
#else
# include <stdlib.h>

View file

@ -27,7 +27,7 @@
#pragma once
#ifdef __serenity__
#include <Kernel/kstdio.h>
# include <Libraries/LibBareMetal/Output/kstdio.h>
#else
#include <stdio.h>
#define kprintf printf