Skip to content

Commit

Permalink
Updated logging related code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Jul 26, 2024
1 parent f887dd8 commit 5523c7a
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 241 deletions.
10 changes: 5 additions & 5 deletions aq/aq.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@
#include <stdio.h>

#include "aqvm/aqvm.h"
#include "aqvm/runtime/debugger/debugger.h"
#include "aqvm/base/logging.h"

int main(int argc, char *argv[]) {
// TODO(Aqvm): Finish this function after completing AQVM development.
AqvmRuntimeDebugger_OutputLog("\"INFO\"", "\"main_Start\"",
AqvmBase_OutputLog("\"INFO\"", "\"main_Start\"",
"\"Aq main program has been started.\"", NULL);

// TODO(Aq): Before the official release, remove the judgment logic for
// command line arguments and design a dedicated component to parse command
// line arguments.
if (argc < 2) {
AqvmRuntimeDebugger_OutputLog(
AqvmBase_OutputLog(
"\"ERROR\"", "\"main_ArgsError\"",
"\"Please provide a file name as an argument.\"", NULL);
return -1;
}

if (Aqvm_StartVm(argv[1]) != 0) {
AqvmRuntimeDebugger_OutputLog("\"ERROR\"", "\"main_InitVmError\"",
AqvmBase_OutputLog("\"ERROR\"", "\"main_InitVmError\"",
"\"Starting Aqvm met error.\"", NULL);
return -1;
}

AqvmRuntimeDebugger_OutputLog("\"INFO\"", "\"main_End\"",
AqvmBase_OutputLog("\"INFO\"", "\"main_End\"",
"\"Aq main program has ended.\"", NULL);
return 0;
}
6 changes: 2 additions & 4 deletions aqvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ include_directories(${PROJECT_SOURCE_DIR})

set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/aqvm.c)

add_subdirectory(runtime)
add_subdirectory(base)
add_subdirectory(memory)
add_subdirectory(os)
add_subdirectory(interpreter)

add_library(Aqvm STATIC ${SOURCES})

target_link_libraries(Aqvm PRIVATE AqvmMemory)
target_link_libraries(Aqvm PRIVATE AqvmOs)
target_link_libraries(Aqvm PRIVATE AqvmRuntime)
target_link_libraries(Aqvm PRIVATE AqvmBase)
target_link_libraries(Aqvm PRIVATE AqvmInterpreter)
6 changes: 3 additions & 3 deletions aqvm/aqvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
#include "aqvm/aqvm.h"

#include "aqvm/memory/memory.h"
#include "aqvm/runtime/debugger/debugger.h"
#include "aqvm/base/logging.h"

int Aqvm_StartVm(const char* FileName) {
// TODO(Aqvm): Finish this function after completing AQVM development.
AqvmRuntimeDebugger_OutputLog("\"INFO\"", "\"Aqvm_StartVm_Start\"",
AqvmBase_OutputLog("\"INFO\"", "\"Aqvm_StartVm_Start\"",
"\"Initializing Aqvm has been started.\"",
NULL);

if (AqvmMemory_CheckMemoryConditions() != 0) {
AqvmRuntimeDebugger_OutputLog(
AqvmBase_OutputLog(
"\"ERROR\"", "\"Aqvm_StartVm_CheckMemoryConditionsError\"",
"\"Checking memory conditions met error.\"", NULL);
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ cmake_minimum_required(VERSION 3.10)

include_directories(${PROJECT_SOURCE_DIR})

set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/debugger.c)
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/logging.c)

add_library(AqvmRuntimeDebugger STATIC ${SOURCES})
add_library(AqvmBase STATIC ${SOURCES})
8 changes: 4 additions & 4 deletions aqvm/runtime/debugger/debugger.c → aqvm/base/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// This program is licensed under the AQ License. You can find the AQ license in
// the root directory.

#include "aqvm/runtime/debugger/debugger.h"
#include "aqvm/base/logging.h"

#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

void AqvmRuntimeDebugger_OutputLog(const char* type, const char* code,
void AqvmBase_OutputLog(const char* type, const char* code,
const char* message,
const char* other_info) {
if (type == NULL) {
Expand All @@ -35,13 +35,13 @@ void AqvmRuntimeDebugger_OutputLog(const char* type, const char* code,
"\"Errno\":%d,\"Message\":\"%s\"},\"OtherInfo\":%s}\n",
time_str, type, code, message, errno, strerror(errno), other_info);

FILE* log_ptr = fopen(".aqvm_debug_report.log", "a");
FILE* log_ptr = fopen(".aqvm_log.log", "a");
if (log_ptr == NULL) {
fprintf(
stderr,
"{\"Time\":%s,\"Type\":%s,\"Code\":%s,\"Message\":%s,\"ErrnoInfo\":{"
"\"Errno\":%d,\"Message\":\"%s\"},\"OtherInfo\":%s}\n",
time_str, "ERROR", "AqvmRuntimeDebugger_OutputLog_OutputToFileError",
time_str, "ERROR", "AqvmBase_OutputLog_OutputToFileError",
"Failed to open log file", errno, strerror(errno), "NULL");
return;
}
Expand Down
10 changes: 5 additions & 5 deletions aqvm/runtime/debugger/debugger.h → aqvm/base/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// This program is licensed under the AQ License. You can find the AQ license in
// the root directory.

#ifndef AQ_AQVM_RUNTIME_DEBUGGER_DEBUGGER_H_
#define AQ_AQVM_RUNTIME_DEBUGGER_DEBUGGER_H_
#ifndef AQ_AQVM_BASE_LOGGING_LOGGING_H_
#define AQ_AQVM_BASE_LOGGING_LOGGING_H_

#include <stdint.h>

Expand All @@ -14,14 +14,14 @@
// common. But |other_info| can be set to NULL if it is not needed. In general,
// |type| should be "ERROR", "WARNING" or "INFO". |code| should be a full
// function name plus a concise description of the error, separated by
// underscores (e.g., AqvmRuntimeDebugger_OutputLog_TestInfo). |message|
// underscores (e.g., AqvmBase_OutputLog_TestInfo). |message|
// should be a detailed and accurate description. |other_info| on the other hand
// should be an additional information to the current log (e.g. system
// information).
// NOTICE: If you need to use the function, please use json format. The output
// is json format. For example, AqvmRuntimeDebugger_OutputLog("\"type\"",
// is json format. For example, AqvmBase_OutputLog("\"type\"",
// "\"code\"", "\"message\"", "\"other_info\"");
void AqvmRuntimeDebugger_OutputLog(const char* type, const char* code,
void AqvmBase_OutputLog(const char* type, const char* code,
const char* message, const char* other_info);

#endif
7 changes: 4 additions & 3 deletions aqvm/interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/interpreter.c)
add_library(AqvmInterpreter STATIC ${SOURCES})

add_subdirectory(bytecode)
add_subdirectory(operator)

target_link_libraries(AqvmInterpreter PRIVATE AqvmRuntime)
target_link_libraries(AqvmInterpreter PRIVATE AqvmBase)
target_link_libraries(AqvmInterpreter PRIVATE AqvmMemory)
target_link_libraries(AqvmInterpreter PRIVATE AqvmOs)
target_link_libraries(AqvmInterpreter PRIVATE AqvmInterpreterBytecode)
target_link_libraries(AqvmInterpreter PRIVATE AqvmInterpreterBytecode)
target_link_libraries(AqvmInterpreter PRIVATE AqvmInterpreterOperator)
5 changes: 1 addition & 4 deletions aqvm/interpreter/bytecode/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/bytecode.c)

add_library(AqvmInterpreterBytecode STATIC ${SOURCES})

add_subdirectory(opcode)

target_link_libraries(AqvmInterpreterBytecode PRIVATE AqvmRuntime)
target_link_libraries(AqvmInterpreterBytecode PRIVATE AqvmInterpreterBytecodeOpcode)
target_link_libraries(AqvmInterpreterBytecode PRIVATE AqvmBase)
13 changes: 0 additions & 13 deletions aqvm/interpreter/bytecode/opcode/CMakeLists.txt

This file was deleted.

106 changes: 0 additions & 106 deletions aqvm/interpreter/bytecode/opcode/opcode.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ cmake_minimum_required(VERSION 3.10)

include_directories(${PROJECT_SOURCE_DIR})

set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/os.c)
set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/operator.c)

add_library(AqvmOs STATIC ${SOURCES})
add_library(AqvmInterpreterOperator STATIC ${SOURCES})

target_link_libraries(AqvmOs PRIVATE AqvmRuntime)
target_link_libraries(AqvmInterpreterOperator PRIVATE AqvmBase)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// This program is licensed under the AQ License. You can find the AQ license in
// the root directory.

#include "aqvm/interpreter/bytecode/opcode/opcode.h"
#include "aqvm/interpreter/operator/operator.h"

#include <stdbool.h>
#include <stddef.h>
Expand Down
Loading

0 comments on commit 5523c7a

Please sign in to comment.