mirror of
https://github.com/irmen/prog8.git
synced 2024-11-25 19:31:36 +00:00
%asmbinary implemented
This commit is contained in:
parent
0ee43294c4
commit
78fbbf7119
@ -2169,7 +2169,11 @@ internal class Compiler(private val rootModule: Module,
|
||||
}
|
||||
|
||||
private fun translateAsmBinary(args: List<DirectiveArg>) {
|
||||
TODO("asmbinary not implemented yet $args")
|
||||
val offset = if(args.size>=2) Value(DataType.UWORD, args[1].int!!) else null
|
||||
val length = if(args.size==3) Value(DataType.UWORD, args[2].int!!) else null
|
||||
val filename = args[0].str!!
|
||||
// reading the actual data is not performed by the compiler but is delegated to the assembler
|
||||
prog.instr(Opcode.INCLUDE_FILE, offset, length, filename)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,9 @@ open class Instruction(val opcode: Opcode,
|
||||
else
|
||||
"inline_assembly"
|
||||
}
|
||||
opcode==Opcode.INCLUDE_FILE -> {
|
||||
"include_file \"$callLabel\" $arg $arg2"
|
||||
}
|
||||
opcode==Opcode.SYSCALL -> {
|
||||
val syscall = Syscall.values().find { it.callNr==arg!!.numericValue() }
|
||||
"syscall $syscall"
|
||||
|
@ -262,7 +262,8 @@ enum class Opcode {
|
||||
BREAKPOINT, // breakpoint
|
||||
TERMINATE, // end the program
|
||||
LINE, // track source file line number
|
||||
INLINE_ASSEMBLY // container to hold inline raw assembly code
|
||||
INLINE_ASSEMBLY, // container to hold inline raw assembly code
|
||||
INCLUDE_FILE // directive to include a file at this position in the memory of the program
|
||||
}
|
||||
|
||||
val opcodesWithVarArgument = setOf(
|
||||
|
@ -472,6 +472,11 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
Opcode.DISCARD_WORD -> " inx"
|
||||
Opcode.DISCARD_FLOAT -> " inx | inx | inx"
|
||||
Opcode.INLINE_ASSEMBLY -> "@inline@" + (ins.callLabel2 ?: "") // All of the inline assembly is stored in the calllabel2 property. the '@inline@' is a special marker to process it.
|
||||
Opcode.INCLUDE_FILE -> {
|
||||
val offset = if(ins.arg==null) "" else ", ${ins.arg.integerValue()}"
|
||||
val length = if(ins.arg2==null) "" else ", ${ins.arg2.integerValue()}"
|
||||
" .binary \"${ins.callLabel}\" $offset $length"
|
||||
}
|
||||
Opcode.SYSCALL -> {
|
||||
if (ins.arg!!.numericValue() in syscallsForStackVm.map { it.callNr })
|
||||
throw CompilerException("cannot translate vm syscalls to real assembly calls - use *real* subroutine calls instead. Syscall ${ins.arg.numericValue()}")
|
||||
|
@ -170,6 +170,13 @@ class Program (val name: String,
|
||||
}
|
||||
}
|
||||
}
|
||||
Opcode.INCLUDE_FILE -> {
|
||||
val argparts = args!!.split(' ')
|
||||
val filename = argparts[0]
|
||||
val offset = if(argparts.size>=2 && argparts[1]!="null") getArgValue(argparts[1], heap) else null
|
||||
val length = if(argparts.size>=3 && argparts[2]!="null") getArgValue(argparts[2], heap) else null
|
||||
Instruction(opcode, offset, length, filename)
|
||||
}
|
||||
else -> {
|
||||
Instruction(opcode, getArgValue(args, heap))
|
||||
}
|
||||
|
@ -1836,6 +1836,7 @@ class StackVm(private var traceOutputFile: String?) {
|
||||
Opcode.RSAVEX -> registerSaveX = variables.getValue("X")
|
||||
Opcode.RRESTOREX -> variables["X"] = registerSaveX
|
||||
Opcode.INLINE_ASSEMBLY -> throw VmExecutionException("stackVm doesn't support executing inline assembly code $ins")
|
||||
Opcode.INCLUDE_FILE -> throw VmExecutionException("stackVm doesn't support including a file $ins")
|
||||
Opcode.PUSH_ADDR_HEAPVAR -> {
|
||||
val heapId = variables.getValue(ins.callLabel!!).heapId
|
||||
if(heapId<0)
|
||||
|
@ -123,8 +123,7 @@ Directives
|
||||
This directive can only be used inside a block.
|
||||
The assembler will include the file as binary bytes at this point, prog8 will not process this at all.
|
||||
The optional offset and length can be used to select a particular piece of the file.
|
||||
The compiler first looks for the file relative to the same directory as the module containing this statement is in,
|
||||
if the file can't be found there it is searched relative to the current directory.
|
||||
The file is located relative to the current working directory!
|
||||
|
||||
.. data:: %asminclude "<filename>", "scopelabel"
|
||||
|
||||
|
@ -74,5 +74,4 @@ of values together (and use it multiple times). Something like::
|
||||
Misc
|
||||
^^^^
|
||||
|
||||
- implement %asmbinary
|
||||
- are there any other missing instructions in the code generator?
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
sub start() {
|
||||
|
||||
%asminclude "primes.p8", "derp"
|
||||
%asmbinary "primes.p8", 10, 20
|
||||
%asmbinary "LICENSE", 100, 200
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user