Skip to content

Commit

Permalink
feat: Start on x86-64 JIT backend
Browse files Browse the repository at this point in the history
This change adds the fundamentals for a x86-64 JIT backend which
translates the Brainfuck instruction list onto x86-64 instructions.

See #61
  • Loading branch information
fabianishere committed Oct 1, 2018
1 parent 1833d5e commit 34addd0
Show file tree
Hide file tree
Showing 5 changed files with 411 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ option(ENABLE_EDITLINE "Enable GNU readline functionality provided by the editli

include_directories(include/)
add_definitions("-Wall -Wextra -O2 -std=c89")
add_executable(brainfuck src/main.c src/brainfuck.c)
add_executable(brainfuck include/brainfuck.h include/jit.h src/main.c src/brainfuck.c src/jit/x86_64.c)
install(TARGETS brainfuck RUNTIME DESTINATION bin)
install(FILES include/brainfuck.h DESTINATION "include")
install(FILES man/brainfuck.1 DESTINATION "share/man/man1")
Expand Down
31 changes: 31 additions & 0 deletions include/jit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2016 Fabian Mastenbroek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef JIT_H
#define JIT_H

#define BRAINFUCK_EUNAVAILABLE 2 /**< Feature not implemented or unavailable */

/**
* Execute the given list of instructions using a Just-in-Time compiler.
*
* @param root The first in the list of instructions.
* @param context The context within the execution takes place.
* @return A negative non-zero integer to indicate a failure, zero on success.
*/
int brainfuck_execute_jit(struct BrainfuckInstruction *,
struct BrainfuckExecutionContext *);

#endif /* JIT_H */
30 changes: 30 additions & 0 deletions src/jit/stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2016 Fabian Mastenbroek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include <jit.h>

/**
* Execute the given list of instructions using a Just-in-Time compiler.
*
* @param root The first in the list of instructions.
* @param context The context within the execution takes place.
* @return A negative non-zero integer to indicate a failure, zero on success.
*/
int brainfuck_execute_jit(BrainfuckInstruction *root,
BrainfuckExecutionContext *context)
{
return BRAINFUCK_EUNAVAILABLE;
}
Loading

0 comments on commit 34addd0

Please sign in to comment.