Advertisement
Ham62

CompilerFrontEnd.bas

Feb 1st, 2018
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define fbc -x rbsc.exe
  2. #inclib "Compiler-DLL"
  3. #include "../include/opcode.bi"
  4. Extern "windows-ms"
  5.     Declare Function BuildBinary(sSource as String, iFileSz as integer, pDestination as Opcode ptr) as integer
  6. End Extern
  7.  
  8. Dim as String sSourceFile = lCase(Command)
  9. Dim as String sOutputFile
  10. var sExtension = Right(sSourceFile, 4)
  11. if (sExtension = ".rbs") orElse (sExtension = ".txt") then
  12.     sOutPutFile = left(sSourceFile, Len(sSourceFile)-3)+"rbc" ' Change extension to .rbc
  13. else
  14.     sOutPutFile = sSourceFile+".rbc"
  15. end if
  16.  
  17. if Open (sSourceFile for binary access read as #1) Then
  18.     Print "Error opening source file!"
  19.     System
  20. End If
  21.  
  22. If Open (sOutputFile for binary access write as #2) then
  23.     Print "Error opening output file!"
  24.     System
  25. End If
  26.  
  27. ' Read source into memory
  28. Dim as string sSrcBuff
  29. Dim as integer iFileSz
  30. iFileSz = LOF(1)          ' Get file length
  31. sSrcBuff = Space(iFileSz) ' Read file into string buffer
  32. Get #1,, sSrcBuff
  33. Close #1
  34.  
  35. ' Call compiler to build source
  36. Dim Shared as Opcode Bytecode(65535)
  37. var iTotalInstructions = BuildBinary(sSrcBuff, iFileSz, @Bytecode(0))
  38. Color 7
  39.  
  40. 'Write binary to file
  41. var pBytecode = @Bytecode(0).Opcode
  42. Put #2, 1, *pBytecode, iTotalInstructions * (sizeof(Opcode) / 2)
  43. Close #2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement