Skip to content

Commit

Permalink
AK: Apply changes for the Bootstrapper environment
Browse files Browse the repository at this point in the history
  • Loading branch information
supercomputer7 authored and awesomekling committed Feb 9, 2020
1 parent 88cf46d commit 8bdb08c
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 37 deletions.
21 changes: 11 additions & 10 deletions AK/Assertions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 3 additions & 3 deletions AK/JsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
});
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion AK/JsonValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ JsonValue::JsonValue(const char* cstring)
{
}

#ifndef KERNEL
#if !defined(BOOTSTRAPPER) && !defined(KERNEL)
JsonValue::JsonValue(double value)
: m_type(Type::Double)
{
Expand Down
14 changes: 7 additions & 7 deletions AK/JsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class JsonValue {
UnsignedInt32,
Int64,
UnsignedInt64,
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
Double,
#endif
Bool,
Expand All @@ -71,7 +71,7 @@ class JsonValue {
JsonValue(i64);
JsonValue(u64);

#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
JsonValue(double);
#endif
JsonValue(bool);
Expand Down Expand Up @@ -175,7 +175,7 @@ class JsonValue {
return *m_value.as_array;
}

#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
double as_double() const
{
ASSERT(is_double());
Expand All @@ -196,7 +196,7 @@ class JsonValue {
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;
Expand All @@ -214,7 +214,7 @@ class JsonValue {
case Type::UnsignedInt32:
case Type::Int64:
case Type::UnsignedInt64:
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
case Type::Double:
#endif
return true;
Expand All @@ -226,7 +226,7 @@ class JsonValue {
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
Expand All @@ -251,7 +251,7 @@ class JsonValue {
StringImpl* as_string { nullptr };
JsonArray* as_array;
JsonObject* as_object;
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
double as_double;
#endif
i32 as_i32;
Expand Down
9 changes: 6 additions & 3 deletions AK/LogStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ 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

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;
Expand All @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions AK/LogStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -44,7 +44,7 @@ class StringView;
class LogStream {
public:
LogStream()
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
: m_errno_restorer(errno)
#endif
{
Expand All @@ -54,7 +54,7 @@ class LogStream {
virtual void write(const char*, int) const = 0;

private:
#ifndef KERNEL
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
ScopedValueRollback<int> m_errno_restorer;
#endif
};
Expand Down
2 changes: 1 addition & 1 deletion AK/PrintfImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
4 changes: 2 additions & 2 deletions AK/RefCounted.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

#pragma once

#include "Assertions.h"
#include "StdLibExtras.h"
#include <AK/Assertions.h>
#include <AK/StdLibExtras.h>

namespace AK {

Expand Down
10 changes: 5 additions & 5 deletions AK/StdLibExtras.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand Down Expand Up @@ -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;
4 changes: 3 additions & 1 deletion AK/kmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion AK/kstdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bdb08c

Please sign in to comment.